summaryrefslogtreecommitdiffstats
path: root/Doc
diff options
context:
space:
mode:
authorErlend Egeberg Aasland <erlend.aasland@innova.no>2022-04-22 01:45:16 (GMT)
committerGitHub <noreply@github.com>2022-04-22 01:45:16 (GMT)
commit29afb7d2efed6ee48a67dafdc1a1f34dd60153cf (patch)
treec1a3cd0033011f3286c1ec97fb7cdc82cdf3250e /Doc
parent1317b70f89606bd14597116b7ab68a968ea6c017 (diff)
downloadcpython-29afb7d2efed6ee48a67dafdc1a1f34dd60153cf.zip
cpython-29afb7d2efed6ee48a67dafdc1a1f34dd60153cf.tar.gz
cpython-29afb7d2efed6ee48a67dafdc1a1f34dd60153cf.tar.bz2
gh-69093: Add indexing and slicing support to sqlite3.Blob (#91599)
Authored-by: Aviv Palivoda <palaviv@gmail.com> Co-authored-by: Erlend E. Aasland <erlend.aasland@innova.no>
Diffstat (limited to 'Doc')
-rw-r--r--Doc/includes/sqlite3/blob.py11
-rw-r--r--Doc/library/sqlite3.rst7
2 files changed, 11 insertions, 7 deletions
diff --git a/Doc/includes/sqlite3/blob.py b/Doc/includes/sqlite3/blob.py
index b3694ad..d947059 100644
--- a/Doc/includes/sqlite3/blob.py
+++ b/Doc/includes/sqlite3/blob.py
@@ -2,15 +2,18 @@ import sqlite3
con = sqlite3.connect(":memory:")
con.execute("create table test(blob_col blob)")
-con.execute("insert into test(blob_col) values (zeroblob(10))")
+con.execute("insert into test(blob_col) values (zeroblob(13))")
# Write to our blob, using two write operations:
with con.blobopen("test", "blob_col", 1) as blob:
- blob.write(b"Hello")
- blob.write(b"World")
+ blob.write(b"hello, ")
+ blob.write(b"world.")
+ # Modify the first and last bytes of our blob
+ blob[0] = b"H"
+ blob[-1] = b"!"
# Read the contents of our blob
with con.blobopen("test", "blob_col", 1) as blob:
greeting = blob.read()
-print(greeting) # outputs "b'HelloWorld'"
+print(greeting) # outputs "b'Hello, world!'"
diff --git a/Doc/library/sqlite3.rst b/Doc/library/sqlite3.rst
index cbe7bb1..69e77e9 100644
--- a/Doc/library/sqlite3.rst
+++ b/Doc/library/sqlite3.rst
@@ -1051,9 +1051,10 @@ Blob Objects
.. class:: Blob
- A :class:`Blob` instance is a :term:`file-like object` that can read and write
- data in an SQLite :abbr:`BLOB (Binary Large OBject)`. Call ``len(blob)`` to
- get the size (number of bytes) of the blob.
+ A :class:`Blob` instance is a :term:`file-like object`
+ that can read and write data in an SQLite :abbr:`BLOB (Binary Large OBject)`.
+ Call :func:`len(blob) <len>` to get the size (number of bytes) of the blob.
+ Use indices and :term:`slices <slice>` for direct access to the blob data.
Use the :class:`Blob` as a :term:`context manager` to ensure that the blob
handle is closed after use.