-
-
Notifications
You must be signed in to change notification settings - Fork 30.4k
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
Clarify how sqlite3 maps parameters onto placeholders #100668
Labels
Comments
See also #99953 |
We should not put too much details into the existing "placeholders how-to"; perhaps we could add a short explanation for how this stuff actually works. |
erlend-aasland
added a commit
that referenced
this issue
Jan 14, 2023
…0960) Co-authored-by: C.A.M. Gerlach <CAM.Gerlach@Gerlach.CAM>
miss-islington
pushed a commit
to miss-islington/cpython
that referenced
this issue
Jan 14, 2023
pythonGH-100960) (cherry picked from commit 206f05a) Co-authored-by: Erlend E. Aasland <erlend.aasland@protonmail.com> Co-authored-by: C.A.M. Gerlach <CAM.Gerlach@Gerlach.CAM>
This was referenced Jan 14, 2023
miss-islington
pushed a commit
to miss-islington/cpython
that referenced
this issue
Jan 14, 2023
pythonGH-100960) (cherry picked from commit 206f05a) Co-authored-by: Erlend E. Aasland <erlend.aasland@protonmail.com> Co-authored-by: C.A.M. Gerlach <CAM.Gerlach@Gerlach.CAM>
miss-islington
added a commit
that referenced
this issue
Jan 14, 2023
miss-islington
added a commit
that referenced
this issue
Jan 14, 2023
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Yes, we should definitely clarify how parameters are interpreted and mapped to the placeholders.
sqlite3
does not check if you use the "qmark" or "named" style (or any other style FWIW1); it only looks at the type of the params supplied:If a dict or dict subclass is supplied, the named style is assumed and you'll get an error if a named parameter is not provided by the supplied dict.
If an exact tuple, an exact list, or a sequence (that is not a dict or dict subclass) is supplied, the qmark style2 is assumed. This means that
sqlite3
iterates over the params and blindly assigns placeholder 13 the first item in the supplied sequence, and so on. This also happens if you use named placeholders and supply, for example, a list. Try it and be surprised. Now, that bug may be too old to be fixed; there's bound to be some code out there that depends on this exact bug. We might be able to introduce a warning and then change the behaviour after a few release cycles, but such a breaking change/bugfix will need a broader discussion.Originally posted by @erlend-aasland in #100630 (comment)
Linked PRs
Footnotes
try for example
cx.execute("select ?2, ?1", ['first', 'second'])
; the SQLite numeric style, which is not PEP-249-compatible, is accepted and correctly applied ↩called nameless in SQLite speak ↩
SQLite placeholders use one-based indices ↩
The text was updated successfully, but these errors were encountered: