Esempio n. 1
0
        //private SqlSection AddJoin(Token[] tokens, ref int i, List<SqlSection> result, SqlQuery parent)
        //{
        //    throw new NotImplementedException();
        //}
        private SqlWhere AddWhere(Token[] tokens, ref int i, SqlQuery parent)
        {
            var section = new SqlWhere(parent);
            section.Sections.Add(new SqlSection(section, new SqlToken(true, tokens[i])));
            parent.Sections.Add(section);

            for (i++; i < tokens.Length; i++)
            {
                if (IsMatch(tokens, i, "ORDER", "BY"))
                {
                    AddOrderBy(tokens, ref i, parent);
                    break;
                }
                else if (IsMatch(tokens, i, "GROUP", "BY"))
                {
                    AddGroupBy(tokens, ref i, parent);
                    break;
                }
                else if (tokens[i].Type == TokenType.StartParenthesis)
                {
                    if (IsMatch(tokens, i + 1, "SELECT"))
                    {
                        var query = new SqlQuery(section);
                        AddTokenSection(query, tokens[i]);
                        i++;
                        AddSelect(tokens, ref i, query);
                        section.Sections.Add(query);
                    }
                    else
                    {
                        AddParenthesisGroup(tokens, ref i, section);
                        continue;
                    }
                }
                else if (tokens[i].Type == TokenType.EndOfQuery || tokens[i].Type == TokenType.EndParenthesis)
                {
                    AddTokenSection(parent, tokens[i]);
                    break;
                }
                else if (IsQueryStart(tokens[i]))
                {
                    i--;
                    break;
                }

                AddTokenSection(section, tokens[i]);
            }
            return section;
        }
Esempio n. 2
0
 private void AddUpdate(Token[] tokens, ref int i, List<SqlSection> result, SqlQuery parent)
 {
     throw new NotImplementedException();
 }
Esempio n. 3
0
        private SqlFrom AddFrom(Token[] tokens, ref int i, SqlQuery parent)
        {
            var section = new SqlFrom(parent);
            section.Sections.Add(new SqlSection(section, new SqlToken(true, tokens[i])));
            parent.Sections.Add(section);

            for (i++; i < tokens.Length; i++)
            {
                if (IsMatch(tokens, i, "WHERE"))
                {
                    AddWhere(tokens, ref i, parent);
                    break;
                }
                else if (IsMatch(tokens, i, "ORDER", "BY"))
                {
                    AddOrderBy(tokens, ref i, parent);
                    break;
                }
                else if (IsMatch(tokens, i, "GROUP", "BY"))
                {
                    AddGroupBy(tokens, ref i, parent);
                    break;
                }
                //else if (IsMatch(tokens, i, "JOIN") ||
                //    (IsMatch(tokens, i, "LEFT") && tokens[i + 1].Type != TokenType.StartParenthesis) ||
                //    (IsMatch(tokens, i, "RIGHT") && tokens[i + 1].Type != TokenType.StartParenthesis) ||
                //    IsMatch(tokens, i, "FULL") ||
                //    IsMatch(tokens, i, "INNER") ||
                //    IsMatch(tokens, i, "OUTER"))
                //{
                //    AddJoin(tokens, ref i, result, parent);
                //    break;
                //}
                else if (tokens[i].Type == TokenType.EndOfQuery || tokens[i].Type == TokenType.EndParenthesis)
                {
                    AddTokenSection(parent, tokens[i]);
                    break;
                }
                else if (IsQueryStart(tokens[i]))
                {
                    i--;
                    break;
                }

                AddTokenSection(section, tokens[i]);
            }
            return section;
        }
Esempio n. 4
0
        private SqlOrderBy AddOrderBy(Token[] tokens, ref int i, SqlQuery parent)
        {
            var section = new SqlOrderBy(parent);
            section.Sections.Add(new SqlSection(section, new SqlToken(true, tokens[i])));
            parent.Sections.Add(section);

            for (i++; i < tokens.Length; i++)
            {
                if (IsMatch(tokens, i, "GROUP", "BY"))
                {
                    AddOrderBy(tokens, ref i, parent);
                    break;
                }
                else if (tokens[i].Type == TokenType.EndOfQuery || tokens[i].Type == TokenType.EndParenthesis)
                {
                    AddTokenSection(parent, tokens[i]);
                    break;
                }
                else if (IsQueryStart(tokens[i]))
                {
                    i--;
                    break;
                }

                AddTokenSection(section, tokens[i]);
            }
            return section;
        }
Esempio n. 5
0
        public SqlSection[] Parse(string text)
        {
            var tokens = Lexer.Tokenize(text);
            var result = new List<SqlSection>();
            var parent = new SqlQuery(null);
            result.Add(parent);

            for (int i = 0; i < tokens.Length; i++)
            {
                if (IsMatch(tokens, i, "SELECT"))
                {
                    AddSelect(tokens, ref i, parent);
                }
                else if (IsMatch(tokens, i, "UPDATE"))
                {
                    AddUpdate(tokens, ref i, result, parent);
                }
                else if (tokens[i].Type == TokenType.EndOfQuery)
                {
                    parent = new SqlQuery(null);
                    result.Add(parent);
                    AddTokenSection(parent, tokens[i]);
                }
                else
                {
                    AddTokenSection(parent, tokens[i]);
                }
            }

            return result.ToArray();
        }