Skip to content

Commit eed7711

Browse files
Docs: group sqlite3.Connection attributes and methods (GH-96090)
(cherry picked from commit 1a140af) Co-authored-by: Erlend E. Aasland <[email protected]>
1 parent c097fe0 commit eed7711

File tree

1 file changed

+37
-39
lines changed

1 file changed

+37
-39
lines changed

Doc/library/sqlite3.rst

+37-39
Original file line numberDiff line numberDiff line change
@@ -532,6 +532,43 @@ Connection objects
532532

533533
.. versionadded:: 3.2
534534

535+
.. attribute:: row_factory
536+
537+
A callable that accepts two arguments,
538+
a :class:`Cursor` object and the raw row results as a :class:`tuple`,
539+
and returns a custom object representing an SQLite row.
540+
541+
Example:
542+
543+
.. literalinclude:: ../includes/sqlite3/row_factory.py
544+
545+
If returning a tuple doesn't suffice and you want name-based access to
546+
columns, you should consider setting :attr:`row_factory` to the
547+
highly optimized :class:`sqlite3.Row` type. :class:`Row` provides both
548+
index-based and case-insensitive name-based access to columns with almost no
549+
memory overhead. It will probably be better than your own custom
550+
dictionary-based approach or even a db_row based solution.
551+
552+
.. XXX what's a db_row-based solution?
553+
554+
.. attribute:: text_factory
555+
556+
A callable that accepts a :class:`bytes` parameter and returns a text
557+
representation of it.
558+
The callable is invoked for SQLite values with the ``TEXT`` data type.
559+
By default, this attribute is set to :class:`str`.
560+
If you want to return ``bytes`` instead, set *text_factory* to ``bytes``.
561+
562+
Example:
563+
564+
.. literalinclude:: ../includes/sqlite3/text_factory.py
565+
566+
.. attribute:: total_changes
567+
568+
Return the total number of database rows that have been modified, inserted, or
569+
deleted since the database connection was opened.
570+
571+
535572
.. method:: cursor(factory=Cursor)
536573

537574
Create and return a :class:`Cursor` object.
@@ -843,45 +880,6 @@ Connection objects
843880
.. versionchanged:: 3.10
844881
Added the ``sqlite3.load_extension`` auditing event.
845882

846-
.. attribute:: row_factory
847-
848-
A callable that accepts two arguments,
849-
a :class:`Cursor` object and the raw row results as a :class:`tuple`,
850-
and returns a custom object representing an SQLite row.
851-
852-
Example:
853-
854-
.. literalinclude:: ../includes/sqlite3/row_factory.py
855-
856-
If returning a tuple doesn't suffice and you want name-based access to
857-
columns, you should consider setting :attr:`row_factory` to the
858-
highly optimized :class:`sqlite3.Row` type. :class:`Row` provides both
859-
index-based and case-insensitive name-based access to columns with almost no
860-
memory overhead. It will probably be better than your own custom
861-
dictionary-based approach or even a db_row based solution.
862-
863-
.. XXX what's a db_row-based solution?
864-
865-
866-
.. attribute:: text_factory
867-
868-
A callable that accepts a :class:`bytes` parameter and returns a text
869-
representation of it.
870-
The callable is invoked for SQLite values with the ``TEXT`` data type.
871-
By default, this attribute is set to :class:`str`.
872-
If you want to return ``bytes`` instead, set *text_factory* to ``bytes``.
873-
874-
Example:
875-
876-
.. literalinclude:: ../includes/sqlite3/text_factory.py
877-
878-
879-
.. attribute:: total_changes
880-
881-
Return the total number of database rows that have been modified, inserted, or
882-
deleted since the database connection was opened.
883-
884-
885883
.. method:: iterdump
886884

887885
Return an :term:`iterator` to dump the database as SQL source code.

0 commit comments

Comments
 (0)