From 85a800680a800c945ce9a888c8c8891ba700197a Mon Sep 17 00:00:00 2001 From: Mike Bayer Date: Tue, 13 Jul 2010 20:52:05 -0400 Subject: [PATCH] - _extract_error_code now expects the raw DBAPI error in all cases for all four MySQL dialects. has_table() passes in the "orig" from the SQLAlchemy exception. continuing of [ticket:1848] --- CHANGES | 12 +++++++----- lib/sqlalchemy/dialects/mysql/base.py | 13 ++++++++----- lib/sqlalchemy/dialects/mysql/mysqlconnector.py | 5 +---- lib/sqlalchemy/dialects/mysql/mysqldb.py | 7 +------ lib/sqlalchemy/dialects/mysql/oursql.py | 5 +---- lib/sqlalchemy/dialects/mysql/pyodbc.py | 2 +- 6 files changed, 19 insertions(+), 25 deletions(-) diff --git a/CHANGES b/CHANGES index 082ec83822..ac180b0f0e 100644 --- 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 ===== diff --git a/lib/sqlalchemy/dialects/mysql/base.py b/lib/sqlalchemy/dialects/mysql/base.py index 46e29694f4..af18ae551e 100644 --- a/lib/sqlalchemy/dialects/mysql/base.py +++ b/lib/sqlalchemy/dialects/mysql/base.py @@ -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 diff --git a/lib/sqlalchemy/dialects/mysql/mysqlconnector.py b/lib/sqlalchemy/dialects/mysql/mysqlconnector.py index 2da18e50ff..bd9c9b8e28 100644 --- a/lib/sqlalchemy/dialects/mysql/mysqlconnector.py +++ b/lib/sqlalchemy/dialects/mysql/mysqlconnector.py @@ -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) diff --git a/lib/sqlalchemy/dialects/mysql/mysqldb.py b/lib/sqlalchemy/dialects/mysql/mysqldb.py index d43b62ce3d..54f10352f7 100644 --- a/lib/sqlalchemy/dialects/mysql/mysqldb.py +++ b/lib/sqlalchemy/dialects/mysql/mysqldb.py @@ -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.""" diff --git a/lib/sqlalchemy/dialects/mysql/oursql.py b/lib/sqlalchemy/dialects/mysql/oursql.py index ebc7264823..41c5414f2c 100644 --- a/lib/sqlalchemy/dialects/mysql/oursql.py +++ b/lib/sqlalchemy/dialects/mysql/oursql.py @@ -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.""" diff --git a/lib/sqlalchemy/dialects/mysql/pyodbc.py b/lib/sqlalchemy/dialects/mysql/pyodbc.py index 1f73c6ef12..eb7b23c07d 100644 --- a/lib/sqlalchemy/dialects/mysql/pyodbc.py +++ b/lib/sqlalchemy/dialects/mysql/pyodbc.py @@ -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) -- 2.47.2