Ejemplo n.º 1
0
        public int Delete()
        {
            var deleter = new DeleteStatementBuilder(_ctx.Info.From.MainTableName);

            deleter.Where.Conditions = _where;
            return(_ctx.Provider.ExecuteNonQuery(deleter.ToSqlStatement(_ctx)));
        }
Ejemplo n.º 2
0
        public void TestDeleteSentenceBuilder1()
        {
            var          dsb = new DeleteStatementBuilder("UserTable");
            const string s   = "DELETE FROM [UserTable];";

            TesterHelper.AssertSqlSentenceEqual(dsb.ToSqlStatement(dd, null).SqlCommandText, s);
        }
Ejemplo n.º 3
0
        public virtual SqlStatement GetDeleteStatement(object obj)
        {
            var builder = new DeleteStatementBuilder(this.Context.Info.From.MainTableName);

            builder.Where.Conditions = ModelContext.GetKeyWhereClause(obj);
            return(builder.ToSqlStatement(this.Context));
        }
Ejemplo n.º 4
0
        public virtual SqlStatement GetDeleteStatement(Condition iwc)
        {
            var builder = new DeleteStatementBuilder(this.Context.Info.From.MainTableName);

            builder.Where.Conditions = iwc;
            return(builder.ToSqlStatement(this.Context));
        }
Ejemplo n.º 5
0
        public void TestDeleteSentenceBuilder2()
        {
            var dsb = new DeleteStatementBuilder("UserTable");

            dsb.Where.Conditions = new OrClause("ID", 3, 1);
            const string Exp = "DELETE FROM [UserTable] WHERE ([ID] = @ID_0) OR ([ID] = @ID_1);\n<Text><30>(@ID_0=3:Int32,@ID_1=1:Int32)";

            TesterHelper.AssertSqlSentenceEqual(Exp, dsb.ToSqlStatement(dd, null).ToString());
        }
Ejemplo n.º 6
0
 private void RemoveManyToManyRelation(Type t, object key1, object key2)
 {
     if ((Info.CrossTables.ContainsKey(t) && (key1 != null)) && (key2 != null))
     {
         CrossTable table     = Info.CrossTables[t];
         var        builder   = new DeleteStatementBuilder(table.Name);
         var        condition = (Condition)(CK.K[table[0].Column] == key1);
         condition &= CK.K[table[1].Column] == key2;
         builder.Where.Conditions = condition;
         var sql = builder.ToSqlStatement(Provider.Dialect, Info.QueryRequiredFields, Info.AllowSqlLog);
         Provider.ExecuteNonQuery(sql);
     }
 }
Ejemplo n.º 7
0
        private int ProcessHasAndBelongsToMany(IDbObject obj)
        {
            int ret = 0;

            foreach (CrossTable mt in Info.CrossTables.Values)
            {
                var sb = new DeleteStatementBuilder(mt.Name);
                sb.Where.Conditions = CK.K[mt[0].Column] == Handler.GetKeyValue(obj);
                var sql = sb.ToSqlStatement(Provider.Dialect, Info.QueryRequiredFields, Info.AllowSqlLog);
                ret += Provider.ExecuteNonQuery(sql);
            }
            return(ret);
        }
Ejemplo n.º 8
0
        public IRelationalCommand Build <TEntity>(SqlStatementKind statementKind, IEntityModel model, TEntity entity, IEntityMapping entityMapping)
        {
            switch (statementKind)
            {
            case SqlStatementKind.CreateTable:

                ISqlStatementBuilder <CreateTableStatement> statementBuilder = new CreateTableStatementBuilder(model, entityMapping);

                ISqlStatement statement = statementBuilder.BuildStatement();

                return(new RelationalCommand(statement.GetText(), null));

            case SqlStatementKind.Insert:

                ISqlStatementBuilder <InsertStatement> insertStatementBuilder = new InsertStatementBuilder(entity, entityMapping);
                InsertStatement insertStatement = insertStatementBuilder.BuildStatement();

                return(new RelationalCommand(insertStatement.GetText(), insertStatement.Parameters));

            case SqlStatementKind.Update:

                ISqlStatementBuilder <UpdateStatement> updateStatementBuilder = new UpdateStatementBuilder(entity, entityMapping);
                UpdateStatement updateStatement = updateStatementBuilder.BuildStatement();

                return(new RelationalCommand(updateStatement.GetText(), updateStatement.Parameters));

            case SqlStatementKind.Delete:

                ISqlStatementBuilder <DeleteStatement> deleteStatementBuilder = new DeleteStatementBuilder(entity, entityMapping);
                DeleteStatement deleteStatement = deleteStatementBuilder.BuildStatement();

                return(new RelationalCommand(deleteStatement.GetText(), deleteStatement.Parameters));

            default:

                throw new NotImplementedException();
            }
        }
Ejemplo n.º 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);
                    //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 sb  = new DeleteStatementBuilder(ctx0.Info.From.MainTableName);
                    var key = ctx0.Info.GetBelongsTo(Info.HandleType).Name;
                    sb.Where.Conditions = CK.K[key] == Handler.GetKeyValue(obj);
                    var sql = sb.ToSqlStatement(ctx0);
                    result += ctx0.Provider.ExecuteNonQuery(sql);
                }
            }
            return(result);
        }
Ejemplo n.º 10
0
 public void TestInitialize()
 {
     deleteStatementBuilder = new DeleteStatementBuilder();
 }