Skip to content

Commit 6bda5b8

Browse files
CAM-Gerlacherlend-aaslandezio-melotti
authored
gh-94635: Frame sqlite3 how-to headings as such & move default adapters to reference (#96136)
Co-authored-by: Erlend E. Aasland <[email protected]> Co-authored-by: Ezio Melotti <[email protected]>
1 parent 1f0eafa commit 6bda5b8

File tree

1 file changed

+48
-48
lines changed

1 file changed

+48
-48
lines changed

Doc/library/sqlite3.rst

Lines changed: 48 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -1543,6 +1543,41 @@ and you can let the :mod:`!sqlite3` module convert SQLite types to
15431543
Python types via :ref:`converters <sqlite3-converters>`.
15441544

15451545

1546+
.. _sqlite3-default-converters:
1547+
1548+
Default adapters and converters (deprecated)
1549+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1550+
1551+
.. note::
1552+
1553+
The default adapters and converters are deprecated as of Python 3.12.
1554+
Instead, use the :ref:`sqlite3-adapter-converter-recipes`
1555+
and tailor them to your needs.
1556+
1557+
The deprecated default adapters and converters consist of:
1558+
1559+
* An adapter for :class:`datetime.date` objects to :class:`strings <str>` in
1560+
`ISO 8601`_ format.
1561+
* An adapter for :class:`datetime.datetime` objects to strings in
1562+
ISO 8601 format.
1563+
* A converter for :ref:`declared <sqlite3-converters>` "date" types to
1564+
:class:`datetime.date` objects.
1565+
* A converter for declared "timestamp" types to
1566+
:class:`datetime.datetime` objects.
1567+
Fractional parts will be truncated to 6 digits (microsecond precision).
1568+
1569+
.. note::
1570+
1571+
The default "timestamp" converter ignores UTC offsets in the database and
1572+
always returns a naive :class:`datetime.datetime` object. To preserve UTC
1573+
offsets in timestamps, either leave converters disabled, or register an
1574+
offset-aware converter with :func:`register_converter`.
1575+
1576+
.. deprecated:: 3.12
1577+
1578+
.. _ISO 8601: https://en.wikipedia.org/wiki/ISO_8601
1579+
1580+
15461581
.. _sqlite3-cli:
15471582

15481583
Command-line interface
@@ -1602,8 +1637,8 @@ both styles:
16021637

16031638
.. _sqlite3-adapters:
16041639

1605-
Using adapters to store custom Python types in SQLite databases
1606-
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1640+
How to adapt custom Python types to SQLite values
1641+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
16071642

16081643
SQLite supports only a limited set of data types natively.
16091644
To store custom Python types in SQLite databases, *adapt* them to one of the
@@ -1620,8 +1655,8 @@ registering custom adapter functions.
16201655

16211656
.. _sqlite3-conform:
16221657

1623-
Letting your object adapt itself
1624-
""""""""""""""""""""""""""""""""
1658+
How to write adaptable objects
1659+
""""""""""""""""""""""""""""""
16251660

16261661
Suppose we have a :class:`!Point` class that represents a pair of coordinates,
16271662
``x`` and ``y``, in a Cartesian coordinate system.
@@ -1634,8 +1669,8 @@ The object passed to *protocol* will be of type :class:`PrepareProtocol`.
16341669
.. literalinclude:: ../includes/sqlite3/adapter_point_1.py
16351670

16361671

1637-
Registering an adapter callable
1638-
"""""""""""""""""""""""""""""""
1672+
How to register adapter callables
1673+
"""""""""""""""""""""""""""""""""
16391674

16401675
The other possibility is to create a function that converts the Python object
16411676
to an SQLite-compatible type.
@@ -1646,8 +1681,8 @@ This function can then be registered using :func:`register_adapter`.
16461681

16471682
.. _sqlite3-converters:
16481683

1649-
Converting SQLite values to custom Python types
1650-
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1684+
How to convert SQLite values to custom Python types
1685+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
16511686

16521687
Writing an adapter lets you convert *from* custom Python types *to* SQLite
16531688
values.
@@ -1686,41 +1721,6 @@ The following example illustrates the implicit and explicit approaches:
16861721
.. literalinclude:: ../includes/sqlite3/converter_point.py
16871722

16881723

1689-
.. _sqlite3-default-converters:
1690-
1691-
Default adapters and converters (deprecated)
1692-
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1693-
1694-
.. note::
1695-
1696-
The default adapters and converters are deprecated as of Python 3.12.
1697-
Instead, use the :ref:`sqlite3-adapter-converter-recipes`
1698-
and tailor them to your needs.
1699-
1700-
The deprecated default adapters and converters consist of:
1701-
1702-
* An adapter for :class:`datetime.date` objects to :class:`strings <str>` in
1703-
`ISO 8601`_ format.
1704-
* An adapter for :class:`datetime.datetime` objects to strings in
1705-
ISO 8601 format.
1706-
* A converter for :ref:`declared <sqlite3-converters>` "date" types to
1707-
:class:`datetime.date` objects.
1708-
* A converter for declared "timestamp" types to
1709-
:class:`datetime.datetime` objects.
1710-
Fractional parts will be truncated to 6 digits (microsecond precision).
1711-
1712-
.. note::
1713-
1714-
The default "timestamp" converter ignores UTC offsets in the database and
1715-
always returns a naive :class:`datetime.datetime` object. To preserve UTC
1716-
offsets in timestamps, either leave converters disabled, or register an
1717-
offset-aware converter with :func:`register_converter`.
1718-
1719-
.. deprecated:: 3.12
1720-
1721-
.. _ISO 8601: https://en.wikipedia.org/wiki/ISO_8601
1722-
1723-
17241724
.. _sqlite3-adapter-converter-recipes:
17251725

17261726
Adapter and converter recipes
@@ -1768,8 +1768,8 @@ This section shows recipes for common adapters and converters.
17681768
17691769
.. _sqlite3-connection-shortcuts:
17701770

1771-
Using connection shortcut methods
1772-
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1771+
How to use connection shortcut methods
1772+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
17731773

17741774
Using the :meth:`~Connection.execute`,
17751775
:meth:`~Connection.executemany`, and :meth:`~Connection.executescript`
@@ -1785,7 +1785,7 @@ directly using only a single call on the :class:`Connection` object.
17851785

17861786
.. _sqlite3-connection-context-manager:
17871787

1788-
Using the connection as a context manager
1788+
How to use the connection context manager
17891789
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
17901790

17911791
A :class:`Connection` object can be used as a context manager that
@@ -1810,8 +1810,8 @@ the context manager is a no-op.
18101810

18111811
.. _sqlite3-uri-tricks:
18121812

1813-
Working with SQLite URIs
1814-
^^^^^^^^^^^^^^^^^^^^^^^^
1813+
How to work with SQLite URIs
1814+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
18151815

18161816
Some useful URI tricks include:
18171817

0 commit comments

Comments
 (0)