@@ -1543,6 +1543,41 @@ and you can let the :mod:`!sqlite3` module convert SQLite types to
1543
1543
Python types via :ref: `converters <sqlite3-converters >`.
1544
1544
1545
1545
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
+
1546
1581
.. _sqlite3-cli :
1547
1582
1548
1583
Command-line interface
@@ -1602,8 +1637,8 @@ both styles:
1602
1637
1603
1638
.. _sqlite3-adapters :
1604
1639
1605
- Using adapters to store custom Python types in SQLite databases
1606
- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1640
+ How to adapt custom Python types to SQLite values
1641
+ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1607
1642
1608
1643
SQLite supports only a limited set of data types natively.
1609
1644
To store custom Python types in SQLite databases, *adapt * them to one of the
@@ -1620,8 +1655,8 @@ registering custom adapter functions.
1620
1655
1621
1656
.. _sqlite3-conform :
1622
1657
1623
- Letting your object adapt itself
1624
- """"""""""""""""""""""""""""""""
1658
+ How to write adaptable objects
1659
+ """"""""""""""""""""""""""""""
1625
1660
1626
1661
Suppose we have a :class: `!Point ` class that represents a pair of coordinates,
1627
1662
``x `` and ``y ``, in a Cartesian coordinate system.
@@ -1634,8 +1669,8 @@ The object passed to *protocol* will be of type :class:`PrepareProtocol`.
1634
1669
.. literalinclude :: ../includes/sqlite3/adapter_point_1.py
1635
1670
1636
1671
1637
- Registering an adapter callable
1638
- """""""""""""""""""""""""""""""
1672
+ How to register adapter callables
1673
+ """""""""""""""""""""""""""""""""
1639
1674
1640
1675
The other possibility is to create a function that converts the Python object
1641
1676
to an SQLite-compatible type.
@@ -1646,8 +1681,8 @@ This function can then be registered using :func:`register_adapter`.
1646
1681
1647
1682
.. _sqlite3-converters :
1648
1683
1649
- Converting SQLite values to custom Python types
1650
- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1684
+ How to convert SQLite values to custom Python types
1685
+ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1651
1686
1652
1687
Writing an adapter lets you convert *from * custom Python types *to * SQLite
1653
1688
values.
@@ -1686,41 +1721,6 @@ The following example illustrates the implicit and explicit approaches:
1686
1721
.. literalinclude :: ../includes/sqlite3/converter_point.py
1687
1722
1688
1723
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
-
1724
1724
.. _sqlite3-adapter-converter-recipes :
1725
1725
1726
1726
Adapter and converter recipes
@@ -1768,8 +1768,8 @@ This section shows recipes for common adapters and converters.
1768
1768
1769
1769
.. _sqlite3-connection-shortcuts :
1770
1770
1771
- Using connection shortcut methods
1772
- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1771
+ How to use connection shortcut methods
1772
+ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1773
1773
1774
1774
Using the :meth: `~Connection.execute `,
1775
1775
:meth: `~Connection.executemany `, and :meth: `~Connection.executescript `
@@ -1785,7 +1785,7 @@ directly using only a single call on the :class:`Connection` object.
1785
1785
1786
1786
.. _sqlite3-connection-context-manager :
1787
1787
1788
- Using the connection as a context manager
1788
+ How to use the connection context manager
1789
1789
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1790
1790
1791
1791
A :class: `Connection ` object can be used as a context manager that
@@ -1810,8 +1810,8 @@ the context manager is a no-op.
1810
1810
1811
1811
.. _sqlite3-uri-tricks :
1812
1812
1813
- Working with SQLite URIs
1814
- ^^^^^^^^^^^^^^^^^^^^^^^^
1813
+ How to work with SQLite URIs
1814
+ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1815
1815
1816
1816
Some useful URI tricks include:
1817
1817
0 commit comments