You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Clarify how sqlite3 maps parameters onto placeholders #100668
agree; you might want to clarify though that the use of "qmark" or "named" is detected automatically on a per-statement basis (provided my understanding of that is correct).
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.
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 ↩
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.
Activity
erlend-aasland commentedon Jan 1, 2023
See also #99953
pythongh-100668: Clarify how sqlite3 maps parameters onto placeholders
erlend-aasland commentedon Jan 11, 2023
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.
gh-100668: Clarify how sqlite3 maps parameters onto placeholders (#10…
pythongh-100668: Clarify how sqlite3 maps parameters onto placeholders (
pythongh-100668: Clarify how sqlite3 maps parameters onto placeholders (
gh-100668: Clarify how sqlite3 maps parameters onto placeholders (GH-…
gh-100668: Clarify how sqlite3 maps parameters onto placeholders (GH-…