diff options
Diffstat (limited to 'Doc/includes')
-rw-r--r-- | Doc/includes/sqlite3/blob.py | 16 |
1 files changed, 10 insertions, 6 deletions
diff --git a/Doc/includes/sqlite3/blob.py b/Doc/includes/sqlite3/blob.py index 61994fb..b3694ad 100644 --- a/Doc/includes/sqlite3/blob.py +++ b/Doc/includes/sqlite3/blob.py @@ -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'" |