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, Repeatable_Read, and Serializable.

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 MX, 2nd Edition 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.