473,500 Members | 1,862 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 2195
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
2085
by: Dave Harrison | last post by:
Hi all, got a problem combinging mx and MySQLdb, when I build and install both for my Python2.1 install on a Solaris 9 box I can import mx fine, but importing MySQLdb causing python to core dump. ...
1
2572
by: Peter Nikolaidis | last post by:
Greetings, I am attempting to get MySQLdb 0.9.2 installed on Mac OS 10.2 with a Fink distribution of Python 2.2.2. I have seen only a few posts on the subject, some of them relate to...
1
2985
by: Derek Fountain | last post by:
I was trying to use MySQLdb to connect to a database. All is OK, except I can't figure out how to get the details of an error. Suppose I try to connect to a non existant server, or with the wrong...
1
1436
by: JZ | last post by:
I cannot execute insert data into TEXT field if that data is bigger than 64KB. :( >>> cursor.execute("INSERT INTO table (field) VALUES(%s) WHERE id=1", myValue) Traceback (most recent call...
2
5033
by: Tim Williams | last post by:
I'm trying to write a simple python program to access a MySQL database. I'm having a problem with using MySQLdb to get the results of a SQL command in a cursor. Sometimes the cursor.execute works,...
21
5213
by: John Fabiani | last post by:
Hi, I'm a newbie and I'm attempting to learn howto create a select statement. When I use >>> string1='18 Tadlock Place' >>> cursor.execute("SELECT * FROM mytest where address = %s",string1) All...
2
2515
by: Daniel Baggott | last post by:
Hi, I'm seeking assistance in troubleshooting connecting to MySQL (4.0.20) using Python (2.3.4) and MySQLdb (1.0.0). When I attempt to make a connection, I get the following exception:...
0
1456
by: Wesley Kincaid | last post by:
I'm attempting to run a simple query through MySQLdb's cursor.execute(). However, when the request includes a timestamp field, I'm getting "ValueError: invalid literal for int(): 9-." Could...
2
2176
by: ws Wang | last post by:
MySQLdb is working fine at command line, however when I tried to use it with mod_python, it give me a "server not initialized" error. This is working fine: ----------------------- testmy.py...
0
7136
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7182
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7232
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
5490
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
4923
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4611
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3110
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
1430
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
672
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.