]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
- MySQL detects errors 2006 (server has gone away) and 2014
authorMike Bayer <mike_mp@zzzcomputing.com>
Fri, 8 Dec 2006 03:27:09 +0000 (03:27 +0000)
committerMike Bayer <mike_mp@zzzcomputing.com>
Fri, 8 Dec 2006 03:27:09 +0000 (03:27 +0000)
(commands out of sync) and invalidates the connection on which it occured.

CHANGES
lib/sqlalchemy/databases/mysql.py
lib/sqlalchemy/pool.py

diff --git a/CHANGES b/CHANGES
index 45caad577267db0ccac0e0eb06b5cc4d08ae3ef5..9d3e5e8ed222289f1d94effe98460bbaa70805ac 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -4,6 +4,8 @@
   time-intensive to generate log messages
   - fixed bug in cascade rules whereby the entire object graph
   could be unnecessarily cascaded on the save/update cascade
+- MySQL detects errors 2006 (server has gone away) and 2014
+(commands out of sync) and invalidates the connection on which it occured.
 - added keywords for EXCEPT, INTERSECT, EXCEPT ALL, INTERSECT ALL
 [ticket:247]
 - added label() function to Select class, when scalar=True is used
index 3253474643c9301781fe3e272f01f95e99961cd4..662d276e930efd8b176f55ef093611c52b486a48 100644 (file)
@@ -289,6 +289,22 @@ class MySQLDialect(ansisql.ANSIDialect):
     def preparer(self):
         return MySQLIdentifierPreparer(self)
 
+    def do_executemany(self, cursor, statement, parameters, **kwargs):
+        try:
+            cursor.executemany(statement, parameters)
+        except mysql.OperationalError, o:
+            if o.args[0] == 2006 or o.args[0] == 2014:
+                cursor.invalidate()
+                raise o
+    def do_execute(self, cursor, statement, parameters, **kwargs):
+        try:
+            cursor.execute(statement, parameters)
+        except mysql.OperationalError, o:
+            if o.args[0] == 2006 or o.args[0] == 2014:
+                cursor.invalidate()
+                raise o
+            
+
     def do_rollback(self, connection):
         # some versions of MySQL just dont support rollback() at all....
         try:
index 99504e1368e795811d18e29ae4922809f483987d..8e74f0343ac65fd648095f758309b4faf288b494 100644 (file)
@@ -187,7 +187,7 @@ class _ConnectionFairy(object):
     """proxies a DBAPI connection object and provides return-on-dereference support"""
     def __init__(self, pool):
         self._threadfairy = _ThreadFairy(self)
-        self.cursors = weakref.WeakKeyDictionary()
+        self.cursors = {}
         self.__pool = pool
         self.__counter = 0
         try:
@@ -220,8 +220,9 @@ class _ConnectionFairy(object):
         self.__counter +=1
         return self    
     def close_open_cursors(self):
-        for c in list(self.cursors):
-            c.close()
+        if self.cursors is not None:
+            for c in list(self.cursors):
+                c.close()
     def close(self):
         self.__counter -=1
         if self.__counter == 0:
@@ -255,13 +256,15 @@ class _CursorFairy(object):
         self.__parent = parent
         self.__parent.cursors[self]=True
         self.cursor = cursor
+    def invalidate(self):
+        self.__parent.invalidate()
     def close(self):
         if self in self.__parent.cursors:
             del self.__parent.cursors[self]
             self.cursor.close()
     def __getattr__(self, key):
         return getattr(self.cursor, key)
-
+            
 class SingletonThreadPool(Pool):
     """Maintains one connection per each thread, never moving a connection to a thread
     other than the one which it was created in.