]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
- _extract_error_code now expects the raw DBAPI error in all cases
authorMike Bayer <mike_mp@zzzcomputing.com>
Wed, 14 Jul 2010 00:52:05 +0000 (20:52 -0400)
committerMike Bayer <mike_mp@zzzcomputing.com>
Wed, 14 Jul 2010 00:52:05 +0000 (20:52 -0400)
for all four MySQL dialects.   has_table() passes in the "orig"
from the SQLAlchemy exception.  continuing of [ticket:1848]

CHANGES
lib/sqlalchemy/dialects/mysql/base.py
lib/sqlalchemy/dialects/mysql/mysqlconnector.py
lib/sqlalchemy/dialects/mysql/mysqldb.py
lib/sqlalchemy/dialects/mysql/oursql.py
lib/sqlalchemy/dialects/mysql/pyodbc.py

diff --git a/CHANGES b/CHANGES
index 082ec838227e8b038acac529ad214896bcca3f25..ac180b0f0eb2be24316976a6c3df5d885852fa08 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -29,12 +29,14 @@ CHANGES
 - mysql
 
   - The _extract_error_code() method now works 
-    correctly with the "mysqldb" dialect.  Previously,
+    correctly with each MySQL dialect (
+    MySQL-python, OurSQL, MySQL-Connector-Python,
+    PyODBC).  Previously,
     the reconnect logic would fail for OperationalError
-    conditions, however since MySQLdb has its
-    own reconnect feature, there was no symptom 
-    here unless one watched the logs.  
-    [ticket:1848]
+    conditions, however since MySQLdb and OurSQL
+    have their own reconnect feature, there was no 
+    symptom for these drivers here unless one 
+    watched the logs.  [ticket:1848]
     
 0.6.2
 =====
index 46e29694f421b3ba6400dc1939c21276e744d5a0..af18ae551e03be35f972a938af91daeb02ace2cf 100644 (file)
@@ -1708,8 +1708,11 @@ class MySQLDialect(default.DefaultDialect):
 
     def is_disconnect(self, e):
         if isinstance(e, self.dbapi.OperationalError):
-            return self._extract_error_code(e) in (2006, 2013, 2014, 2045, 2055)
-        elif isinstance(e, self.dbapi.InterfaceError):  # if underlying connection is closed, this is the error you get
+            return self._extract_error_code(e) in \
+                        (2006, 2013, 2014, 2045, 2055)
+        elif isinstance(e, self.dbapi.InterfaceError):  
+            # if underlying connection is closed, 
+            # this is the error you get
             return "(0, '')" in str(e)
         else:
             return False
@@ -1760,7 +1763,7 @@ class MySQLDialect(default.DefaultDialect):
                 rs.close()
                 return have
             except exc.SQLError, e:
-                if self._extract_error_code(e) == 1146:
+                if self._extract_error_code(e.orig) == 1146:
                     return False
                 raise
         finally:
@@ -2048,7 +2051,7 @@ class MySQLDialect(default.DefaultDialect):
         try:
             rp = connection.execute(st)
         except exc.SQLError, e:
-            if self._extract_error_code(e) == 1146:
+            if self._extract_error_code(e.orig) == 1146:
                 raise exc.NoSuchTableError(full_name)
             else:
                 raise
@@ -2072,7 +2075,7 @@ class MySQLDialect(default.DefaultDialect):
             try:
                 rp = connection.execute(st)
             except exc.SQLError, e:
-                if self._extract_error_code(e) == 1146:
+                if self._extract_error_code(e.orig) == 1146:
                     raise exc.NoSuchTableError(full_name)
                 else:
                     raise
index 2da18e50ff7cbba441156acd3f837f806da1ed72..bd9c9b8e28d9c184f3afd636179b37c55f153db9 100644 (file)
@@ -110,10 +110,7 @@ class MySQLDialect_mysqlconnector(MySQLDialect):
         return connection.connection.get_characterset_info()
 
     def _extract_error_code(self, exception):
-        try:
-            return exception.orig.errno
-        except AttributeError:
-            return None
+        return exception.errno
 
     def is_disconnect(self, e):
         errnos = (2006, 2013, 2014, 2045, 2055, 2048)
index d43b62ce3d2bc565fd964d42d008d67dea562b04..54f10352f704acf3d038f0da2b0a38871df5dac7 100644 (file)
@@ -156,12 +156,7 @@ class MySQLDialect_mysqldb(MySQLDialect):
         return tuple(version)
 
     def _extract_error_code(self, exception):
-        try:
-            return exception.args[0]
-        except AttributeError:
-            # this AttributeError is likely unnecessary,
-            # but would need to confirm against MySQLdb code
-            return None
+        return exception.args[0]
 
     def _detect_charset(self, connection):
         """Sniff out the character set in use for connection results."""
index ebc7264823d2dfc03d6682f0560c09e1ac92e437..41c5414f2c8ac5e5549677fc5f1dd3264a177919 100644 (file)
@@ -230,10 +230,7 @@ class MySQLDialect_oursql(MySQLDialect):
         return tuple(version)
 
     def _extract_error_code(self, exception):
-        try:
-            return exception.orig.errno
-        except AttributeError:
-            return None
+        return exception.errno
 
     def _detect_charset(self, connection):
         """Sniff out the character set in use for connection results."""
index 1f73c6ef12de4e1eef056453d07b31add60a2bcd..eb7b23c07d0ba868ed47adfe472ed561ac698c4e 100644 (file)
@@ -66,7 +66,7 @@ class MySQLDialect_pyodbc(PyODBCConnector, MySQLDialect):
         return 'latin1'
     
     def _extract_error_code(self, exception):
-        m = re.compile(r"\((\d+)\)").search(str(exception.orig.args))
+        m = re.compile(r"\((\d+)\)").search(str(exception.args))
         c = m.group(1)
         if c:
             return int(c)