Beispiel #1
0
        public override void ParseInside(ExpressionParser parser)
        {
            var collection = parser.Collection;

            if (!ParserUtils.ParseCommandPhrase(collection, "alter table"))
            {
                collection.ErrorUnexpected(collection.CurrentOrLast());
            }
            var lex = collection.GotoNextMust();

            Table = TableName.Parse(parser);

            lex = collection.GotoNextMust();
            string s = lex.LexemText.ToLower();

            if (ParserUtils.ParseCommandPhrase(collection, "set schema"))
            {
                lex       = collection.GotoNextMust();
                NewName   = CommonParserFunc.ReadColumnNameOnly(collection);
                AlterType = AlterType.RenameSchema;
                collection.GotoNext();
            }
            else
            if (ParserUtils.ParseCommandPhrase(collection, "rename to", true, false))
            {
                lex       = collection.GotoNextMust();
                NewName   = CommonParserFunc.ReadColumnNameOnly(collection);
                AlterType = AlterType.RenameTable;
                collection.GotoNext();
            }
            else if (ParserUtils.ParseCommandPhrase(collection, "rename column", true, false) || ParserUtils.ParseCommandPhrase(collection, "rename", true, false))
            {
                lex = collection.GotoNextMust();
                var col = CommonParserFunc.ReadColumnNameOnly(collection);
                OldColumnName = col;
                lex           = collection.GotoNextMust();
                if (lex.LexemText.ToLower() != "to")
                {
                    collection.ErrorWaitKeyWord("TO", collection.CurrentOrLast());
                }
                lex       = collection.GotoNextMust();
                NewName   = CommonParserFunc.ReadColumnNameOnly(collection);
                AlterType = AlterType.RenameColumn;
                collection.GotoNext();
            }
            else//actions
            {
                AlterType = AlterType.AlterColumn;
                while (true)
                {
                    lex = collection.CurrentLexem();
                    if (ParserUtils.ParseCommandPhrase(collection, "add column", true, false) || ParserUtils.ParseCommandPhrase(collection, "add", true, false))
                    {
                        collection.GotoNextMust();
                        var cd = CreateTable.ReadColumnInfo(collection);
                        cd.AlterColumn = AlterColumnType.AddColumn;
                        AlterColumns.Add(cd);
                    }
                    else if (ParserUtils.ParseCommandPhrase(collection, "drop column", true, false) || ParserUtils.ParseCommandPhrase(collection, "drop", true, false))
                    {
                        lex = collection.GotoNextMust();
                        var cd = new AlterColumnInfo();
                        cd.Name        = CommonParserFunc.ReadColumnNameOnly(collection);
                        cd.AlterColumn = AlterColumnType.DropColumn;
                        AlterColumns.Add(cd);
                    }
                    else if (ParserUtils.ParseCommandPhrase(collection, "alter column", true, false) || ParserUtils.ParseCommandPhrase(collection, "alter", true, false))
                    {
                        lex = collection.GotoNextMust();
                        var cd = CreateTable.ReadColumnInfo(collection);
                        AlterColumns.Add(cd);
                    }
                    else
                    {
                        collection.ErrorUnexpected(collection.CurrentOrLast());
                    }
                    lex = collection.CurrentLexem();
                    if (lex != null && lex.LexemType == LexType.Zpt)
                    {
                        collection.GotoNextMust();
                        continue;
                    }
                    break;
                }
                collection.GotoNext();
            }
        }
Beispiel #2
0
        public override void ParseInside(ExpressionParser parser)
        {
            var collection = parser.Collection;
            var lex        = collection.CurrentLexem();

            if (lex.LexemText.ToLower() != "create")
            {
                collection.ErrorWaitKeyWord("CREATE", collection.CurrentOrLast());
            }
            lex = collection.GotoNextMust();
            if (lex.LexemText.ToLower() == "unique")
            {
                Unique = true;
                lex    = collection.GotoNextMust();
            }
            if (lex.LexemText.ToLower() != "index")
            {
                collection.ErrorWaitKeyWord("INDEX", collection.CurrentOrLast());
            }
            lex = collection.GotoNextMust();
            if (ParserUtils.ParseCommandPhrase(collection, "if not exists"))
            {
                IfNotExists = true;
                lex         = collection.GotoNextMust();
            }

            IndexName = TableName.Parse(parser);
            lex       = collection.GotoNextMust();
            lex       = collection.CurrentLexem();
            if (lex.LexemType != LexType.Command || lex.LexemText.ToLower() != "on")
            {
                collection.ErrorWaitKeyWord("ON", collection.CurrentOrLast());
            }
            lex     = collection.GotoNextMust();
            OnTable = TableName.Parse(parser);
            lex     = collection.GotoNextMust();
            if (!lex.IsSkobraOpen())
            {
                collection.ErrorWaitKeyWord("(", collection.CurrentOrLast());
            }
            lex = collection.GotoNextMust();
            while (true)
            {
                AlterColumnInfo cd = new AlterColumnInfo();
                lex     = collection.CurrentLexem();
                cd.Name = CommonParserFunc.ReadColumnNameOnly(collection);
                lex     = collection.GotoNextMust();
                if (lex.LexemText.ToLower() == "desc")
                {
                    cd.Sort = ParserCore.SortType.DESC;
                    lex     = collection.GotoNextMust();
                }
                else if (lex.LexemText.ToLower() == "asc")
                {
                    cd.Sort = ParserCore.SortType.ASC;
                    lex     = collection.GotoNextMust();
                }

                IndexColumns.Add(cd);
                lex = collection.CurrentLexem();
                if (lex == null)
                {
                    parser.Collection.UnexceptEndError();
                }
                if (lex.LexemType == LexType.Zpt)
                {
                    collection.GotoNextMust();
                    continue;
                }
                if (lex.IsSkobraClose())
                {
                    break;
                }
                collection.ErrorUnexpected(collection.CurrentOrLast());
            }
            collection.GotoNext();
        }