This question could span the entire range of experience level from beginner to expert.
When you're in a transaction, .commit() says "make everything done in this transaction on this connection permanent." If there are any crashes or improper disconnections in the middle of a transaction then nothing you did in the transaction will persist in the database, it will all be rolled back. If you haven't made any changes then it's still fine to run, it'll just say "that was easy, nothing for me to save." Are you in a transaction? (Python library specific question) See Keith's message for a longer version. But in short... If you did NOT specify "isolation_level = None" in the .connect() call then you probably ARE in a transaction if you've been running queries. If you DID then you're usually NOT in a transaction, unless you explicitly started one (in which case you probably know about transactions). But why do I need to commit my transaction if I'm just reading? If you're just reading then you can commit or rollback. Either is fine. Just don't leave the transaction lingering around still open because someone else may want to write to the database, or to do a checkpoint. If the database is not in WAL mode then their attempt to write will have to wait for your read transaction to finish before it can do any writing. If the database IS in WAL mode, then writers can commit ok, but checkpointing of the WAL will be blocked from the point you started your transaction. You also will not see in your own queries any of those changes from writers until you start a new transaction. (Which may or may not be what you want) Under the hood in the Python library I think all it does is issue a "commit;" command, and suppress any exception raised because you weren't in a transaction already. -----Original Message----- From: sqlite-users <sqlite-users-boun...@mailinglists.sqlite.org> On Behalf Of Peng Yu Sent: Friday, October 25, 2019 12:44 PM To: SQLite mailing list <sqlite-users@mailinglists.sqlite.org> Subject: [sqlite] What does commit actually do? The python manual just tell me what I should do but it is not very clear what commit() actually does under the hood. https://docs.python.org/2/library/sqlite3.html """ commit() This method commits the current transaction. If you don’t call this method, anything you did since the last call to commit() is not visible from other database connections. If you wonder why you don’t see the data you’ve written to the database, please check you didn’t forget to call this method. """ So, only if I want to write something to the db, I need to call commit()? If I just read something from the db, there is no need to call commit()? Thanks. -- Regards, Peng _______________________________________________ sqlite-users mailing list sqlite-users@mailinglists.sqlite.org http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users _______________________________________________ sqlite-users mailing list sqlite-users@mailinglists.sqlite.org http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users