Treat the GO batch separator case-insensitively when splitting - #882
Open
Gares95 wants to merge 1 commit into
Open
Treat the GO batch separator case-insensitively when splitting#882Gares95 wants to merge 1 commit into
Gares95 wants to merge 1 commit into
Conversation
The lexer compiles every pattern with re.IGNORECASE, and is_keyword uppercases only for the dictionary lookup and returns the original spelling, so a lowercase "go" reaches the splitter as (T.Keyword, 'go'). StatementSplitter.process compared that raw value against 'GO', so lowercase and mixed-case batch separators did not split and their batches were merged into the following statement. Every other keyword comparison in the class normalises through value.upper(). This makes that one consistent, and adds case-varied parameters to test_split_go.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
sqlparse.split()only recognises the T-SQL batch separator when it is writtenin uppercase. A script using the equally valid lowercase
gohas its batchesmerged instead of separated.
GO 2behaves the same way: it splits, whilego 2does not.The cause is in
StatementSplitter.process, which compares the raw token valueagainst an uppercase literal:
The lexer compiles every pattern with
re.IGNORECASEandis_keyworduppercasesonly for the dictionary lookup, returning the original spelling, so
goarrivesas
(T.Keyword, 'go')and the comparison fails. Every other keyword comparisonin this class already normalises through
unified = value.upper(); this is theone place that does not.
The fix matches that existing convention:
Tests:
test_split_gois extended with lowercase and mixed-case spellings ofboth
GOandGO 2, so the separator is pinned as case-insensitive.Validation: the suite is
506 passed, 2 xfailed, 1 xpassedbefore the changeand
510 passed, 2 xfailed, 1 xpassedafter it, the four extra cases being thenew parameters.
ruff check sqlparse/passes. After the fix all ofGO,go,Go,gO,GO 2andgo 2split identically.