def execute(self, sql, args=None):
"""
Execute the given sql against current open connection
without caring about the result output
"""
# Turning MySQLdb.Warning into exception, so that we can catch it
# and maintain the same log output format
with warnings.catch_warnings():
warnings.filterwarnings('error', category=MySQLdb.Warning)
try:
cursor = self.conn.cursor()
cursor.execute("%s %s" % (self.query_header, sql), args)
except Warning as db_warning:
log.warning(
"MySQL warning: {}, when executing sql: {}, args: {}"
.format(db_warning, sql, args))
return cursor.rowcount
评论列表
文章目录