Steve,


It depends more on what youre doing, than on a "Best Practice" concept.


If you're inserting into 3 tables, in a Loop, of X times, where if the
loop fails on any iteration, you'd want to roll back the entire
transaction, you'd surround the loop with the cftransaction,


But if you can identify the 3 inserts as a single logical "transaction",
don't mind if  the loop commits changes on each iteration, then you
should put the cftransaction inside the loop.


Example:


Place an order is a single activity.


<Cftransaction>
    INSERT ORDER VIA QUERY
    LOOP
        INSERT ORDER ITEMS, AND OTHER STUFF
    END LOOP
</cftransaction>


Another example:


Deleting Users from a database:


<cfloop>
    <Cftransaction>
        DELETE USER,
        CLEAN UP OTHER TABLES
        OTHER STUFF
    </cftransaction>
</cfloop>

Since "Deleting Users" is the logical atomic  action, you can put
transaction inside every iteration of the loop.  Since placing an order
is the atomic action in the first case, you wrap everything in the
transaction tag.


HTH, sorry sloppy pseudocode.
-Dov

  _____  

From: Steve Nelson [mailto:[EMAIL PROTECTED]
Sent: Thursday, June 10, 2004 2:16 PM
To: CF-Talk
Subject: cftransaction inside or outside cfloops?

Which is better and why?

<cfloop query="whatever">

            <cftransaction>

                        <cfquery>insert....</cfquery>

                        <cfquery>insert....</cfquery>

                        <cfquery>insert....</cfquery>

            </cftransaction>

</cfloop>

Vs.

<cftransaction>

<cfloop query="whatever">

                        <cfquery>insert....</cfquery>

                        <cfquery>insert....</cfquery>

                        <cfquery>insert....</cfquery>

</cfloop>

</cftransaction>

Steve Nelson
  _____
[Todays Threads] [This Message] [Subscription] [Fast Unsubscribe] [User Settings]

Reply via email to