Skip to content

Use quote_identifier() in indexes/xindexes PRAGMA statements - #825

Open
nyxst4ck wants to merge 1 commit into
simonw:mainfrom
nyxst4ck:quote-identifiers-in-index-pragmas
Open

Use quote_identifier() in indexes/xindexes PRAGMA statements#825
nyxst4ck wants to merge 1 commit into
simonw:mainfrom
nyxst4ck:quote-identifiers-in-index-pragmas

Conversation

@nyxst4ck

@nyxst4ck nyxst4ck commented Aug 5, 2026

Copy link
Copy Markdown

Refs #824.

Table.indexes and Table.xindexes were 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 since self.indexes feeds transform(), drop_index() and Database.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 in db.py, including the neighbouring PRAGMA table_info / PRAGMA foreign_key_list). Net −6 lines.

Tests

Two regression tests in tests/test_introspect.py, placed after the existing test_indexes/test_xindexes and following their assertion style:

  • test_indexes_with_double_quotes_in_identifiers — pins both properties on a table named Go"sh with an index on column c"1
  • test_transform_table_with_double_quotes_in_identifiers — pins the transform() cascade so a regression in either property is caught

Red 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 --check clean.


📚 Documentation preview 📚: https://sqlite-utils--825.org.readthedocs.build/en/825/

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant