Exemplo n.º 1
0
        public override void ParseInside(ExpressionParser parser)
        {
            var collection = parser.Collection;
            var lex        = collection.CurrentLexem();

            if (lex.LexemText.ToLower() != "insert")
            {
                throw new Exception("Not INSERT statment");
            }
            lex = collection.GotoNextMust();
            if (lex.LexemText.ToLower() != "into")
            {
                throw new Exception("INTO keyword is not found");
            }
            lex = collection.GotoNextMust();
            string[] tablename = CommonParserFunc.ReadTableName(collection);
            TableClause = TableClause.CreateByTable(tablename, collection.TableGetter.GetTableByName(tablename, collection.TableGetterUseCache));
            lex         = collection.GotoNextMust();
            if (lex.IsSkobraOpen())
            {
                while (true)
                {
                    lex = collection.GotoNextMust(); //пропускаем SET или ','
                    //lex = collection.CurrentLexem();

                    var col = CommonParserFunc.ReadColumn(collection);
                    ColumnOfValues.Add(col);
                    lex = collection.GotoNextMust();
                    if (lex == null)
                    {
                        break;
                    }
                    if (lex.LexemType == LexType.Zpt)
                    {
                        continue;
                    }
                    if (lex.IsSkobraClose())
                    {
                        break;
                    }
                    collection.Error("Unknow lexem", collection.CurrentLexem());
                }
                //пропускаем ')'
                lex = collection.GotoNextMust();
            }
            else
            {
                if (lex.LexemType == LexType.Command && lex.LexemText.ToLower() == "default")
                {
                    lex = collection.GotoNextMust();
                    if (lex.LexemType == LexType.Command && lex.LexemText.ToLower() == "values")
                    {
                        DefaultValues = true;
                        return;
                    }
                    else
                    {
                        collection.Error("Expected keyword VALUES", lex);
                    }
                }
            }

            if (lex == null)
            {
                return;
            }
            if (lex.LexemText.ToLower() == "values")
            {
                lex = collection.GotoNextMust();
                if (!lex.IsSkobraOpen())
                {
                    collection.Error("'(' not found", lex);
                }
                while (true)
                {
                    SubExpression sub = new SubExpression();
                    sub.MultiValues = true;
                    while (true)
                    {
                        lex = collection.GotoNextMust(); //пропускаем SET или ','
                        //lex = collection.CurrentLexem();

                        ExpressionParser e = new ExpressionParser(collection);
                        e.Parse();
                        sub.AddChild(e.Single());
                        lex = collection.CurrentLexem();
                        if (lex == null)
                        {
                            break;
                        }
                        if (lex.LexemType == LexType.Zpt)
                        {
                            continue;
                        }
                        if (lex.IsSkobraClose())
                        {
                            break;
                        }
                        collection.Error("Unknow lexem", collection.CurrentLexem());
                    }
                    Values.Add(sub);
                    lex = collection.GotoNext();
                    if (lex != null && lex.LexemType == LexType.Zpt)
                    {
                        lex = collection.GotoNextMust();
                        if (!lex.IsSkobraOpen())
                        {
                            collection.ErrorWaitKeyWord("(", lex);
                        }
                        continue;
                    }
                    else
                    {
                        break;
                    }
                }
            }
            else
            if (lex.LexemText.ToLower() == "select" || lex.IsSkobraOpen())
            {
                ExpressionParser e = new ExpressionParser(collection);
                e.Parse();
                var expr = e.Single();
                var sel  = ParserUtils.FindSelect(expr);
                if (sel == null)
                {
                    throw new Exception("Values in INSERT not found");
                }
                Select = sel;
            }
            ParseReturining(parser);
        }
Exemplo n.º 2
0
        public override void ParseInside(ExpressionParser parser)
        {
            var collection = parser.Collection;
            var lex        = collection.CurrentLexem();

            if (lex.LexemText.ToLower() != "update")
            {
                throw new Exception("Not UPDATE statment");
            }
            lex = collection.GotoNextMust();

            FromParser fc = new FromParser();

            fc.Parse(collection);
            if (fc.Tables.Count > 1)
            {
                collection.Error("Multi tables in update", collection.CurrentLexem());
            }
            if (fc.Tables.Count == 0)
            {
                collection.Error("Not table clause", collection.CurrentLexem());
            }
            TableClause = fc.Tables[0];


            //string[] tablename = CommonParserFunc.ReadTableName(collection);
            //TableClause = TableClause.CreateByTable(tablename, collection.TableGetter.GetTableByName(tablename));
            //lex = collection.GotoNextMust();
            lex = collection.CurrentLexem();

            if (lex.LexemText.ToLower() != "set")
            {
                collection.Error("SET keyword is not found", collection.CurrentLexem());
            }

            while (true)
            {
                lex = collection.GotoNextMust();//пропускаем SET или ','
                //lex = collection.CurrentLexem();

                SetClause sc = new SetClause();
                sc.Column = CommonParserFunc.ReadColumn(collection);
                lex       = collection.GotoNextMust();
                if (lex.LexemText != "=")
                {
                    collection.Error("Operator '=' is not found", collection.CurrentLexem());
                }
                lex = collection.GotoNextMust();
                ExpressionParser e = new ExpressionParser(parser.Collection);
                e.Parse();
                sc.Value = e.Single();
                Set.Add(sc);
                lex = collection.CurrentLexem();
                if (lex == null)
                {
                    break;
                }
                if (lex.LexemType == LexType.Zpt)
                {
                    continue;
                }
                break;
            }

            if (lex == null)
            {
                return;
            }
            if (lex.LexemText.ToLower() == "where")
            {
                collection.GotoNextMust();
                ExpressionParser e = new ExpressionParser(parser.Collection);
                e.Parse();
                Where = e.Single();
            }
            ParseReturining(parser);
        }