Use quote_identifier() in indexes/xindexes PRAGMA statements - #825
Open
nyxst4ck wants to merge 1 commit into
Open
Use quote_identifier() in indexes/xindexes PRAGMA statements#825nyxst4ck wants to merge 1 commit into
nyxst4ck wants to merge 1 commit into
Conversation
The four PRAGMA sites in Table.indexes and Table.xindexes kept naive f-string quoting after the simonw#678 migration, so identifiers containing a double quote produced malformed SQL and OperationalError — cascading into transform(), drop_index() and Database.create. Closes simonw#824
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.
Refs #824.
Table.indexesandTable.xindexeswere the four remaining sites still using naive f-string quoting after the #678 migration (fb93452):PRAGMA index_list("{self.name}")never doubles an embedded", and the index name was wrapped by a pre-2019 heuristic (startswith('"')) with the same flaw. Any identifier containing a double quote produced malformed SQL →sqlite3.OperationalError, and sinceself.indexesfeedstransform(),drop_index()andDatabase.create,transform()failed outright for such tables — reachable from ordinary CSV/JSON imports whose headers contain quotes.Change
All four sites now use the project's own
quote_identifier()(already used 103 times elsewhere indb.py, including the neighbouringPRAGMA table_info/PRAGMA foreign_key_list). Net −6 lines.Tests
Two regression tests in
tests/test_introspect.py, placed after the existingtest_indexes/test_xindexesand following their assertion style:test_indexes_with_double_quotes_in_identifiers— pins both properties on a table namedGo"shwith an index on columnc"1test_transform_table_with_double_quotes_in_identifiers— pins thetransform()cascade so a regression in either property is caughtRed on main (both fail with
OperationalError: near "sh": syntax error), green with the fix. Full suite: 1370 passed → 1372 passed, 20 skipped, nothing regressed.black --checkclean.📚 Documentation preview 📚: https://sqlite-utils--825.org.readthedocs.build/en/825/