Skip to content

Conversation

aharpervc
Copy link
Contributor

For example, this now parses appropriately:

create procedure test_proc (a int = 42)
...

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

@aharpervc aharpervc force-pushed the mssql-param-default-value branch 2 times, most recently from f7f6284 to 6e18938 Compare September 19, 2025 21:44
@aharpervc aharpervc marked this pull request as ready for review September 19, 2025 21:48
}

#[test]
fn create_procedure_with_parameter_default_value() {
Copy link
Contributor

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

Copy link
Contributor Author

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

Copy link
Contributor

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

Copy link
Contributor Author

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 👍


#[test]
fn create_procedure_with_parameter_default_value() {
let sql = r#"CREATE PROCEDURE test_proc (a INT = 42) AS BEGIN SELECT 1; END"#;
Copy link
Contributor

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

Copy link
Contributor Author

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.

@aharpervc aharpervc force-pushed the mssql-param-default-value branch from 6e18938 to d05b63c Compare September 26, 2025 15:58
@aharpervc aharpervc force-pushed the mssql-param-default-value branch from d05b63c to 88da3b7 Compare September 26, 2025 15:59
}

#[test]
fn create_procedure_with_parameter_default_value() {
Copy link
Contributor

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

Comment on lines 16560 to 16564
name: Ident {
value: "a".into(),
quote_style: None,
span: fake_span,
},
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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

Copy link
Contributor Author

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

Comment on lines 203 to 207
#[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);
}
Copy link
Contributor

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

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done 👍

Copy link
Contributor

@iffyio iffyio left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! Thanks @aharpervc!

@iffyio iffyio added this pull request to the merge queue Oct 8, 2025
Merged via the queue into apache:main with commit 0fb3b6b Oct 8, 2025
10 checks passed
@aharpervc aharpervc deleted the mssql-param-default-value branch October 8, 2025 13:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants