Reputation: 20928
How do I use sqlite transactions in python?
The following code raises the exception OperationalError: cannot commit - no transaction is active
on the cur.execute('COMMIT')
line:
import sqlite3
con = sqlite3.connect(':memory:')
cur = con.cursor()
cur.execute('CREATE TABLE test(p)')
cur.execute('BEGIN')
cur.execute('INSERT INTO test(p) values (?)', (1,))
cur.execute('COMMIT')
I've played around with isolation_level
but none of the values gets rid of the exception.
Upvotes: 1
Views: 1843
Reputation: 168606
Try turning on autocommit mode:
con.isolation_level = None
References:
Upvotes: 1