Hi Chris,

You can skip the try/catch blocks and just put your cftransaction around
all the database operations you want to ensure either work or are rolled
back as a unit.  An error inside of a cftransaction block will
automatically cause the transactions to be rolled back.  The commit is
automatic with the closing cftransaction if no errors occurred.

Tom

-----Original Message-----
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On Behalf Of Christopher
Jordan
Sent: Tuesday, April 24, 2007 12:48 PM
To: Dallas/Fort Worth ColdFusion User Group Mailing List
Subject: [DFW CFUG] cftransaction... is this right?

Hi folks,

I've not used <cftransaction> before, and I'm wondering if this is the 
right idea. The example on livedocs doesn't show the use of the rollback

or commit features, so this is my best guess.

Could someone tell me if I'm doing the right thing?
<cftransaction action="begin">
        <!--- First Delete everything from the back up table --->
        <cftry>
                <cfquery name="Delete" datasource="MyDSN">
                        DELETE FROM BackupTable
                </cfquery>
                
                <cfcatch type="database">
                        <cftransaction action="rollback"/>
                </cfcatch>
        </cftry>
        <!--- copy current data table to BackupTable --->
        <cftry>
                <cfquery name="PerformBackup" datasource="MyDSN">
                        INSERT INTO BackupTable
                        SELECT * FROM ProductionTable
                </cfquery>
                
                <cfcatch type="database">
                        <cftransaction action="rollback"/>
                </cfcatch>
        </cftry>
        <!--- now drop everything from the production table --->
        <cftry>
                <cfquery name="Delete" datasource="MyDSN">
                        DELETE FROM ProductionTable
                </cfquery>
                
                <cfcatch type="database">
                        <cftransaction action="rollback"/>
                </cfcatch>
        </cftry>
        <cftransaction action="commit"/>
</cftransaction>

This is only part of a program, so don't worry that it's not putting any

information back into my production table. I'm just wondering about the 
<cftransaction> code.

Thanks heaps,
Chris

-- 
http://cjordan.info

_______________________________________________
Reply to DFWCFUG: 
  [email protected]
Subscribe/Unsubscribe: 
  http://lists1.safesecureweb.com/mailman/listinfo/list
List Archives: 
    http://www.mail-archive.com/list%40list.dfwcfug.org/             
  http://www.mail-archive.com/list%40dfwcfug.org/
DFWCFUG Sponsors: 
  www.instantspot.com/
  www.teksystems.com/


_______________________________________________
Reply to DFWCFUG:
  [email protected]
Subscribe/Unsubscribe:
  http://lists1.safesecureweb.com/mailman/listinfo/list
List Archives:
    http://www.mail-archive.com/list%40list.dfwcfug.org/
  http://www.mail-archive.com/list%40dfwcfug.org/
DFWCFUG Sponsors:
  www.instantspot.com/
  www.teksystems.com/

Reply via email to