[SQL-CVS] r3757 - SQLObject/trunk/sqlobject/mysql
SQLObject is a Python ORM.
Brought to you by:
ianbicking,
phd
From: <sub...@co...> - 2008-12-25 16:54:27
|
Author: phd Date: 2008-12-25 09:54:25 -0700 (Thu, 25 Dec 2008) New Revision: 3757 Modified: SQLObject/trunk/sqlobject/mysql/mysqlconnection.py Log: Merged a patch by Toshio Kuratomi <a.b...@gm...> from branch 0.9: -- MySQLdb < 1.2.1: only ascii -- MySQLdb = 1.2.1: only unicode -- MySQLdb > 1.2.1: both ascii and unicode Modified: SQLObject/trunk/sqlobject/mysql/mysqlconnection.py =================================================================== --- SQLObject/trunk/sqlobject/mysql/mysqlconnection.py 2008-12-25 16:53:34 UTC (rev 3756) +++ SQLObject/trunk/sqlobject/mysql/mysqlconnection.py 2008-12-25 16:54:25 UTC (rev 3757) @@ -49,6 +49,12 @@ if "sqlobject_encoding" in kw: del kw["sqlobject_encoding"] deprecated("sqlobject_encoding is deprecated and no longer used.") + + # MySQLdb < 1.2.1: only ascii + # MySQLdb = 1.2.1: only unicode + # MySQLdb > 1.2.1: both ascii and unicode + self.need_unicode = (MySQLdb.version_info[:3] >= (1, 2, 1)) and (MySQLdb.version_info[:3] < (1, 2, 2)) + DBAPI.__init__(self, **kw) def connectionFromURI(cls, uri): @@ -92,6 +98,12 @@ conn.autocommit(auto) def _executeRetry(self, conn, cursor, query): + if self.need_unicode and not isinstance(query, unicode): + try: + query = unicode(query, self.dbEncoding) + except UnicodeError: + pass + # When a server connection is lost and a query is attempted, most of # the time the query will raise a SERVER_LOST exception, then at the # second attempt to execute it, the mysql lib will reconnect and |