@@ -426,6 +426,16 @@ Connection Objects
426
426
427
427
.. class :: Connection
428
428
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
+
429
439
An SQLite database connection has the following attributes and methods:
430
440
431
441
.. attribute :: isolation_level
@@ -970,6 +980,22 @@ Connection Objects
970
980
Cursor Objects
971
981
--------------
972
982
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
+
973
999
.. class :: Cursor
974
1000
975
1001
A :class: `Cursor ` instance has the following attributes and methods.
@@ -1135,13 +1161,11 @@ Row Objects
1135
1161
1136
1162
A :class: `Row ` instance serves as a highly optimized
1137
1163
: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.
1139
1167
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.
1145
1169
1146
1170
.. method :: keys
1147
1171
@@ -1640,8 +1664,10 @@ Using :mod:`sqlite3` efficiently
1640
1664
--------------------------------
1641
1665
1642
1666
1643
- Using shortcut methods
1644
- ^^^^^^^^^^^^^^^^^^^^^^
1667
+ .. _sqlite3-connection-shortcuts :
1668
+
1669
+ Using connection shortcut methods
1670
+ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1645
1671
1646
1672
Using the :meth: `~Connection.execute `,
1647
1673
:meth: `~Connection.executemany `, and :meth: `~Connection.executescript `
0 commit comments