Reputation: 8606
I have made it a habbit that when i do cur.execute()
functions, I do a sql.commit()
function right after.
Is sql.commit()
needed if I do not modify the database (i.e. only do a SELECT
query)?
Here is an example:
sql = sqlite3.connect('DB.db')
cur = sql.cursor()
cur.execute('SELECT * FROM table')
sql.commit()
Upvotes: 2
Views: 4558
Reputation: 26599
Python does not begin a transaction for select statements.
From the Transaction control section of the sqlite3 module docs:
By default, the sqlite3 module opens transactions implicitly before a Data Modification Language (DML) statement (i.e. INSERT/UPDATE/DELETE/REPLACE), and commits transactions implicitly before a non-DML, non-query statement (i. e. anything other than SELECT or the aforementioned).
Upvotes: 6