Bug report
Bug description:
sqlite3.Connection.iterdump() raises sqlite3.OperationalError instead of
producing a dump when a table (or column) name contains a single quote, even
though such names are valid SQLite identifiers.
import sqlite3 con = sqlite3.connect(":memory:") con.execute("""CREATE TABLE "a'b" (x)""") con.execute("""INSERT INTO "a'b" VALUES (1)""") list(con.iterdump())
This raises:
sqlite3.OperationalError: near "'": syntax error
The generated INSERT statements are built by embedding the double-quoted
table name inside a single-quoted SQL string literal. The name is quoted
correctly as an identifier for the FROM clause, but its single quotes are
not doubled for the string-literal copy, so a name containing ' produces
broken SQL. Names containing a double quote or a newline are already handled.
The dump should keep round-tripping: a name containing ' must be emitted so
the dump can be replayed with executescript().
CPython versions tested on:
CPython main branch
Operating systems tested on:
macOS
Linked PRs
- gh-153658: Fix sqlite3 iterdump() for table names containing a single quote #153659
- gh-153658: sqlite3.Connection.iterdump() fails for names with single quote #153666
- [3.15] gh-153658: Fix sqlite3 iterdump() for table names containing a single quote (GH-153659) #153682
- [3.14] gh-153658: Fix sqlite3 iterdump() for table names containing a single quote (GH-153659) #153683
- [3.13] gh-153658: Fix sqlite3 iterdump() for table names containing a single quote (GH-153659) #153684