diff options
| author | Andi Albrecht <albrecht.andi@gmail.com> | 2017-09-24 08:54:01 +0200 |
|---|---|---|
| committer | Andi Albrecht <albrecht.andi@gmail.com> | 2017-09-24 08:54:01 +0200 |
| commit | 097478e47fbc0423118f82a0a7b458c2e9dbea7b (patch) | |
| tree | 8223f37023fc85d96277b071c8a59cd667f44c54 | |
| parent | d7a290c43708b3a743472db34e0519159d8ee134 (diff) | |
| download | sqlparse-097478e47fbc0423118f82a0a7b458c2e9dbea7b.tar.gz | |
Fix handling of semicolon when grouping assignments (fixes #359).
When grouping assignments that contain a semicolon itself, the
engine was too greedy. Assignments with semicolon were introduced
in 691c0400e5a7d8229b7dce09bf47176539add328.
| -rw-r--r-- | CHANGELOG | 1 | ||||
| -rw-r--r-- | sqlparse/engine/grouping.py | 2 | ||||
| -rw-r--r-- | tests/test_regressions.py | 10 |
3 files changed, 12 insertions, 1 deletions
@@ -12,6 +12,7 @@ Bug Fixes * Fix parsing of MySQL table names starting with digits (issue337). * Fix detection of identifiers using comparisons (issue327). * Fix parsing of UNION ALL after WHERE (issue349). +* Fix handling of semicolon in assignments (issue359, issue358). diff --git a/sqlparse/engine/grouping.py b/sqlparse/engine/grouping.py index 6684c13..fa87c9f 100644 --- a/sqlparse/engine/grouping.py +++ b/sqlparse/engine/grouping.py @@ -134,7 +134,7 @@ def group_assignment(tlist): return token.match(T.Assignment, ':=') def valid(token): - return token is not None + return token is not None and token.ttype not in (T.Keyword) def post(tlist, pidx, tidx, nidx): m_semicolon = T.Punctuation, ';' diff --git a/tests/test_regressions.py b/tests/test_regressions.py index cc553c2..89828f0 100644 --- a/tests/test_regressions.py +++ b/tests/test_regressions.py @@ -356,3 +356,13 @@ def test_issue322_concurrently_is_keyword(): assert p.tokens[4].value == 'CONCURRENTLY' assert isinstance(p.tokens[6], sql.Identifier) assert p.tokens[6].value == 'myindex' + + +@pytest.mark.parametrize('s', [ + 'SELECT @min_price:=MIN(price), @max_price:=MAX(price) FROM shop;', + 'SELECT @min_price:=MIN(price), @max_price:=MAX(price) FROM shop', + +]) +def test_issue359_index_error_assignments(s): + sqlparse.parse(s) + sqlparse.format(s, strip_comments=True) |
