Looked a bit more on this... Handling binary data in Python <= 2.5 is just a mess... But it looks like the 'array' module should be able to help us out...
Consider a table defined as:
CREATE TABLE tab (s VARCHAR, b BLOB)
Then the following works, but is Python >= 2.6 only:
data = bytearray([dbus.Byte(1),dbus.Byte(2)])
b = sqlite3.Binary(data)
cursor.execute ("INSERT INTO tab VALUES ('teststring', ?)", (b,))
It looks like we could do equivalently in Python 2.5 with:
# Create binary array
data = array.array ("B", [dbus.Byte(1), dbus.Byte(2)])
b = sqlite3.Binary(a)
cursor.execute ("INSERT INTO tab VALUES ('teststring', ?)", (b,))
But the very last execute statement fails with:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ValueError: could not convert BLOB to buffer
-- quite unhelpful backtrace that is :-S Any ideas much appreciated...
Looked a bit more on this... Handling binary data in Python <= 2.5 is just a mess... But it looks like the 'array' module should be able to help us out...
Consider a table defined as:
CREATE TABLE tab (s VARCHAR, b BLOB)
Then the following works, but is Python >= 2.6 only:
data = bytearray( [dbus.Byte( 1),dbus. Byte(2) ]) Binary( data)
b = sqlite3.
cursor.execute ("INSERT INTO tab VALUES ('teststring', ?)", (b,))
It looks like we could do equivalently in Python 2.5 with:
# Create binary array
data = array.array ("B", [dbus.Byte(1), dbus.Byte(2)])
b = sqlite3.Binary(a)
cursor.execute ("INSERT INTO tab VALUES ('teststring', ?)", (b,))
But the very last execute statement fails with:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ValueError: could not convert BLOB to buffer
-- quite unhelpful backtrace that is :-S Any ideas much appreciated...