On 9/10/06, Oleg Broytmann <[EMAIL PROTECTED]> wrote:
> On Sun, Sep 10, 2006 at 04:16:12PM +0200, Markus Gritsch wrote:
> > 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.
>
> This is because from_python() has been called (in main.py, .set()) and
> converted the value to a string.
>
> > Note that since MySQLdb version 1.2.2b1 it is possible to use a
> > unicode string as the query-string.
>
> Yes, but SQLObject is not MySQL-only ORM, and hence uses strings
> internally.
Hmm, but when I try connectionForURI('sqlite:/:memory:'), the type of
the value in the validator is <type 'unicode'>. So it seems to me,
that it is a DB-connection specific problem. Actually I can solve all
problems by inserting
# some MySQLdb options
self.kw['use_unicode'] = 1
self.kw['charset'] = 'utf8'
# SQLObject workaround
self.need_unicode = False
before
DBAPI.__init__(self, **kw)
in the __init__method of MySQLConnection in mysqlconnection.py.
-------------------------------------------------------------------------
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