You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
sqlite3: _completer raises OperationalError when an attached database name contains a double quote #158215
In Lib/sqlite3/_completer.py, the schema name from PRAGMA database_list
is interpolated directly into an SQL string:
SELECT name || ' ' FROM \"{schema}\".sqlite_master
If a user attaches a database whose name contains a double quote, the
resulting SQL is invalid and _complete() raises OperationalError instead
of returning completion matches.
Reproduction:
import sqlite3
from sqlite3 import _completer
con = sqlite3.connect(':memory:')
con.execute('ATTACH DATABASE \':memory:\' AS \'weird"name\'')
_completer._complete(con, 'a', 0)
Output:
OperationalError unrecognized token: "".sqlite_master
WHERE name LIKE REPLACE(:text, '_', '^_') || '%' ESCAPE '^'"
The same problem exists in the column-completion query:
JOIN pragma_table_xinfo(sm.name,'{schema}') AS pti
Suggested fix: quote the schema name as an SQL identifier, replacing
embedded double quotes with two double quotes.
Discovered while reviewing the module with an AI assistant.
Activity
pythongh-158215: Fix sqlite3 completer for schema names with a double…