Exemplo n.º 1
0
        public static AlterColumnInfo ReadColumnInfo(LexemCollection collection)
        {
            var             lex = collection.CurrentLexem();
            var             col = CommonParserFunc.ReadColumnNameOnly(collection);
            AlterColumnInfo cd  = new AlterColumnInfo();

            cd.Name = col;
            lex     = collection.GotoNextMust();
            if (lex.LexemType != LexType.Command)
            {
                collection.ErrorUnexpected(collection.CurrentLexem());
            }
            ExactType?tp = ExactType.Parse(collection);

            if (tp == null)
            {
                collection.Error("Unknow data type", collection.CurrentOrLast());
            }
            cd.Type = tp.Value;
            lex     = collection.GotoNext();
            while (lex != null && lex.LexemType != LexType.Zpt && !lex.IsSkobraClose())
            {
                string s1 = lex.LexemText.ToLower();
                if (ParserUtils.ParseCommandPhrase(collection, "not null"))
                {
                    cd.Nullable = false;
                }
                else if (ParserUtils.ParseCommandPhrase(collection, "null"))
                {
                    cd.Nullable = true;
                }
                else if (ParserUtils.ParseCommandPhrase(collection, "primary key"))
                {
                    cd.PrimaryKey = true;
                }
                else if (lex.LexemType == LexType.Command && (s1 == "auto_increment"))
                {
                    cd.AutoIncrement = true;
                }
                else
                {
                    collection.ErrorUnexpected(collection.CurrentOrLast());
                }
                lex = collection.GotoNext();
            }
            return(cd);
        }
Exemplo n.º 2
0
        public override void ParseInside(ExpressionParser parser)
        {
            var collection = parser.Collection;
            var lex        = collection.CurrentLexem();

            if (lex.LexemText.ToLower() != "create")
            {
                parser.Collection.ErrorWaitKeyWord("CREATE", collection.CurrentLexem());
            }
            lex = collection.GotoNextMust();
            if (lex.LexemText.ToLower() != "table")
            {
                parser.Collection.ErrorWaitKeyWord("TABLE", collection.CurrentLexem());
            }
            lex = collection.GotoNextMust();
            //название
            Table = TableName.Parse(parser);
            lex   = collection.GotoNextMust();
            if (!lex.IsSkobraOpen())
            {
                parser.Collection.ErrorWaitKeyWord("(", collection.CurrentLexem());
            }
            lex = collection.GotoNextMust();
            while (true)
            {
                AlterColumnInfo cd = ReadColumnInfo(collection);
                Columns.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();
        }
Exemplo n.º 3
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();
            }
        }
Exemplo n.º 4
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();
        }