} // selectAll()

        public Query selectAll(FromItem fromItem)
        {
            if (fromItem.getTable() != null)
            {
                Column[] columns = fromItem.getTable().getColumns();
                foreach (Column column in columns)
                {
                    select(column, fromItem);
                }
            }
            else if (fromItem.getJoin() != JoinType.None)
            {
                selectAll(fromItem.getLeftSide());
                selectAll(fromItem.getRightSide());
            }
            else if (fromItem.getSubQuery() != null)
            {
                List <SelectItem> items = fromItem.getSubQuery().getSelectClause().getItems();
                foreach (SelectItem subQuerySelectItem in items)
                {
                    select(new SelectItem(subQuerySelectItem, fromItem));
                }
            }
            else
            {
                throw new MetaModelException("All select items ('*') not determinable with from item: " + fromItem);
            }
            return(this);
        } // selectAll()
Example #2
0
        } // constructor

        /**
         * Creates a SelectItem that references another select item in a subquery
         *
         * @param subQuerySelectItem
         * @param subQueryFromItem
         *            the FromItem that holds the sub-query
         */
        public SelectItem(SelectItem subQuerySelectItem, FromItem subQueryFromItem) :
            this(null, subQueryFromItem, null, null, null, subQuerySelectItem, null, false)
        {
            if (subQueryFromItem.getSubQuery() == null)
            {
                throw new ArgumentException("Only sub-query based FromItems allowed.");
            }
            if (subQuerySelectItem.getQuery() != null &&
                !subQuerySelectItem.getQuery().Equals(subQueryFromItem.getSubQuery()))
            {
                throw new ArgumentException("The SelectItem must exist in the sub-query");
            }
        } // constructor
        } // toStringNoAlias()

        private void appendJoinOnItem(StringBuilder sb, String sideAlias, SelectItem onItem)
        {
            FromItem fromItem = onItem.getFromItem();

            if (fromItem != null && fromItem.getSubQuery() != null && fromItem.getAlias() != null)
            {
                // there's a corner case scenario where an ON item references a
                // subquery being joined. In that case the getSuperQueryAlias()
                // method will include the subquery alias.
                string super_query_alias = onItem.getSuperQueryAlias();
                sb.Append(super_query_alias);
                return;
            }

            if (_join != JoinType.None && _leftSide.getJoin() != JoinType.None)
            {
                sb.Append(onItem.toSql());
                return;
            }

            if (sideAlias != null)
            {
                sb.Append(sideAlias);
                sb.Append('.');
            }
            String superQueryAlias = onItem.getSuperQueryAlias();

            sb.Append(superQueryAlias);
        } // appendJoinOnItem()