Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork33.7k
gh-90016: Reword sqlite3 adapter/converter docs#93095
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 ourterms of service andprivacy 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 from1 commit
598e26ae5b1b889399b5440bb59a82cf3e20b6f381c4dde4872013ef3c70d52681baadbf4cb1f2d1a0c194308ff06657f2b98e36397812bbd3dd5a2f381b6565eb45c172c7d95ac2af9433bf5af7646de6fbcff8b319b544e3b8fde821a7ebc295d89235f8d8484164b579f670e42fa68d97fcbd300b33File 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
- Loading branch information
Uh oh!
There was an error while loading.Please reload this page.
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -199,7 +199,7 @@ Module functions and constants | ||
| .. data:: PARSE_DECLTYPES | ||
| Use this flagtogetherwith 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. | ||
erlend-aasland marked this conversation as resolved. Show resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||
| ``sqlite3`` will look up a converter function using the first word of the | ||
| @@ -220,7 +220,7 @@ Module functions and constants | ||
| .. data:: PARSE_COLNAMES | ||
| Use this flagtogetherwith the *detect_types* parameter of :meth:`connect` to enable | ||
| parsing of column names in queries. | ||
| ``sqlite3`` will look for strings containing square brackets (``[]``), | ||
erlend-aasland marked this conversation as resolved. OutdatedShow resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||
| and will look up a converter function using the word inside the brackets as | ||
erlend-aasland marked this conversation as resolved. OutdatedShow resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||
| @@ -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 | ||
erlend-aasland marked this conversation as resolved. Show resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||
| basic types supported by SQLite: | ||
erlend-aasland marked this conversation as resolved. OutdatedShow resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||
| :class:`int`, :class:`float`, :class:`str`, :class:`bytes`, or :const:`None`. | ||
| @@ -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. | ||
| Supposewe 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. | ||
| To be able to convert SQLite values to custom Python types, we use *converters*. | ||
erlend-aasland marked this conversation as resolved. OutdatedShow resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||
| Let's go back to the :class:`Point` class. We stored the x and y coordinates | ||
| separated via semicolons as strings in SQLite. | ||
| @@ -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`.There are three options: | ||
erlend-aasland marked this conversation as resolved. OutdatedShow resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||
| * Implicit: set *detect_types* to :const:`PARSE_DECLTYPES` | ||
| * Explicit: set *detect_types* to :const:`PARSE_COLNAMES` | ||