Skip to content

Commit d7b1ee3

Browse files
committed
Fix splitting of statements using CASE ... WHEN (fixes andialbrecht#580).
1 parent 990500a commit d7b1ee3

File tree

4 files changed

+16
-1
lines changed

4 files changed

+16
-1
lines changed

CHANGELOG

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ Bug Fixes
2222
* Preserve line breaks when removing comments (issue484).
2323
* Fix parsing error when using square bracket notation (issue583).
2424
* Fix splitting when using DECLARE ... HANDLER (issue581).
25+
* Fix splitting of statements using CASE ... WHEN (issue580).
2526

2627

2728
Release 0.3.1 (Feb 29, 2020)

sqlparse/engine/statement_splitter.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ def _change_splitlevel(self, ttype, value):
6666
self._begin_depth = max(0, self._begin_depth - 1)
6767
return -1
6868

69-
if (unified in ('IF', 'FOR', 'WHILE')
69+
if (unified in ('IF', 'FOR', 'WHILE', 'CASE')
7070
and self._is_create and self._begin_depth > 0):
7171
return 1
7272

tests/files/casewhen_procedure.sql

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
create procedure procName()
2+
begin
3+
select case when column = 'value' then column else 0 end;
4+
end;
5+
create procedure procName()
6+
begin
7+
select 1;
8+
end;

tests/test_split.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,12 @@ def test_split_casewhen():
9797
assert len(stmts) == 2
9898

9999

100+
def test_split_casewhen_procedure(load_file):
101+
# see issue580
102+
stmts = sqlparse.split(load_file('casewhen_procedure.sql'))
103+
assert len(stmts) == 2
104+
105+
100106
def test_split_cursor_declare():
101107
sql = ('DECLARE CURSOR "foo" AS SELECT 1;\n'
102108
'SELECT 2;')

0 commit comments

Comments
 (0)