Skip to content

Commit 8a6e651

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 5e28ec5 commit 8a6e651

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
@@ -495,6 +495,43 @@ Connection objects
495495

496496
.. versionadded:: 3.2
497497

498+
.. attribute:: row_factory
499+
500+
A callable that accepts two arguments,
501+
a :class:`Cursor` object and the raw row results as a :class:`tuple`,
502+
and returns a custom object representing an SQLite row.
503+
504+
Example:
505+
506+
.. literalinclude:: ../includes/sqlite3/row_factory.py
507+
508+
If returning a tuple doesn't suffice and you want name-based access to
509+
columns, you should consider setting :attr:`row_factory` to the
510+
highly optimized :class:`sqlite3.Row` type. :class:`Row` provides both
511+
index-based and case-insensitive name-based access to columns with almost no
512+
memory overhead. It will probably be better than your own custom
513+
dictionary-based approach or even a db_row based solution.
514+
515+
.. XXX what's a db_row-based solution?
516+
517+
.. attribute:: text_factory
518+
519+
A callable that accepts a :class:`bytes` parameter and returns a text
520+
representation of it.
521+
The callable is invoked for SQLite values with the ``TEXT`` data type.
522+
By default, this attribute is set to :class:`str`.
523+
If you want to return ``bytes`` instead, set *text_factory* to ``bytes``.
524+
525+
Example:
526+
527+
.. literalinclude:: ../includes/sqlite3/text_factory.py
528+
529+
.. attribute:: total_changes
530+
531+
Return the total number of database rows that have been modified, inserted, or
532+
deleted since the database connection was opened.
533+
534+
498535
.. method:: cursor(factory=Cursor)
499536

500537
Create and return a :class:`Cursor` object.
@@ -724,45 +761,6 @@ Connection objects
724761
.. versionchanged:: 3.10
725762
Added the ``sqlite3.load_extension`` auditing event.
726763

727-
.. attribute:: row_factory
728-
729-
A callable that accepts two arguments,
730-
a :class:`Cursor` object and the raw row results as a :class:`tuple`,
731-
and returns a custom object representing an SQLite row.
732-
733-
Example:
734-
735-
.. literalinclude:: ../includes/sqlite3/row_factory.py
736-
737-
If returning a tuple doesn't suffice and you want name-based access to
738-
columns, you should consider setting :attr:`row_factory` to the
739-
highly optimized :class:`sqlite3.Row` type. :class:`Row` provides both
740-
index-based and case-insensitive name-based access to columns with almost no
741-
memory overhead. It will probably be better than your own custom
742-
dictionary-based approach or even a db_row based solution.
743-
744-
.. XXX what's a db_row-based solution?
745-
746-
747-
.. attribute:: text_factory
748-
749-
A callable that accepts a :class:`bytes` parameter and returns a text
750-
representation of it.
751-
The callable is invoked for SQLite values with the ``TEXT`` data type.
752-
By default, this attribute is set to :class:`str`.
753-
If you want to return ``bytes`` instead, set *text_factory* to ``bytes``.
754-
755-
Example:
756-
757-
.. literalinclude:: ../includes/sqlite3/text_factory.py
758-
759-
760-
.. attribute:: total_changes
761-
762-
Return the total number of database rows that have been modified, inserted, or
763-
deleted since the database connection was opened.
764-
765-
766764
.. method:: iterdump
767765

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

0 commit comments

Comments
 (0)