The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.
|
 |
|
Dev Shed Forums
> Programming Languages - More
> ColdFusion Development
|
Want to always commit a certain CFQUERY Insert within a CFTRANSACTION
Discuss Want to always commit a certain CFQUERY Insert within a CFTRANSACTION in the ColdFusion Development forum on Dev Shed. Want to always commit a certain CFQUERY Insert within a CFTRANSACTION ColdFusion Development forum discussing CFML coding practices, tips on CFML, and other CFML related topics. Find out why ColdFusion is the tool of choice for many e-commerce developers.
|
|
 |
|
|
|
|

Dev Shed Forums Sponsor:
|
|
|

June 15th, 2012, 09:28 AM
|
|
Registered User
|
|
Join Date: Jun 2012
Posts: 3
Time spent in forums: 30 m 5 sec
Reputation Power: 0
|
|
|
Want to always commit a certain CFQUERY Insert within a CFTRANSACTION
I have a situation where I would like to always COMMIT a CFQUERY Insert statement into a Log table within a CFTRANSACTION block whether the transaction succeeds or fails. I am a Coldfusion newbie, so I am uncertain how best to proceed.
It seems from what I have researched that I might have 2 possible ways to do this.
1. Use CFTHREAD to kick off an asynchronous process to do this Insert. I'm uncertain if this would be immune from being Rolledback in a failed transaction, however.
2. Use Setsavepoint within the CFTRANSACTION and explicitly commit only that short block of code, obviously, without committing anything outside the Savepoint. I am unclear from the documentation if this would work as I intend or not.
We are running Coldfusion version 9.
I would appreciate any comments or advice here. Perhaps there is a better way of doing this altogether that I am overlooking?? 
|

June 15th, 2012, 12:23 PM
|
|
Moderator
|
|
Join Date: Jun 2002
Location: Raleigh, NC
|
|
|
If you want one of the updates to happen even if the transaction fails, then it shouldn't be part of the transaction. A transaction is an atomic unit, meaning it all succeeds or it all fails. So unless I'm missing something, you want to run this query either before or after the transaction, not within it.
|

June 15th, 2012, 01:24 PM
|
|
Registered User
|
|
Join Date: Jun 2012
Posts: 3
Time spent in forums: 30 m 5 sec
Reputation Power: 0
|
|
Kiteless, I hear you and understand that. My issue then is the variables I need to output to my log table are multiple levels deep inside the Transaction. So, I guess my only choice is to pull the variables I need up the tree (so to speak) until I'm outside the transaction? Is that doable without losing the variable data??
I am pulling up some of the data a level while I was testing solutions with cfset caller.xxxxx function.... Not crazy about doing that, but I don't know a better way currently, being a Newbie and all..
Any further thoughts??
Quote: | Originally Posted by kiteless If you want one of the updates to happen even if the transaction fails, then it shouldn't be part of the transaction. A transaction is an atomic unit, meaning it all succeeds or it all fails. So unless I'm missing something, you want to run this query either before or after the transaction, not within it. |
|

June 15th, 2012, 02:38 PM
|
|
Moderator
|
|
Join Date: Jun 2002
Location: Raleigh, NC
|
|
|
Without seeing everything you're doing, it's hard to say. But it sounds like what you want to do is have the method running the transaction return some value or an object containing the data you need, and then use that to do your insert.
|

June 19th, 2012, 10:02 AM
|
|
Registered User
|
|
Join Date: Jun 2012
Posts: 3
Time spent in forums: 30 m 5 sec
Reputation Power: 0
|
|
OK, I guess I'll work that direction, then. Appreciate the input....
Quote: | Originally Posted by kiteless If you want one of the updates to happen even if the transaction fails, then it shouldn't be part of the transaction. A transaction is an atomic unit, meaning it all succeeds or it all fails. So unless I'm missing something, you want to run this query either before or after the transaction, not within it. |
|
Developer Shed Advertisers and Affiliates
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Rate This Thread |
Linear Mode
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|