Inheritance: LoopStatement
Esempio n. 1
0
        private SqlStatement VisitForLoop(ForLoopStatement statement)
        {
            var loop = new ForLoopStatement(statement.IndexName, statement.LowerBound, statement.UpperBound);

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

            return(loop);
        }
Esempio n. 2
0
        protected override SqlStatement PrepareStatement(IContext context)
        {
            var statement = new ForLoopStatement(IndexName, LowerBound, UpperBound, Reverse);

            foreach (var child in Statements)
            {
                var prepared = child.Prepare(context);
                statement.Statements.Add(prepared);
            }

            return(statement);
        }
Esempio n. 3
0
        public async void ForwardForLoop()
        {
            var loop = new ForLoopStatement("i",
                                            SqlExpression.Constant(SqlObject.BigInt(0)),
                                            SqlExpression.Constant(SqlObject.BigInt(5)));

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

            var statement = loop.Prepare(context);
            var result    = await statement.ExecuteAsync(context);

            Assert.Null(result);
        }
Esempio n. 4
0
        protected override SqlStatement PrepareExpressions(ISqlExpressionPreparer preparer)
        {
            var lower = LowerBound.Prepare(preparer);
            var upper = UpperBound.Prepare(preparer);

            var loop = new ForLoopStatement(IndexName, lower, upper, Reverse);

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

            return(loop);
        }
Esempio n. 5
0
        public void SerializeForLoop()
        {
            var loop = new ForLoopStatement("i",
                                            SqlExpression.Constant(SqlObject.BigInt(0)),
                                            SqlExpression.Constant(SqlObject.BigInt(5)),
                                            true);

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

            var result = BinarySerializeUtil.Serialize(loop);

            Assert.NotNull(result);
            Assert.NotNull(result.LowerBound);
            Assert.NotNull(result.UpperBound);
        }
Esempio n. 6
0
        public void GetStringWithoutLabel()
        {
            var loop = new ForLoopStatement("i",
                                            SqlExpression.Constant(SqlObject.BigInt(0)),
                                            SqlExpression.Constant(SqlObject.BigInt(5)),
                                            true);

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

            var sql = new StringBuilder();

            sql.AppendLine("FOR i IN 0..5");
            sql.AppendLine("LOOP");
            sql.AppendLine("  CONTINUE;");
            sql.Append("END LOOP;");

            Assert.Equal(sql.ToString(), loop.ToString());
        }
Esempio n. 7
0
        public static void ForLoopGoto()
        {
            var loop = new ForLoopStatement("i", SqlExpression.Constant(0), SqlExpression.Reference(new ObjectName("x")));
            loop.Statements.Add(new ConditionStatement(SqlExpression.Equal(SqlExpression.VariableReference("i"), SqlExpression.Constant(3)), new SqlStatement[] {
                new GoToStatement("lbl_3")
            }));

            var sql = loop.ToString();
            var expected = new StringBuilder();
            expected.AppendLine("FOR i IN 0...x");
            expected.AppendLine("LOOP");
            expected.AppendLine("  IF :i = 3 THEN");
            expected.AppendLine("    GOTO 'lbl_3'");
            expected.AppendLine("  END IF");
            expected.Append("END LOOP");

            Assert.AreEqual(expected.ToString(), sql);
        }
        public static void ForLoopGoto()
        {
            var loop = new ForLoopStatement("i", SqlExpression.Constant(0), SqlExpression.Reference(new ObjectName("x")));

            loop.Statements.Add(new ConditionStatement(SqlExpression.Equal(SqlExpression.VariableReference("i"), SqlExpression.Constant(3)), new SqlStatement[] {
                new GoToStatement("lbl_3")
            }));

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

            expected.AppendLine("FOR i IN 0...x");
            expected.AppendLine("LOOP");
            expected.AppendLine("  IF :i = 3 THEN");
            expected.AppendLine("    GOTO 'lbl_3'");
            expected.AppendLine("  END IF");
            expected.Append("END LOOP");

            Assert.AreEqual(expected.ToString(), sql);
        }
Esempio n. 9
0
        public void SimpleForLoop()
        {
            var loop = new ForLoopStatement("i", SqlExpression.Constant(0), SqlExpression.Constant(200));
            loop.Statements.Add(new DeclareVariableStatement("a", PrimitiveTypes.String()));
            loop.Statements.Add(new AssignVariableStatement(SqlExpression.VariableReference("a"),
                SqlExpression.FunctionCall("cast",
                    new SqlExpression[] {SqlExpression.VariableReference("i"), SqlExpression.Constant("varchar")})));
            loop.Statements.Add(
                new ConditionStatement(SqlExpression.Equal(SqlExpression.VariableReference("i"), SqlExpression.Constant(200)),
                    new SqlStatement[] {new ReturnStatement(SqlExpression.VariableReference("a"))}));

             var result = AdminQuery.ExecuteStatement(loop);

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

            var value = result.Result.GetValue(0, 0);
            Assert.IsNotNull(value);
            Assert.IsFalse(Field.IsNullField(value));
            // TODO: the context should return the value of RETURN statement
        }
Esempio n. 10
0
        protected override SqlStatement PrepareExpressions(IExpressionPreparer preparer)
        {
            var lower = LowerBound.Prepare(preparer);
            var upper = UpperBound.Prepare(preparer);

            var loop = new ForLoopStatement(IndexName, lower, upper) {Reverse = Reverse};
            foreach (var statement in Statements) {
                loop.Statements.Add(statement);
            }
            return loop;
        }
Esempio n. 11
0
        private SqlStatement VisitForLoop(ForLoopStatement statement)
        {
            var loop = new ForLoopStatement(statement.IndexName, statement.LowerBound, statement.UpperBound);

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

            return loop;
        }
        public void ForLoop()
        {
            var statement = new ForLoopStatement("i", SqlExpression.Constant(22), SqlExpression.Constant(56));
            statement.Statements.Add(new CallStatement(new ObjectName("proc1")));

            SerializeAndAssert(statement, (serialized, deserialized) => {
                Assert.IsNotNull(deserialized);
                Assert.IsNotNull(deserialized.IndexName);
                Assert.AreEqual("i", deserialized.IndexName);
                Assert.IsNotNull(deserialized.LowerBound);
                Assert.IsNotNull(deserialized.UpperBound);
                Assert.IsNotNull(deserialized.Statements);
                Assert.IsNotEmpty(deserialized.Statements);
            });
        }