/// <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);
        }
Exemplo n.º 2
0
        private string GetAlias(string name)
        {
            if (_projectionsContext.IsUnqualifiedShorthandProjection())
            {
                return(null);
            }
            string rawName = SqlUtil.GetExactlyValue(name);

            foreach (var projection in _projectionsContext.GetProjections())
            {
                if (SqlUtil.GetExactlyExpression(rawName).EqualsIgnoreCase(SqlUtil.GetExactlyExpression(SqlUtil.GetExactlyValue(projection.GetExpression()))))
                {
                    return(projection.GetAlias());
                }
                if (rawName.EqualsIgnoreCase(projection.GetAlias()))
                {
                    return(rawName);
                }
            }

            return(null);
        }