Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 34k
gh-90016: Deprecate default sqlite3 adapters and converters#94276
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Uh oh!
There was an error while loading. Please reload this page.
Changes from all commits
2a586c42ba83f6fb18ab627eaa23d3dd3b4df4dc31ffdf6316213c3b07988dcFile filter
Filter by extension
Conversations
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Uh oh!
There was an error while loading. Please reload this page.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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 | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
| 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. | ||
| .. _sqlite3-default-converters: | ||
| The default converters are registered under the name "date" for | ||
| :class:`datetime.date` and under the name "timestamp" for | ||
| :class:`datetime.datetime`. | ||
| Default adapters and converters (deprecated) | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
| 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. | ||
| .. note:: | ||
erlend-aasland marked this conversation as resolved. Show resolvedHide resolvedUh oh!There was an error while loading. Please reload this page. | ||
| The following example demonstrates this. | ||
| 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. | ||
| .. literalinclude:: ../includes/sqlite3/pysqlite_datetime.py | ||
| The deprecated default adapters and converters consist of: | ||
| 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). | ||
erlend-aasland marked this conversation as resolved. Show resolvedHide resolvedUh oh!There was an error while loading. Please reload this page. | ||
| .. 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: | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -55,16 +55,25 @@ def TimestampFromTicks(ticks): | ||
| collections.abc.Sequence.register(Row) | ||
| def register_adapters_and_converters(): | ||
| from warnings import warn | ||
erlend-aasland marked this conversation as resolved. Show resolvedHide resolvedUh oh!There was an error while loading. Please reload this page. | ||
| msg = ("The default{what} is deprecated as of Python 3.12; " | ||
| "see the sqlite3 documentation for suggested replacement recipes") | ||
| def adapt_date(val): | ||
| warn(msg.format(what="date adapter"), DeprecationWarning, stacklevel=2) | ||
| return val.isoformat() | ||
| def adapt_datetime(val): | ||
| warn(msg.format(what="datetime adapter"), DeprecationWarning, stacklevel=2) | ||
| return val.isoformat(" ") | ||
| def convert_date(val): | ||
| warn(msg.format(what="date converter"), DeprecationWarning, stacklevel=2) | ||
| return datetime.date(*map(int, val.split(b"-"))) | ||
| def convert_timestamp(val): | ||
| warn(msg.format(what="timestamp converter"), DeprecationWarning, stacklevel=2) | ||
| datepart, timepart = val.split(b" ") | ||
| year, month, day = map(int, datepart.split(b"-")) | ||
| timepart_full = timepart.split(b".") | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| Deprecate :mod:`sqlite3` :ref:`default adapters and converters | ||
| <sqlite3-default-converters>`. Patch by Erlend E. Aasland. |
Uh oh!
There was an error while loading. Please reload this page.