コード例 #1
0
 public SelectCommandContext(SchemaMetaData schemaMetaData, string sql, ParameterContext parameterContext, SelectCommand sqlCommand) : base(sqlCommand)
 {
     _tablesContext      = new TablesContext(sqlCommand.GetSimpleTableSegments());
     _groupByContext     = new GroupByContextEngine().CreateGroupByContext(sqlCommand);
     _orderByContext     = new OrderByContextEngine().CreateOrderBy(sqlCommand, _groupByContext);
     _projectionsContext = new ProjectionsContextEngine(schemaMetaData).CreateProjectionsContext(sql, sqlCommand, _groupByContext, _orderByContext);
     _paginationContext  = new PaginationContextEngine().CreatePaginationContext(sqlCommand, _projectionsContext, parameterContext);
     _containsSubQuery   = ContainsSubQuery();
 }
コード例 #2
0
 // TODO to be remove, for test case only
 public SelectCommandContext(SelectCommand sqlCommand, GroupByContext groupByContext,
                             OrderByContext orderByContext, ProjectionsContext projectionsContext, PaginationContext paginationContext) : base(sqlCommand)
 {
     _tablesContext           = new TablesContext(sqlCommand.GetSimpleTableSegments());
     this._groupByContext     = groupByContext;
     this._orderByContext     = orderByContext;
     this._projectionsContext = projectionsContext;
     this._paginationContext  = paginationContext;
     _containsSubQuery        = ContainsSubQuery();
 }
コード例 #3
0
        public OrderByContext CreateOrderBy(SelectCommand selectCommand, GroupByContext groupByContext)
        {
            if (null == selectCommand.OrderBy || !selectCommand.OrderBy.GetOrderByItems().Any())
            {
                OrderByContext orderByContext = CreateOrderByContextForDistinctRowWithoutGroupBy(selectCommand, groupByContext);
                return(null != orderByContext ? orderByContext : new OrderByContext(groupByContext.GetItems(), groupByContext.GetItems().Any()));
            }

            ICollection <OrderByItem> orderByItems = new LinkedList <OrderByItem>();

            foreach (var orderByItemSegment in selectCommand.OrderBy.GetOrderByItems())
            {
                OrderByItem orderByItem = new OrderByItem(orderByItemSegment);
                if (orderByItemSegment is IndexOrderByItemSegment indexOrderByItemSegment)
                {
                    orderByItem.SetIndex(indexOrderByItemSegment.GetColumnIndex());
                }

                orderByItems.Add(orderByItem);
            }

            return(new OrderByContext(orderByItems, false));
        }
コード例 #4
0
 private ICollection <IProjection> GetDerivedOrderByColumns(ICollection <IProjection> projections, OrderByContext orderByContext, SelectCommand selectCommand)
 {
     return(GetDerivedOrderColumns(projections, orderByContext.GetItems(), DerivedColumn.Get(DerivedColumnEnum.ORDER_BY_ALIAS), selectCommand));
 }
コード例 #5
0
        /// <summary>
        /// Create projections context.
        /// </summary>
        /// <param name="sql"></param>
        /// <param name="selectCommand"></param>
        /// <param name="groupByContext"></param>
        /// <param name="orderByContext"></param>
        /// <returns></returns>
        public ProjectionsContext CreateProjectionsContext(string sql, SelectCommand selectCommand, GroupByContext groupByContext, OrderByContext orderByContext)
        {
            ProjectionsSegment        projectionsSegment = selectCommand.Projections;
            ICollection <IProjection> projections        = GetProjections(sql, selectCommand.GetSimpleTableSegments(), projectionsSegment);
            ProjectionsContext        result             = new ProjectionsContext(projectionsSegment.GetStartIndex(), projectionsSegment.GetStopIndex(), projectionsSegment.IsDistinctRow(), projections);

            result.GetProjections().AddAll(GetDerivedGroupByColumns(projections, groupByContext, selectCommand));
            result.GetProjections().AddAll(GetDerivedOrderByColumns(projections, orderByContext, selectCommand));
            return(result);
        }