Skip to content

Commit 1981db9

Browse files
miss-islingtonerlend-aaslandCAM-Gerlach
authored
gh-100668: Clarify how sqlite3 maps parameters onto placeholders (GH-100960)
(cherry picked from commit 206f05a) Co-authored-by: Erlend E. Aasland <[email protected]> Co-authored-by: C.A.M. Gerlach <[email protected]>
1 parent 94f9198 commit 1981db9

File tree

1 file changed

+17
-9
lines changed

1 file changed

+17
-9
lines changed

Doc/library/sqlite3.rst

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1437,15 +1437,18 @@ close the single quote and inject ``OR TRUE`` to select all rows::
14371437
Instead, use the DB-API's parameter substitution. To insert a variable into a
14381438
query string, use a placeholder in the string, and substitute the actual values
14391439
into the query by providing them as a :class:`tuple` of values to the second
1440-
argument of the cursor's :meth:`~Cursor.execute` method. An SQL statement may
1441-
use one of two kinds of placeholders: question marks (qmark style) or named
1442-
placeholders (named style). For the qmark style, ``parameters`` must be a
1443-
:term:`sequence <sequence>`. For the named style, it can be either a
1444-
:term:`sequence <sequence>` or :class:`dict` instance. The length of the
1445-
:term:`sequence <sequence>` must match the number of placeholders, or a
1446-
:exc:`ProgrammingError` is raised. If a :class:`dict` is given, it must contain
1447-
keys for all named parameters. Any extra items are ignored. Here's an example of
1448-
both styles:
1440+
argument of the cursor's :meth:`~Cursor.execute` method.
1441+
1442+
An SQL statement may use one of two kinds of placeholders:
1443+
question marks (qmark style) or named placeholders (named style).
1444+
For the qmark style, *parameters* must be a
1445+
:term:`sequence` whose length must match the number of placeholders,
1446+
or a :exc:`ProgrammingError` is raised.
1447+
For the named style, *parameters* should be
1448+
an instance of a :class:`dict` (or a subclass),
1449+
which must contain keys for all named parameters;
1450+
any extra items are ignored.
1451+
Here's an example of both styles:
14491452

14501453
.. testcode::
14511454

@@ -1472,6 +1475,11 @@ both styles:
14721475

14731476
[('C', 1972)]
14741477

1478+
.. note::
1479+
1480+
:pep:`249` numeric placeholders are *not* supported.
1481+
If used, they will be interpreted as named placeholders.
1482+
14751483

14761484
.. _sqlite3-adapters:
14771485

0 commit comments

Comments
 (0)