Skip to content

Commit e003b64

Browse files
Erlend Egeberg AaslandCAM-Gerlach
Erlend Egeberg Aasland
andauthored
gh-95273: Improve sqlite3 class descriptions (#95379)
Co-authored-by: CAM Gerlach <CAM.Gerlach@Gerlach.CAM>
1 parent f0bf795 commit e003b64

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
@@ -426,6 +426,16 @@ Connection Objects
426426

427427
.. class:: Connection
428428

429+
Each open SQLite database is represented by a ``Connection`` object,
430+
which is created using :func:`sqlite3.connect`.
431+
Their main purpose is creating :class:`Cursor` objects,
432+
and :ref:`sqlite3-controlling-transactions`.
433+
434+
.. seealso::
435+
436+
* :ref:`sqlite3-connection-shortcuts`
437+
* :ref:`sqlite3-connection-context-manager`
438+
429439
An SQLite database connection has the following attributes and methods:
430440

431441
.. attribute:: isolation_level
@@ -970,6 +980,22 @@ Connection Objects
970980
Cursor Objects
971981
--------------
972982

983+
A ``Cursor`` object represents a `database cursor`_
984+
which is used to execute SQL statements,
985+
and manage the context of a fetch operation.
986+
Cursors are created using :meth:`Connection.cursor`,
987+
or by using any of the :ref:`connection shortcut methods
988+
<sqlite3-connection-shortcuts>`.
989+
990+
Cursor objects are :term:`iterators <iterator>`,
991+
meaning that if you :meth:`~Cursor.execute` a ``SELECT`` query,
992+
you can simply iterate over the cursor to fetch the resulting rows::
993+
994+
for row in cur.execute("select * from data"):
995+
print(row)
996+
997+
.. _database cursor: https://en.wikipedia.org/wiki/Cursor_(databases)
998+
973999
.. class:: Cursor
9741000

9751001
A :class:`Cursor` instance has the following attributes and methods.
@@ -1135,13 +1161,11 @@ Row Objects
11351161

11361162
A :class:`Row` instance serves as a highly optimized
11371163
:attr:`~Connection.row_factory` for :class:`Connection` objects.
1138-
It tries to mimic a tuple in most of its features.
1164+
It tries to mimic a :class:`tuple` in most of its features,
1165+
and supports iteration, :func:`repr`, equality testing, :func:`len`,
1166+
and :term:`mapping` access by column name and index.
11391167

1140-
It supports mapping access by column name and index, iteration,
1141-
representation, equality testing and :func:`len`.
1142-
1143-
If two :class:`Row` objects have exactly the same columns and their
1144-
members are equal, they compare equal.
1168+
Two row objects compare equal if have equal columns and equal members.
11451169

11461170
.. method:: keys
11471171

@@ -1640,8 +1664,10 @@ Using :mod:`sqlite3` efficiently
16401664
--------------------------------
16411665

16421666

1643-
Using shortcut methods
1644-
^^^^^^^^^^^^^^^^^^^^^^
1667+
.. _sqlite3-connection-shortcuts:
1668+
1669+
Using connection shortcut methods
1670+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
16451671

16461672
Using the :meth:`~Connection.execute`,
16471673
:meth:`~Connection.executemany`, and :meth:`~Connection.executescript`

0 commit comments

Comments
 (0)