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

            if (projection is AggregationProjectionSegment aggregationProjectionSegment)
            {
                aggregationProjectionSegment.SetAlias(alias);
                return(projection);
            }
            if (projection is ExpressionProjectionSegment expressionProjection)
            {
                expressionProjection.SetAlias(alias);
                return(projection);
            }
            if (projection is CommonExpressionSegment commonExpressionSegment)
            {
                ExpressionProjectionSegment r = new ExpressionProjectionSegment(commonExpressionSegment.GetStartIndex(), commonExpressionSegment.GetStopIndex(), commonExpressionSegment.GetText());
                r.SetAlias(alias);
                return(r);
            }
            // FIXME :For DISTINCT()
            if (projection is ColumnSegment)
            {
                ExpressionProjectionSegment r = new ExpressionProjectionSegment(ctx.Start.StartIndex, ctx.Stop.StopIndex, ctx.GetText());
                r.SetAlias(alias);
                return(r);
            }
            if (projection is SubQueryExpressionSegment subQueryExpressionSegment)
            {
                SubQueryProjectionSegment r = new SubQueryProjectionSegment(subQueryExpressionSegment.SubQuery);
                r.SetAlias(alias);
                return(r);
            }
            LiteralExpressionSegment    column = (LiteralExpressionSegment)projection;
            ExpressionProjectionSegment result = null == alias ? new ExpressionProjectionSegment(column.GetStartIndex(), column.GetStopIndex(), $"{column.GetLiterals()}")
                    : new ExpressionProjectionSegment(column.GetStartIndex(), ctx.alias().Stop.StopIndex, $"{column.GetLiterals()}");

            result.SetAlias(alias);
            return(result);
        }
コード例 #2
0
        public override IASTNode VisitProjection(MySqlCommandParser.ProjectionContext ctx)
        {
            // FIXME :The stop index of project is the stop index of projection, instead of alias.
            if (null != ctx.qualifiedShorthand())
            {
                MySqlCommandParser.QualifiedShorthandContext shorthand = ctx.qualifiedShorthand();
                ShorthandProjectionSegment 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 == ctx.alias() ? null : (AliasSegment)Visit(ctx.alias());

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