Skip to content

Commit

Permalink
Don't treat DECLARE within BEGIN blocks as relevant to split level (f…
Browse files Browse the repository at this point in the history
…ixes #193).
  • Loading branch information
andialbrecht committed Jul 26, 2015
1 parent d9b717a commit 621e1d8
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGES
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ Development version

Bug Fixes
* Fix a regression in get_alias() introduced in 0.1.15 (issue185).
* Fix a bug in the splitter regarding DECLARE (issue193).


Release 0.1.15 (Apr 15, 2015)
Expand Down
2 changes: 1 addition & 1 deletion sqlparse/engine/filter.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def _change_splitlevel(self, ttype, value):

unified = value.upper()

if unified == 'DECLARE' and self._is_create:
if unified == 'DECLARE' and self._is_create and self._begin_depth == 0:
self._in_declare = True
return 1

Expand Down
13 changes: 12 additions & 1 deletion tests/test_regressions.py
Original file line number Diff line number Diff line change
Expand Up @@ -243,4 +243,15 @@ def test_null_with_as():
' NULL AS c2',
'FROM t1'
])
assert formatted == tformatted
assert formatted == tformatted


def test_issue193_splitting_function():
sql = """CREATE FUNCTION a(x VARCHAR(20)) RETURNS VARCHAR(20)
BEGIN
DECLARE y VARCHAR(20);
RETURN x;
END;
SELECT * FROM a.b;"""
splitted = sqlparse.split(sql)
assert len(splitted) == 2

0 comments on commit 621e1d8

Please sign in to comment.