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

Fix DECLARE Delimitation #1615

Merged
merged 4 commits into from
Oct 13, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/sqlfluff/dialects/dialect_tsql.py
Original file line number Diff line number Diff line change
Expand Up @@ -399,8 +399,7 @@ class DeclareStatementSegment(BaseSegment):
"""

type = "declare_segment"
match_grammar = StartsWith("DECLARE")
parse_grammar = Sequence(
match_grammar = Sequence(
"DECLARE",
Delimited(Ref("ParameterNameSegment")),
Ref("DatatypeSegment"),
Expand All @@ -414,6 +413,7 @@ class DeclareStatementSegment(BaseSegment):
),
optional=True,
),
Ref("DelimiterSegment", optional=True),
)


Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
CREATE PROC Reporting.DeclareProblem AS
BEGIN

DECLARE @DateNow DATE = GETDATE();

IF OBJECT_ID('tempdb..#UP') IS NOT NULL DROP TABLE #UP;

END
56 changes: 56 additions & 0 deletions test/fixtures/dialects/tsql/declare_with_following_statements.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
# YML test files are auto-generated from SQL files and should not be edited by
# hand. To help enforce this, the "hash" field in the file must match a hash
# computed by SQLFluff when running the tests. Please run
# `python test/generate_parse_fixture_yml.py` to generate them after adding or
# altering SQL files.
_hash: ad453da731f5e59bb6c6e901bf7d80e49b4847ba3f4e8b13f19bcc3b84891680
file:
batch:
create_procedure_statement:
- keyword: CREATE
- keyword: PROC
- object_reference:
- identifier: Reporting
- dot: .
- identifier: DeclareProblem
- keyword: AS
- procedure_statement:
begin_end_block:
- keyword: BEGIN
- statement:
declare_segment:
keyword: DECLARE
parameter: '@DateNow'
data_type:
identifier: DATE
comparison_operator: '='
function:
function_name:
function_name_identifier: GETDATE
bracketed:
start_bracket: (
end_bracket: )
statement_terminator: ;
- statement:
if_then_statement:
keyword: IF
expression:
- function:
function_name:
function_name_identifier: OBJECT_ID
bracketed:
start_bracket: (
expression:
literal: "'tempdb..#UP'"
end_bracket: )
- keyword: IS
- keyword: NOT
- keyword: 'NULL'
statement:
drop_statement:
- keyword: DROP
- keyword: TABLE
- table_reference:
identifier: '#UP'
statement_terminator: ;
- keyword: END