Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sigmaprojects/152c30b5ecab7dc5d65872737873bfeb to your computer and use it in GitHub Desktop.
Save sigmaprojects/152c30b5ecab7dc5d65872737873bfeb to your computer and use it in GitHub Desktop.
<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