def execute(self, sql: str, params: typing.Union[typing.Mapping, typing.Iterable] = None):
"""
Executes SQL in the current transaction.
"""
# lock to ensure nothing else is using the connection at once
logger.debug("Running SQL {} with params {}".format(sql, params))
async with self._lock:
async with threadpool():
for stmt in separate_statements(sql):
try:
if params is None:
res = self.connection.execute(stmt)
else:
res = self.connection.execute(stmt, params)
except sqlite3.IntegrityError as e:
raise IntegrityError(*e.args)
except sqlite3.OperationalError as e:
raise DatabaseException(*e.args)
return res
评论列表
文章目录