I have an sqlite3 database that I have created which I'm filling with data from a db2 database. I get an error when I run the following:
for row in db2_connection.execute(query):
sqlite3_connection.execute("INSERT INTO MY_TABLE VALUES (?, ?, ?)", row)
Here's the error:
File "example.py", line 72, in load_micr_db
sqlite3_connection.execute("INSERT INTO MY_TABLE VALUES (?, ?, ?)", row)
sqlite3.ProgrammingError: You must not use 8-bit bytestrings unless you use a
text_factory that c开发者_StackOverflow中文版an interpret 8-bit bytestrings (like text_factory = str).
It is highly recommended that you instead just switch your application to
Unicode strings.
This sounds like excellent advice, but I don't know how to follow it. How do I "switch my application to Unicode strings"?
I'm using Python 2.6, pyodbc
to query db2 9, sqlite3
.
Use string literals prefixed with a u
.
print u'I am a Unicode string.'
"Unicode in Python, Completely Demystified"
精彩评论