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.
Projectandialbrecht/sqlparse
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
| 7 | 7 | def _reset(self): | |
| 8 | 8 | """Set the filter attributes to its default values""" | |
| 9 | 9 | self._in_declare = False | |
| 10 | + | self._in_case = False | |
| 10 | 11 | self._is_create = False | |
| 11 | 12 | self._begin_depth = 0 | |
| 12 | 13 | ||
| ⋯ | |||
| 48 | 49 | return 1 | |
| 49 | 50 | return 0 | |
| 50 | 51 | ||
| 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 | |
| 55 | 53 | 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 | |
| 57 | 58 | return -1 | |
| 58 | 59 | ||
| 59 | 60 | if (unified in ('IF', 'FOR', 'WHILE', 'CASE') | |
| 60 | 61 | and self._is_create and self._begin_depth > 0): | |
| 62 | + | if unified == 'CASE': | |
| 63 | + | self._in_case = True | |
| 61 | 64 | return 1 | |
| 62 | 65 | ||
| 63 | 66 | if unified in ('END IF', 'END FOR', 'END WHILE'): | |
The check that tells the two apart
fail→pass·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
- 2026-07-25Fix get_real_name for names with more than two dotted parts (#332)
- 2026-07-22Fix function grouping skipped for lowercase 'as' in CREATE TABLE AS SELECT
- 2025-11-29StatementSplitter
- 2025-11-28StatementSplitter
- 2024-04-13Raise SQLParseError instead of RecursionError.
- 2024-04-13Fix Function.get_parameters(), add Funtion.get_window()