isInTransaction()
Last updated September 25, 2012
Version: 1 | Requires: CF9 | Library: DatabaseLib
Description:
The function can be used within code to determine whether one is currently within a CFTRANSACTION or not. Credit for the technique must go to Bilal from boncode.blogspot.co.uk who wrote this article from which I lifted the concept: http://boncode.blogspot.co.uk/2009/02/cf-detecting-nested-transactions.html. All I have done is turned it into a UDF.
This calls an internal ColdFusion Java class, so will not work on Railo or OpenBD. It has been tested to work on CFMX7, CF9 and CF10 (I have not tested on CF8 as I don't have a CF8 server to test with, but see no reason why it would not work on CF8 if it works on the version either side of it.
Return Values:
Returns true if the call was within a CFTRANSACTION, otherwise false.
Example:
<cfoutput>
Before: #isInTransaction()#<br />
<cftransaction>
Within: #isInTransaction()#<br />
</cftransaction>
After: #isInTransaction()#<br />
</cfoutput>
Parameters:
No arguments.
Full UDF Source:
/**
* Returns true if the call to it is within a CFTRANSACTION block
* v0.1 by Bilal Soylu
* v1.0 by Adam Cameron: simplifying logic & converting to script
* v1.1 by Adam Cameron: fixed bug causing potential false positives (as advised by Bilal)
*
* @return Returns true if the call was within a CFTRANSACTION, otherwise false.
* @author Bilal Soylu (bilalsoylu@gmail.com)
* @version 1.1, September 24, 2012
*/
function isInTransaction(){
var result = createObject("java", "coldfusion.tagext.sql.TransactionTag").getCurrent();
return structKeyExists(local, "result");
}
Search CFLib.org
Latest Additions
Raymond Camden added
QueryDeleteRows
November 04, 2017
Leigh added
nullPad
May 11, 2016
Raymond Camden added
stripHTML
May 10, 2016
Kevin Cotton added
date2ExcelDate
May 05, 2016
Raymond Camden added
CapFirst
April 25, 2016