mirror of
https://github.com/apache/datafusion-sqlparser-rs.git
synced 2025-08-22 23:14:07 +00:00
Parse START TRANSACTION when followed by a semicolon
Co-authored-by: Nikhil Benesch <nikhil.benesch@gmail.com>
This commit is contained in:
parent
abf68c6af6
commit
2bb38c9b27
2 changed files with 13 additions and 2 deletions
|
@ -2026,7 +2026,7 @@ impl Parser {
|
|||
TransactionMode::AccessMode(TransactionAccessMode::ReadOnly)
|
||||
} else if self.parse_keywords(vec!["READ", "WRITE"]) {
|
||||
TransactionMode::AccessMode(TransactionAccessMode::ReadWrite)
|
||||
} else if required || self.peek_token().is_some() {
|
||||
} else if required {
|
||||
self.expected("transaction mode", self.peek_token())?
|
||||
} else {
|
||||
break;
|
||||
|
|
|
@ -2455,6 +2455,17 @@ fn parse_start_transaction() {
|
|||
verified_stmt("START TRANSACTION ISOLATION LEVEL REPEATABLE READ");
|
||||
verified_stmt("START TRANSACTION ISOLATION LEVEL SERIALIZABLE");
|
||||
|
||||
// Regression test for https://github.com/andygrove/sqlparser-rs/pull/139,
|
||||
// in which START TRANSACTION would fail to parse if followed by a statement
|
||||
// terminator.
|
||||
assert_eq!(
|
||||
parse_sql_statements("START TRANSACTION; SELECT 1"),
|
||||
Ok(vec![
|
||||
verified_stmt("START TRANSACTION"),
|
||||
verified_stmt("SELECT 1"),
|
||||
])
|
||||
);
|
||||
|
||||
let res = parse_sql_statements("START TRANSACTION ISOLATION LEVEL BAD");
|
||||
assert_eq!(
|
||||
ParserError::ParserError("Expected isolation level, found: BAD".to_string()),
|
||||
|
@ -2463,7 +2474,7 @@ fn parse_start_transaction() {
|
|||
|
||||
let res = parse_sql_statements("START TRANSACTION BAD");
|
||||
assert_eq!(
|
||||
ParserError::ParserError("Expected transaction mode, found: BAD".to_string()),
|
||||
ParserError::ParserError("Expected end of statement, found: BAD".to_string()),
|
||||
res.unwrap_err()
|
||||
);
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue