Re: [SQLObject] Unicode problem with MySQL-python < 1.2.2
SQLObject is a Python ORM.
Brought to you by:
ianbicking,
phd
From: Toshio K. <a.b...@gm...> - 2008-10-20 17:02:32
|
Oleg Broytmann wrote: > On Fri, Oct 17, 2008 at 04:32:00PM -0700, Toshio Kuratomi wrote: >> Oleg Broytmann wrote: >>> Another question: do I understand it right that MySQLdb *allows* unicode >>> query strings but doesn't *require* them? Becasue my (humble and >>> uninformed) opinion is to use that "loophole" and do not use unicode with >>> MySQLdb (yet). >> You have it backwards. In MySQL-python-1.2.1 the query string was >> required to be unicode. Sending in a byte string with non-ASCii causes >> an error to be raised. >> >> I do not know if MySQL-python < 1.2.1 had the opposite problem but the >> lower bound version check in the previous chunk makes me suspicious that >> that was the case. > > AFAIK MySQLdb before 1.2.1 only allowed ascii query strings. So: > > -- MySQLdb < 1.2.1: only ascii > -- MySQLdb = 1.2.1: only unicode > -- MySQLdb > 1.2.1: both ascii and unicode > > Right? > With the information you provided, that is correct. And the caveat that only MySQL-python release since 1.2.1 is 1.2.2. >>>> + if self.need_unicode and not isinstance(query, unicode): >>>> + try: >>>> + query = unicode(query, self.dbEncoding) >>>> + except UnicodeError: >>>> + pass > > What if the data cannot be converted (BLOB data, e.g.)? 'query' still > is ascii after that try/except. How would MySQLdb 1.2.1 react? > I don't know what MySQL's BLOB syntax is but if the data is in the query string then BLOBs are broken when using python-MySQL-1.2.1. If the query string does not convert and there are non-ASCii characters then you will get a traceback. Some values of dbEncoding will encode the data to unicode type. I haven't looked at the MySQL-python code to see if this is a problem... it depends on what decoding and encoding the MySQL-python code is doing before storing the BLOB and after retrieving it. If that's messed up, though, then the MySQL BLOB code is broken for any application using BLOBs at all. So this patch makes the situation better with MySQL-python=1.2.1 but does not make it perfect. You could say that SQLObject simply does not work with MySQL-python <= 1.2.1 in lieu of this patch. -Toshio |