Whole file
David-Wobrock/sqlvalidator
The author described this change as “Fix #38 -- Handle nested case expressions”. It counts as a record because the check below fails on the code as it stood at 2827c2a16 and passes on 581435475, with nothing else changed between the two runs.
ProjectDavid-Wobrock/sqlvalidator
Fix saved2022-04-15
Sharing licenceMIT · LICENSE
Change size+6 −0
What the code was meant to do, written into the code itself as a save note
Fix #38 -- Handle nested case expressions
The change
| 47 | 47 | next_token = next(tokens, None) | |
| 48 | 48 | count_parenthesis = 0 if first_token != "(" else 1 | |
| 49 | 49 | count_square_brackets = 0 if first_token != "[" else 1 | |
| 50 | + | count_case_expr = 0 if first_token != "case" else 1 | |
| 50 | 51 | while next_token is not None and not ( | |
| 51 | 52 | lower(next_token) in stop_words | |
| 52 | 53 | and count_parenthesis <= 0 | |
| 53 | 54 | and count_square_brackets <= 0 | |
| 55 | + | and count_case_expr <= 0 | |
| 54 | 56 | and ( | |
| 55 | 57 | not argument_tokens | |
| 56 | 58 | or (lower(argument_tokens[-1]), lower(next_token)) not in keep | |
| ⋯ | |||
| 65 | 67 | count_square_brackets += 1 | |
| 66 | 68 | elif next_token == "]": | |
| 67 | 69 | count_square_brackets -= 1 | |
| 70 | + | elif lower(next_token) == "case": | |
| 71 | + | count_case_expr += 1 | |
| 72 | + | elif lower(next_token) == "end": | |
| 73 | + | count_case_expr -= 1 | |
| 68 | 74 | next_token = next(tokens, None) | |
| 69 | 75 | ||
| 70 | 76 | return argument_tokens, next_token | |
The check that tells the two apart
fail→pass·tests/integration/test_formatting.py::test_nesting_case_expr
Check file tests/integration/test_formatting.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 it2827c2a16d0dbfeba6b90fb2e8ee2bdacc6d0286
Broken version dated2022-04-15
Modulesqlvalidator.grammar.tokeniser
Units changedget_tokens_until_one_of
Fingerprint45a891374bb0814d
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 David-Wobrock/sqlvalidator
- 2021-12-22Fix #29 -- Handle strings containing others quotes
- 2021-12-22Fix #35 -- Handle index based access on function call
- 2021-12-22Fix #34 -- Handle parsing a function with a single comma string
- 2021-11-15Fix validating between predicate conditions
- 2021-11-15Fix handling Any return type as invalid WHERE/HAVING condition
- 2021-11-14Fix Alias.known_fields for aliased subqueries with specific fields