Skip to content

Commit c26470f

Browse files
miss-islingtonErlend Egeberg Aasland
and
Erlend Egeberg Aasland
authored
gh-95273: Improve sqlite3 class descriptions (GH-95379)
Co-authored-by: CAM Gerlach <[email protected]> (cherry picked from commit e003b64) Co-authored-by: Erlend Egeberg Aasland <[email protected]>
1 parent 00566a8 commit c26470f

File tree

1 file changed

+34
-8
lines changed

1 file changed

+34
-8
lines changed

Doc/library/sqlite3.rst

+34-8
Original file line numberDiff line numberDiff line change
@@ -416,6 +416,16 @@ Connection Objects
416416

417417
.. class:: Connection
418418

419+
Each open SQLite database is represented by a ``Connection`` object,
420+
which is created using :func:`sqlite3.connect`.
421+
Their main purpose is creating :class:`Cursor` objects,
422+
and :ref:`sqlite3-controlling-transactions`.
423+
424+
.. seealso::
425+
426+
* :ref:`sqlite3-connection-shortcuts`
427+
* :ref:`sqlite3-connection-context-manager`
428+
419429
An SQLite database connection has the following attributes and methods:
420430

421431
.. attribute:: isolation_level
@@ -960,6 +970,22 @@ Connection Objects
960970
Cursor Objects
961971
--------------
962972

973+
A ``Cursor`` object represents a `database cursor`_
974+
which is used to execute SQL statements,
975+
and manage the context of a fetch operation.
976+
Cursors are created using :meth:`Connection.cursor`,
977+
or by using any of the :ref:`connection shortcut methods
978+
<sqlite3-connection-shortcuts>`.
979+
980+
Cursor objects are :term:`iterators <iterator>`,
981+
meaning that if you :meth:`~Cursor.execute` a ``SELECT`` query,
982+
you can simply iterate over the cursor to fetch the resulting rows::
983+
984+
for row in cur.execute("select * from data"):
985+
print(row)
986+
987+
.. _database cursor: https://en.wikipedia.org/wiki/Cursor_(databases)
988+
963989
.. class:: Cursor
964990

965991
A :class:`Cursor` instance has the following attributes and methods.
@@ -1125,13 +1151,11 @@ Row Objects
11251151

11261152
A :class:`Row` instance serves as a highly optimized
11271153
:attr:`~Connection.row_factory` for :class:`Connection` objects.
1128-
It tries to mimic a tuple in most of its features.
1154+
It tries to mimic a :class:`tuple` in most of its features,
1155+
and supports iteration, :func:`repr`, equality testing, :func:`len`,
1156+
and :term:`mapping` access by column name and index.
11291157

1130-
It supports mapping access by column name and index, iteration,
1131-
representation, equality testing and :func:`len`.
1132-
1133-
If two :class:`Row` objects have exactly the same columns and their
1134-
members are equal, they compare equal.
1158+
Two row objects compare equal if have equal columns and equal members.
11351159

11361160
.. method:: keys
11371161

@@ -1623,8 +1647,10 @@ Using :mod:`sqlite3` efficiently
16231647
--------------------------------
16241648

16251649

1626-
Using shortcut methods
1627-
^^^^^^^^^^^^^^^^^^^^^^
1650+
.. _sqlite3-connection-shortcuts:
1651+
1652+
Using connection shortcut methods
1653+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
16281654

16291655
Using the :meth:`~Connection.execute`,
16301656
:meth:`~Connection.executemany`, and :meth:`~Connection.executescript`

0 commit comments

Comments
 (0)