How to use [data.transaction.commit]
The reference page of data.transaction.commit has its arguments, constraints and declaration.
Although you should be careful with database transactions, sometimes you really need them. For those cases you can use the following 3 slots to create, rollback, and/or commit transactions towards your underlying database.
- [data.transaction.create] - Creates a new database transaction
- [data.transaction.commit] - Commits an existing open transaction
- [data.transaction.rollback] - Roll back an existing open transaction
Notice - The default logic for a database transaction, is that unless it’s explicitly committed before leaving scope, it will roll back by default. Below is an example of a transaction that will rollback, since it’s not explicitly committed before leaving scope.
data.connect:sakila
data.transaction.create
data.execute:delete from film_actor
/*
* If you uncomment the line below the
* transaction will be committed, resulting
* in that everything from your film_actor
* table will be deleted.
*/
//data.transaction.commit
data.connect:sakila
/*
* Notice, this still returns 5462 items, since
* transaction was implicitly rolled back above.
*/
data.scalar:select count(*) from film_actor
A transaction typically follows your connection, implying to count items after the transaction has been rolled back, we’ll need a new connection, as the above example illustrates.