Application-level database transaction best practices

I saw several different examples cftransactionand read different sites and still have not been able to find a definitive answer to which parts are cftransactionneeded. What I'm trying to accomplish is very simple:

  • start a transaction
  • run multiple attachments / updates
  • close transaction

If there is an error during insertions / updates, I want to cancel the transaction. Here is what I have done in the past:

<cftransaction>
 <cftry>
  <!--- multiple insert/update queries --->
 <cfcatch type="any">
  <cftransaction action="rollback">
  <!--- log error, show user message --->
 </cfcatch>
 </cftry>
<cftransaction action="commit">
</cftransaction>

It is right? What is the best practice? Not all instances cftransactionfollow the above example. Some have only start and end tags.

, . set transaction isolation level read committed , .

+3
3

, "commit" "rollback" . , , , - . , .

:

<cftry>
  <cftransaction>
    <!--- multiple insert/update queries --->
  </cftransaction>
  <cfcatch type="database">
    <!--- log error, show user message --->
  </cfcatch>
</cftry>
+1

:

, cftry cftransaction. , .

-, , , , . , . , , .

0

, , ColdFusion 9:

<cfscript>
  transaction {
    // ... your DB code
  }
</cfscript>

, : ( ), .

-, , , . , , .

0
source

Source: https://habr.com/ru/post/1726463/


All Articles