开发者

Error inserting (unicode?) text into sqlite3 database

开发者 https://www.devze.com 2023-02-09 15:12 出处:网络
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:

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"

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号