gsr
04/11/2023, 5:50 PM<cftransaction>
<cftry>
<cftransaction action="begin"/>
<cfset delObject = 'delete the file'>
<cfif !delObject>
<cfthrow message="Unable to delete">
</cfif>
<cfcatch type="any">
<cfthrow/>
</cfcatch>
</cftry>
<cftry>
<cfset uploader = 'upload a file'>
<cfif !isArray(uploader)>
<cfthrow message="uploader">
<cfelse>
<cfquery>
update query
</cfquery>
</cfif>
<cftransaction action="commit/">
<cfcatch type="any">
<cftransaction action="rollback/">
</cftry>
</cftransaction>Dave Merrill
04/11/2023, 6:20 PMAdam Cameron
even if it's an errorWhat sort of error? What's the actual error that it's apparently ignoring? ---- Also: what are you trying to achieve with this:
<cftry>
<--- ... --->
<cfcatch type="any">
<cfthrow/>
</cfcatch>
</cftry>
All that will really do is swap a clear & situation-specific exception for one that isn't?
----
Also... what I'm intrigued by what - specifically - <cftransaction action="begin"/> actually does. But that's just for my own education.Adam Cameron
Unless I'm slipping a gear or two, your tag nesting is foobar.Some of those
<cftransaction> tags are self-closing. It makes it seem like it's whack, but it's actually not.Adam Cameron
david.kreimer
04/11/2023, 6:29 PMdavid.kreimer
04/11/2023, 6:29 PMdavid.kreimer
04/11/2023, 6:30 PM<cftransaction action="commit/">
im surprised these transaction tags execute with /s in the actiongsr
04/11/2023, 6:31 PMAdam Cameron
gsr
04/11/2023, 6:32 PMdavid.kreimer
04/11/2023, 6:33 PMgsr
04/11/2023, 6:33 PMAdam Cameron
Adam Cameron
Adam Cameron
david.kreimer
04/11/2023, 6:36 PMMichael Schmidt
04/11/2023, 6:37 PMgsr
04/11/2023, 6:37 PMAdam Cameron
<cftransaction action="begin"/> is pointless.Adam Cameron
doing something with throw to actually send it to catchWhat does that mean?
gsr
04/11/2023, 6:51 PMgsr
04/11/2023, 6:51 PMgsr
04/11/2023, 6:51 PMdavid.kreimer
04/11/2023, 6:54 PMEvil Ware
04/11/2023, 7:38 PMAdam Cameron
Cftransaction is some kind of WEIRD
<cftransaction> just tells the DB connection to perform transaction operations. There's nothing weird going on.gsr
04/11/2023, 9:27 PMAdam Cameron
<cftransaction> doesn't quite do what you thought it did?Adam Cameron
Evil Ware
04/12/2023, 12:28 PMMichael Schmidt
04/12/2023, 12:43 PMAdam Cameron
Evil Ware
04/13/2023, 3:18 PMAdam Cameron
A: Read a record that has a counter of how many times it was processed
B: Do some other stuff
C: Increment a counter in the record
D: Write record back
Along come two processes:
Without a transaction:
P1: Step A - counter is 1
P2: Step A - counter is 1
P1: Step B
P2: Step B
P1: Step C - counter is 2
P2: Step C - counter is 2
P1: Step D - writes back 2
P2: Step D - writes back 2 <--- wrong
But in a transaction:
P1: creates a transaction
P1: Step A - counter is 1
P2: waits
P1: Step B
P2: waits
P1: Step C - counter is 2
P2: waits
P1: Step D - writes back 2
P1: releases transaction
P2: creates a transaction
P2: Step A - counter is 2
P2: Step B
P2: Step C - counter is 3
P2: Step D - writes back 3 <--- woohoo!
Transactions are also smarter than this very naive implementation, and won't block if they don't need to (or unless they're told to)
They're for the same reason application code can have synchronised blocks (<cflock> in CFML). But for the DB.
They handle race conditions, and the notion of race conditions are not some sort of arcanery from times past. Esp in web applications they're not at all uncommon. And we do need to be dealing with them.
Over and above that, transactions allow one to run programs that perform multiple incremental DB write operations, and if any of them fail... back out the whole lot. Or maybe just back out some of it and try it again. Or go "yep I'm done, write all that back now". And throughout the whole process none of the updates impact anyone else going about their DB activity because the changes are "staged" before being committed (or rolled-back).
Having a handle on this stuff is pretty fundamental to being a web dev in a data-driven environment.Evil Ware
04/13/2023, 7:37 PMAdam Cameron
gsr
04/14/2023, 3:37 AMEvil Ware
04/14/2023, 12:25 PMseancorfield
Evil Ware
04/14/2023, 7:23 PMAdam Cameron
seancorfield
seancorfield
Adam Cameron
Adam Cameron
Adam Cameron
seancorfield
Michael Schmidt
04/14/2023, 8:27 PMAdam Cameron
shawnoden
04/14/2023, 9:02 PMshawnoden
04/14/2023, 9:03 PMgsr
04/14/2023, 9:11 PMflabbergasted someone used it as an alternative to surprised , not a very common word i hear a lot.Evil Ware
04/18/2023, 12:58 PM