示例#1
0
        public static IColumn VisitSelectElement(SelectElementContext context)
        {
            switch (context)
            {
            case SelectColumnElementContext selectColumnElementContext:
                return(new PropertyColumn
                {
                    Name = IdentifierUtility.Parse(selectColumnElementContext.fullColumnName().GetText()),
                    Alias = IdentifierUtility.Unescape(selectColumnElementContext.alias?.GetText()),
                });

            case SelectFunctionElementContext selectFunctionElementContext:
            {
                if (selectFunctionElementContext.builtInFunctionCall() is CountFunctionCallContext)
                {
                    return new CountFunctionColumn
                           {
                               Alias = IdentifierUtility.Unescape(selectFunctionElementContext.alias?.GetText()),
                           }
                }
                ;

                return(VisitorHelper.ThrowNotSupportedFeature <IColumn>("Select Element Function"));
            }

            case SelectExpressionElementContext _:
                return(VisitorHelper.ThrowNotSupportedFeature <IColumn>("Select Element Expression"));
            }

            return(VisitorHelper.ThrowNotSupportedContext <IColumn>(context));
        }
示例#2
0
        public static QsiColumnNode VisitSelectElement(SelectElementContext context)
        {
            QsiColumnNode node;

            switch (context)
            {
            case SelectColumnElementContext columnElementContext:
            {
                node = VisitSelectColumnElement(columnElementContext);
                break;
            }

            case SelectFunctionElementContext selectFunctionElementContext:
            {
                if (selectFunctionElementContext.builtInFunctionCall() is CountFunctionCallContext countFunctionCallContext)
                {
                    return(TreeHelper.Create <QsiDerivedColumnNode>(n =>
                        {
                            n.Expression.SetValue(TreeHelper.Create <QsiInvokeExpressionNode>(en =>
                            {
                                en.Member.SetValue(TreeHelper.CreateFunction("count"));
                            }));

                            if (selectFunctionElementContext.alias != null)
                            {
                                n.Alias.SetValue(CreateAliasNode(selectFunctionElementContext.alias));
                            }

                            PrimarSqlTree.PutContextSpan(n, countFunctionCallContext);
                        }));
                }

                throw TreeHelper.NotSupportedFeature("Select Element Function");
            }

            case SelectExpressionElementContext _:
                throw TreeHelper.NotSupportedFeature("Select Element Expression");

            default:
            {
                node = null;
                break;
            }
            }

            return(node);
        }