diff options
author | Erlend E. Aasland <erlend.aasland@protonmail.com> | 2023-01-14 22:58:06 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-01-14 22:58:06 (GMT) |
commit | 206f05a46b426eb374f724f8e7cd42f2f9643bb8 (patch) | |
tree | a75d05079ae7b908d32046d1a4437b1df53e3060 /Doc/library/sqlite3.rst | |
parent | 124af17b6e49f0f22fbe646fb57800393235d704 (diff) | |
download | cpython-206f05a46b426eb374f724f8e7cd42f2f9643bb8.zip cpython-206f05a46b426eb374f724f8e7cd42f2f9643bb8.tar.gz cpython-206f05a46b426eb374f724f8e7cd42f2f9643bb8.tar.bz2 |
gh-100668: Clarify how sqlite3 maps parameters onto placeholders (#100960)
Co-authored-by: C.A.M. Gerlach <CAM.Gerlach@Gerlach.CAM>
Diffstat (limited to 'Doc/library/sqlite3.rst')
-rw-r--r-- | Doc/library/sqlite3.rst | 26 |
1 files changed, 17 insertions, 9 deletions
diff --git a/Doc/library/sqlite3.rst b/Doc/library/sqlite3.rst index 1708cd9..ba72b96 100644 --- a/Doc/library/sqlite3.rst +++ b/Doc/library/sqlite3.rst @@ -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 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 -argument of the cursor's :meth:`~Cursor.execute` method. An SQL statement may -use one of two kinds of placeholders: question marks (qmark style) or named -placeholders (named style). For the qmark style, ``parameters`` must be a -:term:`sequence <sequence>`. For the named style, it can be either a -:term:`sequence <sequence>` or :class:`dict` instance. The length of the -:term:`sequence <sequence>` must match the number of placeholders, or a -:exc:`ProgrammingError` is raised. If a :class:`dict` is given, it must contain -keys for all named parameters. Any extra items are ignored. Here's an example of -both styles: +argument of the cursor's :meth:`~Cursor.execute` method. + +An SQL statement may use one of two kinds of placeholders: +question marks (qmark style) or named placeholders (named style). +For the qmark style, *parameters* must be a +:term:`sequence` whose length must match the number of placeholders, +or a :exc:`ProgrammingError` is raised. +For the named style, *parameters* should be +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:: @@ -1975,6 +1978,11 @@ both styles: [('C', 1972)] +.. note:: + + :pep:`249` numeric placeholders are *not* supported. + If used, they will be interpreted as named placeholders. + .. _sqlite3-adapters: |