Inheritance: IDdlStatement
 public virtual void Visit(ExtDdlCreatePolicy node)
 {
 }
Example #2
0
        /// <summary>nothing has been pre-consumed</summary>
        /// <exception cref="System.SqlSyntaxErrorException" />
        public virtual IDdlStatement DdlStmt()
        {
            Identifier idTemp1;
            Identifier idTemp2;
            SpecialIdentifier siTemp;
            switch (lexer.Token())
            {
                case MySqlToken.KwAlter:
                {
                    var ignore = false;
                    if (lexer.NextToken() == MySqlToken.KwIgnore)
                    {
                        ignore = true;
                        lexer.NextToken();
                    }
                    switch (lexer.Token())
                    {
                        case MySqlToken.KwTable:
                        {
                            lexer.NextToken();
                            idTemp1 = Identifier();
                            var alterTableStatement = new DdlAlterTableStatement(ignore, idTemp1);
                            return AlterTable(alterTableStatement);
                        }

                        default:
                        {
                            throw Err("Only ALTER TABLE is supported");
                        }
                    }
                    //goto case MySqlToken.KwCreate;
                }

                case MySqlToken.KwCreate:
                {
                    switch (lexer.NextToken())
                    {
                        case MySqlToken.KwUnique:
                        case MySqlToken.KwFulltext:
                        case MySqlToken.KwSpatial:
                        {
                            lexer.NextToken();
                            goto case MySqlToken.KwIndex;
                        }

                        case MySqlToken.KwIndex:
                        {
                            lexer.NextToken();
                            idTemp1 = Identifier();
                            for (; lexer.Token() != MySqlToken.KwOn; lexer.NextToken())
                            {
                            }
                            lexer.NextToken();
                            idTemp2 = Identifier();
                            return new DdlCreateIndexStatement(idTemp1, idTemp2);
                        }

                        case MySqlToken.KwTable:
                        {
                            lexer.NextToken();
                            return CreateTable(false);
                        }

                        case MySqlToken.Identifier:
                        {
                            siTemp = specialIdentifiers.GetValue(lexer.GetStringValueUppercase());
                            if (siTemp != SpecialIdentifier.None)
                            {
                                switch (siTemp)
                                {
                                    case SpecialIdentifier.Temporary:
                                    {
                                        lexer.NextToken();
                                        Match(MySqlToken.KwTable);
                                        return CreateTable(true);
                                    }

                                    case SpecialIdentifier.Policy:
                                    {
                                        lexer.NextToken();
                                        var policyName = Identifier();
                                        Match(MySqlToken.PuncLeftParen);
                                        var policy = new ExtDdlCreatePolicy(policyName);
                                        for (var j = 0; lexer.Token() != MySqlToken.PuncRightParen; ++j)
                                        {
                                            if (j > 0)
                                            {
                                                Match(MySqlToken.PuncComma);
                                            }
                                            var id = (int)lexer.GetIntegerValue();
                                            Match(MySqlToken.LiteralNumPureDigit);
                                            var val = exprParser.Expression();
                                            policy.AddProportion(id, val);
                                        }
                                        Match(MySqlToken.PuncRightParen);
                                        return policy;
                                    }
                                }
                            }
                            goto default;
                        }

                        default:
                        {
                            throw Err("unsupported Ddl for CREATE");
                        }
                    }
                    //goto case MySqlToken.KwDrop;
                }

                case MySqlToken.KwDrop:
                {
                    switch (lexer.NextToken())
                    {
                        case MySqlToken.KwIndex:
                        {
                            lexer.NextToken();
                            idTemp1 = Identifier();
                            Match(MySqlToken.KwOn);
                            idTemp2 = Identifier();
                            return new DdlDropIndexStatement(idTemp1, idTemp2);
                        }

                        case MySqlToken.KwTable:
                        {
                            lexer.NextToken();
                            return DropTable(false);
                        }

                        case MySqlToken.Identifier:
                        {
                            siTemp = specialIdentifiers.GetValue(lexer.GetStringValueUppercase());
                            if (siTemp != SpecialIdentifier.None)
                            {
                                switch (siTemp)
                                {
                                    case SpecialIdentifier.Temporary:
                                    {
                                        lexer.NextToken();
                                        Match(MySqlToken.KwTable);
                                        return DropTable(true);
                                    }

                                    case SpecialIdentifier.Policy:
                                    {
                                        lexer.NextToken();
                                        var policyName = Identifier();
                                        return new ExtDdlDropPolicy(policyName);
                                    }
                                }
                            }
                            goto default;
                        }

                        default:
                        {
                            throw Err("unsupported Ddl for DROP");
                        }
                    }
                    //goto case MySqlToken.KwRename;
                }

                case MySqlToken.KwRename:
                {
                    lexer.NextToken();
                    Match(MySqlToken.KwTable);
                    idTemp1 = Identifier();
                    Match(MySqlToken.KwTo);
                    idTemp2 = Identifier();
                    IList<Pair<Identifier, Identifier>> list;
                    if (lexer.Token() != MySqlToken.PuncComma)
                    {
                        list = new List<Pair<Identifier, Identifier>>(1);
                        list.Add(new Pair<Identifier, Identifier>(idTemp1, idTemp2));
                        return new DdlRenameTableStatement(list);
                    }
                    list = new List<Pair<Identifier, Identifier>>();
                    list.Add(new Pair<Identifier, Identifier>(idTemp1, idTemp2));
                    for (; lexer.Token() == MySqlToken.PuncComma;)
                    {
                        lexer.NextToken();
                        idTemp1 = Identifier();
                        Match(MySqlToken.KwTo);
                        idTemp2 = Identifier();
                        list.Add(new Pair<Identifier, Identifier>(idTemp1, idTemp2));
                    }
                    return new DdlRenameTableStatement(list);
                }

                case MySqlToken.Identifier:
                {
                    var si = specialIdentifiers.GetValue(lexer.GetStringValueUppercase());
                    if (si != SpecialIdentifier.None)
                    {
                        switch (si)
                        {
                            case SpecialIdentifier.Truncate:
                            {
                                return Truncate();
                            }
                        }
                    }
                    goto default;
                }

                default:
                {
                    throw Err("unsupported Ddl");
                }
            }
        }