Skip to content

sqlite3: issue a warning if a sequence of params are used with named placeholders in queries #101693

Closed

Description

@erlend-aasland

(See Discourse topic.)

Per now, it is possible to supply a sequence of params to queries with named placeholders:

>>> cx.execute("select :name", [42]).fetchall()
[(42,)]
>>> cx.execute("select :other", [42]).fetchall()
[(42,)]

This may result in unexpected results if a user misuse the sqlite3 module and use PEP-249 style numeric placeholders:

>>> cx.execute("select :1", ("first",)).fetchall()
[('first',)]
>>> cx.execute("select :1, :2", ("first", "second")).fetchall()
[('first', 'second')]
>>> cx.execute("select :2, :1", ("first", "second")).fetchall()  # Unexpected result follows
[('first', 'second')]

PEP-249 style numeric placeholders are not supported by sqlite3; it only supports PEP-249 style named placeholders and PEP-249 style qmark placeholders, so the placeholders in the above example are interpreted as named, not numeric, placeholders.

Based on the discussion in the above linked Discourse topic, I propose to now issue a deprecation warning if sequences are used with named placeholders. The deprecation warning should inform that from Python 3.14 and onward, sqlite3.ProgrammingError will be raised instead.

Linked PRs

Activity

  1. converted this from a draft issue on Feb 8, 2023
  2. moved this from TODO: Feature to In Progress in sqlite3 issueson Feb 8, 2023
  3. added a commit that references this issue on Feb 15, 2023
  4. moved this from In Progress to Done in sqlite3 issueson Feb 15, 2023
  5. added 2 commits that reference this issue on May 10, 2024
  6. added a commit that references this issue on Jul 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions