mirror of https://github.com/python/cpython.git
gh-100668: Clarify how sqlite3 maps parameters onto placeholders (#100960)
Co-authored-by: C.A.M. Gerlach <CAM.Gerlach@Gerlach.CAM>
This commit is contained in:
parent
124af17b6e
commit
206f05a46b
|
@ -1940,15 +1940,18 @@ close the single quote and inject ``OR TRUE`` to select all rows::
|
||||||
Instead, use the DB-API's parameter substitution. To insert a variable into a
|
Instead, use the DB-API's parameter substitution. To insert a variable into a
|
||||||
query string, use a placeholder in the string, and substitute the actual values
|
query string, use a placeholder in the string, and substitute the actual values
|
||||||
into the query by providing them as a :class:`tuple` of values to the second
|
into the query by providing them as a :class:`tuple` of values to the second
|
||||||
argument of the cursor's :meth:`~Cursor.execute` method. An SQL statement may
|
argument of the cursor's :meth:`~Cursor.execute` method.
|
||||||
use one of two kinds of placeholders: question marks (qmark style) or named
|
|
||||||
placeholders (named style). For the qmark style, ``parameters`` must be a
|
An SQL statement may use one of two kinds of placeholders:
|
||||||
:term:`sequence <sequence>`. For the named style, it can be either a
|
question marks (qmark style) or named placeholders (named style).
|
||||||
:term:`sequence <sequence>` or :class:`dict` instance. The length of the
|
For the qmark style, *parameters* must be a
|
||||||
:term:`sequence <sequence>` must match the number of placeholders, or a
|
:term:`sequence` whose length must match the number of placeholders,
|
||||||
:exc:`ProgrammingError` is raised. If a :class:`dict` is given, it must contain
|
or a :exc:`ProgrammingError` is raised.
|
||||||
keys for all named parameters. Any extra items are ignored. Here's an example of
|
For the named style, *parameters* should be
|
||||||
both styles:
|
an instance of a :class:`dict` (or a subclass),
|
||||||
|
which must contain keys for all named parameters;
|
||||||
|
any extra items are ignored.
|
||||||
|
Here's an example of both styles:
|
||||||
|
|
||||||
.. testcode::
|
.. testcode::
|
||||||
|
|
||||||
|
@ -1975,6 +1978,11 @@ both styles:
|
||||||
|
|
||||||
[('C', 1972)]
|
[('C', 1972)]
|
||||||
|
|
||||||
|
.. note::
|
||||||
|
|
||||||
|
:pep:`249` numeric placeholders are *not* supported.
|
||||||
|
If used, they will be interpreted as named placeholders.
|
||||||
|
|
||||||
|
|
||||||
.. _sqlite3-adapters:
|
.. _sqlite3-adapters:
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue