Instructs the database management system to treat multiple
database operations as a single transaction. Provides database
commit and rollback processing.
Note that distributed transactions (transactions across multiple datasources) are not supported - you must commit one transaction and begin a separate transaction to one database before writing a query to another (CFMX7 Manual)
<cftransaction>
transaction { }
beginbegin: the start of the block of code to executecommit: commits a pending transactionrollback: rolls back a pending transactionsetsavepoint: Marks a place within the transaction as a savepoint.
begincommitrollbacksetsavepointread_uncommitted: dirty reads, non-repeatable reads and phantoms can all occur. A dirty read is reading a row another transaction changed but has not yet committed.read_committed: prevents dirty reads, but non-repeatable reads and phantoms can occur. A non-repeatable read is reading the same row twice and getting different data, because another transaction changed or deleted it and committed in between.repeatable_read: prevents dirty and non-repeatable reads, but phantoms can occur. A phantom is running the same search twice and getting extra rows, because another transaction inserted matching rows in between.serializable: prevents dirty reads, non-repeatable reads and phantoms. It is the strictest level, and the most likely to block or conflict with concurrent transactions.
read_uncommittedread_committedrepeatable_readserializableaction="setsavepoint" or action="rollback"
truefalsesavepoint attribute prior to 5.3.9
transaction {
try {
// code to run
transaction action="commit";
}
catch(any e) {
transaction action="rollback";
}
}
<cftransaction>
<cftry>
<!--- code to run --->
<cftransaction action="commit" />
<cfcatch type="any">
<cftransaction action="rollback" />
</cfcatch>
</cftry>
</cftransaction>
Signup for cfbreak to stay updated on the latest news from the ColdFusion / CFML community. One email, every friday.