Exemplo n.º 1
0
        public override void PerformOnWhen(CaseExpression node)
        {
            if (node == null)
            {
                throw new ArgumentNullException("node");
            }

            m_sql.Append(NewLine);
        }
Exemplo n.º 2
0
        SwitchFunction MakeSwitch(CaseExpression caseExpr)
        {
            if (caseExpr == null)
            {
                throw new ArgumentNullException("caseExpr");
            }

            IExpression    left       = caseExpr.Case;
            SwitchFunction switchFunc = new SwitchFunction();

            CaseAlternative alt = caseExpr.Alternatives;

            if (alt == null)
            {
                throw new InvalidOperationException("CASE has no alternatives.");
            }

            // branch expressions will be tailored through caseExpr.Alternatives

            if (left != null)
            {
                while (alt != null)
                {
                    alt.When = new Expression(left.Clone(), ExpressionOperator.Equal,
                                              alt.When);

                    CaseAlternative next = alt.Next;
                    alt.Next = null;
                    switchFunc.Add(alt);

                    alt = next;
                }
            }
            else
            {
                switchFunc.Alternatives = alt;
            }

            IExpression elseExpr = caseExpr.Else;

            if (elseExpr != null)
            {
                // elseExpr will be tailored through caseExpr.Else

                CaseAlternative last = new CaseAlternative(
                    new Expression(
                        new IntegerValue(1),
                        ExpressionOperator.Equal,
                        new IntegerValue(1)),
                    elseExpr);
                switchFunc.Add(last);
            }

            return(switchFunc);
        }
Exemplo n.º 3
0
        public override void PerformBefore(CaseExpression node)
        {
            if (node == null)
            {
                throw new ArgumentNullException("node");
            }

            ReplaceTerm(node, MakeSwitch(node));

            base.PerformBefore(node);
        }
Exemplo n.º 4
0
        public override void PerformOnElse(CaseExpression node)
        {
            if (node == null)
            {
                throw new ArgumentNullException("node");
            }

            if (node.Else != null)
            {
                m_sql.Append("ELSE ");
            }
        }
Exemplo n.º 5
0
        public override void PerformBefore(CaseExpression node)
        {
            if (node == null)
            {
                throw new ArgumentNullException("node");
            }

            m_sql.Append("CASE");
            if (node.Case != null)
            {
                m_sql.Append(' ');
            }
        }
Exemplo n.º 6
0
        public override void PerformAfter(CaseExpression node)
        {
            if (node == null)
            {
                throw new ArgumentNullException("node");
            }

            if (node.Else != null)
            {
                m_sql.Append(NewLine);
            }

            m_sql.Append("END");
        }
Exemplo n.º 7
0
        public INode Clone()
        {
            CaseExpression caseExpression = new CaseExpression();

            if (m_case != null)
            {
                caseExpression.Case = (IExpression)(m_case.Clone());
            }

            if (m_else != null)
            {
                caseExpression.Else = (IExpression)(m_else.Clone());
            }

            if (m_alternatives != null)
            {
                caseExpression.Alternatives = (CaseAlternative)(m_alternatives.Clone());
            }

            return(caseExpression);
        }
Exemplo n.º 8
0
 public virtual void PerformAfter(CaseExpression node)
 {
 }
Exemplo n.º 9
0
 public virtual void PerformOnElse(CaseExpression node)
 {
 }
Exemplo n.º 10
0
 public virtual void PerformOnWhen(CaseExpression node)
 {
 }
Exemplo n.º 11
0
 public virtual void PerformBefore(CaseExpression node)
 {
 }
Exemplo n.º 12
0
        INode MakeSubstring(FunctionCall substringCall)
        {
            if (substringCall == null)
            {
                throw new ArgumentNullException("substringCall");
            }

            if (TailorUtil.HasNullArgument(substringCall))
            {
                return(NullValue.Value);
            }

            ExpressionItem val = substringCall.ExpressionArguments;

            if (val == null)
            {
                throw new InvalidOperationException("No parameters for SUBSTRING.");
            }

            ExpressionItem start = val.Next;

            if (start == null)
            {
                throw new InvalidOperationException("Too few parameters for SUBSTRING.");
            }

            ExpressionItem len = start.Next;

            // before adding len to the list
            Expression when = MakeNotNullCheck(substringCall.ExpressionArguments);

            if (len == null)
            {
                IExpression argument = TailorUtil.MakeLenArg(start.Expression,
                                                             val.Expression, "LEN");
                start.Add(new ExpressionItem(argument));
            }
            else
            {
                if (len.Next != null)
                {
                    throw new InvalidOperationException("Too many parameters for SUBSTRING.");
                }
            }

            if (when != null)
            {
                CaseExpression caseExpression = new CaseExpression();
                caseExpression.Alternatives = new CaseAlternative(when, substringCall);

                Expression elseExpr = new Expression();
                elseExpr.Left       = NullValue.Value;
                caseExpression.Else = elseExpr;

                return(caseExpression);
            }
            else
            {
                return(substringCall);
            }
        }
Exemplo n.º 13
0
 public override void PerformAfter(CaseExpression node)
 {
     PopKnownParent(node);
 }
Exemplo n.º 14
0
 public override void PerformBefore(CaseExpression node)
 {
     PushParent(node);
 }