internal override void CreateSetUpdatedUpdateFields(DmlfUpdate cmd, string targetEntityAlias, TargetEntitySqlModel targetEntityModel)
 {
     cmd.Columns.Add(new DmlfUpdateField
     {
         TargetColumn = ValidToColumn,
         Expr = SqlScriptCompiler.ImportDateTimeExpression
     });
 }
 internal override void CreateReliveUpdateFields(DmlfUpdate cmd, string targetEntityAlias, TargetEntitySqlModel targetEntityModel)
 {
     if (!String.IsNullOrEmpty(DeletedDateColumn))
     {
         cmd.Columns.Add(new DmlfUpdateField
         {
             TargetColumn = DeletedDateColumn,
             Expr = new DmlfLiteralExpression { Value = null }
         });
     }
     if (!String.IsNullOrEmpty(IsDeletedColumn))
     {
         cmd.Columns.Add(new DmlfUpdateField
         {
             TargetColumn = IsDeletedColumn,
             Expr = new DmlfLiteralExpression { Value = 0 }
         });
     }
 }
Esempio n. 3
0
 internal virtual void CreateSetUpdatedUpdateFields(DmlfUpdate cmd, string targetEntityAlias, TargetEntitySqlModel targetEntityModel)
 {
 }
 internal override void CreateSetDeletedUpdateFields(DmlfUpdate cmd, string targetEntityAlias, TargetEntitySqlModel targetEntityModel)
 {
     if (!String.IsNullOrEmpty(DeletedDateColumn))
     {
         cmd.Columns.Add(new DmlfUpdateField
         {
             TargetColumn = DeletedDateColumn,
             Expr = SqlScriptCompiler.ImportDateTimeExpression
         });
     }
     if (!String.IsNullOrEmpty(IsDeletedColumn))
     {
         cmd.Columns.Add(new DmlfUpdateField
         {
             TargetColumn = IsDeletedColumn,
             Expr = new DmlfLiteralExpression { Value = 1 }
         });
     }
 }
Esempio n. 5
0
        private DmlfUpdate CompileUpdateCore(Func<TargetColumnSqlModelBase, bool> compareColumn, Func<TargetColumnSqlModelBase, bool> updateColumn, Action<DmlfUpdate> createUpdateSpecialColumns, CompareColumnContext compareContext, UpdateColumnContext updateContext)
        {
            var cmd = new DmlfUpdate();
            cmd.UpdateTarget = new DmlfSource { Alias = "target" };
            cmd.From.Add(SourceJoinModel.SourceToRefsJoin);
            cmd.From.Add(new DmlfFromItem
            {
                Source = new DmlfSource
                {
                    Alias = "target",
                    TableOrView = TargetTableSqlName,
                    LinkedInfo = TargetLinkedInfo,
                }
            });
            CreateKeyCondition(cmd, "target");
            CreateLifetimeConditions(cmd, "target");
            CreateFilterConditions(cmd);

            createUpdateSpecialColumns(cmd);

            foreach (var column in TargetColumns)
            {
                bool? update = _dbsh.LifetimeHandler.UpdateColumn(column.Name, updateContext);
                if (update == null) update = updateColumn(column);
                if (!update.Value) continue;
                cmd.Columns.Add(new DmlfUpdateField
                {
                    TargetColumn = column.Name,
                    Expr = column.CreateSourceExpression(SourceJoinModel, false),
                });
            }

            var orCondition = new DmlfOrCondition();
            foreach (var column in TargetColumns)
            {
                bool? compare = _dbsh.LifetimeHandler.CompareColumn(column.Name, compareContext);

                if (compare == null) compare = compareColumn(column);
                if (!compare.Value) continue;
                if (column.CannotBeCompared) continue;

                orCondition.Conditions.Add(new DmlfNotEqualWithNullTestCondition
                {
                    LeftExpr = column.CreateCompareExpression(column.CreateSourceExpression(SourceJoinModel, false)),
                    RightExpr = column.CreateCompareExpression(column.CreateTargetExpression("target")),
                    CollateSpec = column.UseCollate(SourceJoinModel) ? "DATABASE_DEFAULT" : null,
                });
            }
            if (orCondition.Conditions.Any()) cmd.AddAndCondition(orCondition);

            if (!cmd.Columns.Any()) return null;
            return cmd;
        }
Esempio n. 6
0
 private DmlfUpdate CompileMarkDeleted()
 {
     var res = new DmlfUpdate();
     res.UpdateTarget = new DmlfSource { Alias = "target" };
     res.SingleFrom.Source = new DmlfSource
     {
         Alias = "target",
         TableOrView = TargetTableSqlName,
         LinkedInfo = TargetLinkedInfo,
     };
     var existSelect = new DmlfSelect();
     res.AddAndCondition(new DmlfNotExistCondition
     {
         Select = existSelect,
     });
     existSelect.SelectAll = true;
     existSelect.From.Add(SourceJoinModel.SourceToRefsJoin);
     CreateKeyCondition(existSelect, "target");
     CreateRestrictionCondition(res, "target");
     CreateLifetimeConditions(res, "target");
     CreateFilterConditions(existSelect);
     _dbsh.LifetimeHandler.CreateSetDeletedUpdateFields(res, "target", this);
     return res;
 }
Esempio n. 7
0
 private DmlfUpdate CompileMarkRelived()
 {
     var res = new DmlfUpdate();
     res.UpdateTarget = new DmlfSource { Alias = "target" };
     res.From.Add(SourceJoinModel.SourceToRefsJoin);
     res.From.Add(new DmlfFromItem
     {
         Source = new DmlfSource
         {
             Alias = "target",
             TableOrView = TargetTableSqlName,
             LinkedInfo = TargetLinkedInfo,
         }
     });
     CreateKeyCondition(res, "target");
     CreateFilterConditions(res);
     _dbsh.LifetimeHandler.CreateReliveConditions(res, "target", this);
     _dbsh.LifetimeHandler.CreateReliveUpdateFields(res, "target", this);
     return res;
 }
Esempio n. 8
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);
                }
            }
        }