Last active
February 19, 2017 09:07
-
-
Save sigmaprojects/152c30b5ecab7dc5d65872737873bfeb to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<cfscript> | |
table = "closure_test_table"; | |
dsn = "a-valid-dsn"; | |
try { | |
queryExecute(sql=" | |
CREATE TABLE #table# ( | |
[id] INT NOT NULL IDENTITY(1, 1), | |
[val] varchar(13) NOT NULL, | |
PRIMARY KEY (ID) | |
); | |
", | |
options={datasource=dsn} | |
); | |
} catch(lucee.runtime.exp.DatabaseException e) { | |
writeOutput("Error creating table (Might already exist) "); | |
} | |
iterations = [1,2,3,4,5,6,7,8,9,10]; | |
transaction action="begin" { | |
try { | |
// if this each() is converted to a for loop, the rollback will take place. | |
each(iterations, function(item) { | |
queryExecute(sql="INSERT INTO #table# (val) VALUES (#item#)",options={datasource=dsn}); | |
if( item == 8 ) { | |
writeOutput("force failed "); | |
force=throw; | |
} | |
}, true, 4); | |
transactionCommit(); | |
writeOutput("Transaction commited "); | |
} catch(any e) { | |
transactionRollback(); | |
writeOutput("Transaction should have been rolled back "); | |
} | |
} | |
data = queryExecute(sql="SELECT * FROM #table#",options={datasource=dsn}); | |
writedump(data); | |
queryExecute(sql="DELETE FROM #table#",options={datasource=dsn}); | |
</cfscript> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment