1 Reply Latest reply on Nov 8, 2013 11:41 AM by Aegis Kleais

    deleting records

    jemz

      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>  
      
      
        • 1. Re: deleting records
          Aegis Kleais Level 3

          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>