diff options
| author | Andi Albrecht <albrecht.andi@gmail.com> | 2015-07-28 20:24:06 +0200 |
|---|---|---|
| committer | Andi Albrecht <albrecht.andi@gmail.com> | 2015-07-28 20:24:06 +0200 |
| commit | 5d71c27e5194dfc8b8869f3170803e1d18bad6dc (patch) | |
| tree | 944522019decb4e54067efec4b2ec3c77ee8134b | |
| parent | 8987a3a6b540ea35bbb1f9c5f49f3306501289cd (diff) | |
| download | sqlparse-5d71c27e5194dfc8b8869f3170803e1d18bad6dc.tar.gz | |
Handle END IF correctly when splitting statements (fixes #194).
| -rw-r--r-- | CHANGES | 3 | ||||
| -rw-r--r-- | sqlparse/engine/filter.py | 3 | ||||
| -rw-r--r-- | tests/test_regressions.py | 13 |
3 files changed, 18 insertions, 1 deletions
@@ -1,7 +1,8 @@ Development Version ------------------- -Nothing yet. +Bug Fixes +* Fix another splitter bug regarding DECLARE (issue194). Release 0.1.16 (Jul 26, 2015) diff --git a/sqlparse/engine/filter.py b/sqlparse/engine/filter.py index e7ea0ec..f7dd264 100644 --- a/sqlparse/engine/filter.py +++ b/sqlparse/engine/filter.py @@ -51,6 +51,9 @@ class StatementFilter: return 1 return 0 + if unified in ('END IF', 'END FOR'): + return -1 + if unified == 'END': # Should this respect a preceeding BEGIN? # In CASE ... WHEN ... END this results in a split level -1. diff --git a/tests/test_regressions.py b/tests/test_regressions.py index ea8cd56..a64b400 100644 --- a/tests/test_regressions.py +++ b/tests/test_regressions.py @@ -256,6 +256,19 @@ SELECT * FROM a.b;""" splitted = sqlparse.split(sql) assert len(splitted) == 2 +def test_issue194_splitting_function(): + sql = """CREATE FUNCTION a(x VARCHAR(20)) RETURNS VARCHAR(20) +BEGIN + DECLARE y VARCHAR(20); + IF (1 = 1) THEN + SET x = y; + END IF; + RETURN x; +END; +SELECT * FROM a.b;""" + splitted = sqlparse.split(sql) + assert len(splitted) == 2 + def test_issue186_get_type(): sql = "-- comment\ninsert into foo" |
