Add support for PRINT statement for SQL Server#1811
Conversation
| Print { | ||
| message: Box<Expr>, | ||
| }, |
There was a problem hiding this comment.
Yeah we can use a separate struct for repr
| } | ||
|
|
||
| #[test] | ||
| fn parse_print() { |
There was a problem hiding this comment.
Do we need a test that asserts a particular error for a bare PRINT? Not sure what the conventions are for that
| Print { | ||
| message: Box<Expr>, | ||
| }, |
There was a problem hiding this comment.
Yeah we can use a separate struct for repr
| } | ||
| // `COMMENT` is snowflake specific https://docs.snowflake.com/en/sql-reference/sql/comment | ||
| Keyword::COMMENT if self.dialect.supports_comment_on() => self.parse_comment(), | ||
| Keyword::PRINT if dialect_of!(self is MsSqlDialect) => { |
There was a problem hiding this comment.
| Keyword::PRINT if dialect_of!(self is MsSqlDialect) => { | |
| Keyword::PRINT => { |
we can parse unconditionally?
4b9efe8 to
4bb97d6
Compare
|
Rebased & updated |
| let print_stmt = ms().one_statement_parses_to(print_string_literal, ""); | ||
| assert_eq!( | ||
| print_stmt, | ||
| Statement::Print(PrintStatement { | ||
| message: Box::new(Expr::Value( | ||
| (Value::SingleQuotedString("Hello, world!".to_string())).with_empty_span() | ||
| )), | ||
| }) | ||
| ); | ||
|
|
||
| let print_national_string = "PRINT N'Hello, ⛄️!'"; | ||
| let print_stmt = ms().one_statement_parses_to(print_national_string, ""); | ||
| assert_eq!( | ||
| print_stmt, | ||
| Statement::Print(PrintStatement { | ||
| message: Box::new(Expr::Value( | ||
| (Value::NationalStringLiteral("Hello, ⛄️!".to_string())).with_empty_span() | ||
| )), | ||
| }) | ||
| ); | ||
|
|
||
| let print_variable = "PRINT @my_variable"; | ||
| let print_stmt = ms().one_statement_parses_to(print_variable, ""); | ||
| assert_eq!( | ||
| print_stmt, | ||
| Statement::Print(PrintStatement { | ||
| message: Box::new(Expr::Identifier(Ident::new("@my_variable"))), | ||
| }) | ||
| ); |
There was a problem hiding this comment.
oh was there a requirement to use one_statement_parses_to instead of verified_stmt for these tests?
Also with vierified_stmt we can simplify the tests except, for the hello world example, to skip assertion on the AST
There was a problem hiding this comment.
I'm unaware of any requirement, it's just that I don't understand the project testing conventions & I'm trying to follow the patterns already present in the file. I'll switch it over to your suggestion
There was a problem hiding this comment.
I think we might want to inspect the ast in the future if we do an enum of value params instead of an expr, but we can cross that bridge if/when we ever come to it. This suggestion is complete 👍
4bb97d6 to
7c224ee
Compare
iffyio
left a comment
There was a problem hiding this comment.
LGTM! Thanks @aharpervc!
cc @alamb
Reference: https://learn.microsoft.com/en-us/sql/t-sql/language-elements/print-transact-sql?view=sql-server-ver16
Making
messageaBox<Expr>instead of an enum of (national) string literal, variable, or expression is slightly lazy and also seems completely acceptable for the time being.