From b9b0aca7575e347dfd62221c9d515decee4c75f6 Mon Sep 17 00:00:00 2001 From: Mike Bayer Date: Wed, 19 Dec 2007 19:51:46 +0000 Subject: - auto-reconnect support improved; a Connection can now automatically reconnect after its underlying connection is invalidated, without needing to connect() again from the engine. This allows an ORM session bound to a single Connection to not need a reconnect. Open transactions on the Connection must be rolled back after an invalidation of the underlying connection else an error is raised. Also fixed bug where disconnect detect was not being called for cursor(), rollback(), or commit(). --- lib/sqlalchemy/databases/mysql.py | 8 ++++++-- lib/sqlalchemy/databases/sqlite.py | 3 +++ 2 files changed, 9 insertions(+), 2 deletions(-) (limited to 'lib/sqlalchemy/databases') diff --git a/lib/sqlalchemy/databases/mysql.py b/lib/sqlalchemy/databases/mysql.py index 122c24bff..a738887f4 100644 --- a/lib/sqlalchemy/databases/mysql.py +++ b/lib/sqlalchemy/databases/mysql.py @@ -1527,8 +1527,12 @@ class MySQLDialect(default.DefaultDialect): connection.ping() def is_disconnect(self, e): - return isinstance(e, self.dbapi.OperationalError) and \ - e.args[0] in (2006, 2013, 2014, 2045, 2055) + if isinstance(e, self.dbapi.OperationalError): + return e.args[0] 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 def get_default_schema_name(self, connection): try: diff --git a/lib/sqlalchemy/databases/sqlite.py b/lib/sqlalchemy/databases/sqlite.py index 16dd9427c..e028b1c53 100644 --- a/lib/sqlalchemy/databases/sqlite.py +++ b/lib/sqlalchemy/databases/sqlite.py @@ -237,6 +237,9 @@ class SQLiteDialect(default.DefaultDialect): def oid_column_name(self, column): return "oid" + def is_disconnect(self, e): + return isinstance(e, self.dbapi.ProgrammingError) and "Cannot operate on a closed database." in str(e) + def table_names(self, connection, schema): s = "SELECT name FROM sqlite_master WHERE type='table'" return [row[0] for row in connection.execute(s)] -- cgit v1.2.1