Ejemplo n.º 1
0
        /// <summary>
        /// Deletes rows from a table using a variable list of and-connected where
        /// conditions. Fields identified using the 'parameters' collection need not
        /// be part of the primary key.
        /// </summary>
        public static commandprimitive delete_wildcard(Iddl db, string targettable, deletecommandparameters parameters)
        {
            expressionlist expressions = new expressionlist();
            /* build the where clause */
            bool bneedand = false;

            foreach (deletecommandparameter parm in parameters)
            {
                if (bneedand)
                {
                    expressions.Add(where_and);
                }
                if (parm.size.HasValue)
                {
                    expressions.Add(where_fld_eq_p(parm.fieldname, parm.paramname, parm.paramtype, parm.size.Value));
                }
                else
                {
                    expressions.Add(where_fld_eq_p(parm.fieldname, parm.paramname, parm.paramtype));
                }
                bneedand = true;
            }
            if (expressions.Count <= 0)
            {
                throw new ArgumentOutOfRangeException("parameters", "Cannot execute a delete_wildcard statement without specifying any restrictions.");
            }
            /* compose the final statement */
            deletestatement del = new deletestatement(
                targettable,
                new whereclause(expressions)
                );

            return(new commandadhoc(db, del));
        }
Ejemplo n.º 2
0
        protected override bool CompileDelete()
        {
            deletestatement st = stmt as deletestatement;

            RegisterDeleteRowsourceQualifierAliases(st);
            /* 1. get the header part */
            s = new StringBuilder();
            string tableliteral;

            if (!GetSubquery(st.TargetTable, true, out tableliteral))
            {
                throw new InvalidOperationException();
            }
            /* [dlatikay 20110323] syntax is "delete x from table x where" */
            string alias_if_needed = String.Empty;

            if (!String.IsNullOrWhiteSpace(st.TargetTable.Alias))
            {
                alias_if_needed = st.TargetTable.Alias + " ";
            }
            /* render the statement */
            s.AppendLine(sindent + String.Format("DELETE {0}FROM {1}", alias_if_needed, tableliteral.Trim()));
            /* 2. render the where clause */
            if (st.Where != null)
            {
                AppendWhereClause(s, st.Where);
            }
            return(true);
        }
Ejemplo n.º 3
0
        protected override bool CompileDelete()
        {
            deletestatement st = stmt as deletestatement;

            /* 1. get the header part */
            s = new StringBuilder();
            string tableliteral;

            if (!GetSubquery(st.TargetTable, true, out tableliteral))
            {
                throw new InvalidOperationException();
            }
            s.AppendLine(sindent + String.Format("DELETE * FROM {0}", tableliteral.Trim()));
            /* 2. render the where clause */
            if (st.Where != null)
            {
                AppendWhereClause(s, st.Where);
            }
            return(true);
        }