mirror of
https://github.com/python/cpython.git
synced 2025-07-25 20:24:11 +00:00

Authored-by: Aviv Palivoda <palaviv@gmail.com> Co-authored-by: Erlend E. Aasland <erlend.aasland@innova.no>
19 lines
561 B
Python
19 lines
561 B
Python
import sqlite3
|
|
|
|
con = sqlite3.connect(":memory:")
|
|
con.execute("create table test(blob_col blob)")
|
|
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.")
|
|
# 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'Hello, world!'"
|