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(); }
// 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(); }
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)); }
private ICollection <IProjection> GetDerivedOrderByColumns(ICollection <IProjection> projections, OrderByContext orderByContext, SelectCommand selectCommand) { return(GetDerivedOrderColumns(projections, orderByContext.GetItems(), DerivedColumn.Get(DerivedColumnEnum.ORDER_BY_ALIAS), selectCommand)); }
/// <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); }