diff options
| -rw-r--r-- | CHANGELOG | 5 | ||||
| -rw-r--r-- | sqlparse/engine/statement_splitter.py | 2 | ||||
| -rw-r--r-- | tests/test_grouping.py | 4 | ||||
| -rw-r--r-- | tests/test_split.py | 7 |
4 files changed, 13 insertions, 5 deletions
@@ -5,6 +5,11 @@ Notable Changes * Remove support for end-of-life Python 2.7 and 3.4. Python 3.5+ is now required. +* Remaining strings that only consist of whitespaces are not treated as + statements anymore. Code that ignored the last element from + sqlparse.split() should be updated accordingly since that function + now doesn't return an empty string as the last element in some + cases (issue496). Bug Fixes diff --git a/sqlparse/engine/statement_splitter.py b/sqlparse/engine/statement_splitter.py index fb22c65..40cfec3 100644 --- a/sqlparse/engine/statement_splitter.py +++ b/sqlparse/engine/statement_splitter.py @@ -103,5 +103,5 @@ class StatementSplitter: self.consume_ws = True # Yield pending statement (if any) - if self.tokens: + if self.tokens and not all(t.is_whitespace for t in self.tokens): yield sql.Statement(self.tokens) diff --git a/tests/test_grouping.py b/tests/test_grouping.py index 879ba29..cf629e9 100644 --- a/tests/test_grouping.py +++ b/tests/test_grouping.py @@ -399,10 +399,6 @@ def test_statement_get_type(): assert f(' update foo').get_type() == 'UPDATE' assert f('\nupdate foo').get_type() == 'UPDATE' assert f('foo').get_type() == 'UNKNOWN' - # Statements that have a whitespace after the closing semicolon - # are parsed as two statements where later only consists of the - # trailing whitespace. - assert f('\n').get_type() == 'UNKNOWN' def test_identifier_with_operators(): diff --git a/tests/test_split.py b/tests/test_split.py index 8214756..c073298 100644 --- a/tests/test_split.py +++ b/tests/test_split.py @@ -139,6 +139,13 @@ def test_split_simple(): assert stmts[1] == 'select * from bar;' +def test_split_ignores_empty_newlines(): + stmts = sqlparse.split('select foo;\nselect bar;\n') + assert len(stmts) == 2 + assert stmts[0] == 'select foo;' + assert stmts[1] == 'select bar;' + + def test_split_quotes_with_new_line(): stmts = sqlparse.split('select "foo\nbar"') assert len(stmts) == 1 |
