8000 gh-69093: Add mapping protocol support to sqlite3.Blob by erlend-aasland · Pull Request #91599 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

gh-69093: Add mapping protocol support to sqlite3.Blob #91599

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Address review: reword docs and modify example
  • Loading branch information
Erlend E. Aasland committed Apr 18, 2022
commit ed6a9b62da79b991b3376f6d88ff95baf1d4ef6b
11 changes: 7 additions & 4 deletions Doc/includes/sqlite3/blob.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,18 @@

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!'"
6 changes: 3 additions & 3 deletions Doc/library/sqlite3.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1054,10 +1054,10 @@ Blob Objects

.. class:: Blob

A :class:`Blob` instance is a :term:`file-like object` with
:term:`mapping` support,
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.
Call :func:`len(blob) <len>` 4AC3 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.
Expand Down
0