@@ -416,6 +416,16 @@ Connection Objects
416
416
417
417
.. class :: Connection
418
418
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
+
419
429
An SQLite database connection has the following attributes and methods:
420
430
421
431
.. attribute :: isolation_level
@@ -960,6 +970,22 @@ Connection Objects
960
970
Cursor Objects
961
971
--------------
962
972
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
+
963
989
.. class :: Cursor
964
990
965
991
A :class: `Cursor ` instance has the following attributes and methods.
@@ -1125,13 +1151,11 @@ Row Objects
1125
1151
1126
1152
A :class: `Row ` instance serves as a highly optimized
1127
1153
: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.
1129
1157
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.
1135
1159
1136
1160
.. method :: keys
1137
1161
@@ -1623,8 +1647,10 @@ Using :mod:`sqlite3` efficiently
1623
1647
--------------------------------
1624
1648
1625
1649
1626
- Using shortcut methods
1627
- ^^^^^^^^^^^^^^^^^^^^^^
1650
+ .. _sqlite3-connection-shortcuts :
1651
+
1652
+ Using connection shortcut methods
1653
+ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1628
1654
1629
1655
Using the :meth: `~Connection.execute `,
1630
1656
:meth: `~Connection.executemany `, and :meth: `~Connection.executescript `
0 commit comments