diff options
| -rw-r--r-- | CHANGELOG | 1 | ||||
| -rw-r--r-- | sqlparse/engine/statement_splitter.py | 2 | ||||
| -rw-r--r-- | tests/files/casewhen_procedure.sql | 8 | ||||
| -rw-r--r-- | tests/test_split.py | 6 |
4 files changed, 16 insertions, 1 deletions
@@ -22,6 +22,7 @@ Bug Fixes * Preserve line breaks when removing comments (issue484). * Fix parsing error when using square bracket notation (issue583). * Fix splitting when using DECLARE ... HANDLER (issue581). +* Fix splitting of statements using CASE ... WHEN (issue580). Release 0.3.1 (Feb 29, 2020) diff --git a/sqlparse/engine/statement_splitter.py b/sqlparse/engine/statement_splitter.py index 40cfec3..afe53d0 100644 --- a/sqlparse/engine/statement_splitter.py +++ b/sqlparse/engine/statement_splitter.py @@ -66,7 +66,7 @@ class StatementSplitter: self._begin_depth = max(0, self._begin_depth - 1) return -1 - if (unified in ('IF', 'FOR', 'WHILE') + if (unified in ('IF', 'FOR', 'WHILE', 'CASE') and self._is_create and self._begin_depth > 0): return 1 diff --git a/tests/files/casewhen_procedure.sql b/tests/files/casewhen_procedure.sql new file mode 100644 index 0000000..e590d49 --- /dev/null +++ b/tests/files/casewhen_procedure.sql @@ -0,0 +1,8 @@ +create procedure procName() +begin + select case when column = 'value' then column else 0 end; +end; +create procedure procName() +begin + select 1; +end; diff --git a/tests/test_split.py b/tests/test_split.py index f69e3d2..a9d7576 100644 --- a/tests/test_split.py +++ b/tests/test_split.py @@ -97,6 +97,12 @@ def test_split_casewhen(): assert len(stmts) == 2 +def test_split_casewhen_procedure(load_file): + # see issue580 + stmts = sqlparse.split(load_file('casewhen_procedure.sql')) + assert len(stmts) == 2 + + def test_split_cursor_declare(): sql = ('DECLARE CURSOR "foo" AS SELECT 1;\n' 'SELECT 2;') |
