Name

COMMIT TRANSACTION — Finish and commit a transaction

Syntax

image with no caption

Common Usage

COMMIT;

Description

The COMMIT TRANSACTION command attempts to close and commit any changes made during the current transaction. The alias END TRANSACTION may also be used. If a COMMIT command is made while SQLite is in autocommit mode, an error will be issued.

If the COMMIT is successful, the database will be synchronized and any modifications made within the transaction will become a permanent part of the database record and the database connection will be put back in autocommit mode.

If the commit is not successful, the transaction may or may not be rolled back, depending on the type of error. If the transaction is not rolled back, you can usually just reissue the COMMIT command. If the transaction is rolled back, all modifications made as part of the transaction are lost. You can determine the specific state of the database connection using the sqlite3_get_autocommit() API call, or by trying to issue the BEGIN command. If the database returns a logical error as a result of the BEGIN command, the database is still in a valid transaction. You can also issue the ROLLBACK command, which will either roll back the transaction if it is still in place, or return an error if the transaction was already rolled back.

There is a significant cost associated with committing a transaction. See BEGIN TRANSACTION for more details ...

Get Using SQLite now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.