예제 #1
0
        static void ReplaceLeft(FunctionCall node)
        {
            if (node == null)
            {
                throw new ArgumentNullException("node");
            }

            ExpressionItem head = node.ExpressionArguments;

            if (head == null)
            {
                throw new InvalidOperationException("LEFT has no arguments.");
            }

            ExpressionItem next = head.Next;

            if (next == null)
            {
                throw new InvalidOperationException("LEFT has only one argument.");
            }

            node.Name = TailorUtil.SUBSTR.ToUpperInvariant();

            ExpressionItem tail = new ExpressionItem(
                new IntegerValue(1));

            tail.Next = next;

            head.Next = tail;
        }
예제 #2
0
        static void ReplaceRight(FunctionCall node)
        {
            if (node == null)
            {
                throw new ArgumentNullException("node");
            }

            ExpressionItem head = node.ExpressionArguments;

            if (head == null)
            {
                throw new InvalidOperationException("RIGHT has no arguments.");
            }

            ExpressionItem next = head.Next;

            if (next == null)
            {
                throw new InvalidOperationException("RIGHT has only one argument.");
            }

            if (next.HasNext)
            {
                throw new InvalidOperationException("RIGHT has too many arguments.");
            }

            node.Name = TailorUtil.SUBSTR.ToUpperInvariant();
            head.Next = new ExpressionItem(
                new Expression(new IntegerValue(-1), ExpressionOperator.Mult,
                               next));
        }
예제 #3
0
        Expression MakeModCall(FunctionCall functionCall)
        {
            if (functionCall == null)
            {
                throw new ArgumentNullException("functionCall");
            }

            ExpressionItem head = functionCall.ExpressionArguments;

            if (head == null)
            {
                throw new InvalidOperationException("MOD has no arguments.");
            }

            ExpressionItem next = head.Next;

            if (next == null)
            {
                throw new InvalidOperationException("MOD has only one argument.");
            }

            if (next.Next != null)
            {
                throw new InvalidOperationException("MOD has too many arguments.");
            }

            return(new Expression(head.Expression,
                                  m_modOp,
                                  next.Expression));
        }
예제 #4
0
        static Expression MakeNotNullCheck(ExpressionItem list)
        {
            Expression top = null;

            while (list != null)
            {
                INode term = TailorUtil.GetTerm(list.Expression);
                if (!(term is IntegerValue) && !(term is StringValue))
                {
                    Expression leaf = new Expression();
                    leaf.Left     = term.Clone();
                    leaf.Operator = ExpressionOperator.IsNotNull;

                    if (top == null)
                    {
                        top = leaf;
                    }
                    else
                    {
                        top = new Expression(top, ExpressionOperator.Or, leaf);
                    }
                }

                list = list.Next;
            }

            return(top);
        }
예제 #5
0
        static INode MakeNotNullCheck(ExpressionItem list)
        {
            INode top = null;

            while (list != null)
            {
                INode        term         = TailorUtil.GetTerm(list.Expression);
                IntegerValue integerValue = term as IntegerValue;
                if (integerValue == null)
                {
                    FunctionCall leaf = new FunctionCall("IsNull");
                    leaf.ExpressionArguments = new ExpressionItem(term.Clone());

                    if (top == null)
                    {
                        top = leaf;
                    }
                    else
                    {
                        top = new Expression(top, ExpressionOperator.Or, leaf);
                    }
                }

                list = list.Next;
            }

            return(top);
        }
예제 #6
0
        INode MakeIif(ExpressionItem args)
        {
            if (args == null)
            {
                throw new ArgumentNullException("args");
            }

            ExpressionItem tail = args.Next;

            if (tail == null)
            {
                return(args.Expression);
            }
            else
            {
                INode current = args.Expression;

                FunctionCall testArg = new FunctionCall("IsNull");
                testArg.ExpressionArguments = new ExpressionItem(current.Clone());

                FunctionCall outer = new FunctionCall("Iif");
                outer.ExpressionArguments = new ExpressionItem(testArg);
                outer.ExpressionArguments.Add(
                    new ExpressionItem(MakeIif(tail)));
                outer.ExpressionArguments.Add(new ExpressionItem(current));

                return(outer);
            }
        }
예제 #7
0
        INode MakeSubstring(FunctionCall substringCall)
        {
            if (substringCall == null)
            {
                throw new ArgumentNullException("substringCall");
            }

            substringCall.Name = TailorUtil.GetCapitalized(TailorUtil.MID);

            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;

            INode cond = MakeNotNullCheck(start);   // Mid actually handles NULL

            // in the first parameter

            if (len == null)
            {
                // We don't need to add length in the normal case, but it's
                // useful when the start position is too large and the call
                // ought to fail (which Mid doesn't, unless it's called with
                // a negative length).
                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 (cond == null)
            {
                return(substringCall);
            }
            else
            {
                FunctionCall iifCall = new FunctionCall("Iif");
                iifCall.ExpressionArguments = new ExpressionItem(cond);
                iifCall.ExpressionArguments.Add(new ExpressionItem(NullValue.Value));
                iifCall.ExpressionArguments.Add(new ExpressionItem(substringCall));
                return(iifCall);
            }
        }
예제 #8
0
        public INode Clone()
        {
            ExpressionItem expressionItem = new ExpressionItem(m_expression.Clone());

            if (m_next != null)
            {
                expressionItem.Add((ExpressionItem)(m_next.Clone()));
            }

            return(expressionItem);
        }
예제 #9
0
        public override void PerformAfter(ExpressionItem node)
        {
            if (node == null)
            {
                throw new ArgumentNullException("node");
            }

            if (node.HasNext)
            {
                m_sql.Append(", ");
            }
        }
예제 #10
0
        public void Add(ExpressionItem tail)
        {
            if (tail == null)
            {
                throw new ArgumentNullException("tail");
            }

            if (m_next == null)
            {
                m_next = tail;
            }
            else
            {
                m_next.Add(tail);
            }
        }
예제 #11
0
        void CoalesceToIif(FunctionCall coalesce)
        {
            ExpressionItem args = coalesce.ExpressionArguments;

            if (args == null)
            {
                throw new InvalidOperationException("COALESCE has no arguments.");
            }

            if (args.Next == null)
            {
                throw new InvalidOperationException("COALESCE has just one argument.");
            }

            FunctionCall iif = (FunctionCall)MakeIif(args);

            coalesce.Name = iif.Name;
            coalesce.ExpressionArguments = iif.ExpressionArguments;
        }
예제 #12
0
        public static bool HasNullArgument(FunctionCall functionCall)
        {
            if (functionCall == null)
            {
                throw new ArgumentNullException("functionCall");
            }

            ExpressionItem argument = functionCall.ExpressionArguments;

            while (argument != null)
            {
                INode term = GetTerm(argument.Expression);
                if (term == NullValue.Value)
                {
                    return(true);
                }

                argument = argument.Next;
            }

            return(false);
        }
예제 #13
0
 public virtual void PerformAfter(ExpressionItem node)
 {
 }
예제 #14
0
 public virtual void PerformBefore(ExpressionItem node)
 {
 }
예제 #15
0
 public override void PerformAfter(ExpressionItem node)
 {
     PopKnownParent(node);
 }
예제 #16
0
        public override void PerformBefore(InsertStatement node)
        {
            if (node == null)
            {
                throw new ArgumentNullException("node");
            }

            if (node.ColumnNames == null)
            {
                throw new InvalidOperationException("Insert has no names.");
            }

            bool shaving = true;

            while (shaving)
            {
                ExpressionItem headValue = node.ColumnValues;
                if (headValue == null)
                {
                    throw new InvalidOperationException(
                              "Insert statement has too few values.");
                }

                if (headValue.Expression.Equals(DefaultValue.Value))
                {
                    AliasedItem headColumn = node.ColumnNames.Next;
                    if (headColumn == null)
                    {
                        throw new InvalidOperationException(
                                  "MS Access cannot insert only default values.");
                    }

                    node.ColumnNames  = headColumn;
                    node.ColumnValues = headValue.Next;
                }
                else
                {
                    shaving = false;
                }
            }

            AliasedItem    tailColumn = node.ColumnNames;
            ExpressionItem tailValue  = node.ColumnValues;

            while (tailColumn.Next != null)
            {
                if (tailValue.Next == null)
                {
                    throw new InvalidOperationException("Insert has too few values.");
                }

                if (tailValue.Next.Expression.Equals(DefaultValue.Value))
                {
                    tailColumn.Next = tailColumn.Next.Next;
                    tailValue.Next  = tailValue.Next.Next;
                }
                else
                {
                    tailColumn = tailColumn.Next;
                    tailValue  = tailValue.Next;
                }
            }

            base.PerformBefore(node);
        }
예제 #17
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);
            }
        }
예제 #18
0
 public override void PerformBefore(ExpressionItem node)
 {
     PushParent(node);
 }