Artificial intelligent assistant

python3+SQlite でPDFデータをINSERTするにはどうすればよいか python3SQlitePDF blob →blob python

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')

xcX3v84RxoQ-4GxG32940ukFUIEgYdPy dea922ecc75e6d3e30327a9a7166c91b