Skip to content
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

feat(tsql): Support for stored procedure options #4260

Merged
merged 8 commits into from
Oct 18, 2024

Conversation

rsanchez-xtillion
Copy link
Contributor

@rsanchez-xtillion rsanchez-xtillion commented Oct 17, 2024

Added support for transact sql stored procedure options. Example:

CREATE PROCEDURE dbo.usp_add_kitchen @dept_id INT, @kitchen_count INT NOT NULL
WITH EXECUTE AS OWNER, SCHEMABINDING, NATIVE_COMPILATION -- These are stored procedure options
AS
BEGIN ATOMIC WITH (TRANSACTION ISOLATION LEVEL = SNAPSHOT, LANGUAGE = N'us_english')

UPDATE dbo.Departments
SET kitchen_count = ISNULL(kitchen_count, 0) + @kitchen_count
WHERE ID = @dept_id
END;

I added support by:

  • Adding a new WithStoredProcedureOptions property expression
  • Added OPTIONS_TYPE for the possible stored procedure options and for the EXECUTE AS clause
  • Implemented _parse_function_parameter in the TSQL dialect
  • Added if condition in the property parser to parse the stored procedure options

@georgesittas
Copy link
Collaborator

Hi @rsanchez-xtillion, is this ready for review? What's pending?

@rsanchez-xtillion rsanchez-xtillion marked this pull request as ready for review October 17, 2024 15:45
@rsanchez-xtillion
Copy link
Contributor Author

It is ready for review now, I was making sure the checks passed and added a description.

@georgesittas
Copy link
Collaborator

Appreciate it, thanks. Will take a look.

Copy link
Collaborator

@georgesittas georgesittas left a comment

Choose a reason for hiding this comment

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

Looks good, thanks a lot for the PR. Just a few minor comments to refactor this a bit.

sqlglot/dialects/tsql.py Outdated Show resolved Hide resolved
sqlglot/dialects/tsql.py Outdated Show resolved Hide resolved
sqlglot/generator.py Show resolved Hide resolved
sqlglot/parser.py Outdated Show resolved Hide resolved
sqlglot/dialects/tsql.py Outdated Show resolved Hide resolved
sqlglot/dialects/tsql.py Outdated Show resolved Hide resolved
sqlglot/parser.py Outdated Show resolved Hide resolved
sqlglot/parser.py Show resolved Hide resolved
sqlglot/parser.py Show resolved Hide resolved
Copy link
Collaborator

@georgesittas georgesittas left a comment

Choose a reason for hiding this comment

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

Great work @rsanchez-xtillion, thank you for your patience & appreciate the quick iteration.

@georgesittas georgesittas merged commit 04dccf3 into tobymao:main Oct 18, 2024
6 checks passed
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