On 9/10/06, Oleg Broytmann <[EMAIL PROTECTED]> wrote:
> On Sun, Sep 10, 2006 at 03:29:22PM +0200, Markus Gritsch wrote:
> > >> # -*- coding: latin-1 -*-
> [skip]
> > return codecs.utf_8_decode(input, errors, True)
> > UnicodeDecodeError: 'utf8' codec can't decode bytes in position 3-4:
> > unexpected end of data
>
> This is why I always recommend against u'' strings. Along with coding
> pseudocomment they form a good base for subtle bugs.
Yes, you are right, but I just used u'' to get a unicode string for
the example program. In my real application I use Qt and have
therefore unicode strings all over the place.
The problem seems to me, that although I give SQLObject a unicode
string, it tries to make another unicode string out of it:
col.py:
class UnicodeStringValidator(validators.Validator):
def to_python(self, value, state):
if value is None:
return None
if isinstance(value, unicode):
return value
if isinstance(value, array_type): # MySQL
return unicode(value.tostring(), self.db_encoding)
return unicode(value, self.db_encoding)
If I print the type of the value, it says <type 'str'> which is IMO
the problem. The
if isinstance(value, unicode):
line does therefore not match, and the last line of the method
return unicode(value, self.db_encoding)
is executed, which raises the exception. If I modify the last line to
return value
the value is inserted correctly into the database.
Note that since MySQLdb version 1.2.2b1 it is possible to use a
unicode string as the query-string.
-------------------------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
sqlobject-discuss mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/sqlobject-discuss