private SqlSelect AddSelect(Token[] tokens, ref int i, SqlQuery parent) { var section = new SqlSelect(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, "FROM")) { AddFrom(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); }
private SqlSelect AddSelect(Token[] tokens, ref int i, SqlQuery parent) { var section = new SqlSelect(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, "FROM")) { AddFrom(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; }