How to communicate ONLY IN UNICODE with MySQL Database using OurSQL in python?
I was reading the documentation of oursql and encountered this description for establishing a connection:
By default, oursql will try to use unicode wherever possible, and set the connection charset to utf8.
My tables and all the columns store every string in utf8.
Does this mean, when I connect to my database like this
conn = oursql.connect(host='127.0.0.1', user='habnabit', passwd='foobar',
db='example', port=3307)
I can pass unicode strings to the cursor and the cursor will turn them to utf8 automatically? And the other way around, the cursor will return any string from the database as unicode? So I do not have to bother with decoding or encoding?
I have to n开发者_如何学Cow this for sure. :-)
You should be able to, yes. My guess is you just need to set the MySQL character set connection variables. SET NAMES
is usually sufficient.
精彩评论