Exemplo n.º 1
0
        public override string GetSyntax()
        {
            /*
             *  insert into [target_schema].[target_table] (col1, col2,...)
             *      select
             *          col1 = [tbl].col,
             *          col2 = [tbl].col ...
             *      from [schema].[table] [tbl]
             *          joins...
             *      where
             *          <policy>
             */

            if (TargetTable == null)
            {
                return("");
            }

            var sql_insert = string.Format("insert into {0} ({1})", TargetTable.FullName, string.Join(", ", ColumnsValues.Select(cv => cv.TargetColumn.FullName).ToList()));

            sql_insert += "\r\nselect" + string.Join(",\r\n\t", ColumnsValues.Select(cv => cv.ToString()).ToList());
            //sql_insert += "\r\nfrom " + Table.FullName + " [tbl]";

            //joins
            sql_insert += WherePolicy == null ? "" : WherePolicy.GetQuery(false, true);

            //where key
            sql_insert += (WherePolicy == null ? "\r\nwhere" : "") + " [tbl].[" + Table.PrimaryKey.Columns.First().Name + "] = @pk_value";

            //where
            //if (WherePolicy != null)
            //    sql_insert += "\r\nAND\r\n" + WherePolicy.WhereExpression;

            return(sql_insert);
        }
Exemplo n.º 2
0
        public override string GetSyntax()
        {
            /*
             *  delete  [target_schema].[target_table]
             *      from [schema].[table] [tbl]
             *          joins...
             *      where
             *          <policy>
             */

            var sql_delete = string.Format("delete from {0}", TargetTable.FullName);

            //joins
            sql_delete += WherePolicy == null ? "" : WherePolicy.GetQuery(false, true);

            //where key
            sql_delete += (WherePolicy == null ? "\r\nwhere" : "") + " [tbl].[" + Table.PrimaryKey.Columns.First().Name + "] = @pk_value";

            //where
            //if (WherePolicy != null)
            //    sql_insert += "\r\nAND\r\n" + WherePolicy.WhereExpression;

            return(sql_delete);
        }