mirror of
https://github.com/apache/datafusion-sqlparser-rs.git
synced 2025-08-04 06:18:17 +00:00
Support parsing of multiple statements (5/5)
Parser::parse_sql() can now parse a semicolon-separated list of statements, returning them in a Vec<SQLStatement>. To support this we: - Move handling of inter-statement tokens from the end of individual statement parsers (`parse_select` and `parse_delete`; this was not implemented for other top-level statements) to the common statement-list parsing code (`parse_sql`); - Change the "Unexpected token at end of ..." error, which didn't have tests and prevented us from parsing successive statements -> "Expected end of statement" (i.e. a delimiter - currently only ";" - or the EOF); - Add PartialEq on ParserError to be able to assert_eq!() that parsing statements that do not terminate properly returns an expected error.
This commit is contained in:
parent
5a0e0ec928
commit
707c58ad57
3 changed files with 91 additions and 71 deletions
|
@ -372,13 +372,20 @@ fn verified_stmt(query: &str) -> SQLStatement {
|
|||
/// converting AST back to string equals to `canonical` (unless an empty string
|
||||
/// is provided).
|
||||
fn one_statement_parses_to(sql: &str, canonical: &str) -> SQLStatement {
|
||||
let only_statement = Parser::parse_sql(&PostgreSqlDialect {}, sql.to_string()).unwrap();
|
||||
let mut statements = parse_sql_statements(&sql).unwrap();
|
||||
assert_eq!(statements.len(), 1);
|
||||
|
||||
let only_statement = statements.pop().unwrap();
|
||||
if !canonical.is_empty() {
|
||||
assert_eq!(canonical, only_statement.to_string())
|
||||
}
|
||||
only_statement
|
||||
}
|
||||
|
||||
fn parse_sql_statements(sql: &str) -> Result<Vec<SQLStatement>, ParserError> {
|
||||
Parser::parse_sql(&PostgreSqlDialect {}, sql.to_string())
|
||||
}
|
||||
|
||||
fn parse_sql_expr(sql: &str) -> ASTNode {
|
||||
debug!("sql: {}", sql);
|
||||
let mut parser = parser(sql);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue