5.3.10 Transaction

A transaction is always either automatic or explicit. If it is automatic, (autocommit), every operation is performed as part of a new transaction that is automatically committed.

Beginning, committing, and rolling back a transaction


Begin a transaction. No arguments are required. If a transaction is already active, an exception is thrown.

commit(Function(Object error) callback);

Commit a transaction.

This method takes as its sole argument a callback function that returns an error object.

rollback(Function(Object error) callback);

Roll back a transaction. Errors are reported in the callback function.

Transaction information methods

Boolean isActive();

Determine whether or not a given transaction is currently active. Returns true if a transaction is active, and false otherwise.

isActive() requires no arguments.


Mark the transaction as rollback-only. Once this is done, commit() rolls back the transaction and throws an exception; rollback() rolls the transaction back, but does not throw an exception. To mark a transaction as rollback-only, call the setRollbackOnly() method, as shown here.

This method is one-way; a transaction marked as rollback-only cannot be unmarked. Invoking setRollbackOnly() while in autocommit mode throws an exception. This method requires no arguments.

boolean getRollbackOnly();

Determine whether a transaction has been marked as rollback-only. Returns true if the transaction has been so marked. setRollbackOnly() takes no arguments.

User Comments
User comments in this section are, as the name implies, provided by MySQL users. The MySQL documentation team is not responsible for, nor do they endorse, any of the information provided here.
Sign Up Login You must be logged in to post a comment.