From c416dad6c652262bafbb137e6412054481db8e2f Mon Sep 17 00:00:00 2001 From: Mike Bayer Date: Mon, 2 Apr 2007 22:03:06 +0000 Subject: - merged the patch from #516 + fixes - improves the framework for auto-invalidation of connections that have lost their underlying database - the error catching/invalidate step is totally moved to the connection pool. - added better condition checking for do_rollback() and do_commit() including SQLError excepetion wrapping --- lib/sqlalchemy/databases/mysql.py | 25 +++++++++++-------------- 1 file changed, 11 insertions(+), 14 deletions(-) (limited to 'lib/sqlalchemy/databases/mysql.py') diff --git a/lib/sqlalchemy/databases/mysql.py b/lib/sqlalchemy/databases/mysql.py index 65ccb6af1..7ea98e92f 100644 --- a/lib/sqlalchemy/databases/mysql.py +++ b/lib/sqlalchemy/databases/mysql.py @@ -328,21 +328,12 @@ class MySQLDialect(ansisql.ANSIDialect): return MySQLIdentifierPreparer(self) def do_executemany(self, cursor, statement, parameters, context=None, **kwargs): - try: - rowcount = cursor.executemany(statement, parameters) - if context is not None: - context._rowcount = rowcount - except self.dbapi.OperationalError, o: - if o.args[0] == 2006 or o.args[0] == 2014: - cursor.invalidate() - raise o + rowcount = cursor.executemany(statement, parameters) + if context is not None: + context._rowcount = rowcount + def do_execute(self, cursor, statement, parameters, **kwargs): - try: - cursor.execute(statement, parameters) - except self.dbapi.OperationalError, o: - if o.args[0] == 2006 or o.args[0] == 2014: - cursor.invalidate() - raise o + cursor.execute(statement, parameters) def do_rollback(self, connection): # MySQL without InnoDB doesnt support rollback() @@ -351,6 +342,12 @@ class MySQLDialect(ansisql.ANSIDialect): except: pass + def get_disconnect_checker(self): + def disconnect_checker(e): + return isinstance(e, self.dbapi.OperationalError) and e.args[0] in (2006, 2014) + return disconnect_checker + + def get_default_schema_name(self): if not hasattr(self, '_default_schema_name'): self._default_schema_name = text("select database()", self).scalar() -- cgit v1.2.1