By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
448,996 Members | 1,539 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 448,996 IT Pros & Developers. It's quick & easy.

MySQLDB - return strange type of variable

P: n/a
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
Mar 25 '06 #1
Share this Question
Share on Google+
1 Reply


P: n/a
Grzegorz Smith wrote:
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
Mar 25 '06 #2

This discussion thread is closed

Replies have been disabled for this discussion.