Ejemplo n.º 1
0
        public void GetCommands(DmlfBatch res, DatabaseInfo db, IDialectDataAdapter dda, ICdlValueConvertor converter)
        {
            var cmd = new DmlfInsert();
            cmd.InsertTarget = TargetTable;

            var table = db.FindTable(TargetTable);
            if (table == null) return;

            var autoinc = table.FindAutoIncrementColumn();
            bool isAutoInc = autoinc != null && Values.Any(x => x.Column == autoinc.Name);

            GetValues(cmd.Columns, Values, table, dda, converter);

            if (isAutoInc)
            {
                res.AllowIdentityInsert(table.FullName, true);
            }

            res.Commands.Add(cmd);

            if (isAutoInc)
            {
                res.AllowIdentityInsert(table.FullName, false);
            }
        }
Ejemplo n.º 2
0
        public void GetInsertCommands(DmlfBatch res, DatabaseInfo db, ChangeSetModel model, IDialectDataAdapter dda, ICdlValueConvertor converter)
        {
            var table = db.FindTable(TargetTable);
            if (table == null) return;

            if (IsDuplicatingIdentity(db, model))
            {
                res.AllowIdentityInsert(table.FullName, true);
                var insert = new DmlfInsertSelect
                    {
                        TargetTable = table.FullName,
                    };
                insert.Select = new DmlfSelect();
                insert.Select.SingleFrom = new DmlfFromItem
                    {
                        Source = new DmlfSource
                            {
                                TableOrView = table.FullName,
                                Alias = "basetbl",
                            }
                    };

                GetConditions(insert.Select, this, Conditions, db);

                foreach (var col in table.Columns)
                {
                    var valcol = Values.FirstOrDefault(x => x.Column == col.Name);
                    insert.TargetColumns.Add(col.Name);
                    if (valcol == null)
                    {
                        insert.Select.Columns.Add(DmlfResultField.BuildFromColumn(col.Name, insert.Select.SingleFrom.Source));
                    }
                    else
                    {
                        insert.Select.Columns.Add(new DmlfResultField
                            {
                                Expr = new DmlfLiteralExpression
                                    {
                                        Value = valcol.Value,
                                    }
                            });
                    }
                }
                res.Commands.Add(insert);
                res.AllowIdentityInsert(table.FullName, false);
            }
        }