Skip to content

Commit 95573ad

Browse files
author
Erlend Egeberg Aasland
authored
gh-69093: sqlite3 blob doc amendments (GH-91561)
- document that you cannot open a blob handle in a WITHOUT ROWID table - document the blobopen() positional arguments in the same order as they appear - relocate sqlite3.Blob section
1 parent f2bc12f commit 95573ad

File tree

1 file changed

+55
-52
lines changed

1 file changed

+55
-52
lines changed

Doc/library/sqlite3.rst

+55-52
Original file line numberDiff line numberDiff line change
@@ -397,9 +397,12 @@ Connection Objects
397397
.. method:: blobopen(table, column, row, /, *, readonly=False, name="main")
398398

399399
Open a :class:`Blob` handle to the :abbr:`BLOB (Binary Large OBject)`
400-
located in row *row*, column *column*, table *table* of database *name*.
400+
located in table name *table*, column name *column*, and row index *row*
401+
of database *name*.
401402
When *readonly* is :const:`True` the blob is opened without write
402403
permissions.
404+
Trying to open a blob in a ``WITHOUT ROWID`` table will raise
405+
:exc:`OperationalError`.
403406

404407
.. note::
405408

@@ -1044,6 +1047,57 @@ Now we plug :class:`Row` in::
10441047
35.14
10451048

10461049

1050+
Blob Objects
1051+
------------
1052+
1053+
.. versionadded:: 3.11
1054+
1055+
.. class:: Blob
1056+
1057+
A :class:`Blob` instance is a :term:`file-like object` that can read and write
1058+
data in an SQLite :abbr:`BLOB (Binary Large OBject)`. Call ``len(blob)`` to
1059+
get the size (number of bytes) of the blob.
1060+
1061+
Use the :class:`Blob` as a :term:`context manager` to ensure that the blob
1062+
handle is closed after use.
1063+
1064+
.. literalinclude:: ../includes/sqlite3/blob.py
1065+
1066+
.. method:: close()
1067+
1068+
Close the blob.
1069+
1070+
The blob will be unusable from this point onward. An
1071+
:class:`~sqlite3.Error` (or subclass) exception will be raised if any
1072+
further operation is attempted with the blob.
1073+
1074+
.. method:: read(length=-1, /)
1075+
1076+
Read *length* bytes of data from the blob at the current offset position.
1077+
If the end of the blob is reached, the data up to
1078+
:abbr:`EOF (End of File)` will be returned. When *length* is not
1079+
specified, or is negative, :meth:`~Blob.read` will read until the end of
1080+
the blob.
1081+
1082+
.. method:: write(data, /)
1083+
1084+
Write *data* to the blob at the current offset. This function cannot
1085+
change the blob length. Writing beyond the end of the blob will raise
1086+
:exc:`ValueError`.
1087+
1088+
.. method:: tell()
1089+
1090+
Return the current access position of the blob.
1091+
1092+
.. method:: seek(offset, origin=os.SEEK_SET, /)
1093+
1094+
Set the current access position of the blob to *offset*. The *origin*
1095+
argument defaults to :data:`os.SEEK_SET` (absolute blob positioning).
1096+
Other values for *origin* are :data:`os.SEEK_CUR` (seek relative to the
1097+
current position) and :data:`os.SEEK_END` (seek relative to the blob’s
1098+
end).
1099+
1100+
10471101
.. _sqlite3-exceptions:
10481102

10491103
Exceptions
@@ -1104,57 +1158,6 @@ Exceptions
11041158

11051159
.. _sqlite3-blob-objects:
11061160

1107-
Blob Objects
1108-
------------
1109-
1110-
.. versionadded:: 3.11
1111-
1112-
.. class:: Blob
1113-
1114-
A :class:`Blob` instance is a :term:`file-like object` that can read and write
1115-
data in an SQLite :abbr:`BLOB (Binary Large OBject)`. Call ``len(blob)`` to
1116-
get the size (number of bytes) of the blob.
1117-
1118-
Use the :class:`Blob` as a :term:`context manager` to ensure that the blob
1119-
handle is closed after use.
1120-
1121-
.. literalinclude:: ../includes/sqlite3/blob.py
1122-
1123-
.. method:: close()
1124-
1125-
Close the blob.
1126-
1127-
The blob will be unusable from this point onward. An
1128-
:class:`~sqlite3.Error` (or subclass) exception will be raised if any
1129-
further operation is attempted with the blob.
1130-
1131-
.. method:: read(length=-1, /)
1132-
1133-
Read *length* bytes of data from the blob at the current offset position.
1134-
If the end of the blob is reached, the data up to
1135-
:abbr:`EOF (End of File)` will be returned. When *length* is not
1136-
specified, or is negative, :meth:`~Blob.read` will read until the end of
1137-
the blob.
1138-
1139-
.. method:: write(data, /)
1140-
1141-
Write *data* to the blob at the current offset. This function cannot
1142-
change the blob length. Writing beyond the end of the blob will raise
1143-
:exc:`ValueError`.
1144-
1145-
.. method:: tell()
1146-
1147-
Return the current access position of the blob.
1148-
1149-
.. method:: seek(offset, origin=os.SEEK_SET, /)
1150-
1151-
Set the current access position of the blob to *offset*. The *origin*
1152-
argument defaults to :data:`os.SEEK_SET` (absolute blob positioning).
1153-
Other values for *origin* are :data:`os.SEEK_CUR` (seek relative to the
1154-
current position) and :data:`os.SEEK_END` (seek relative to the blob’s
1155-
end).
1156-
1157-
11581161
.. _sqlite3-types:
11591162

11601163
SQLite and Python types

0 commit comments

Comments
 (0)