Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it a good practice to enable auto-commit in sqlite python all the time? [closed]

In sqlite python, one has to run commit() to make sure a SQL statement is executed if auto-commit is not enabled. Auto-commit is enabled by doing something like this sqlite3.connect('sqlitedb.db', isolation_level=None)

Is it a good practice to enable auto-commit all the time? THis is to avoid bugs that can happen when one forgets to run commit().

What are some situations, if any, that auto-commit is better to be disabled?

I am using sqlite3 and python v3.6

like image 320
guagay_wk Avatar asked Mar 29 '26 00:03

guagay_wk


1 Answers

Autocommit should be disabled if multiple operations belong together logically to ensure that not only some of them are executed (atomicity).

Additionally it should be disabled if multiple operations are done consecutively in a short period of time for performance reasons.

For databases with concurrent access from different threads/processes additional consistency considerations apply but this usage is unlikely for Sqlite.

like image 175
Michael Butscher Avatar answered Mar 31 '26 10:03

Michael Butscher



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!