SQLite3BLOB
Webpython2.x`buffer(blob)`python3insert
select
pdfpdf
import sqlite3
from contextlib import closing
rf = 'C:\\test\\read.jpg' #
wf = 'C:\\test\\write.jpg' #
with closing(sqlite3.connect('blob_test.db')) as db:
#
cursor = db.cursor()
try:
cursor.execute('create table img_table (img blob);')
except sqlite3.OperationalError:
cursor.execute('delete from img_table')
#
with open(rf, 'rb') as f:
blob = f.read()
#
db.execute('insert into img_table values(?)', [blob])
db.commit()
#
for row in cursor.execute('select img from img_table limit 1'):
blob = row[0]
#
with open(wf, 'wb') as f:
f.write(blob)
#
db.execute('drop table img_table')