Esempio 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);
            }
        }
Esempio n. 2
0
 public void AdaptValue(ICdlValueReader reader, DbTypeBase type, ICdlValueWriter writer, ICdlValueConvertor converter)
 {
     if (reader.GetFieldType() == TypeStorage.Null)
     {
         m_holder.SetNull();
     }
     else
     {
         ConvertNotNullValue(reader, type, m_holder, converter);
         ApplyTypeRestrictions(m_holder, type);
     }
     writer.ReadFrom(m_holder);
 }
Esempio n. 3
0
 protected static void GetValues(DmlfUpdateFieldCollection fields, List<ChangeSetValue> values, TableInfo table, IDialectDataAdapter dda, ICdlValueConvertor converter)
 {
     var input = new CdlValueHolder();
     var output = new CdlValueHolder();
     foreach (var col in values)
     {
         var colinfo = table.FindColumn(col.Column);
         if (colinfo == null) continue;
         input.ReadFrom(col.Value);
         dda.AdaptValue(input, colinfo.CommonType, output, converter);
         fields.Add(new DmlfUpdateField
             {
                 TargetColumn = colinfo.Name,
                 Expr = new DmlfLiteralExpression
                     {
                         Value = output.GetValue(),
                     }
             });
     }
 }
Esempio n. 4
0
 protected virtual void ConvertNotNullValue(ICdlValueReader reader, DbTypeBase type, CdlValueHolder valueHolder, ICdlValueConvertor converter)
 {
     converter.ConvertValue(reader, type.DefaultStorage, valueHolder);
 }
Esempio n. 5
0
 public void AdaptValue(ICdlValueReader reader, DbTypeBase type, ICdlValueWriter writer, ICdlValueConvertor converter)
 {
     if (reader.GetFieldType() == TypeStorage.Null)
     {
         m_holder.SetNull();
     }
     else
     {
         ConvertNotNullValue(reader, type, m_holder, converter);
         ApplyTypeRestrictions(m_holder, type);
     }
     writer.ReadFrom(m_holder);
 }
Esempio n. 6
0
 public RecordToDbAdapter(TargetColumnMap columnMap, IDatabaseFactory targetFactory, DataFormatSettings formatSettings)
 {
     _columnMap = columnMap;
     _dda = targetFactory.CreateDataAdapter();
     _outputConv = new CdlValueConvertor(formatSettings);
 }
Esempio n. 7
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);
            }
        }
Esempio n. 8
0
        protected static void GetValues(DmlfUpdateFieldCollection fields, List <ChangeSetValue> values, TableInfo table, IDialectDataAdapter dda, ICdlValueConvertor converter)
        {
            var input  = new CdlValueHolder();
            var output = new CdlValueHolder();

            foreach (var col in values)
            {
                var colinfo = table.FindColumn(col.Column);
                if (colinfo == null)
                {
                    continue;
                }
                input.ReadFrom(col.Value);
                dda.AdaptValue(input, colinfo.CommonType, output, converter);
                fields.Add(new DmlfUpdateField
                {
                    TargetColumn = colinfo.Name,
                    Expr         = new DmlfLiteralExpression
                    {
                        Value = output.GetValue(),
                    }
                });
            }
        }
Esempio n. 9
0
        public void GetCommands(DmlfBatch res, DatabaseInfo db, ChangeSetModel model, IDialectDataAdapter dda, ICdlValueConvertor converter)
        {
            var table = db.FindTable(TargetTable);

            if (table == null)
            {
                return;
            }

            if ((UpdateReferences || model.UpdateReferences) && IsUpdatingPk(db))
            {
                var refs = GenerateCascadeUpdates(db);
                foreach (var item in refs)
                {
                    item.GetCommands(res, db, model, dda, converter);
                }
            }

            if (!IsDuplicatingIdentity(db, model))
            {
                var cmd = new DmlfUpdate();
                cmd.UpdateTarget = new DmlfSource
                {
                    TableOrView = TargetTable,
                    LinkedInfo  = LinkedInfo,
                    Alias       = "basetbl",
                };
                cmd.From.Add(new DmlfFromItem
                {
                    Source = cmd.UpdateTarget,
                });
                if (GetConditions(cmd, this, Conditions, db))
                {
                    GetValues(cmd.Columns, Values, table, dda, converter);
                    res.Commands.Add(cmd);
                }
            }
        }
Esempio n. 10
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);
            }
        }
Esempio n. 11
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);
            }
        }
Esempio n. 12
0
        public void GetCommands(DmlfBatch res, DatabaseInfo db, ChangeSetModel model, IDialectDataAdapter dda, ICdlValueConvertor converter)
        {
            var table = db.FindTable(TargetTable);
            if (table == null) return;

            if ((UpdateReferences || model.UpdateReferences) && IsUpdatingPk(db))
            {
                var refs = GenerateCascadeUpdates(db);
                foreach (var item in refs)
                {
                    item.GetCommands(res, db, model, dda, converter);
                }
            }

            if (!IsDuplicatingIdentity(db, model))
            {
                var cmd = new DmlfUpdate();
                cmd.UpdateTarget = new DmlfSource
                    {
                        TableOrView = TargetTable,
                        LinkedInfo = LinkedInfo,
                        Alias = "basetbl",
                    };
                cmd.From.Add(new DmlfFromItem
                    {
                        Source = cmd.UpdateTarget,
                    });
                if (GetConditions(cmd, this, Conditions, db))
                {
                    GetValues(cmd.Columns, Values, table, dda, converter);
                    res.Commands.Add(cmd);
                }
            }
        }
Esempio n. 13
0
 protected virtual void ConvertNotNullValue(ICdlValueReader reader, DbTypeBase type, CdlValueHolder valueHolder, ICdlValueConvertor converter)
 {
     converter.ConvertValue(reader, type.DefaultStorage, valueHolder);
 }
Esempio n. 14
0
 public RecordToDbAdapter(TargetColumnMap columnMap, IDatabaseFactory targetFactory, DataFormatSettings formatSettings)
 {
     _columnMap  = columnMap;
     _dda        = targetFactory.CreateDataAdapter();
     _outputConv = new CdlValueConvertor(formatSettings);
 }