[SQL-CVS] r3755 - SQLObject/branches/0.9/sqlobject/mysql
SQLObject is a Python ORM.
Brought to you by:
ianbicking,
phd
From: <sub...@co...> - 2008-12-25 16:50:48
|
Author: phd Date: 2008-12-25 09:50:45 -0700 (Thu, 25 Dec 2008) New Revision: 3755 Modified: SQLObject/branches/0.9/sqlobject/mysql/mysqlconnection.py Log: A patch by Toshio Kuratomi <a.b...@gm...>: -- MySQLdb < 1.2.1: only ascii -- MySQLdb = 1.2.1: only unicode -- MySQLdb > 1.2.1: both ascii and unicode Modified: SQLObject/branches/0.9/sqlobject/mysql/mysqlconnection.py =================================================================== --- SQLObject/branches/0.9/sqlobject/mysql/mysqlconnection.py 2008-12-25 16:17:41 UTC (rev 3754) +++ SQLObject/branches/0.9/sqlobject/mysql/mysqlconnection.py 2008-12-25 16:50:45 UTC (rev 3755) @@ -44,6 +44,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): @@ -87,6 +93,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 |