def execute(self, *args, **kwargs):
try:
result = self._cursor.execute(*args, **kwargs)
except MySQLdb.ProgrammingError as e:
raise MySQLdb.ProgrammingError(e.args[0], e.args[1] + '.\nSTATEMENT: {}'.format(self._cursor._last_executed))
except MySQLdb.OperationalError as e:
# Sometimes a MySQL session times out. In this case, we wish to reconnect, and reissue the query.
if e[0] == 2006:
self.connect()
result = self._cursor.execute(*args, **kwargs)
else:
raise MySQLdb.OperationalError(e.args[0], e.args[1] + '.\nSTATEMENT: {}'.format(self._cursor._last_executed))
return result
评论列表
文章目录