Skip to content
Merged
Changes from 1 commit
Commits
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
Apply suggestions from CAM and Ezio
Co-authored-by: C.A.M. Gerlach <CAM.Gerlach@Gerlach.CAM>
Co-authored-by: Ezio Melotti <ezio.melotti@gmail.com>
  • Loading branch information
3 people authored Oct 12, 2023
commit dc4c8205ea174f10fc7205cf88e6a845e9f52884
14 changes: 7 additions & 7 deletions Doc/library/sqlite3.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2595,20 +2595,20 @@ instead of a :class:`~collections.namedtuple`.
How to handle non-UTF-8 text encodings
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

By default, :mod:`!sqlite3` adapts SQLite values with the ``TEXT`` data type
using :class:`str`.
This works well for UTF-8 encoded text, but it will fail for other encodings
By default, :mod:`!sqlite3` uses :class:`str` to adapt SQLite values
with the ``TEXT`` data type.
This works well for UTF-8 encoded text, but it might fail for other encodings
and invalid UTF-8.
You can use a custom :attr:`~Connection.text_factory` to handle such cases.

Because of SQLite's `flexible typing`_, it is not uncommon to encounter table
columns with the ``TEXT`` data type, containing non-UTF-8 encodings,
columns with the ``TEXT`` data type containing non-UTF-8 encodings,
or even arbitrary data.
Comment thread
erlend-aasland marked this conversation as resolved.
To demonstrate, let's assume we've got a database with ISO-8859-2 (Latin 2)
To demonstrate, let's assume we have a database with ISO-8859-2 (Latin-2)
encoded text, for example a table of Czech-English dictionary entries.
Assuming we now have a :class:`Connection` instance :py:data:`!con`
connected to this database,
we can decode the Latin 2 encoded text using this :attr:`~Connection.text_factory`:
we can decode the Latin-2 encoded text using this :attr:`~Connection.text_factory`:

.. testcode::

Expand All @@ -2623,7 +2623,7 @@ you can use the following technique, borrowed from the :ref:`unicode-howto`:

.. note::

Strings containing surrogate escapes and must be treated with care.
Strings containing surrogate escapes must be treated with care.
For example, you cannot pass them back to SQLite,
since the :mod:`!sqlite3` module API does not support strings
containing surrogate escape codes.
Comment thread
erlend-aasland marked this conversation as resolved.
Outdated
Expand Down