O'Reilly logo

Programming ColdFusion by Rob Brooks-Bilson

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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, 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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required