Skip to content

Commit 1a140af

Browse files
Docs: group sqlite3.Connection attributes and methods (#96090)
1 parent ede771c commit 1a140af

File tree

1 file changed

+37
-39
lines changed

1 file changed

+37
-39
lines changed

Doc/library/sqlite3.rst

Lines changed: 37 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -545,6 +545,43 @@ Connection objects
545545

546546
.. versionadded:: 3.2
547547

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

550587
Create and return a :class:`Cursor` object.
@@ -856,45 +893,6 @@ Connection objects
856893
.. versionchanged:: 3.10
857894
Added the ``sqlite3.load_extension`` auditing event.
858895

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

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

0 commit comments

Comments
 (0)