Наследование: SqlStatement, IPreparableStatement
Пример #1
0
        public static void SimpleDelete()
        {
            var condition = SqlExpression.GreaterThan(SqlExpression.Reference(new ObjectName("id")), SqlExpression.Constant(22));
            var statement = new DeleteStatement(ObjectName.Parse("t1"), condition);

            var sql      = statement.ToString();
            var expected = "DELETE FROM t1 WHERE id > 22";

            Assert.AreEqual(expected, sql);
        }
Пример #2
0
        public static void SimpleDelete()
        {
            var condition = SqlExpression.GreaterThan(SqlExpression.Reference(new ObjectName("id")), SqlExpression.Constant(22));
            var statement = new DeleteStatement(ObjectName.Parse("t1"), condition);

            var sql = statement.ToString();
            var expected = "DELETE FROM t1 WHERE id > 22";

            Assert.AreEqual(expected, sql);
        }
Пример #3
0
        public static void Limited()
        {
            var condition = SqlExpression.SmallerThan(SqlExpression.Reference(new ObjectName("code")), SqlExpression.Constant(1002));
            var statement = new DeleteStatement(ObjectName.Parse("t1"), condition);
            statement.Limit = 10;

            var sql = statement.ToString();
            var expected = "DELETE FROM t1 WHERE code < 1002 LIMIT 10";

            Assert.AreEqual(expected, sql);
        }
Пример #4
0
        public static void Limited()
        {
            var condition = SqlExpression.SmallerThan(SqlExpression.Reference(new ObjectName("code")), SqlExpression.Constant(1002));
            var statement = new DeleteStatement(ObjectName.Parse("t1"), condition);

            statement.Limit = 10;

            var sql      = statement.ToString();
            var expected = "DELETE FROM t1 WHERE code < 1002 LIMIT 10";

            Assert.AreEqual(expected, sql);
        }
        public void DeleteTwoRows()
        {
            var tableName = ObjectName.Parse("APP.test_table");
            var expr = SqlExpression.Parse("last_name = 'Provenzano'");

            var statement = new DeleteStatement(tableName, expr);

            var result = Query.ExecuteStatement(statement);

            Assert.IsNotNull(result);
            Assert.AreEqual(1, result.RowCount);

            var count = result.GetValue(0, 0).AsBigInt();
            Assert.AreEqual(2L, ((SqlNumber)count.Value).ToInt64());

            var table = Query.GetTable(tableName);

            Assert.AreEqual(0, table.RowCount);
        }
Пример #6
0
        public void DeleteTwoRows()
        {
            var tableName = ObjectName.Parse("APP.test_table");
            var expr      = SqlExpression.Parse("last_name = 'Provenzano'");

            var statement = new DeleteStatement(tableName, expr);

            var result = Query.ExecuteStatement(statement);

            Assert.IsNotNull(result);
            Assert.AreEqual(1, result.RowCount);

            var count = result.GetValue(0, 0).AsBigInt();

            Assert.AreEqual(2L, ((SqlNumber)count.Value).ToInt64());

            var table = Query.GetTable(tableName);

            Assert.AreEqual(0, table.RowCount);
        }
Пример #7
0
        public static SqlStatement Build(PlSqlParser.DeleteStatementContext context)
        {
            var tableName = Name.Object(context.objectName());
            var whereClause = WhereClause.Form(context.whereClause());

            if (whereClause.CurrentOf != null)
                return new DeleteCurrentStatement(tableName, whereClause.CurrentOf);

            var statement = new DeleteStatement(tableName, whereClause.Expression);

            if (context.deleteLimit() != null) {
                var limit = Number.PositiveInteger(context.deleteLimit().numeric());
                if (limit == null)
                    throw new ParseCanceledException("Invalid delete limit.");

                statement.Limit = limit.Value;
            }

            return statement;
        }
Пример #8
0
 protected override SqlStatement VisitDelete(DeleteStatement statement)
 {
     (statement as ISqlFormattable).AppendTo(builder);
     return(base.VisitDelete(statement));
 }
Пример #9
0
 protected virtual SqlStatement VisitDelete(DeleteStatement statement)
 {
     return new DeleteStatement(statement.TableName, statement.WhereExpression, statement.Limit);
 }
Пример #10
0
 protected override SqlStatement VisitDelete(DeleteStatement statement)
 {
     (statement as ISqlFormattable).AppendTo(builder);
     return base.VisitDelete(statement);
 }
Пример #11
0
 protected virtual SqlStatement VisitDelete(DeleteStatement statement)
 {
     return(new DeleteStatement(statement.TableName, statement.WhereExpression, statement.Limit));
 }