def run(self, connection):
statements = sqlparse.parse(self.content)
content = "".join((six.text_type(stmt) for stmt in statements))
if content != self.content:
raise SQLRunnerException("sqlparse failed to properly split input")
rows = 0
with connection.cursor() as cursor:
for statement in statements:
if clean_sql_code(str(statement)).strip() in ("", ";"):
# Sometimes sqlparse keeps the empty lines here,
# this could negatively affect libpq
continue
logger.debug("Running one statement... <<%s>>", str(statement))
cursor.execute(str(statement).replace("\\timing\n", ""))
logger.debug("Affected %s rows", cursor.rowcount)
rows += cursor.rowcount
return rows
评论列表
文章目录