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); }
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); }
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); }
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); }
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); }