From 5d71c27e5194dfc8b8869f3170803e1d18bad6dc Mon Sep 17 00:00:00 2001 From: Andi Albrecht Date: Tue, 28 Jul 2015 20:24:06 +0200 Subject: Handle END IF correctly when splitting statements (fixes #194). --- CHANGES | 3 ++- sqlparse/engine/filter.py | 3 +++ tests/test_regressions.py | 13 +++++++++++++ 3 files changed, 18 insertions(+), 1 deletion(-) diff --git a/CHANGES b/CHANGES index 0c29db4..b6f8de6 100644 --- a/CHANGES +++ b/CHANGES @@ -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" -- cgit v1.2.1