python / python/cpython

sqlite3 completion fail on attached names with quotes

Open
#153,768 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

stdlib topic-sqlite3 type-bug
Dominant language
Python
Stars
77.2k
Forks
35.9k
PR merge metrics
PR metrics pending

Description

Bug report

Bug description:

Tab completion fails in sqlite3 when the name of an attached DB contains a quote.

Minimal code repro:

import sqlite3
from sqlite3._completer import _complete

con = sqlite3.connect(":memory:")
con.execute("""ATTACH ':memory:' AS [has"quote]""")
con.execute("""CREATE TABLE [has"quote].example_table(value)""")
print(_complete(con, "exam", 0)) # sqlite3.OperationalError: unrecognized token: "".sqlite_master
con.close()

Minimal CLI repro if you prefer:

(open the CLI)
>>> <python executable≥ -m sqlite3
(in CLI):
>>> ATTACH ':memory:' AS "has""quote";
>>> CREATE TABLE "has""quote".example_table(value);
>>> SELECT * FROM exam<press tab here and it doesn't work>
CPython versions tested on:

CPython main branch, 3.15

Operating systems tested on:

macOS

Linked PRs
  • gh-153770

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start at sqlite3._completer._complete and reproduce the failure with an attached database name containing a quote, using the Python or CLI example in the issue. Trace the completion path until the generated SQLite lookup fails. Done means tab completion succeeds for the quoted attached name without the unrecognized-token error.

Written by the indexing model from the issue text.

Assessment

Tech stack
python, sqlite
Domain
cli, database
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.