Inheritance: LoopStatement
Beispiel #1
0
        protected virtual SqlStatement VisitWhileLoop(WhileLoopStatement statement)
        {
            var loop = new WhileLoopStatement(statement.ConditionExpression);

            foreach (var child in statement.Statements)
            {
                loop.Statements.Add(VisitStatement(child));
            }

            return(loop);
        }
Beispiel #2
0
        public void SerializeSimpleLoop()
        {
            var loop = new WhileLoopStatement(SqlExpression.Constant(SqlObject.Boolean(true)));

            loop.Statements.Add(new ExitStatement());

            var result = BinarySerializeUtil.Serialize(loop);

            Assert.NotNull(result);
            Assert.NotNull(result.Condition);
            Assert.IsType <SqlConstantExpression>(result.Condition);
        }
Beispiel #3
0
        public async void WhileTrueExit()
        {
            var loop = new WhileLoopStatement(SqlExpression.Constant(SqlObject.Boolean(true)));

            loop.Statements.Add(new ExitStatement());

            var statement = loop.Prepare(context);

            var result = await statement.ExecuteAsync(context);

            Assert.Null(result);
        }
Beispiel #4
0
        public void GetStringWithoutLabel()
        {
            var loop = new WhileLoopStatement(SqlExpression.Constant(SqlObject.Boolean(true)));

            loop.Statements.Add(new ExitStatement());

            var sql = new StringBuilder();

            sql.AppendLine("WHILE TRUE");
            sql.AppendLine("LOOP");
            sql.AppendLine("  EXIT;");
            sql.Append("END LOOP;");

            Assert.Equal(sql.ToString(), loop.ToString());
        }
        public static void WhileLoop()
        {
            var loop = new WhileLoopStatement(SqlExpression.Constant(true));
            loop.Statements.Add(new CallStatement(ObjectName.Parse("SYSTEM.print"), new SqlExpression[] {
                SqlExpression.Constant("iterated")
            }));

            var sql = loop.ToString();
            var expected = new StringBuilder();
            expected.AppendLine("WHILE TRUE");
            expected.AppendLine("LOOP");
            expected.AppendLine("  CALL SYSTEM.print('iterated')");
            expected.Append("END LOOP");

            Assert.AreEqual(expected.ToString(), sql);
        }
        public static void WhileLoop()
        {
            var loop = new WhileLoopStatement(SqlExpression.Constant(true));

            loop.Statements.Add(new CallStatement(ObjectName.Parse("SYSTEM.print"), new SqlExpression[] {
                SqlExpression.Constant("iterated")
            }));

            var sql      = loop.ToString();
            var expected = new StringBuilder();

            expected.AppendLine("WHILE TRUE");
            expected.AppendLine("LOOP");
            expected.AppendLine("  CALL SYSTEM.print('iterated')");
            expected.Append("END LOOP");

            Assert.AreEqual(expected.ToString(), sql);
        }
Beispiel #7
0
        protected virtual SqlStatement VisitWhileLoop(WhileLoopStatement statement)
        {
            var loop = new WhileLoopStatement(statement.ConditionExpression);

            foreach (var child in statement.Statements) {
                loop.Statements.Add(VisitStatement(child));
            }

            return loop;
        }
Beispiel #8
0
        public void WhileLoop()
        {
            var loop = new WhileLoopStatement(SqlExpression.SmallerThan(SqlExpression.VariableReference("a"), SqlExpression.Constant(33)));
            loop.Statements.Add(new DeclareVariableStatement("b", PrimitiveTypes.Integer()));
            loop.Statements.Add(new AssignVariableStatement(SqlExpression.VariableReference("b"),
                SqlExpression.Add(SqlExpression.VariableReference("a"), SqlExpression.Constant(40))));
            loop.Statements.Add(new AssignVariableStatement(SqlExpression.VariableReference("a"),
                SqlExpression.Add(SqlExpression.VariableReference("a"), SqlExpression.Constant(1))));

            var block = new PlSqlBlockStatement();
            block.Declarations.Add(new DeclareVariableStatement("a", PrimitiveTypes.Integer()));

            var result = AdminQuery.ExecuteStatement(block);

            Assert.IsNotNull(result);
            Assert.AreEqual(StatementResultType.Result, result.Type);

            var value = result.Result.GetValue(0, 0);
            Assert.IsNotNull(value);
            Assert.IsFalse(Field.IsNullField(value));
        }
        public void WhileLoop()
        {
            var whileLoop =
                new WhileLoopStatement(SqlExpression.SmallerOrEqualThan(SqlExpression.VariableReference("a"),
                    SqlExpression.Constant(20)));
            whileLoop.Statements.Add(new ExitStatement());

            SerializeAndAssert(whileLoop, (serialized, deserialized) => {
                Assert.IsNotNull(deserialized);
                Assert.IsNotNull(deserialized.ConditionExpression);
                Assert.IsNotNull(deserialized.Statements);
                Assert.IsNotEmpty(deserialized.Statements);
            });
        }