Reputation: 438
I have read the documentation about cftransaction but can't figure out the difference between rolling back with <cfdump var="#myVar#" abort>
, <cftransaction action="rollback" />
or <cfthrow message="Error">
Assume that var a
is preset for example purposes. All queries inside the cftransaction
tag only do a rollback when using cfdump abort
. With the proper rollback action
or a cfthrow
tag they do not rollback.
I'm new with CF2016. Can someone explain to me the differences between a rollback with one or another?
<cftransaction action="begin">
...somecode with querys...
<cfif a eq 1>
<cftransaction action="rollback" />
<cfelseif a eq 2>
<cfthrow message="Error">
<cfelse>
<cfdump var="Error" abort>
</cfif>
</cftransaction>
Upvotes: 2
Views: 866
Reputation: 567
Try to set a save-point before doing the rollback action... I'm not 100% sure if you need to explicitly set that before actually being able to do the rollback
Because <cfabort>
stops processing of the page all the queries that were made in the <cftransaction>
tag would be reversed,regardless of save points while with the <cftransaction action="rollback" />
you can reset it to a specific point in the set of queries.
For example think about the following flow
<cftransaction>
<Query 1 >
<Query 2 >
<cftransaction action = "setsavepoint" savepoint = "#point#"/>
<Query 3 >
</cftransaction>
If query 3 fails with <cftransaction action="rollback" savepoint="#point#" />
you can roll back to a point where you wouldnt have to redo the <Query 1 > <Query 2 >
and just worry about <Query 3 >
saving you some overhead by not repeating those queries. With CFABORT in the CFDUMP it would abort the entire transaction
The last example on this page with the withdraws shows the use of savepoints https://helpx.adobe.com/coldfusion/cfml-reference/coldfusion-tags/tags-t/cftransaction.html
Upvotes: 1