Beispiel #1
0
        public override void PerformBefore(AliasedItem node)
        {
            if (node == null)
            {
                throw new ArgumentNullException("node");
            }

            base.PerformBefore(node);

            if (m_inFromClause > 0)
            {
                ChopCrossJoins(node);
                BracketJoinConditions(node);
                ChopJoinChains(node);
            }

            if (m_inSelectItems)
            {
                Debug.Assert(m_selectItemAliases != null);

                Identifier alias = node.Alias;
                if (alias != null)
                {
                    string key = Identifier.Canonicalize(alias.ID);
                    if (m_selectItemAliases.ContainsKey(key))
                    {
                        string message = string.Format("Duplicate output alias {0}.",
                                                       alias.ID);
                        throw new InvalidOperationException(message);
                    }

                    m_selectItemAliases.Add(key, node);
                }
            }
        }
Beispiel #2
0
        static void ChopCrossJoins(AliasedItem node)
        {
            Table head = GetHead(node);

            AliasedItem current = node;
            Table       prev    = head;

            while (prev.Next != null)
            {
                Table next = prev.Next;
                if (next.JoinType == Join.Cross)
                {
                    if (next.JoinCondition != null)
                    {
                        throw new InvalidOperationException(
                                  "Cross join with join condition.");
                    }

                    next.JoinType = null;

                    prev.Next = null;
                    AliasedItem splice = new AliasedItem(next);
                    splice.Next  = current.Next;
                    current.Next = splice;
                    current      = splice;
                }

                prev = next;
            }
        }
Beispiel #3
0
        public override void PerformBefore(DbObject node)
        {
            if (node == null)
            {
                throw new ArgumentNullException("node");
            }

            if (!node.HasNext)
            {
                if (TailorUtil.IsSysdate(node.Identifier))
                {
                    ReplaceTerm(node, new FunctionCall(
                                    TailorUtil.GetCapitalized(TailorUtil.NOW)));
                }

                if (!m_inSelectItems && (m_selectItemAliases != null))
                {
                    string key = Identifier.Canonicalize(node.Identifier.ID);
                    if (m_selectItemAliases.ContainsKey(key))
                    {
                        AliasedItem orig = m_selectItemAliases[key];
                        ReplaceTerm(node, orig.Item.Clone());
                    }
                }
            }

            base.PerformBefore(node);
        }
Beispiel #4
0
        public override void PerformAfter(AliasedItem node)
        {
            if (node == null)
            {
                throw new ArgumentNullException("node");
            }

            if (node.HasNext)
            {
                m_sql.Append(", ");
            }
        }
Beispiel #5
0
        public override void PerformOnAlias(AliasedItem node)
        {
            if (node == null)
            {
                throw new ArgumentNullException("node");
            }

            if (node.Alias != null)
            {
                m_sql.Append(" AS ");
            }
        }
Beispiel #6
0
        static void BracketJoinConditions(AliasedItem node)
        {
            Table table = GetHead(node);

            while (table != null)
            {
                IExpression cond = table.JoinCondition;
                if ((cond != null) && !(cond is BracketedExpression))
                {
                    table.JoinCondition = new BracketedExpression(cond);
                }

                table = table.Next;
            }
        }
Beispiel #7
0
        public void Add(AliasedItem tail)
        {
            if (tail == null)
            {
                throw new ArgumentNullException("tail");
            }

            if (m_next == null)
            {
                m_next = tail;
            }
            else
            {
                m_next.Add(tail);
            }
        }
Beispiel #8
0
        public INode Clone()
        {
            AliasedItem aliasedItem = new AliasedItem(m_item.Clone());

            if (m_alias != null)
            {
                aliasedItem.Alias = (Identifier)(m_alias.Clone());
            }

            if (m_next != null)
            {
                aliasedItem.Add((AliasedItem)(m_next.Clone()));
            }

            return(aliasedItem);
        }
Beispiel #9
0
        static Table GetHead(AliasedItem node)
        {
            if (node == null)
            {
                throw new ArgumentNullException("node");
            }

            Table head = node.Item as Table;

            if (head == null)
            {
                throw new InvalidOperationException(
                          "FROM clause can contain only Table items.");
            }

            return(head);
        }
Beispiel #10
0
        public override void PerformBefore(QueryExpression node)
        {
            if (node == null)
            {
                throw new ArgumentNullException("node");
            }

            base.PerformBefore(node);

            if (node.Where == null)
            {
                AliasedItem from = node.From;
                if ((from != null) && (from.Alias == null) && !from.HasNext)
                {
                    Table singleTable = from.Item as Table;
                    if ((singleTable != null) && (singleTable.Alias == null) &&
                        (singleTable.JoinCondition == null) &&
                        (singleTable.JoinType == null) && !singleTable.HasNext)
                    {
                        DbObject singleName = TailorUtil.GetTerm(
                            singleTable.Source) as DbObject;
                        if ((singleName != null) && !singleName.HasNext)
                        {
                            Identifier identifier = singleName.Identifier;

                            // Not canonicalizing - we're accepting quoted "dual"
                            // as a regular identifier.
                            if (TailorUtil.DUAL.Equals(
                                    identifier.ID.ToLowerInvariant()))
                            {
                                node.From = null;
                            }
                        }
                    }
                }
            }

            if (node.LimitFormat != ' ')
            {
                node.LimitFormat = 'L';
            }
        }
Beispiel #11
0
        static void ChopJoinChains(AliasedItem node)
        {
            Table head = GetHead(node);
            Table next = head.Next;

            while (next != null)
            {
                Table tail = next.Next;
                if (tail != null)
                {
                    next.Next = null;
                    BracketedExpression expr = new BracketedExpression(head);
                    head      = new Table(expr);
                    head.Next = tail;
                }

                next = tail;
            }

            node.Item = head;
        }
Beispiel #12
0
 public virtual void PerformBefore(AliasedItem node)
 {
 }
Beispiel #13
0
 public override void PerformAfter(AliasedItem node)
 {
     PopKnownParent(node);
 }
Beispiel #14
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);
        }
Beispiel #15
0
 public virtual void PerformOnAlias(AliasedItem node)
 {
 }
Beispiel #16
0
 public virtual void PerformAfter(AliasedItem node)
 {
 }
Beispiel #17
0
 public override void PerformBefore(AliasedItem node)
 {
     PushParent(node);
 }