guan404ming commented on code in PR #2186:
URL:
https://github.com/apache/datafusion-sqlparser-rs/pull/2186#discussion_r2749179803
##########
src/dialect/mssql.rs:
##########
@@ -145,7 +145,22 @@ impl Dialect for MsSqlDialect {
}
fn parse_statement(&self, parser: &mut Parser) -> Option<Result<Statement,
ParserError>> {
- if parser.peek_keyword(Keyword::IF) {
+ if parser.parse_keyword(Keyword::BEGIN) {
+ if parser.peek_keyword(Keyword::TRANSACTION)
+ || parser.peek_keyword(Keyword::WORK)
+ || parser.peek_keyword(Keyword::TRY)
+ || parser.peek_keyword(Keyword::CATCH)
+ || parser.peek_keyword(Keyword::DEFERRED)
+ || parser.peek_keyword(Keyword::IMMEDIATE)
+ || parser.peek_keyword(Keyword::EXCLUSIVE)
+ || parser.peek_token_ref().token == Token::SemiColon
+ || parser.peek_token_ref().token == Token::EOF
+ {
+ parser.prev_token();
+ return None;
+ }
+ Some(parser.parse_begin_exception_end())
Review Comment:
Thanks for the review. These keywords are checked because `parse_begin()`
handles more than just BEGIN TRANSACTION. It also handles WORK, TRY, CATCH,
DEFERRED, IMMEDIATE, EXCLUSIVE (since MsSql's
supports_start_transaction_modifier() returns true), as well as bare BEGIN;. If
any of these are missed, they'd be incorrectly routed to
parse_begin_exception_end() and fail to parse.
For example, `BEGIN TRY ... END TRY` is valid MSSQL syntax. If we only check
for BEGIN TRANSACTION, then BEGIN TRY would fall through to
`parse_begin_exception_end()`, which would try to parse TRY as a SQL statement
and fail. because TRY is supposed to be handled as a
https://github.com/apache/datafusion-sqlparser-rs/blob/c8b7f7cf4281cdfff3e08e9827928662b8be8095/src/parser/mod.rs#L17938-L17939
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]