Пример #1
0
        /// <summary>first <code>(</code> has been consumed</summary>
        /// <exception cref="System.SqlSyntaxErrorException" />
        public virtual Ref RefsOrQuery()
        {
            Ref   temp;
            Refs  rst;
            Union u;

            switch (lexer.Token())
            {
            case MySqlToken.KwSelect:
            {
                u = new Union();
                for (;;)
                {
                    var s = SelectPrimary();
                    u.AddSelect(s);
                    if (lexer.Token() == MySqlToken.KwUnion)
                    {
                        lexer.NextToken();
                    }
                    else
                    {
                        break;
                    }
                }
                if (u.selects.Count == 1)
                {
                    return(u.selects[0]);
                }
                return(u);
            }

            case MySqlToken.PuncLeftParen:
            {
                lexer.NextToken();
                temp = RefsOrQuery();
                Match(MySqlToken.PuncRightParen);
                if (temp is Query)
                {
                    if (temp is Select)
                    {
                        if (lexer.Token() == MySqlToken.KwUnion)
                        {
                            u = new Union();
                            u.AddSelect((Select)temp);
                            while (lexer.Token() == MySqlToken.KwUnion)
                            {
                                lexer.NextToken();
                                temp = SelectPrimary();
                                u.AddSelect((Select)temp);
                            }
                            return(u);
                        }
                    }
                    if (lexer.Token() == MySqlToken.KwAs)
                    {
                        lexer.NextToken();
                        var alias = lexer.GetStringValue();
                        temp = new SubQuery((Query)temp, alias);
                        lexer.NextToken();
                    }
                    else
                    {
                        return(temp);
                    }
                }
                // ---- build factor complete---------------
                temp = BuildRef(temp);
                // ---- build ref complete---------------
                break;
            }

            default:
            {
                temp = Ref();
                break;
            }
            }
            if (lexer.Token() == MySqlToken.PuncComma)
            {
                rst = new Refs();
                rst.AddRef(temp);
                for (; lexer.Token() == MySqlToken.PuncComma;)
                {
                    lexer.NextToken();
                    temp = Ref();
                    rst.AddRef(temp);
                }
                return(rst);
            }
            return(temp);
        }
Пример #2
0
        /// <summary>first <code>(</code> has been consumed</summary>
        /// <exception cref="System.SqlSyntaxErrorException" />
        public virtual Ref RefsOrQuery()
        {
            Ref temp;
            Refs rst;
            Union u;
            switch (lexer.Token())
            {
                case MySqlToken.KwSelect:
                {
                    u = new Union();
                    for (;;)
                    {
                        var s = SelectPrimary();
                        u.AddSelect(s);
                        if (lexer.Token() == MySqlToken.KwUnion)
                        {
                            lexer.NextToken();
                        }
                        else
                        {
                            break;
                        }
                    }
                    if (u.selects.Count == 1)
                    {
                        return u.selects[0];
                    }
                    return u;
                }

                case MySqlToken.PuncLeftParen:
                {
                    lexer.NextToken();
                    temp = RefsOrQuery();
                    Match(MySqlToken.PuncRightParen);
                    if (temp is Query)
                    {
                        if (temp is Select)
                        {
                            if (lexer.Token() == MySqlToken.KwUnion)
                            {
                                u = new Union();
                                u.AddSelect((Select)temp);
                                while (lexer.Token() == MySqlToken.KwUnion)
                                {
                                    lexer.NextToken();
                                    temp = SelectPrimary();
                                    u.AddSelect((Select)temp);
                                }
                                return u;
                            }
                        }
                        if (lexer.Token() == MySqlToken.KwAs)
                        {
                            lexer.NextToken();
                            var alias = lexer.GetStringValue();
                            temp = new SubQuery((Query)temp, alias);
                            lexer.NextToken();
                        }
                        else
                        {
                            return temp;
                        }
                    }
                    // ---- build factor complete---------------
                    temp = BuildRef(temp);
                    // ---- build ref complete---------------
                    break;
                }

                default:
                {
                    temp = Ref();
                    break;
                }
            }
            if (lexer.Token() == MySqlToken.PuncComma)
            {
                rst = new Refs();
                rst.AddRef(temp);
                for (; lexer.Token() == MySqlToken.PuncComma;)
                {
                    lexer.NextToken();
                    temp = Ref();
                    rst.AddRef(temp);
                }
                return rst;
            }
            return temp;
        }