コード例 #1
0
        public override void ParseInside(ExpressionParser parser)
        {
            var collection = parser.Collection;
            var lex        = collection.CurrentLexem();

            if (lex.LexemText.ToLower() != "create")
            {
                parser.Collection.Error("error", collection.CurrentLexem());
            }
            lex = collection.GotoNextMust();
            if (lex.LexemText.ToLower() != "view")
            {
                parser.Collection.Error("error", collection.CurrentLexem());
            }
            lex = collection.GotoNextMust();
            //название
            Table = TableName.Parse(parser);
            lex   = collection.GotoNextMust();
            if (lex.IsSkobraOpen())
            {
                lex = collection.GotoNextMust();
                Columns.Clear();
                while (true)
                {
                    var col = CommonParserFunc.ReadColumnNameOnly(collection);
                    Columns.Add(col);
                    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());
                }
                lex = collection.GotoNextMust();
            }
            lex = collection.CurrentLexem();
            if (lex.LexemText.ToLower() != "as")
            {
                parser.Collection.ErrorWaitKeyWord("AS", collection.CurrentLexem());
            }
            lex      = collection.GotoNextMust();
            AsSelect = new SelectExpresion();
            AsSelect.ParseInside(parser);

            //переходим к следующей лексеме
            collection.GotoNext();
        }
コード例 #2
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);
        }
コード例 #3
0
ファイル: TableName.cs プロジェクト: mamont80/everewhereSQL
        public static TableName Parse(ExpressionParser parser)
        {
            string[]  strTables = CommonParserFunc.ReadTableName(parser.Collection);
            TableName tn        = new TableName();

            if (strTables.Length < 1 || strTables.Length > 2)
            {
                parser.Collection.ErrorUnexpected(parser.Collection.CurrentOrLast());
            }
            if (strTables.Length > 1)
            {
                tn.Schema = strTables[0];
                tn.Name   = strTables[1];
            }
            else
            {
                tn.Name = strTables[0];
            }
            return(tn);
        }
コード例 #4
0
ファイル: AlterTable.cs プロジェクト: mamont80/everewhereSQL
        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();
            }
        }
コード例 #5
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();
        }