Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
erlend-aasland opened this issue Feb 8, 2023 · 0 comments
Assignees
Labels
topic-sqlite3 type-feature A feature request or enhancement

Comments

@erlend-aasland
Copy link
Contributor

erlend-aasland commented Feb 8, 2023

(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

@erlend-aasland erlend-aasland converted this from a draft issue Feb 8, 2023
@erlend-aasland erlend-aasland self-assigned this Feb 8, 2023
@erlend-aasland erlend-aasland added type-feature A feature request or enhancement topic-sqlite3 labels Feb 8, 2023
@erlend-aasland erlend-aasland moved this from TODO: Feature to In Progress in sqlite3 issues Feb 8, 2023
erlend-aasland added a commit that referenced this issue Feb 15, 2023
@github-project-automation github-project-automation bot moved this from In Progress to Done in sqlite3 issues Feb 15, 2023
erlend-aasland added a commit to erlend-aasland/cpython that referenced this issue May 10, 2024
erlend-aasland added a commit that referenced this issue May 14, 2024
…ers (#118929)

Follow-up of gh-101693. The previous DeprecationWarning is replaced with 
raising sqlite3.ProgrammingError.

Co-authored-by: Hugo van Kemenade <[email protected]>
estyxx pushed a commit to estyxx/cpython that referenced this issue Jul 17, 2024
…ceholders (python#118929)

Follow-up of pythongh-101693. The previous DeprecationWarning is replaced with 
raising sqlite3.ProgrammingError.

Co-authored-by: Hugo van Kemenade <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
topic-sqlite3 type-feature A feature request or enhancement
Projects
Status: Done
Development

No branches or pull requests

1 participant