-
Notifications
You must be signed in to change notification settings - Fork 654
Add support for procedure parameter default values #2041
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
Conversation
f7f6284
to
6e18938
Compare
tests/sqlparser_common.rs
Outdated
} | ||
|
||
#[test] | ||
fn create_procedure_with_parameter_default_value() { |
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.
Can we merge the test into the existing parse_create_procedure_with_parameter_modes
? since they cover the same feature
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.
Hm, I don't understand. A parameter can be in/out and still have/not have a default, right? Are you suggesting like
pub enum ArgMode {
In,
Out,
InOut,
+ InWithDefault(Expr),
+ OutWithDefault(Expr),
+ InOutWithDefault(Expr),
}
Perhaps I'm not understanding
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.
Ah no I meant to only inline this test case into that parse_create_procedure_with_parameter_modes
function vs having one function per test case
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.
Oh yes, I understand now 👍
tests/sqlparser_common.rs
Outdated
|
||
#[test] | ||
fn create_procedure_with_parameter_default_value() { | ||
let sql = r#"CREATE PROCEDURE test_proc (a INT = 42) AS BEGIN SELECT 1; END"#; |
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.
Can we add scenarios demonstrating
- multiple paramenters having defaults (i.e.
(a INT= 42, b INT=43)
) - parameters that include a
mode
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.
Done 👍. I've also added an additional unit test for SQL Server, since the parameter identifier syntax is different there.
6e18938
to
d05b63c
Compare
d05b63c
to
88da3b7
Compare
tests/sqlparser_common.rs
Outdated
} | ||
|
||
#[test] | ||
fn create_procedure_with_parameter_default_value() { |
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.
Ah no I meant to only inline this test case into that parse_create_procedure_with_parameter_modes
function vs having one function per test case
tests/sqlparser_common.rs
Outdated
name: Ident { | ||
value: "a".into(), | ||
quote_style: None, | ||
span: fake_span, | ||
}, |
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.
name: Ident { | |
value: "a".into(), | |
quote_style: None, | |
span: fake_span, | |
}, | |
name: Ident::new("a"), |
I think this can be simplified? that would let us skip introducing the fake span as well
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.
Yes, certainly. I did it this way because that's how the similar modes test did it, but I will simplify
tests/sqlparser_mssql.rs
Outdated
#[test] | ||
fn parse_mssql_create_procedure_with_parameter_default_value() { | ||
let sql = r#"CREATE PROCEDURE foo (IN @a INTEGER = 1, OUT @b TEXT = '2', INOUT @c DATETIME = NULL, @d BOOL = 0) AS BEGIN SELECT 1; END"#; | ||
let _ = ms().verified_stmt(sql); | ||
} |
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.
Similar comment here that we can inline this scenario into the parse_mssql_create_procedure
function above
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.
Done 👍
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.
LGTM! Thanks @aharpervc!
For example, this now parses appropriately:
Syntax documentation reference: https://learn.microsoft.com/en-us/sql/t-sql/statements/create-procedure-transact-sql?view=sql-server-ver17#e-use-a-procedure-with-wildcard-parameters. This is the syntax used by SQL Server, but I've implemented this as a "normal" Option property of the ProcedureParam struct.
I also added a corresponding common unit test