#196 sqlobject-0.7.1dev_r1884, Mysql and unicode

closed
nobody
MySQL (29)
5
2006-09-04
2006-08-28
dado1945
No

Please, check if suplied string is not unicode already
in mysqlconnection.py. There is extract how it could
look like:

import types
.....
if self.need_unicode:
# For MysqlDB 1.2.1 and later, we go
# encoding->unicode->charset (in
the mysql db)
if type(query) != types.UnicodeType:
query = unicode(query,
self.encoding)
return cursor.execute(query)
else:
return cursor.execute(query)
.....

Or use "isinstance(query, unicode)". I don't know what
different we will have and which one is better to use
however.

Discussion

  • Oleg Broytman
    Oleg Broytman
    2006-09-01

    Logged In: YES
    user_id=4799

    But how can the query be unicode in _executeRetry()? The
    query came from SQLObject so it must be an ascii string here...

     
  • dado1945
    dado1945
    2006-09-01

    Logged In: YES
    user_id=1533929

    Here how it happens. I have checked all the traceback and
    have not found anything what would change unicode string to
    simple string. I happens only in select it seems. Assignment
    work OK as far as I remember.

    File
    "D:\daliaus\projects\tekshtpleksht\tekshtpleksht\controllers.py",
    line 208, in save
    page = model.Article.byName(pagename)
    File "<string>", line 1, in <lambda>
    File "d:\program
    files\python2.4\lib\site-packages\SQLObject-0.7.1dev_r1860-py2.4.egg\sqlobject\main.py",
    line 1266, in _SO_fetchAlternateID
    result, obj = cls._findAlternateID(name, dbName, value,
    connection)
    File "d:\program
    files\python2.4\lib\site-packages\SQLObject-0.7.1dev_r1860-py2.4.egg\sqlobject\main.py",
    line 1262, in _findAlternateID
    value), None
    File "d:\program
    files\python2.4\lib\site-packages\SQLObject-0.7.1dev_r1860-py2.4.egg\sqlobject\dbconnection.py",
    line 590, in _SO_selectOneAlt
    return self.queryOne("SELECT %s FROM %s WHERE %s = %s" %
    File "d:\program
    files\python2.4\lib\site-packages\SQLObject-0.7.1dev_r1860-py2.4.egg\sqlobject\dbconnection.py",
    line 760, in queryOne
    return self._dbConnection._queryOne(self._connection, s)
    File "d:\program
    files\python2.4\lib\site-packages\SQLObject-0.7.1dev_r1860-py2.4.egg\sqlobject\dbconnection.py",
    line 342, in _queryOne
    self._executeRetry(conn, c, s)
    File "D:\Program
    Files\Python2.4\lib\site-packages\sqlobject-0.7.1dev_r1860-py2.4.egg\sqlobject\mysql\mysqlconnection.py",
    line 74, in _executeRetry
    myquery = unicode(query, self.encoding)
    TypeError: decoding Unicode is not supported

     
  • dado1945
    dado1945
    2006-09-01

    Logged In: YES
    user_id=1533929

    I think here is answer:

    >>> u = u'1'
    >>> a = '%s' % u
    >>> type(a)
    <type 'unicode'>

     
  • Oleg Broytman
    Oleg Broytman
    2006-09-04

    Logged In: YES
    user_id=4799

    The problem is in the code
    page = model.Article.byName(pagename)
    "pagename" is unicode here. This is a longstanding problem
    in SQLObject that I fixed a few days ago. But I have
    forgotted to fix .byName() case. Thank you for reminding!
    Fixed it now. Committed in the revision 1896 to the trunk,
    1897 to the 0.7-branch.

     
  • Oleg Broytman
    Oleg Broytman
    2006-09-04

    • status: open --> closed