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.

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

4747 next_token = next(tokens, None)
4848 count_parenthesis = 0 if first_token != "(" else 1
4949 count_square_brackets = 0 if first_token != "[" else 1
50+ count_case_expr = 0 if first_token != "case" else 1
5051 while next_token is not None and not (
5152 lower(next_token) in stop_words
5253 and count_parenthesis <= 0
5354 and count_square_brackets <= 0
55+ and count_case_expr <= 0
5456 and (
5557 not argument_tokens
5658 or (lower(argument_tokens[-1]), lower(next_token)) not in keep
6567 count_square_brackets += 1
6668 elif next_token == "]":
6769 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
6874 next_token = next(tokens, None)
6975
7076 return argument_tokens, next_token

The check that tells the two apart

failpass·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