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(); }
/// <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); }
private string IsRowNumberAlias(ProjectionsContext projectionsContext) { foreach (var item in ROW_NUMBER_IDENTIFIERS) { var alias = projectionsContext.FindAlias(item); if (alias != null) { return(alias); } } return(null); }
public UsageRepository(ProjectionsContext dbContext) { _dbContext = dbContext; }
/** * Create pagination context. * * @param andPredicates and predicates * @param projectionsContext projections context * @param parameters SQL parameters * @return pagination context */ public PaginationContext CreatePaginationContext(ICollection <AndPredicateSegment> andPredicates, ProjectionsContext projectionsContext, ParameterContext parameterContext) { var rowNumberAlias = IsRowNumberAlias(projectionsContext); if (rowNumberAlias == null) { return(new PaginationContext(null, null, parameterContext)); } ICollection <PredicateSegment> rowNumberPredicates = GetRowNumberPredicates(andPredicates, rowNumberAlias); return(!rowNumberPredicates.Any() ? new PaginationContext(null, null, parameterContext) : CreatePaginationWithRowNumber(rowNumberPredicates, parameterContext)); }
public PaginationContext CreatePaginationContext(SelectCommand selectCommand, ProjectionsContext projectionsContext, ParameterContext parameterContext) { var limitSegment = selectCommand.Limit; if (limitSegment != null) { return(new ParserBinder.Segment.Select.Pagination.Engine.LimitPaginationContextEngine().CreatePaginationContext(limitSegment, parameterContext)); } var topProjectionSegment = FindTopProjection(selectCommand); var whereSegment = selectCommand.Where; if (topProjectionSegment != null) { return(new TopPaginationContextEngine().CreatePaginationContext( topProjectionSegment, whereSegment?.GetAndPredicates() ?? new List <AndPredicateSegment>(0), parameterContext)); } if (whereSegment != null) { return(new RowNumberPaginationContextEngine().CreatePaginationContext(whereSegment.GetAndPredicates(), projectionsContext, parameterContext)); } return(new PaginationContext(null, null, parameterContext)); }