Skip to content

sqlite3.Connection.iterdump() fails for a table name containing a single quote #153658

Description

@tonghuaroot

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

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions