mirror of
https://github.com/python/cpython.git
synced 2025-07-24 19:54:21 +00:00
gh-69093: Add context manager support to sqlite3.Blob (GH-91562)
This commit is contained in:
parent
4e661cd691
commit
a861756675
6 changed files with 135 additions and 11 deletions
|
@ -4,9 +4,13 @@ con = sqlite3.connect(":memory:")
|
|||
con.execute("create table test(blob_col blob)")
|
||||
con.execute("insert into test(blob_col) values (zeroblob(10))")
|
||||
|
||||
blob = con.blobopen("test", "blob_col", 1)
|
||||
blob.write(b"Hello")
|
||||
blob.write(b"World")
|
||||
blob.seek(0)
|
||||
print(blob.read()) # will print b"HelloWorld"
|
||||
blob.close()
|
||||
# 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")
|
||||
|
||||
# Read the contents of our blob
|
||||
with con.blobopen("test", "blob_col", 1) as blob:
|
||||
greeting = blob.read()
|
||||
|
||||
print(greeting) # outputs "b'HelloWorld'"
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue