[Tutor] pgdb and unicode
Ismael Farfán Estrada
sulfurfff at hotmail.com
Mon Oct 22 18:29:29 CEST 2007
Hi there.
I have a small system in production with wxPython and PostgreSQL running on
a machine with Centos 5.
At first everytihing was running ok but now a weird bug was discovered:
they can't insert characters like á é í ó ú ä ë ñ .... (non english characters)
Does anyone knows how can I make pgdb accept that kind of characters?
I wrote a little script...
But first
CREATE DATABASE test;
CREATE TABLE tabla(
cad character varying
) ;
#!/usr/bin/python
# -*- coding: utf8 -*-
import pgdb
con = pgdb.connect(user="farfan", password='000000', host='localhost', database='test')
cur = con.cursor()
cur.execute("INSERT INTO tabla VALUES ('é')")
con.commit()
cur.execute(u"INSERT INTO tabla VALUES ('é')")
con.commit()
and this is the result
python Aplicacion.py
Traceback (most recent call last):
File "Aplicacion.py", line 10, in ?
cur.execute(u"INSERT INTO tabla VALUES ('é')")
File "/usr/lib/python2.4/site-packages/pgdb.py", line 175, in execute
self.executemany(operation, (params,))
File "/usr/lib/python2.4/site-packages/pgdb.py", line 198, in executemany
raise OperationalError, "internal error in '%s': %s" % (sql,err)
pg.OperationalError[farfan at Kriemhild ~]$ python Aplicacion.py
Traceback (most recent call last):
File "Aplicacion.py", line 8, in ?
cur.execute(u"INSERT INTO tabla VALUES ('é')")
File "/usr/lib/python2.4/site-packages/pgdb.py", line 175, in execute
self.executemany(operation, (params,))
File "/usr/lib/python2.4/site-packages/pgdb.py", line 198, in executemany
raise OperationalError, "internal error in '%s': %s" % (sql,err)
pg.OperationalError
As you can see, the first insert statement is executed in ascii format and is succeful,
the second, which is in Unicode, fails
the problem is thas wxPython will allways send the script in unicode format...
any ideas on how to fix it?
rb3m dijo: Un buen programador no es uno que se sepa un lenguaje al derecho y al revés, sino el que sabe resolver un problema y después implementar la solución en el lenguaje más adecuado.
_________________________________________________________________
Express yourself instantly with MSN Messenger! Download today it's FREE!
http://messenger.msn.click-url.com/go/onm00200471ave/direct/01/
More information about the Tutor
mailing list