Instead of defining individual columns
to hold unicode data in sqlobject
class Mytable(SQLObject)
mycol=UnicodeCol()
...
I would rather use normal string columns
class Mytable(SQLObject)
mycol=StringCol()
...
and declare the whole database to use utf-8.
I can do this in mysql
alter database mydb character set utf8
and then I can fill in unicode strings from python mysqldb
>>> ustr=someunicodestring
>>> import MySQLdb
>>> con=MySQLdb.connect(...)
>>> c=con.cursor()
>>> c.execute("insert into mytable (mycol) values (%s)", ustr)
but I can't from sqlobject:
# mycol=StringCol() as above
from model import Mytable
m=Mytable()
mytable.mycol=ustr
File
"/opt/tg/lib/python2.4/site-packages/SQLObject-0.7.0-py2.4.egg/sqlobject/main.py",
line 1031, in _SO_setValue
dbValue = from_python(value, self._SO_validatorState)
File
"/opt/tg/lib/python2.4/site-packages/SQLObject-0.7.0-py2.4.egg/sqlobject/col.py",
line 498, in from_python
return value.encode("ascii")
UnicodeEncodeError: 'ascii' codec can't encode character u'\xfc' in position 1:
ordinal not in range(128)
Any advice?
-Andreas