Yes, the database will roll back the transactions automatically, but if you
want your page to continue processing (on the coldfusion server) then you
will need the try/catch block.  The database will roll back the error, then
report to the CF server of the error.  CF will then abort processing unless
there is a TRY/CATCH.  What's unnecessary is a <cftransaction
action="rollback'/> within your cfcatch block because it will already have
been done by the database server since there was an error.

Hope this helps!

Dave 

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

Oh! So that's why they don't give examples of how to use those features...
they're built into the main tag. I'll ditch the try/catch blocks and the
rollback and commit lines, but I've got to wonder why they would offer those
features if they weren't really necessary.

Thanks heaps, Tom! :o)
Chris

Tom Woestman wrote:
> 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