Esempio n. 1
0
        private SqlOrderByClause Substitute(SqlSelectSpec spec, SqlIdentifier inputParam, SqlOrderByClause orderByClause)
        {
            if (orderByClause == null)
            {
                return(null);
            }

            if (spec is SqlSelectStarSpec)
            {
                return(orderByClause);
            }

            SqlSelectValueSpec selValue = spec as SqlSelectValueSpec;

            if (selValue != null)
            {
                SqlScalarExpression replaced         = selValue.Expression;
                SqlOrderByItem[]    substitutedItems = new SqlOrderByItem[orderByClause.OrderByItems.Length];
                for (int i = 0; i < substitutedItems.Length; ++i)
                {
                    SqlScalarExpression substituted = SqlExpressionManipulation.Substitute(replaced, inputParam, orderByClause.OrderByItems[i].Expression);
                    substitutedItems[i] = SqlOrderByItem.Create(substituted, orderByClause.OrderByItems[i].IsDescending);
                }
                SqlOrderByClause result = SqlOrderByClause.Create(substitutedItems);
                return(result);
            }

            throw new DocumentQueryException("Unexpected SQL select clause type: " + spec.GetType());
        }
        public override SqlObject Visit(SqlOrderByClause sqlOrderByClause)
        {
            SqlOrderByItem[] items = new SqlOrderByItem[sqlOrderByClause.OrderByItems.Length];
            for (int i = 0; i < sqlOrderByClause.OrderByItems.Length; i++)
            {
                items[i] = sqlOrderByClause.OrderByItems[i].Accept(this) as SqlOrderByItem;
            }

            return(SqlOrderByClause.Create(items));
        }
        public override SqlObject VisitOrder_by_clause([NotNull] sqlParser.Order_by_clauseContext context)
        {
            Contract.Requires(context != null);

            List <SqlOrderByItem> orderByItems = new List <SqlOrderByItem>();

            foreach (sqlParser.Order_by_itemContext orderByItemContext in context.order_by_items().order_by_item())
            {
                SqlOrderByItem orderByItem = (SqlOrderByItem)this.VisitOrder_by_item(orderByItemContext);
                orderByItems.Add(orderByItem);
            }

            return(SqlOrderByClause.Create(orderByItems.ToImmutableArray()));
        }
Esempio n. 4
0
        public QueryUnderConstruction UpdateOrderByClause(SqlOrderByClause thenBy, TranslationContext context)
        {
            List <SqlOrderByItem> items = new List <SqlOrderByItem>(context.currentQuery.orderByClause.OrderByItems);

            items.AddRange(thenBy.OrderByItems);
            context.currentQuery.orderByClause = SqlOrderByClause.Create(items.ToImmutableArray());

            foreach (Binding binding in context.CurrentSubqueryBinding.TakeBindings())
            {
                context.currentQuery.AddBinding(binding);
            }

            return(context.currentQuery);
        }