> > > I have three queries that insert information, I need to be 
> > > sure that all three inserts take place, if not they are 
> > > discarded. How would I use cftransaction to accomplish this 
> > > task?
> > 
> > <cftransaction>
> >     <cfquery name="insert1" datasource="#dsn#">
> >         sql statement1
> >     </cfquery>
> >     <cfquery name="insert2" datasource="#dsn#">
> >         sql statement2
> >     </cfquery>
> >     <cfquery name="insert3" datasource="#dsn#">
> >        sql statement3
> >    </cfquery>
> > </cftransaction>
> 
> No what your looking for is this:
> 
> <CFTRANSACTION ACTION="BEGIN">
> <CFTRY>
> <!--- All your insert queries here --->
> <CFCATCH TYPE="Database">
> <CFTRANSACTION ACTION="ROLLBACK"/>
> </CFCATCH>
> <CFCATCH TYPE="Any">
> <CFTRANSACTION ACTION="ROLLBACK"/>
> </CFCATCH>
> </CFTRY>
> </CFTRANSACTION>

Actually, the CFTRY/CFCATCH isn't necessary to handle this. Just placing all
three queries within a CFTRANSACTION block will rollback all queries if any
fail, as long as all queries use the same datasource, username and password.

Dave Watts, CTO, Fig Leaf Software
http://www.figleaf.com/
voice: (202) 797-5496
fax: (202) 797-5444

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Structure your ColdFusion code with Fusebox. Get the official book at 
http://www.fusionauthority.com/bkinfo.cfm

Archives: http://www.mail-archive.com/cf-talk@houseoffusion.com/
Unsubscribe: http://www.houseoffusion.com/index.cfm?sidebar=lists

Reply via email to