472,119 Members | 1,621 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,119 software developers and data experts.

MySQLDB - return strange type of variable

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
1 2107
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.

Similar topics

reply views Thread by Dave Harrison | last post: by
1 post views Thread by Peter Nikolaidis | last post: by
1 post views Thread by Derek Fountain | last post: by
1 post views Thread by JZ | last post: by
21 posts views Thread by John Fabiani | last post: by
2 posts views Thread by Daniel Baggott | last post: by
reply views Thread by Wesley Kincaid | last post: by
2 posts views Thread by ws Wang | last post: by
reply views Thread by leo001 | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.