From c6538b6b3400cbfa939d4e3e8d0f0530e0530e9d Mon Sep 17 00:00:00 2001 From: Mike Bayer Date: Fri, 8 Dec 2006 03:27:09 +0000 Subject: - MySQL detects errors 2006 (server has gone away) and 2014 (commands out of sync) and invalidates the connection on which it occured. --- lib/sqlalchemy/databases/mysql.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'lib/sqlalchemy/databases/mysql.py') diff --git a/lib/sqlalchemy/databases/mysql.py b/lib/sqlalchemy/databases/mysql.py index 325347464..662d276e9 100644 --- a/lib/sqlalchemy/databases/mysql.py +++ b/lib/sqlalchemy/databases/mysql.py @@ -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: -- cgit v1.2.1