-
Notifications
You must be signed in to change notification settings - Fork 710
MSSQL: Support THROW statement
#2202
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1029,6 +1029,7 @@ define_keywords!( | |
| TEXT, | ||
| TEXTFILE, | ||
| THEN, | ||
| THROW, | ||
| TIES, | ||
| TIME, | ||
| TIMEFORMAT, | ||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -670,6 +670,7 @@ impl<'a> Parser<'a> { | |||||||||||||||||||
| Keyword::RELEASE => self.parse_release(), | ||||||||||||||||||||
| Keyword::COMMIT => self.parse_commit(), | ||||||||||||||||||||
| Keyword::RAISERROR => Ok(self.parse_raiserror()?), | ||||||||||||||||||||
| Keyword::THROW => Ok(self.parse_throw()?), | ||||||||||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
see RAISE for an example. we're moving to have the statement parsing functions return the actual struct instead of a |
||||||||||||||||||||
| Keyword::ROLLBACK => self.parse_rollback(), | ||||||||||||||||||||
| Keyword::ASSERT => self.parse_assert(), | ||||||||||||||||||||
| // `PREPARE`, `EXECUTE` and `DEALLOCATE` are Postgres-specific | ||||||||||||||||||||
|
|
@@ -18260,6 +18261,31 @@ impl<'a> Parser<'a> { | |||||||||||||||||||
| } | ||||||||||||||||||||
| } | ||||||||||||||||||||
|
|
||||||||||||||||||||
| /// Parse a MSSQL `THROW` statement | ||||||||||||||||||||
| /// See <https://learn.microsoft.com/en-us/sql/t-sql/language-elements/throw-transact-sql> | ||||||||||||||||||||
| pub fn parse_throw(&mut self) -> Result<Statement, ParserError> { | ||||||||||||||||||||
| // THROW with no arguments is a re-throw inside a CATCH block | ||||||||||||||||||||
| if self.peek_token_ref().token == Token::SemiColon | ||||||||||||||||||||
| || self.peek_token_ref().token == Token::EOF | ||||||||||||||||||||
| { | ||||||||||||||||||||
| return Ok(Statement::Throw { | ||||||||||||||||||||
| error_number: None, | ||||||||||||||||||||
| message: None, | ||||||||||||||||||||
| state: None, | ||||||||||||||||||||
| }); | ||||||||||||||||||||
| } | ||||||||||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
I think we can skip this logic, it would be expected for the function to return an error if the input is empty (per the previous comment about making this function stand-alone)
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ok, that makes sense to me. Just moved~ |
||||||||||||||||||||
| let error_number = Box::new(self.parse_expr()?); | ||||||||||||||||||||
| self.expect_token(&Token::Comma)?; | ||||||||||||||||||||
| let message = Box::new(self.parse_expr()?); | ||||||||||||||||||||
| self.expect_token(&Token::Comma)?; | ||||||||||||||||||||
| let state = Box::new(self.parse_expr()?); | ||||||||||||||||||||
| Ok(Statement::Throw { | ||||||||||||||||||||
| error_number: Some(error_number), | ||||||||||||||||||||
| message: Some(message), | ||||||||||||||||||||
| state: Some(state), | ||||||||||||||||||||
| }) | ||||||||||||||||||||
| } | ||||||||||||||||||||
|
|
||||||||||||||||||||
| /// Parse a SQL `DEALLOCATE` statement | ||||||||||||||||||||
| pub fn parse_deallocate(&mut self) -> Result<Statement, ParserError> { | ||||||||||||||||||||
| let prepare = self.parse_keyword(Keyword::PREPARE); | ||||||||||||||||||||
|
|
||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we're slowly moving away from this representation over to having all statements wrapped in a named struct. As a result, can we do something like this instead?
See the RAISE statement for an example
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for your information. I just update with wrapped named struct.