Skip to content

gh-96168: Add sqlite3 row factory how-to #99507

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

Merged
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
Address review
  • Loading branch information
erlend-aasland committed Nov 23, 2022
commit cd12c6bcb657fb2db4c9250f53da9a2dcad7b35e
13 changes: 7 additions & 6 deletions Doc/library/sqlite3.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1321,7 +1321,8 @@ Connection objects
for :class:`Cursor` objects created from this connection.
Assigning to this attribute does not affect the :attr:`!row_factory`
of existing cursors belonging to this connection, only new ones.
Is ``None`` by default.
Is ``None`` by default,
meaning each row is returned as a :class:`tuple`.

See :ref:`sqlite3-howto-row-factory` for more details.

Expand Down Expand Up @@ -1577,11 +1578,11 @@ Cursor objects
.. attribute:: row_factory

Control how a row fetched from this :class:`!Cursor` is represented.
Set to :class:`sqlite3.Row`;
or a custom :term:`callable` that accepts two arguments,
a :class:`Cursor` object and a :class:`tuple` of the row results,
If ``None``, a row is represented as a :class:`tuple`.
Can be set to the included :class:`sqlite3.Row`;
or a :term:`callable` that accepts two arguments,
a :class:`Cursor` object and the :class:`!tuple` of row values,
and returns a custom object representing an SQLite row.
If ``None``, a fetched row is represented as a :class:`tuple`.

Defaults to what :attr:`Connection.row_factory` was set to
when the :class:`!Cursor` was created.
Expand Down Expand Up @@ -2350,7 +2351,7 @@ can be found in the `SQLite URI documentation`_.
How to create and use row factories
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

By default, :mod:`!sqlite3` represents each fetched row as a :class:`tuple`.
By default, :mod:`!sqlite3` represents each row as a :class:`tuple`.
If a :class:`!tuple` does not suit your needs,
you can use the :class:`sqlite3.Row` class
or a custom :attr:`~Cursor.row_factory`.
Expand Down
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy