コード例 #1
0
        private IASTNode CreateProjection(SqlServerCommandParser.ProjectionContext context, AliasSegment alias)
        {
            IASTNode projection = Visit(context.expr());

            if (projection is AggregationProjectionSegment aggregationProjectionSegment)
            {
                aggregationProjectionSegment.SetAlias(alias);
                return(projection);
            }
            if (projection is ExpressionProjectionSegment expressionProjectionSegment)
            {
                expressionProjectionSegment.SetAlias(alias);
                return(projection);
            }
            if (projection is CommonExpressionSegment commonExpressionSegment)
            {
                ExpressionProjectionSegment commonResult = new ExpressionProjectionSegment(commonExpressionSegment.GetStartIndex(), commonExpressionSegment.GetStopIndex(), commonExpressionSegment.GetText());
                commonResult.SetAlias(alias);
                return(commonResult);
            }
            // FIXME :For DISTINCT()
            if (projection is ColumnSegment columnSegment)
            {
                ExpressionProjectionSegment columnResult = new ExpressionProjectionSegment(context.Start.StartIndex, context.Stop.StopIndex, context.GetText());
                columnResult.SetAlias(alias);
                return(columnResult);
            }
            if (projection is SubQueryExpressionSegment subQueryExpressionSegment)
            {
                SubQueryProjectionSegment subQueryResult = new SubQueryProjectionSegment(subQueryExpressionSegment.SubQuery);
                subQueryResult.SetAlias(alias);
                return(subQueryResult);
            }
            LiteralExpressionSegment    column = (LiteralExpressionSegment)projection;
            ExpressionProjectionSegment result = null == alias ? new ExpressionProjectionSegment(column.GetStartIndex(), column.GetStopIndex(), column.GetLiterals()?.ToString())
                : new ExpressionProjectionSegment(column.GetStartIndex(), context.alias().Stop.StopIndex, column.GetLiterals()?.ToString());

            result.SetAlias(alias);
            return(result);
        }
コード例 #2
0
        public override IASTNode VisitProjection(SqlServerCommandParser.ProjectionContext context)
        {
            // FIXME :The stop index of project is the stop index of projection, instead of alias.
            if (null != context.qualifiedShorthand())
            {
                var             shorthand  = context.qualifiedShorthand();
                var             result     = new ShorthandProjectionSegment(shorthand.Start.StartIndex, shorthand.Stop.StopIndex);
                IdentifierValue identifier = new IdentifierValue(shorthand.identifier().GetText());
                result.SetOwner(new OwnerSegment(shorthand.identifier().Start.StartIndex, shorthand.identifier().Stop.StopIndex, identifier));
                return(result);
            }
            AliasSegment alias = null == context.alias() ? null : (AliasSegment)Visit(context.alias());

            if (null != context.columnName())
            {
                ColumnSegment           column = (ColumnSegment)Visit(context.columnName());
                ColumnProjectionSegment result = new ColumnProjectionSegment(column);
                result.SetAlias(alias);
                return(result);
            }
            return(CreateProjection(context, alias));
        }