Skip to content

Commit 4e72a1a

Browse files
pythongh-95273: Improve sqlite3 class descriptions
1 parent 2361908 commit 4e72a1a

File tree

1 file changed

+33
-8
lines changed

1 file changed

+33
-8
lines changed

Doc/library/sqlite3.rst

+33-8
Original file line numberDiff line numberDiff line change
@@ -413,6 +413,17 @@ Connection Objects
413413

414414
.. class:: Connection
415415

416+
Each open SQLite database is represented by a connection object.
417+
A connection object is created with :func:`sqlite3.connect`.
418+
The main purpose of connection objects is creating
419+
:class:`cursors objects <Cursor>`,
420+
and :ref:`sqlite3-controlling-transactions`.
421+
422+
.. seealso::
423+
424+
* :ref:`sqlite3-connection-shortcuts`
425+
* :ref:`sqlite3-connection-context-manager`
426+
416427
An SQLite database connection has the following attributes and methods:
417428

418429
.. attribute:: isolation_level
@@ -957,6 +968,20 @@ Connection Objects
957968
Cursor Objects
958969
--------------
959970

971+
A cursor object represents a database cursor,
972+
which is used to execute SQL statements,
973+
and manage the context of a fetch operation.
974+
Cursors are created with :meth:`Connection.cursor`,
975+
or by using any of the :ref:`connection shortcut methods
976+
<sqlite3-connection-shortcuts>`.
977+
978+
Cursors objects are :term:`iterators <iterator>`,
979+
meaning that if you :meth:`execute` a ``SELECT`` query,
980+
you can simply iterate over the cursor to fetch the resulting rows::
981+
982+
for row in cur.execute("select * from data"):
983+
print(row)
984+
960985
.. class:: Cursor
961986

962987
A :class:`Cursor` instance has the following attributes and methods.
@@ -1111,15 +1136,13 @@ Row Objects
11111136

11121137
.. class:: Row
11131138

1114-
A :class:`Row` instance serves as a highly optimized
1139+
A :class:`Row` instance that serves as a highly optimized
11151140
:attr:`~Connection.row_factory` for :class:`Connection` objects.
1116-
It tries to mimic a tuple in most of its features.
1117-
1118-
It supports mapping access by column name and index, iteration,
1141+
It tries to mimic a :class:`tuple` in most of its features,
1142+
and supports :term:`mapping` access by column name and index, iteration,
11191143
representation, equality testing and :func:`len`.
11201144

1121-
If two :class:`Row` objects have exactly the same columns and their
1122-
members are equal, they compare equal.
1145+
Two row objects are equal if they have equal columns and equal members.
11231146

11241147
.. method:: keys
11251148

@@ -1618,8 +1641,10 @@ Using :mod:`sqlite3` efficiently
16181641
--------------------------------
16191642

16201643

1621-
Using shortcut methods
1622-
^^^^^^^^^^^^^^^^^^^^^^
1644+
.. _sqlite3-connection-shortcuts:
1645+
1646+
Using connection shortcut methods
1647+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
16231648

16241649
Using the nonstandard :meth:`execute`, :meth:`executemany` and
16251650
:meth:`executescript` methods of the :class:`Connection` object, your code can

0 commit comments

Comments
 (0)