Stabilize formatting of invalid WHERE clauses.

This commit is contained in:
Andi Albrecht 2020-09-30 15:39:54 +02:00
parent f578d03ef7
commit 11a6b7db8b
3 changed files with 10 additions and 0 deletions

View File

@ -24,6 +24,7 @@ Bug Fixes
* Fix splitting when using DECLARE ... HANDLER (issue581).
* Fix splitting of statements using CASE ... WHEN (issue580).
* Improve formatting of type casts in parentheses.
* Stabilize formatting of invalid SQL statements.
Release 0.3.1 (Feb 29, 2020)

View File

@ -102,7 +102,10 @@ class ReindentFilter:
def _process_where(self, tlist):
tidx, token = tlist.token_next_by(m=(T.Keyword, 'WHERE'))
if not token:
return
# issue121, errors in statement fixed??
print(tidx, token, tlist)
tlist.insert_before(tidx, self.nl())
with indent(self):

View File

@ -405,3 +405,9 @@ def test_as_in_parentheses_indents():
# did raise NoneType has no attribute is_group in _process_parentheses
formatted = sqlparse.format('(as foo)', reindent=True)
assert formatted == '(as foo)'
def test_format_invalid_where_clause():
# did raise ValueError
formatted = sqlparse.format('where, foo', reindent=True)
assert formatted == 'where, foo'