Exemplo n.º 1
0
        public void GetDeleteCommands(DmlfBatch res, DatabaseInfo db, ChangeSetModel model)
        {
            var table = db.FindTable(TargetTable);

            if (table == null)
            {
                return;
            }

            if (IsDuplicatingIdentity(db, model))
            {
                var del = new DmlfDelete();
                del.DeleteTarget = new DmlfSource
                {
                    TableOrView = table.FullName,
                    Alias       = "basetbl",
                };
                del.SingleFrom = new DmlfFromItem
                {
                    Source = del.DeleteTarget
                };
                GetConditions(del, this, Conditions, db);

                res.Commands.Add(del);
            }
        }
Exemplo n.º 2
0
        public void GetCommands(DmlfBatch res, DatabaseInfo db, ChangeSetModel model, bool allowCascade = true)
        {
            if (allowCascade && (DeleteReferencesCascade || model.DeleteReferencesCascade))
            {
                var refs = GenerateCascadeDeletions(db);
                foreach (var item in refs)
                {
                    item.GetCommands(res, db, model, false);
                }
            }

            if (model.DeleteReferencesCascade && model.DeleteSkipList != null && model.DeleteSkipList.Contains(TargetTable))
            {
                return;
            }
            var cmd = new DmlfDelete();

            cmd.DeleteTarget = new DmlfSource
            {
                TableOrView = TargetTable,
                LinkedInfo  = LinkedInfo,
                Alias       = "basetbl",
            };
            cmd.From.Add(new DmlfFromItem
            {
                Source = cmd.DeleteTarget,
            });
            if (!GetConditions(cmd, this, Conditions, db))
            {
                return;
            }
            res.Commands.Add(cmd);
        }
Exemplo n.º 3
0
 public bool IsDuplicatingIdentity(DatabaseInfo db, ChangeSetModel model)
 {
     if (!UpdateReferences && !model.UpdateReferences) return false;
     if (!IsUpdatingPk(db)) return false;
     var table = db.FindTable(TargetTable);
     if (table == null) return false;
     var autoinc = table.FindAutoIncrementColumn();
     return autoinc != null && Values.Any(x => x.Column == autoinc.Name);
 }
Exemplo n.º 4
0
        public static ChangeSetModel LoadFromFile(string fileName)
        {
            var doc = new XmlDocument();

            doc.LoadXml(File.ReadAllText(fileName));
            var res = new ChangeSetModel();

            res.LoadProperties(doc.DocumentElement);
            return(res);
        }
Exemplo n.º 5
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);
            }
        }
Exemplo n.º 6
0
        public bool IsDuplicatingIdentity(DatabaseInfo db, ChangeSetModel model)
        {
            if (!UpdateReferences && !model.UpdateReferences)
            {
                return(false);
            }
            if (!IsUpdatingPk(db))
            {
                return(false);
            }
            var table = db.FindTable(TargetTable);

            if (table == null)
            {
                return(false);
            }
            var autoinc = table.FindAutoIncrementColumn();

            return(autoinc != null && Values.Any(x => x.Column == autoinc.Name));
        }
Exemplo n.º 7
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);
                }
            }
        }
Exemplo n.º 8
0
        public void GetCommands(DmlfBatch res, DatabaseInfo db, ChangeSetModel model, bool allowCascade = true)
        {
            if (allowCascade && (DeleteReferencesCascade || model.DeleteReferencesCascade))
            {
                var refs = GenerateCascadeDeletions(db);
                foreach (var item in refs)
                {
                    item.GetCommands(res, db, model, false);
                }
            }

            if (model.DeleteReferencesCascade && model.DeleteSkipList != null && model.DeleteSkipList.Contains(TargetTable)) return;
            var cmd = new DmlfDelete();
            cmd.DeleteTarget = new DmlfSource
            {
                TableOrView = TargetTable,
                LinkedInfo = LinkedInfo,
                Alias = "basetbl",
            };
            cmd.From.Add(new DmlfFromItem
            {
                Source = cmd.DeleteTarget,
            });
            if (!GetConditions(cmd, this, Conditions, db)) return;
            res.Commands.Add(cmd);
        }
Exemplo n.º 9
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);
            }
        }
Exemplo n.º 10
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);
                }
            }
        }
Exemplo n.º 11
0
        public void GetDeleteCommands(DmlfBatch res, DatabaseInfo db, ChangeSetModel model)
        {
            var table = db.FindTable(TargetTable);
            if (table == null) return;

            if (IsDuplicatingIdentity(db, model))
            {
                var del = new DmlfDelete();
                del.DeleteTarget = new DmlfSource
                    {
                        TableOrView = table.FullName,
                        Alias = "basetbl",
                    };
                del.SingleFrom = new DmlfFromItem
                    {
                        Source = del.DeleteTarget
                    };
                GetConditions(del, this, Conditions, db);

                res.Commands.Add(del);
            }
        }
Exemplo n.º 12
0
 public static ChangeSetModel LoadFromFile(string fileName)
 {
     var doc = new XmlDocument();
     doc.LoadXml(File.ReadAllText(fileName));
     var res = new ChangeSetModel();
     res.LoadProperties(doc.DocumentElement);
     return res;
 }