Skip to content

Commit 5d71c27

Browse files
committed
Handle END IF correctly when splitting statements (fixes andialbrecht#194).
1 parent 8987a3a commit 5d71c27

3 files changed

Lines changed: 18 additions & 1 deletion

File tree

CHANGES

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
Development Version
22
-------------------
33

4-
Nothing yet.
4+
Bug Fixes
5+
* Fix another splitter bug regarding DECLARE (issue194).
56

67

78
Release 0.1.16 (Jul 26, 2015)

sqlparse/engine/filter.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,9 @@ def _change_splitlevel(self, ttype, value):
5151
return 1
5252
return 0
5353

54+
if unified in ('END IF', 'END FOR'):
55+
return -1
56+
5457
if unified == 'END':
5558
# Should this respect a preceeding BEGIN?
5659
# In CASE ... WHEN ... END this results in a split level -1.

tests/test_regressions.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,19 @@ def test_issue193_splitting_function():
256256
splitted = sqlparse.split(sql)
257257
assert len(splitted) == 2
258258

259+
def test_issue194_splitting_function():
260+
sql = """CREATE FUNCTION a(x VARCHAR(20)) RETURNS VARCHAR(20)
261+
BEGIN
262+
DECLARE y VARCHAR(20);
263+
IF (1 = 1) THEN
264+
SET x = y;
265+
END IF;
266+
RETURN x;
267+
END;
268+
SELECT * FROM a.b;"""
269+
splitted = sqlparse.split(sql)
270+
assert len(splitted) == 2
271+
259272

260273
def test_issue186_get_type():
261274
sql = "-- comment\ninsert into foo"

0 commit comments

Comments
 (0)