I am trying to save a BLOB created from an integer array (i.e. a packed array of integers) in SQLite DB. The script below gives the following trace. As far as I understand from the Python 2.7 sqlite3 documentation, it should be possible to insert a buffer object into a table where it is supposed to be saved as a BLOB. However, I cannot complete this work. (FWIW, isinstance (b, buffer) print True if inserted in the script, so I really create a buffer object.)
Any suggestions?
Thanks, -P.
Traceback (most recent call last):
File "example.py", line 13, in <module>
conn.execute( 'insert into foo values (?)', (b,) )
ValueError: could not convert BLOB to buffer
import sqlite3
import sys
import array
ar = array.array( 'I' )
ar.extend( [1,0,3,11,43] )
b = buffer( ar )
conn = sqlite3.connect( ':memory:' )
conn.execute( 'create table foo( bar BLOB )' )
conn.commit()
conn.execute( 'insert into foo values (?)', (b,) )
conn.commit()
source
share