Created
August 19, 2011 03:13
-
-
Save m-mizutani/1155940 to your computer and use it in GitHub Desktop.
Insert binary data as array.array type to sqlite3 DB as BLOB in python
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sqlite3 | |
import array | |
a = array.array('B', [3, 1, 2,5,41,44,231,212,0,66,67,68]) | |
b = buffer(a.tostring()) | |
conn = sqlite3.connect ('test.db') | |
conn.execute ('create table if not exists test (id integer primary key, b blob)') | |
conn.execute ('delete from test') | |
conn.execute ('insert into test (b) values (?)', (b,)) | |
conn.commit () | |
cur = conn.cursor () | |
cur.execute ('select b from test') | |
r = cur.fetchone() | |
print 'returned value', r[0].__class__ | |
print 'matching', ("OK" if r[0] == b else "NG") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment