Discussion:
Encoding problems with cursor.execute
Ernesto Revilla
2005-08-10 22:33:31 UTC
Permalink
Hello.

When I query the database with the .execute method, and results have
international chars, I receive results with wrong international chars. (at
least I don't know the encoding.) Result are strings, not unicodes.

Could anyone give me some hints?
Here everything runs with UTF-8 (postgresql, shell, rekall, etc.) My code
is:
def eventFunc(ctrl, qrow, value):
# read default address
flds=("domicilio","poblacion","codigopostal","provincia")
blk=ctrl.__parent__.direccion
sql=u"select %s from personasdirecciones where personaid=%s AND orden=1"
cur=ctrl.cursor()
cur.execute(sql % (",".join(flds), value),[])
if cur.rowcount>0:
res=cur.fetchone()
for i,fld in enumerate(flds):
print cur.description()[i],"(",type(res[i]),"):",res[i]
getattr(blk,fld).value=res[i]


Best regards,
Erny
Spain
Mike Richardson
2005-08-16 15:01:06 UTC
Permalink
Post by Ernesto Revilla
Hello.
When I query the database with the .execute method, and results have
international chars, I receive results with wrong international chars. (at
least I don't know the encoding.) Result are strings, not unicodes.
Abel is doing some great stuff to get unicode working with python, so a bunch
of stuff in this area is about to get sorted ....
Post by Ernesto Revilla
Could anyone give me some hints?
Here everything runs with UTF-8 (postgresql, shell, rekall, etc.) My code
# read default address
flds=("domicilio","poblacion","codigopostal","provincia")
blk=ctrl.__parent__.direccion
sql=u"select %s from personasdirecciones where personaid=%s AND orden=1"
cur=ctrl.cursor()
cur.execute(sql % (",".join(flds), value),[])
res=cur.fetchone()
print cur.description()[i],"(",type(res[i]),"):",res[i]
getattr(blk,fld).value=res[i]
Best regards,
Erny
Spain
--
Regards
Mike

http://www.rekallrevealed.org
*THE* GPL/Open Source database front end for Linux and Windows.
Loading...