Transaction Processing
ColdFusion provides support for database
transaction processing using the CFTRANSACTION
tag. The CFTRANSACTION
tag lets you treat all
query operations with the <CFTRANSACTION>
and </CFTRANSACTION>
tags as a single
transaction. Changes to the database aren’t committed until all
queries in the transaction have executed successfully. In the event a
query within the transaction fails, all previous queries are
automatically rolled back. The exception to this occurs when the
database itself is changed, as in the case when a table or column is
created or deleted.
The CFTRANSACTION
tag accepts two optional attributes for controlling how transactions
are processed, ACTION
and
ISOLATION
:
-
ACTION
Specifies the transaction action to take. Valid options include:
-
Begin (default)
Specifies the beginning of the block of code to execute
-
Commit
Commits a pending transaction
-
Rollback
Rolls back a pending transaction
-
-
ISOLATION
Specifies the ODBC lock type to use for the transaction. The following ODBC lock types are supported:
Read_Uncommitted
,Read_Committed
,Repeat-able_Read
, andSerializable
.
Note that not all databases and/or database drivers support isolation levels. Many support only a subset of those listed. Refer to your particular database/driver’s documentation for more information on the isolation levels supported.
Example 11-26 shows how to use the
CFTRANSACTION
tag with two queries that delete records from different tables within the same data source. You need ...
Get Programming ColdFusion 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.