2022-04-15 02:02:56 +02:00
|
|
|
import sqlite3
|
|
|
|
|
|
|
|
|
|
con = sqlite3.connect(":memory:")
|
|
|
|
|
con.execute("create table test(blob_col blob)")
|
2022-04-22 03:45:16 +02:00
|
|
|
con.execute("insert into test(blob_col) values (zeroblob(13))")
|
2022-04-15 02:02:56 +02:00
|
|
|
|
2022-04-16 06:21:12 +02:00
|
|
|
# Write to our blob, using two write operations:
|
|
|
|
|
with con.blobopen("test", "blob_col", 1) as blob:
|
2022-04-22 03:45:16 +02:00
|
|
|
blob.write(b"hello, ")
|
|
|
|
|
blob.write(b"world.")
|
|
|
|
|
# Modify the first and last bytes of our blob
|
|
|
|
|
blob[0] = b"H"
|
|
|
|
|
blob[-1] = b"!"
|
2022-04-16 06:21:12 +02:00
|
|
|
|
|
|
|
|
# Read the contents of our blob
|
|
|
|
|
with con.blobopen("test", "blob_col", 1) as blob:
|
|
|
|
|
greeting = blob.read()
|
|
|
|
|
|
2022-04-22 03:45:16 +02:00
|
|
|
print(greeting) # outputs "b'Hello, world!'"
|