【发布时间】:2018-07-03 22:00:05
【问题描述】:
在执行connection.commit() 之前多次对cursor.execute(…) 进行有效的PyMySQL 操作,或者是否需要在每个执行语句之后发生connection.commit() 才能正确存储结果?这个想法是消除尽可能多的冗余语句,因为该过程是长时间运行的。
代码结构:
with connection.cursor() as cursor:
…
cursor.execute(SQLtype1, rowToInsert)
cursor.execute(SQLtype2, otherToInsert)
connection.commit() # does this account for both execute statements, or just the last?
我查看了以下内容:
PyMySQL execute/commit example,但只有一个示例只有一个执行语句。
Python MySQLdb example,但有一个示例显示每个执行语句之后的提交
Python SQLite example,在提交前显示多个执行语句,但不确定SQLite是否处理不同
注意:由于 SQL 查询不同,executemany 似乎不是一个选项。
【问题讨论】:
标签: pymysql