mirror of
https://github.com/python/cpython.git
synced 2025-09-18 14:40:43 +00:00
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>
This commit is contained in:
parent
1317b70f89
commit
29afb7d2ef
5 changed files with 349 additions and 16 deletions
|
@ -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!'"
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue