Inheritance: SqlStatement, IPreparableStatement
Exemplo n.º 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);
        }
Exemplo n.º 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);
        }
Exemplo n.º 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);
        }
Exemplo n.º 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);
        }
Exemplo n.º 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);
        }
Exemplo n.º 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;
        }
Exemplo n.º 8
0
 protected override SqlStatement VisitDelete(DeleteStatement statement)
 {
     (statement as ISqlFormattable).AppendTo(builder);
     return(base.VisitDelete(statement));
 }
Exemplo n.º 9
0
 protected virtual SqlStatement VisitDelete(DeleteStatement statement)
 {
     return new DeleteStatement(statement.TableName, statement.WhereExpression, statement.Limit);
 }
Exemplo n.º 10
0
 protected override SqlStatement VisitDelete(DeleteStatement statement)
 {
     (statement as ISqlFormattable).AppendTo(builder);
     return base.VisitDelete(statement);
 }
Exemplo n.º 11
0
 protected virtual SqlStatement VisitDelete(DeleteStatement statement)
 {
     return(new DeleteStatement(statement.TableName, statement.WhereExpression, statement.Limit));
 }