MySQLDB - return strange type of variable

G

Grzegorz Smith

Hi all. I'm trying get data from text field in MySQl 5.0 with my National
characters. Data are stored in utf8 encodings. Here is the script:
import MySQLdb, MySQLdb.cursors
conn = MySQLdb.connect(host='localhost', user='root', passwd='123456',
db='profile_locale')
c = conn.cursor(MySQLdb.cursors.DictCursor)
c.execute("SET CHARACTER SET utf8")
c.execute("SELECT string_value FROM lang_pl_pl WHERE id=8")
row = c.fetchone()
print row
and i get:
{'string_value': array('c', 'Zmie\xc5\x84 has\xc5\x82o')}
where it come array type?
How can i get value 'Zmie\xc5\x84 has\xc5\x82o' ?? because I trying do this
and I can't achieve. If I do c.fetchone -shouldn't i get type tuple?
I'm using MySQLdb 1.2.0 on Windows XP Professional SP2 installed
Any help will be appreciated
 
J

Jeffrey Froman

Grzegorz said:
Hi all. I'm trying get data from text field in MySQl 5.0 with my National
characters. Data are stored in utf8 encodings. Here is the script:
import MySQLdb, MySQLdb.cursors
conn = MySQLdb.connect(host='localhost', user='root', passwd='123456',
db='profile_locale')
c = conn.cursor(MySQLdb.cursors.DictCursor)
c.execute("SET CHARACTER SET utf8")
c.execute("SELECT string_value FROM lang_pl_pl WHERE id=8")
row = c.fetchone()
print row
and i get:
{'string_value': array('c', 'Zmie\xc5\x84 has\xc5\x82o')}
where it come array type?

Recent versions of MySQL/MySQLdb return "binary strings" as Python array
objects, rather than bytestrings (I think the change was around version 4.2
of MySQL.) Details on array objects are here:

http://www.python.org/doc/lib/module-array

How can i get value 'Zmie\xc5\x84 has\xc5\x82o' ??

array('c', 'Zmie\xc5\x84 has\xc5\x82o').tostring()

If I do c.fetchone -shouldn't i get type tuple?

If you use the default MySQLdb cursor object you will get a tuple. Using the
DictCursor as you are returns a dictionary instead.


Jeffrey
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,982
Messages
2,570,186
Members
46,739
Latest member
Clint8040

Latest Threads

Top