mirror of
https://github.com/python/cpython.git
synced 2025-08-03 16:39:00 +00:00
gh-90016: Deprecate default sqlite3 adapters and converters (#94276)
Co-authored-by: CAM Gerlach <CAM.Gerlach@Gerlach.CAM>
This commit is contained in:
parent
000a4eebe7
commit
6dadf6ca01
7 changed files with 66 additions and 49 deletions
|
@ -1333,6 +1333,8 @@ This function can then be registered using :func:`register_adapter`.
|
|||
.. literalinclude:: ../includes/sqlite3/adapter_point_2.py
|
||||
|
||||
|
||||
.. _sqlite3-converters:
|
||||
|
||||
Converting SQLite values to custom Python types
|
||||
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
|
@ -1373,27 +1375,28 @@ The following example illustrates the implicit and explicit approaches:
|
|||
.. literalinclude:: ../includes/sqlite3/converter_point.py
|
||||
|
||||
|
||||
Default adapters and converters
|
||||
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
.. _sqlite3-default-converters:
|
||||
|
||||
There are default adapters for the date and datetime types in the datetime
|
||||
module. They will be sent as ISO dates/ISO timestamps to SQLite.
|
||||
Default adapters and converters (deprecated)
|
||||
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
The default converters are registered under the name "date" for
|
||||
:class:`datetime.date` and under the name "timestamp" for
|
||||
:class:`datetime.datetime`.
|
||||
.. note::
|
||||
|
||||
This way, you can use date/timestamps from Python without any additional
|
||||
fiddling in most cases. The format of the adapters is also compatible with the
|
||||
experimental SQLite date/time functions.
|
||||
The default adapters and converters are deprecated as of Python 3.12.
|
||||
Instead, use the :ref:`sqlite3-adapter-converter-recipes`
|
||||
and tailor them to your needs.
|
||||
|
||||
The following example demonstrates this.
|
||||
The deprecated default adapters and converters consist of:
|
||||
|
||||
.. literalinclude:: ../includes/sqlite3/pysqlite_datetime.py
|
||||
|
||||
If a timestamp stored in SQLite has a fractional part longer than 6
|
||||
numbers, its value will be truncated to microsecond precision by the
|
||||
timestamp converter.
|
||||
* An adapter for :class:`datetime.date` objects to :class:`strings <str>` in
|
||||
`ISO 8601`_ format.
|
||||
* An adapter for :class:`datetime.datetime` objects to strings in
|
||||
ISO 8601 format.
|
||||
* A converter for :ref:`declared <sqlite3-converters>` "date" types to
|
||||
:class:`datetime.date` objects.
|
||||
* A converter for declared "timestamp" types to
|
||||
:class:`datetime.datetime` objects.
|
||||
Fractional parts will be truncated to 6 digits (microsecond precision).
|
||||
|
||||
.. note::
|
||||
|
||||
|
@ -1402,6 +1405,10 @@ timestamp converter.
|
|||
offsets in timestamps, either leave converters disabled, or register an
|
||||
offset-aware converter with :func:`register_converter`.
|
||||
|
||||
.. deprecated:: 3.12
|
||||
|
||||
.. _ISO 8601: https://en.wikipedia.org/wiki/ISO_8601
|
||||
|
||||
|
||||
.. _sqlite3-adapter-converter-recipes:
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue