Skip to main content
Inspiring
September 16, 2008
Question

cftransaction question

  • September 16, 2008
  • 2 replies
  • 712 views
Hi all, for a cftransaction similar as shown below,

<cftransaction action="BEGIN">
<cftry>

<cfquery ............>
SQL statement
</cfquery>

<cfquery ............>
SQL statement
</cfquery>

other statements

<cftransaction action="commit" /> <!--- is this necessary??? --->

<cfcatch type="any">
<cftransaction action="rollback" />
<cfoutput>
#cfcatch.detail#
</cfoutput>
</cfcatch>

</cftry>

</cftransaction>


Is the <cftransaction action="commit" /> necessary? What happens if I remove this line?
This topic has been closed for replies.

2 replies

dongzkyAuthor
Inspiring
September 19, 2008
Thanks
Participating Frequently
September 16, 2008
Removing the COMMIT may or may not affect the outcome, as it probably depends on the particular RDBMS that you are using, and whether or not your "session" is set for auto-commit, etc, but one major point of using CFTRANSACTION is to allow you to control whether or not your transaction is committed or rolled back if something goes wrong, etc. This is in addition to giving you control over "holding" the state of certain database updates so that you can guarantee that state against other transactions until you complete your transaction, etc.

Phil