Work at SourceForge, help us to make it a better place! We have an immediate need for a Support Technician in our San Francisco or Denver office.

Close

#101 Unicode value can't be converted?

open
nobody
PgNumeric (6)
5
2008-03-11
2008-03-11
Pietro Bernardi
No

All versions of PgSQL (including last one, 2.5.1) have this omission:

Unlike StringType, UnicodeType can't be converted to PgNumeric; see example:

>>> from pyPgSQL import PgSQL
>>> a = '10.1'
>>> b = PgSQL.PgNumeric(a)
>>> b
<PgNumeric instance - precision: 3 scale: 1 value: 10.1>
>>> c = u'10.1'
>>> d = PgSQL.PgNumeric(c)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib/python2.5/site-packages/pyPgSQL/PgSQL.py", line 1447, in __init__
raise TypeError, "value can not be converted to a PgNumeric."
TypeError: value can not be converted to a PgNumeric.

Almost all wxwidgets now return unicode value, which must be casted to string for conversion to PgNumeric.

Simple patch can remedy it:

PgSQL.py line 1469:

elif type(value) in (FloatType, StringType):

replace it with:

elif type(value) in (FloatType, StringType, UnicodeType):

Regards,
Pietro

Discussion