Learn how easy it is to sync an existing GitHub or Google Code repo to a SourceForge project! See Demo

Close

#52 unicode queries break

closed-out-of-date
Oleg Broytman
General (125)
5
2006-11-13
2005-01-01
Wichert Akkerman
No

When trying to store unicode data in a database I get
an exception with the backtrace below. Tested using
current SVN trunk.

File "./parse", line 10, in StoreChannels
nc[xid]=tvguide.database.Channel.byXid(xid)
File "<string>", line 1, in <lambda>
File
"/usr/local/lib/python2.3/site-packages/sqlobject/main.py",
line 961, in
_SO_fetchAlternateID
value)
File
"/usr/local/lib/python2.3/site-packages/sqlobject/dbconnection.py",
line 400, in _SO_selectOneAlt
return self.queryOne("SELECT %s FROM %s WHERE %s =
%s" %
File
"/usr/local/lib/python2.3/site-packages/sqlobject/dbconnection.py",
line 230, in queryOne
return self._runWithConnection(self._queryOne, s)
File
"/usr/local/lib/python2.3/site-packages/sqlobject/dbconnection.py",
line 125, in _runWithConnection
val = meth(conn, *args)
File
"/usr/local/lib/python2.3/site-packages/sqlobject/dbconnection.py",
line 223, in _queryOne
self._executeRetry(conn, c, s)
File
"/usr/local/lib/python2.3/site-packages/sqlobject/dbconnection.py",
line 196, in _executeRetry
return cursor.execute(query)
TypeError: argument 1 must be str, not unicode

Discussion

  • Oleg Broytman
    Oleg Broytman
    2005-03-01

    Logged In: YES
    user_id=4799

    What type is xid column? Can you provide a test program?

     
  • Oleg Broytman
    Oleg Broytman
    2005-06-17

    Logged In: YES
    user_id=4799

    Use UnicodeCol to convert unicode to DB strings.

     
  • Oleg Broytman
    Oleg Broytman
    2005-06-17

    • status: open --> closed-fixed
     
    • status: closed-fixed --> open-fixed
     
  • Logged In: YES
    user_id=15420

    This code did use a UnicodeCol. The class definition used is:

    class Channel(sqlobject.SQLObject):
    xid = sqlobject.StringCol(length=32, varchar=True,
    alternateID=True)
    name = sqlobject.UnicodeCol(length=64, varchar=True,
    notNone=True)

    programs = sqlobject.MultipleJoin("Program")

    xid is not StringCol here, which is correct it is only
    allowed to store ASCII data.

     
  • Oleg Broytman
    Oleg Broytman
    2006-01-12

    Logged In: YES
    user_id=4799

    Call me stupid, but I see

    xid = sqlobject.StringCol(length=32, varchar=True,
    alternateID=True)

    xid *IS* StringCol in my eyes! Are my eyes lying?

    Well, it is a known problem in SQLObject: if you do
    .select(), .selectBy() or .by*() you have to convert unicode
    to string yourself:

    Channel.byXid(xid.encode(dbEncoding))

    even for UnicodeColumns.

     
  • Oleg Broytman
    Oleg Broytman
    2006-01-12

    • assigned_to: nobody --> phd
    • status: open-fixed --> open
     
  • Oleg Broytman
    Oleg Broytman
    2006-11-13

    • status: open --> closed-out-of-date