Skip to content

Commit

Permalink
Fix splitting when using DECLARE ... HANDLER (fixes #581).
Browse files Browse the repository at this point in the history
  • Loading branch information
andialbrecht committed Sep 30, 2020
1 parent cd4a723 commit 990500a
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ Bug Fixes
* Improved parsing of IN(...) statements (issue566, pr567 by hurcy).
* Preserve line breaks when removing comments (issue484).
* Fix parsing error when using square bracket notation (issue583).
* Fix splitting when using DECLARE ... HANDLER (issue581).


Release 0.3.1 (Feb 29, 2020)
Expand Down
2 changes: 1 addition & 1 deletion sqlparse/keywords.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ def is_keyword(value):
(r'DOUBLE\s+PRECISION\b', tokens.Name.Builtin),
(r'GROUP\s+BY\b', tokens.Keyword),
(r'ORDER\s+BY\b', tokens.Keyword),
(r'HANDLER\s+FOR\b', tokens.Keyword),
(r'(LATERAL\s+VIEW\s+)'
r'(EXPLODE|INLINE|PARSE_URL_TUPLE|POSEXPLODE|STACK)\b',
tokens.Keyword),
Expand Down Expand Up @@ -294,7 +295,6 @@ def is_keyword(value):
'GRANTED': tokens.Keyword,
'GROUPING': tokens.Keyword,

'HANDLER': tokens.Keyword,
'HAVING': tokens.Keyword,
'HIERARCHY': tokens.Keyword,
'HOLD': tokens.Keyword,
Expand Down
10 changes: 10 additions & 0 deletions tests/files/mysql_handler.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
create procedure proc1()
begin
declare handler for foo begin end;
select 1;
end;

create procedure proc2()
begin
select 1;
end;
6 changes: 6 additions & 0 deletions tests/test_split.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,3 +154,9 @@ def test_split_quotes_with_new_line():
stmts = sqlparse.split("select 'foo\n\bar'")
assert len(stmts) == 1
assert stmts[0] == "select 'foo\n\bar'"


def test_split_mysql_handler_for(load_file):
# see issue581
stmts = sqlparse.split(load_file('mysql_handler.sql'))
assert len(stmts) == 2

0 comments on commit 990500a

Please sign in to comment.