I'm pretty sure the rollback is not occurring because your cfstoredproc call
inside your saveDataToDatabase() function is running in it's own
transaction.  I think you'd need to include a "rollback;" command inside
your stored procedure if you have a failure.

Dave

-----Original Message-----
From: Christophe Maso [mailto:zum...@hotmail.com] 
Sent: Friday, December 11, 2009 10:12 AM
To: cf-talk
Subject: cftransaction


Hi all, I understand the gist of cftransaction, but I've tried using it with
a conditional rollback on an action page in the below example and it doesn't
seem to work. saveDataToDatabase() submits data to a stored procedure, which
always returns a string: empty string if the data was saved, or a message
stating what the problem was if not.

<cfset allReturnMessages = "">
<cftransaction>
  <cfloop>
      <cfset returnMessage = someCFC.saveDataToDatabase()>
      <cfset allReturnMessages = allReturnMessages & returnMessage & "<br>">
  </cfloop>
  <cfif len(trim(allReturnMessages))>
     <cftransaction action="rollback" />
  </cfif>
</cftransaction>

I'm not including cftry in this example, just to illustrate that I'm not
looking for a database or other type of CF error per se - rather, I'm
looking for any return message from the stored proc that isn't an empty
string, such as "sorry - everything is otherwise kosher, but this stored
proc is coded not to save the data if field x is above value y". That's not
a database error as far as CF is concerned, so cftry wouldn't catch it. But
in testing this code, I've found that the rollback doesn't take place, even
when the cfif statement is true. Am I not using cftransaction correctly? 



~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Want to reach the ColdFusion community with something they want? Let them know 
on the House of Fusion mailing lists
Archive: 
http://www.houseoffusion.com/groups/cf-talk/message.cfm/messageid:329096
Subscription: http://www.houseoffusion.com/groups/cf-talk/subscribe.cfm
Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=89.70.4

Reply via email to