背景
我正在尝试弄清楚如何在使用 Python 中的 SQLite 时正确地覆盖自动事务。当我尝试运行以下命令时:
cursor.execute("BEGIN;")
.....an assortment of insert statements...
cursor.execute("END;")
I get the following error:
OperationalError: cannot commit - no transaction is active
我知道这是因为Python中的SQLite在每次修改语句(本例中为INSERT)上自动开启一个事务。
问题:
我尝试通过在每几千个记录中执行一次事务来加快插入速度。 如何克服自动打开事务的问题?