MACROMEDIA COLDFUSION 5 - CFML Reference page 303

Cfml reference
Hide thumbs Also See for COLDFUSION 5 - CFML:
Table of Contents

Advertisement

Alphabetical List of ColdFusion Tags
Example
<!--- This example shows the use of cftransaction --->
<html>
<head>
<title>cftransaction Example</title>
</head>
<body>
<H3>cftransaction Example</H3>
<P>cftransaction can be used to group multiple queries
using cfquery into a single business event. Changes to data
requested by these queries can be committed on the basis
of the success or failure of the query by using the actions
commit and rollback, respectively.
<P>The following is a sample listing (see code in right pane):
<!---------------------------------------------------------------------
---------------------------------------------------------------------->
<cftry>
<----------------------------------------------------------------------
Initialize commitIt to Yes.
---------------------------------------------------------------------->
<cfset commitIt = "Yes">
<cftransaction action = "begin">
You can enclose the transaction in a cftry/cfcatch block in order
to catch database errors and make commitment or rollback or the
transaction contingent on the errors received.
<cfquery name = 'makeNewCourse' dataSource = 'cfsnippets'>
INSERT INTO Courses
(Course_Num, Descript)
VALUES
('#myNumber#', '#myDescription#')
</cfquery>
<!------------------------------------------------------------------
Rolls back the pending insertion if database exception is caught.
------------------------------------------------------------------->
<cfcatch type = "DATABASE">
<cftransaction action = "rollback"/>
<cfset commitIt = "No">
</cfcatch>
<cfif commitIt>
<cftransaction action = "commit"/>
<!--------------------------------------------------------------
Commits the pending insertion.
---------------------------------------------------------------->
<cfelse>
<cfset commitIt = "Yes">
</cfif>
285

Advertisement

Table of Contents
loading
Need help?

Need help?

Do you have a question about the COLDFUSION 5 - CFML and is the answer not in the manual?

This manual is also suitable for:

Coldfusion 5

Table of Contents