Beispiel #1
0
        public virtual SqlExpression VisitCondition(SqlConditionExpression expression)
        {
            var test = expression.Test;

            if (test != null)
            {
                test = Visit(test);
            }

            var ifTrue = expression.IfTrue;

            if (ifTrue != null)
            {
                ifTrue = Visit(ifTrue);
            }

            var ifFalse = expression.IfFalse;

            if (ifFalse != null)
            {
                ifFalse = Visit(ifFalse);
            }

            return(SqlExpression.Condition(test, ifTrue, ifFalse));
        }
        public override SqlExpression VisitSimpleCaseExpression(PlSqlParser.SimpleCaseExpressionContext context)
        {
            var exp = Visit(context.atom());

            var switches = new List <CaseSwitch>();

            foreach (var partContext in context.simpleCaseWhenExpressionPart())
            {
                var otherExp = Visit(partContext.conditionWrapper());
                switches.Add(new CaseSwitch {
                    Condition        = SqlExpression.Equal(exp, otherExp),
                    ReturnExpression = Visit(partContext.expressionWrapper())
                });
            }

            if (context.caseElseExpressionPart() != null)
            {
                var returnExp = Visit(context.caseElseExpressionPart().expressionWrapper());
                switches.Add(new CaseSwitch {
                    Condition        = SqlExpression.Constant(SqlObject.Boolean(true)),
                    ReturnExpression = returnExp
                });
            }

            SqlConditionExpression conditional = null;

            for (int i = switches.Count - 1; i >= 0; i--)
            {
                var current = switches[i];

                var condition = SqlExpression.Condition(current.Condition, current.ReturnExpression);

                if (conditional != null)
                {
                    conditional = SqlExpression.Condition(current.Condition, current.ReturnExpression, conditional);
                }
                else
                {
                    conditional = condition;
                }
            }

            return(conditional);
        }