Skip to content

Commit 097478e

Browse files
committed
Fix handling of semicolon when grouping assignments (fixes andialbrecht#359).
When grouping assignments that contain a semicolon itself, the engine was too greedy. Assignments with semicolon were introduced in 691c040.
1 parent d7a290c commit 097478e

3 files changed

Lines changed: 12 additions & 1 deletion

File tree

CHANGELOG

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ Bug Fixes
1212
* Fix parsing of MySQL table names starting with digits (issue337).
1313
* Fix detection of identifiers using comparisons (issue327).
1414
* Fix parsing of UNION ALL after WHERE (issue349).
15+
* Fix handling of semicolon in assignments (issue359, issue358).
1516

1617

1718

sqlparse/engine/grouping.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ def match(token):
134134
return token.match(T.Assignment, ':=')
135135

136136
def valid(token):
137-
return token is not None
137+
return token is not None and token.ttype not in (T.Keyword)
138138

139139
def post(tlist, pidx, tidx, nidx):
140140
m_semicolon = T.Punctuation, ';'

tests/test_regressions.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -356,3 +356,13 @@ def test_issue322_concurrently_is_keyword():
356356
assert p.tokens[4].value == 'CONCURRENTLY'
357357
assert isinstance(p.tokens[6], sql.Identifier)
358358
assert p.tokens[6].value == 'myindex'
359+
360+
361+
@pytest.mark.parametrize('s', [
362+
'SELECT @min_price:=MIN(price), @max_price:=MAX(price) FROM shop;',
363+
'SELECT @min_price:=MIN(price), @max_price:=MAX(price) FROM shop',
364+
365+
])
366+
def test_issue359_index_error_assignments(s):
367+
sqlparse.parse(s)
368+
sqlparse.format(s, strip_comments=True)

0 commit comments

Comments
 (0)