Oleg Broytmann wrote: > On Fri, Oct 17, 2008 at 12:57:03PM -0700, Toshio Kuratomi wrote: >> I looked at the SQLObject source and found that SQLObject used to change >> the query into a byte string but that's no longer the case. The >> relevant revisions are svn diff -r 3021:3022 which removes the >> functionality and the chunk of svn diff -r 3175:3176 that removes >> self.need_unicode (as it was no longer used). > > This is an area where SQLObject was changing to and fro many times > without much success. Any implemented solution caused troubles for some > users. :( > <nod> I was afraid of something like that.
>> If it was removed just because someone thought it wasn't necessary >> (without thinking about old versions of MySQL-python) I'd be happy to >> submit a patch which converts to unicode if the MySQL-python version >>> =1.2.1 < 1.2.2. > > IWBN to see a patch, so interested parties can discuss it. > Patch attached. This is a very slight variant on what we have currently in production. It's almost what was in the code before with the one change being that there's an upper bound on the versions of MySQL-python that we do the conversion for as well as a lower bound. -Toshio
Index: sqlobject/mysql/mysqlconnection.py =================================================================== --- sqlobject/mysql/mysqlconnection.py (revision 3623) +++ sqlobject/mysql/mysqlconnection.py (working copy) @@ -28,6 +28,12 @@ self.db = db self.user = user self.password = password + + if MySQLdb.version_info[:3] >= (1, 2, 1) and MySQLdb.version_info[:3] < (1, 2, 2): + self.need_unicode = True + else: + self.need_unicode = False + self.kw = {} for key in ("unix_socket", "init_command", "read_default_file", "read_default_group", "conv"): @@ -104,6 +110,12 @@ # reconnect flag must be set when making the connection to indicate # that autoreconnecting is desired. In MySQLdb 1.2.2 or newer this is # done by calling ping(True) on the connection. + if self.need_unicode and not isinstance(query, unicode): + try: + query = unicode(query, self.dbEncoding) + except UnicodeError: + pass + for count in range(3): try: return cursor.execute(query)
signature.asc
Description: OpenPGP digital signature
------------------------------------------------------------------------- This SF.Net email is sponsored by the Moblin Your Move Developer's challenge Build the coolest Linux based applications with Moblin SDK & win great prizes Grand prize is a trip for two to an Open Source event anywhere in the world http://moblin-contest.org/redirect.php?banner_id=100&url=/
_______________________________________________ sqlobject-discuss mailing list sqlobject-discuss@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/sqlobject-discuss