Пример #1
0
        public int Update()
        {
            _updater.Where.Conditions = _where;
            var n = _ctx.Provider.ExecuteNonQuery(_updater.ToSqlStatement(_ctx));

            return(n);
        }
        public override SqlStatement GetUpdateStatement(object obj, Condition iwc)
        {
            var sb = new UpdateStatementBuilder(Context.Info.From);

            Context.Handler.SetValuesForUpdate(sb, obj);
            var lv = (int)Context.Info.LockVersion.GetValue(obj);

            sb.Where.Conditions = iwc && (CK.K[Context.Info.LockVersion.Name] == lv);
            bool find = false;

            foreach (var kv in sb.Values)
            {
                if (kv.Key == Context.Info.LockVersion.Name)
                {
                    kv.Value = lv + 1;
                    find     = true;
                    break;
                }
            }
            if (!find)
            {
                sb.Values.Add(new KeyOpValue(Context.Info.LockVersion.Name, lv + 1, KvOpertation.None));
            }
            return(sb.ToSqlStatement(Context));
        }
Пример #3
0
        public override SqlStatement GetDeleteStatement(Condition iwc)
        {
            var sb = new UpdateStatementBuilder(Context.Info.From);

            sb.Values.Add(new KeyOpValue(_columnName, true, KvOpertation.None));
            sb.Where.Conditions = iwc && _colExp;
            return(sb.ToSqlStatement(Context));
        }
Пример #4
0
        public virtual SqlStatement GetUpdateStatement(object obj, Condition iwc)
        {
            var isv = new UpdateStatementBuilder(this.Context.Info.From);

            this.Context.Handler.SetValuesForUpdate(isv, obj);
            isv.Where.Conditions = iwc;
            return(isv.ToSqlStatement(this.Context));
        }
Пример #5
0
        public void TestUpdatedOn()
        {
            var dc = new DataProvider("SQLite");
            var sb = new UpdateStatementBuilder(new FromClause("user"));

            sb.Values.Add(new KeyOpValue("UpdatedOn", null, KvOpertation.Now));
            SqlStatement sql = sb.ToSqlStatement(dc.Dialect, null);

            Assert.AreEqual("UPDATE [user] SET [UpdatedOn]=DATETIME(CURRENT_TIMESTAMP, 'localtime') ;\n", sql.SqlCommandText);
        }
Пример #6
0
 public override void AddColumn(ModelContext ctx, string columnName, object o)
 {
     base.AddColumn(ctx, columnName, null);
     if (o != null)
     {
         var stm = new UpdateStatementBuilder(ctx.Info.From);
         stm.Values.Add(new KeyOpValue(columnName, o, KvOpertation.None));
         var sql = stm.ToSqlStatement(ctx);
         ctx.Provider.ExecuteNonQuery(sql);
     }
 }
Пример #7
0
        public virtual SqlStatement GetUpdateStatement(Condition iwc, object obj)
        {
            var isv = new UpdateStatementBuilder(this.Context.Info.From);

            foreach (var property in obj.GetType().GetProperties())
            {
                isv.Values.Add(new KeyOpValue(property.Name, property.GetValue(obj, null), KvOpertation.None));
            }
            isv.Where.Conditions = iwc;
            return(isv.ToSqlStatement(this.Context));
        }
Пример #8
0
        public virtual SqlStatement GetUpdateStatement(object obj, Condition iwc)
        {
            var isv = new UpdateStatementBuilder(this.Context.Info.From);
            var o   = obj as DbObjectSmartUpdate;

            if (o != null)
            {
                if (!o.FindUpdateColumns(isv))
                {
                    return(null);
                }
            }
            else
            {
                this.Context.Handler.SetValuesForUpdate(isv, obj);
            }
            isv.Where.Conditions = iwc;
            return(isv.ToSqlStatement(this.Context));
        }
Пример #9
0
        private int ProcessHasManyAndHasOne(IDbObject obj)
        {
            var result = 0;

            foreach (var member in Info.RelationMembers)
            {
                if (member.Is.HasMany || member.Is.HasOne)
                {
                    var t    = member.MemberInfo.MemberType.GetGenericArguments()[0];
                    var ctx0 = ModelContext.GetInstance(t);
                    ctx0.Operator.Fixer.TryFix();
                    var sb  = new UpdateStatementBuilder(ctx0.Info.From);
                    var key = ctx0.Info.GetBelongsTo(Info.HandleType).Name;
                    sb.Values.Add(new KeyOpValue(key, null, KvOpertation.None));
                    sb.Where.Conditions = CK.K[key] == Handler.GetKeyValue(obj);
                    var sql = sb.ToSqlStatement(ctx0);
                    result += ctx0.Provider.ExecuteNonQuery(sql);
                }
            }
            return(result);
        }