I am trying to query an Microsoft SQL 2005 database, process the data and write the keys to the data I updated to an sqllite3 database store locally on my machine.
The tools I’m using are python 2.7, pyodbc and sqllite3. I am on windows 7 and the driver I’ve tried connecting to my mssql db using the sql server and sql native client driver with pyodbc and both yield the same results.
The field I am having issues with is a uuid field that is binary(16) in mssql. When I query the data using pyodbc it is coming back to me in a bytearray().
This is the output I get when I run the following.
id = mycursor.fetchone()
print id
àO÷�eÅO‹1ÝWt‘E
repr(id)
bytearray(b’\xe0O\xf7\x1d\x9de\xc5O\x8b1\x0e\xddWt\x91E’)
When I go to insert that Id into an sqllite3 database I get the following.
s = sqlite3.connect('tmp.db')
cursor = s.cursor()
s.execute("create table recs(uuid blob)")
s.commit()
s.execute("insert into recs (uuid) values(?)", id)
1 s.execute(“insert into recs (uuid) values(?)”, id)
ProgrammingError: Incorrect number of bindings supplied. The current statement uses 1, and there are 16 supplied.
The Python value needs to be a
bufferobject: