コード例 #1
0
        protected override SqlStatement PrepareExpressions(ISqlExpressionPreparer preparer)
        {
            var test = Condition.Prepare(preparer);

            var statement = new ConditionalStatement(test, Label, Else);

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

            return(statement);
        }
コード例 #2
0
        public async void IfTrueReturn()
        {
            var test      = SqlExpression.Constant(SqlObject.Boolean(true));
            var condition = new ConditionalStatement(test);

            condition.Statements.Add(new ReturnStatement(SqlExpression.Constant(SqlObject.BigInt(33))));

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

            Assert.NotNull(result);
            Assert.IsType <StatementExpressionResult>(result);
            Assert.Equal((SqlNumber)33L, ((SqlConstantExpression)((StatementExpressionResult)result).Value).Value.Value);
        }
コード例 #3
0
        public void SerializeConditional()
        {
            var test      = SqlExpression.Constant(SqlObject.Boolean(true));
            var condition = new ConditionalStatement(test, new ReturnStatement(SqlExpression.Constant(SqlObject.BigInt(100))));

            condition.Statements.Add(new ReturnStatement(SqlExpression.Constant(SqlObject.BigInt(33))));

            var result = BinarySerializeUtil.Serialize(condition);

            Assert.NotNull(result);
            Assert.NotNull(result.Condition);
            Assert.NotNull(condition.Else);
            Assert.NotEmpty(condition.Statements);
            Assert.Equal(1, result.Statements.Count);
        }
コード例 #4
0
        public void GetStringWithNoElse()
        {
            var test      = SqlExpression.Constant(SqlObject.Boolean(true));
            var condition = new ConditionalStatement(test);

            condition.Statements.Add(new ReturnStatement(SqlExpression.Constant(SqlObject.BigInt(33))));

            var expected = new StringBuilder();

            expected.AppendLine("IF TRUE THEN");
            expected.AppendLine("  RETURN 33;");
            expected.Append("END IF;");

            var sql = condition.ToString();

            Assert.Equal(expected.ToString(), sql);
        }
コード例 #5
0
        protected override SqlStatement PrepareStatement(IContext context)
        {
            var @else = Else;

            if (@else != null)
            {
                @else = @else.Prepare(context);
            }

            var statement = new ConditionalStatement(Condition, Label, @else);

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

            return(statement);
        }