Skip to content
Merged
Changes from 1 commit
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
598e26a
gh-90016: Reword sqlite3 adapter/converter docs
erlend-aasland May 23, 2022
e5b1b88
Add current adapters/converter as recipes: improve this
erlend-aasland May 23, 2022
9399b54
default role
erlend-aasland May 23, 2022
40bb59a
Formatting
erlend-aasland May 23, 2022
82cf3e2
Address Serhiy's review
erlend-aasland May 23, 2022
0b6f381
Address Alex' review
erlend-aasland May 25, 2022
c4dde48
Nit
erlend-aasland May 25, 2022
72013ef
Address Alex' nitpicks
erlend-aasland May 25, 2022
3c70d52
Address in-house review
erlend-aasland May 25, 2022
681baad
Recipes, take 1
erlend-aasland May 25, 2022
bf4cb1f
Docstring wording
erlend-aasland May 25, 2022
2d1a0c1
Update Doc/library/sqlite3.rst
Jun 22, 2022
94308ff
Update Doc/library/sqlite3.rst
Jun 22, 2022
06657f2
Update Doc/library/sqlite3.rst
Jun 22, 2022
b98e363
Update Doc/library/sqlite3.rst
Jun 22, 2022
97812bb
Update Doc/library/sqlite3.rst
Jun 22, 2022
d3dd5a2
Update Doc/library/sqlite3.rst
Jun 22, 2022
f381b65
Update Doc/library/sqlite3.rst
Jun 22, 2022
65eb45c
Update Doc/library/sqlite3.rst
Jun 22, 2022
172c7d9
Update Doc/library/sqlite3.rst
Jun 22, 2022
5ac2af9
Update Doc/library/sqlite3.rst
Jun 22, 2022
433bf5a
Update Doc/library/sqlite3.rst
Jun 22, 2022
f7646de
Update Doc/library/sqlite3.rst
Jun 22, 2022
6fbcff8
Assuming direct control
Jun 22, 2022
b319b54
Address the last part of CAM's review
erlend-aasland Jun 23, 2022
4e3b8fd
Merge branch 'main' into sqlite-doc-converters
erlend-aasland Jun 23, 2022
e821a7e
Clarify parse column names further
erlend-aasland Jun 23, 2022
bc295d8
Revert unneeded change
erlend-aasland Jun 23, 2022
9235f8d
Further clarify register_converter
erlend-aasland Jun 23, 2022
8484164
Use testsetup/doctest
erlend-aasland Jun 23, 2022
b579f67
Revert "Use testsetup/doctest"
erlend-aasland Jun 23, 2022
0e42fa6
Update Doc/library/sqlite3.rst
Jun 24, 2022
8d97fcb
Reflow
erlend-aasland Jun 25, 2022
d300b33
Merge remote-tracking branch 'upstream/main' into sqlite-doc-converters
erlend-aasland Jun 25, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Address in-house review
  • Loading branch information
erlend-aasland committed May 25, 2022
commit 3c70d523c34d1408c950a66dbcad84f9a9b043d6
19 changes: 9 additions & 10 deletions Doc/library/sqlite3.rst
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ Module functions and constants

.. data:: PARSE_DECLTYPES

Use this flag with the *detect_types* parameter of :meth:`connect` to enable
Use this flag together with the *detect_types* parameter of :meth:`connect` to enable
parsing of declared types for each column returned.
The types are declared when the database table is created.
Comment thread
erlend-aasland marked this conversation as resolved.
``sqlite3`` will look up a converter function using the first word of the
Expand All @@ -220,7 +220,7 @@ Module functions and constants

.. data:: PARSE_COLNAMES

Use this flag with the *detect_types* parameter of :meth:`connect` to enable
Use this flag together with the *detect_types* parameter of :meth:`connect` to enable
parsing of column names in queries.
``sqlite3`` will look for strings containing square brackets (``[]``),
Comment thread
erlend-aasland marked this conversation as resolved.
Outdated
and will look up a converter function using the word inside the brackets as
Comment thread
erlend-aasland marked this conversation as resolved.
Outdated
Expand Down Expand Up @@ -1220,7 +1220,7 @@ Using adapters to store custom Python types in SQLite databases
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

SQLite supports only a limited set of types natively.
To store custom Python types in SQLite databases, **adapt** them to one of the
To store custom Python types in SQLite databases, *adapt* them to one of the
Comment thread
erlend-aasland marked this conversation as resolved.
basic types supported by SQLite:
Comment thread
erlend-aasland marked this conversation as resolved.
Outdated
:class:`int`, :class:`float`, :class:`str`, :class:`bytes`, or :const:`None`.

Expand Down Expand Up @@ -1256,19 +1256,18 @@ This function can then be registered using :meth:`register_adapter`.
.. literalinclude:: ../includes/sqlite3/adapter_point_2.py

The :mod:`sqlite3` module has two default adapters for Python's built-in
:class:`datetime.date` and :class:`datetime.datetime` types. Now let's suppose
we want to store :class:`datetime.datetime` objects not in ISO representation,
but as a Unix timestamp.
:class:`datetime.date` and :class:`datetime.datetime` types.
Suppose we want to store :class:`datetime.datetime` objects not in ISO
representation, but as a Unix timestamp.

.. literalinclude:: ../includes/sqlite3/adapter_datetime.py


Converting SQLite values to custom Python types
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Writing an adapter lets you send custom Python types to SQLite. But to make it
really useful we need to make the Python to SQLite to Python roundtrip work.
To be able to convert SQLite values to custom Python types, we use _converters_.
Writing an adapter lets you send custom Python types to SQLite.
To be able to convert SQLite values to custom Python types, we use *converters*.
Comment thread
erlend-aasland marked this conversation as resolved.
Outdated

Let's go back to the :class:`Point` class. We stored the x and y coordinates
separated via semicolons as strings in SQLite.
Expand All @@ -1289,7 +1288,7 @@ and constructs a :class:`Point` object from it.

We now need to tell ``sqlite3`` when it should convert a given SQLite value.
This is done when connecting to a database, using the *detect_types* parameter
of :meth:`connect`. We've got three options:
of :meth:`connect`. There are three options:
Comment thread
erlend-aasland marked this conversation as resolved.
Outdated

* Implicit: set *detect_types* to :const:`PARSE_DECLTYPES`
* Explicit: set *detect_types* to :const:`PARSE_COLNAMES`
Expand Down