Skip to content

Commit 990500a

Browse files
committed
Fix splitting when using DECLARE ... HANDLER (fixes andialbrecht#581).
1 parent cd4a723 commit 990500a

File tree

4 files changed

+18
-1
lines changed

4 files changed

+18
-1
lines changed

CHANGELOG

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ Bug Fixes
2121
* Improved parsing of IN(...) statements (issue566, pr567 by hurcy).
2222
* Preserve line breaks when removing comments (issue484).
2323
* Fix parsing error when using square bracket notation (issue583).
24+
* Fix splitting when using DECLARE ... HANDLER (issue581).
2425

2526

2627
Release 0.3.1 (Feb 29, 2020)

sqlparse/keywords.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ def is_keyword(value):
8484
(r'DOUBLE\s+PRECISION\b', tokens.Name.Builtin),
8585
(r'GROUP\s+BY\b', tokens.Keyword),
8686
(r'ORDER\s+BY\b', tokens.Keyword),
87+
(r'HANDLER\s+FOR\b', tokens.Keyword),
8788
(r'(LATERAL\s+VIEW\s+)'
8889
r'(EXPLODE|INLINE|PARSE_URL_TUPLE|POSEXPLODE|STACK)\b',
8990
tokens.Keyword),
@@ -294,7 +295,6 @@ def is_keyword(value):
294295
'GRANTED': tokens.Keyword,
295296
'GROUPING': tokens.Keyword,
296297

297-
'HANDLER': tokens.Keyword,
298298
'HAVING': tokens.Keyword,
299299
'HIERARCHY': tokens.Keyword,
300300
'HOLD': tokens.Keyword,

tests/files/mysql_handler.sql

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
create procedure proc1()
2+
begin
3+
declare handler for foo begin end;
4+
select 1;
5+
end;
6+
7+
create procedure proc2()
8+
begin
9+
select 1;
10+
end;

tests/test_split.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,3 +154,9 @@ def test_split_quotes_with_new_line():
154154
stmts = sqlparse.split("select 'foo\n\bar'")
155155
assert len(stmts) == 1
156156
assert stmts[0] == "select 'foo\n\bar'"
157+
158+
159+
def test_split_mysql_handler_for(load_file):
160+
# see issue581
161+
stmts = sqlparse.split(load_file('mysql_handler.sql'))
162+
assert len(stmts) == 2

0 commit comments

Comments
 (0)