Whatever message this page gives is out now! Go check it out!
action = "begin|commit|rollback|setsavepoint"
isolation = "read_uncommitted|read_committed|repeatable_read"
savepoint = "savepoint name">
</cftransaction>Attribute | Req/Opt | Default | Description |
action | Optional | begin |
|
isolation | Optional | Isolation level, which indicates which type of read can occur during the execution of concurrent SQL transactions. The possible read actions include dirty read, in which a second SQL transaction reads a row before the first SQL transaction executes a COMMIT; non-repeatable read, in which a SQL transaction reads a row and then a second SQL transaction modifies or deletes the row and executes a COMMIT; and phantom, in which a SQL transaction reads rows that meet search criteria, a second SQL transaction then generates at least one row that meets the first transaction's search criteria, and then the first transaction repeats the search, resulting in a different result set.
| |
savepoint | Optional | The name of the savepoint in the transaction. Setting savepoints lets you roll back portions of a transaction. For example, if your transaction includes an insert, an update, and a delete, and you set a savepoint after the update, you can roll back the transaction to exclude the delete. | |
nested | Optional | true | This attribute specifies whether the cftransaction tag can be nested inside another cftransaction tag. If the attribute value is false and there is a parent cftransaction tag, ColdFusion generates an error. |
<cftransaction>
<cfquery name="iquery" datasource="dsn">
insert into region(regionid, regiondescription) values('111', 'YPR')
</cfquery>
<cftransaction>
<cfquery name="iquery" datasource="dsn">
update region set regiondescription = 'new' where regionid='111'
</cfquery>
</cftransaction>
</cftransaction>the cfquery tag into one business event. Changes to data that is requested
by the queries are not committed to the datasource until all actions within
the transaction block have executed successfully.
<p>This a view-only example.
<!---
<cftransaction>
<cfquery name='makeNewCourse' datasource='Snippets'>
INSERT INTO Courses
(Number, Descript)
VALUES
('#myNumber#', '#myDescription#')
</cfquery>
<cfquery name='insertNewCourseToList' datasource='Snippets'>
INSERT INTO CourseList
(CorNumber, CorDesc, Dept_ID,
CorName, CorLevel, LastUpdate)
VALUES
('#myNumber#', '#myDescription#', '#myDepartment#',
'#myDescription#', '#myCorLevel#', #Now()#)
</cfquery>
</cftransaction>
---><!--- This example performs batch processing of withdrawals --->
<!--- from a bank account. The withdrawal amounts are stored --->
<!--- in an array. --->
<!--- There is a CFC named bank.cfc whose contains appear --->
<!--- after the example. --->
<cftransaction>
<!--- Get the account balance. --->
<cfinvoke component="bank" method="getBalance"
returnvariable="getacctbalance" accountnum=1>
<cfloop index="withdrawnum" from="1" to="#ArrayLen(withdrawals)#">
<!--- Set a savepoint before making the withdrawal. --->
<cfset noxfer = "point" & #withdrawnum#>
<cftransaction action = "setsavepoint" savepoint = "#noxfer#"/>
<!--- Make the withdrawal. --->
<cfinvoke component="bank" method="makewithdrawal"
returnvariable="getacctbalance" accountnum=1
withdrawamount="#withdrawals[withdrawnum]#">
<!--- Get the account balance. --->
<cfinvoke component="bank" method="getBalance"
returnvariable="getacctbalance" accountnum=1>
<!--- If the balance is negative, roll back the transaction. --->
<cfif getacctbalance.balance lt 0>
<cftransaction action="rollback" savepoint="#noxfer#" />
</cfif>
</cfloop>
</cftransaction>
<!--- The bank.cfc contains the following:
cfcomponent>
<cffunction name="getBalance" access="public" returntype="query">
<cfargument name="accountnum" type="numeric" required="yes">
<cfquery name="getacctbalance" datasource="testsqlserver">
SELECT * FROM dbo.mybank
WHERE accountid = #accountnum#
</cfquery>
<cfreturn getacctbalance>
</cffunction>
<cffunction name="makewithdrawal" access="public" returntype="query">
<cfargument name="accountnum" type="numeric" required="yes">
<cfargument name="withdrawamount" type="numeric" required="yes">
<cfquery name="withdrawfromacct" datasource="testsqlserver">
UPDATE dbo.mybank SET balance = balance - #withdrawamount#
WHERE accountid = 1
</cfquery>
<cfinvoke method="getBalance" returnvariable="getacctbalance"
accountnum=1>
<cfreturn getacctbalance>
</cffunction>
</cfcomponent>
--->