Skip to main content
Participant
November 8, 2013
Question

deleting records

  • November 8, 2013
  • 1 reply
  • 397 views

HI, can i ask some help,...i have some sql statement that will delete records to the database.but i am confuse on this,what if the third sql statement failed to process and then the first and second delete statement are successfully deleted the records?.how can i return the data that was deleted...

I am using cf version 9

<cftry>
     <
cfquery>
     
// delete statement here

  
</cfquery>

  <
cfquery>
     
// delete statement here

  
</cfquery>

    <
cfquery>
     
// delete statement here

  
</cfquery>

     <
cfcatch type='Any'>

    <
cfset log_error='#CFCATCH.Detail# #CFCATCH.Message#'>

     <
cfquery name="automatedtask" datasource="#mysource#">
     
//   INSERT statemnent here
    
</cfquery
   </
cfcatch>

</
cftry

This topic has been closed for replies.

1 reply

Inspiring
November 8, 2013

If the 3 statements need to happen together or not (when 1 or more fail), and your database supports transactions, you should use <cftransaction>

The short of it is:

<cftransaction action="begin">

     <cftry>

          <cfquery name="test1" datasource="dsn">

               select * from blah

          </cfquery>

          <cfquery name="test1" datasource="dsn">

               select * from blah

          </cfquery>

         

          <cfquery name="test1" datasource="dsn">

               select * from blah

          </cfquery>

          <cfcatch>

               <cftransaction action="rollback" />

          </cfcatch>

     </cftry>

     <cftransaction action="commit" />

</cftransaction>