[SQL-CVS] r2166 - SQLObject/trunk/sqlobject/mysql
SQLObject is a Python ORM.
Brought to you by:
ianbicking,
phd
|
From: <sub...@co...> - 2006-12-29 15:17:46
|
Author: phd
Date: 2006-12-29 08:17:40 -0700 (Fri, 29 Dec 2006)
New Revision: 2166
Modified:
SQLObject/trunk/sqlobject/mysql/mysqlconnection.py
Log:
Another bugfix by Dan Pascu <da...@ag...> for MySQL errors 2006 and 2013 (SERVER_GONE, SERVER_LOST).
Modified: SQLObject/trunk/sqlobject/mysql/mysqlconnection.py
===================================================================
--- SQLObject/trunk/sqlobject/mysql/mysqlconnection.py 2006-12-28 20:55:44 UTC (rev 2165)
+++ SQLObject/trunk/sqlobject/mysql/mysqlconnection.py 2006-12-29 15:17:40 UTC (rev 2166)
@@ -78,7 +78,19 @@
conn.autocommit(auto)
def _executeRetry(self, conn, cursor, query):
- while 1:
+ # 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
+ # succeed. However is a few cases, the first attempt raises the
+ # SERVER_GONE exception, the second attempt the SERVER_LOST exception
+ # and only the third succeeds. Thus the 3 in the loop count.
+ # If it doesn't reconnect even after 3 attempts, while the database is
+ # up and running, it is because a 5.0.x (or newer) server is used
+ # which no longer permits autoreconnects by default. In their case a
+ # reconnect flag must be set when making the connection to indicate
+ # that autoreconnecting is desired and the python-mysqldb module
+ # doesn't set this flag.
+ for c in range(0, 3):
try:
if self.need_unicode:
# For MysqlDB 1.2.1 and later, we go
@@ -88,7 +100,9 @@
else:
return cursor.execute(query)
except MySQLdb.OperationalError, e:
- if e.args[0] == 2013: # SERVER_LOST error
+ if e.args[0] in (2006, 2013): # SERVER_GONE or SERVER_LOST error
+ if c == 2:
+ raise OperationalError(ErrorMessage(e))
if self.debug:
self.printDebug(conn, str(e), 'ERROR')
else:
|