One function

StatementSplitter in andialbrecht/sqlparse

The author described this change as Fix error when splitting statements that contain multiple CASE clauses within a BEGIN block (fixes #784).. It counts as a record because the check below fails on the code as it stood at 073099d96 and passes on 791e25de4, with nothing else changed between the two runs.

Fix saved2024-07-15
Sharing licenceBSD-3-Clause · LICENSE
Change size+8 5

What the code was meant to do, written into the code itself as a docstring

Filter that split stream at individual statements

The change

77 def _reset(self):
88 """Set the filter attributes to its default values"""
99 self._in_declare = False
10+ self._in_case = False
1011 self._is_create = False
1112 self._begin_depth = 0
1213
4849 return 1
4950 return 0
5051
51- # Should this respect a preceding BEGIN?
52- # In CASE ... WHEN ... END this results in a split level -1.
53- # Would having multiple CASE WHEN END and a Assignment Operator
54- # cause the statement to cut off prematurely?
52+ # BEGIN and CASE/WHEN both end with END
5553 if unified == 'END':
56- self._begin_depth = max(0, self._begin_depth - 1)
54+ if not self._in_case:
55+ self._begin_depth = max(0, self._begin_depth - 1)
56+ else:
57+ self._in_case = False
5758 return -1
5859
5960 if (unified in ('IF', 'FOR', 'WHILE', 'CASE')
6061 and self._is_create and self._begin_depth > 0):
62+ if unified == 'CASE':
63+ self._in_case = True
6164 return 1
6265
6366 if unified in ('END IF', 'END FOR', 'END WHILE'):

The check that tells the two apart

failpass·tests/test_split.py::test_split_multiple_case_in_begin

Check file tests/test_split.py, taken without changes from the fix and copied onto the older code, so the exact same check runs against both versions.

Origin and history

The code before it073099d963e904ca45817e85d10bd81bf2b4373a
Broken version dated2024-07-12
Modulesqlparse.engine.statement_splitter
Units changedStatementSplitter
Fingerprint5da0c7403f813402
Checked2026-08-18 by goldset/0.1

Every field above is generated by our program. None of it is written by hand.

Other bugs found in andialbrecht/sqlparse