Author: phd
Date: 2007-03-06 08:09:34 -0700 (Tue, 06 Mar 2007)
New Revision: 2396
Modified:
SQLObject/branches/0.7/docs/News.txt
SQLObject/branches/0.7/sqlobject/mysql/mysqlconnection.py
Log:
A patch by Markus Gritsch <m.g...@gm...>: for MySQLdb 1.2.2+
call ping(True) on the connection to allow autoreconnect after a timeout.
Modified: SQLObject/branches/0.7/docs/News.txt
===================================================================
--- SQLObject/branches/0.7/docs/News.txt 2007-03-05 22:57:11 UTC (rev 2395)
+++ SQLObject/branches/0.7/docs/News.txt 2007-03-06 15:09:34 UTC (rev 2396)
@@ -10,6 +10,12 @@
SQLObject 0.7.4
===============
+Small Features
+--------------
+
+* For MySQLdb 1.2.2+ call ping(True) on the connection to allow
+ autoreconnect after a timeout.
+
Bug Fixes
---------
Modified: SQLObject/branches/0.7/sqlobject/mysql/mysqlconnection.py
===================================================================
--- SQLObject/branches/0.7/sqlobject/mysql/mysqlconnection.py 2007-03-05 22:57:11 UTC (rev 2395)
+++ SQLObject/branches/0.7/sqlobject/mysql/mysqlconnection.py 2007-03-06 15:09:34 UTC (rev 2396)
@@ -11,7 +11,7 @@
def __init__(self, db, user, passwd='', host='localhost', port=None, **kw):
global MySQLdb
if MySQLdb is None:
- import MySQLdb
+ import MySQLdb, MySQLdb.constants.CR, MySQLdb.constants.ER
self.module = MySQLdb
self.host = host
self.port = port
@@ -53,6 +53,10 @@
try:
conn = self.module.connect(host=self.host, port=self.port,
db=self.db, user=self.user, passwd=self.password, **self.kw)
+ if MySQLdb.version_info[0] > 1 or (MySQLdb.version_info[0] == 1 and
+ (MySQLdb.version_info[1] > 2 or (MySQLdb.version_info[1] == 2 and
+ MySQLdb.version_info[2] >= 2))):
+ conn.ping(True) # Attempt to reconnect. This setting is persistent.
except self.module.OperationalError, e:
raise self.module.OperationalError(
"%s; used connection string: host=%s, port=%s, db=%s, user=%s, pwd=%s" % (
|