/// <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 ICollection <SimpleTableSegment> GetAllTablesFromProjections(ProjectionsSegment projections) { ICollection <SimpleTableSegment> result = new LinkedList <SimpleTableSegment>(); foreach (var projection in projections.GetProjections()) { var table = GetTableSegment(projection); if (table != null) { result.Add(table); } } return(result); }
public override IASTNode VisitProjections(SqlServerCommandParser.ProjectionsContext context) { ICollection <IProjectionSegment> projections = new LinkedList <IProjectionSegment>(); if (null != context.unqualifiedShorthand()) { projections.Add(new ShorthandProjectionSegment(context.unqualifiedShorthand().Start.StartIndex, context.unqualifiedShorthand().Stop.StopIndex)); } foreach (var projectionContext in context.projection()) { projections.Add((IProjectionSegment)Visit(projectionContext)); } ProjectionsSegment result = new ProjectionsSegment(context.Start.StartIndex, context.Stop.StopIndex); result.GetProjections().AddAll(projections); return(result); }
private ICollection <IProjection> GetProjections(string sql, ICollection <SimpleTableSegment> tableSegments, ProjectionsSegment projectionsSegment) { List <IProjection> result = new List <IProjection>(projectionsSegment.GetProjections().Count()); foreach (var projection in projectionsSegment.GetProjections()) { var p = _projectionEngine.CreateProjection(sql, tableSegments, projection); if (p != null) { result.Add(p); } } return(result); }