User Guide Cancel

TransactionCommit

 

Description

Commits the current active transaction.

Returns

Nothing

Category

Transaction functions

Function Syntax

TransactionCommit()

See also

TransactionRollbackTransactionSetSavePoint

History

ColdFusion 9: Added this function.

Usage

You can call this function only from within an active transaction.

Example

<cfscript>
q = new query();
q.setDatasource("cfartgallery");
WriteDump(q.execute(sql="select * from art where artid = 60").getResult());
transaction
{
q.execute(sql="insert into art (artid,artistid,artname,description,price) values (60,3,'tom','tom',2000)");
transactionSetSavePoint('sp1');
WriteDump(q.execute(sql="select * from art where artid = 60").getResult());
transaction
{
q.execute(sql="update art set artistid=4 where artid = 60");
transactionSetSavePoint('sp2');
WriteDump(q.execute(sql="select * from art where artid = 60").getResult());
transaction
{
try
{
q.execute(sql="update art set artistid='badvalue' where artid = 60");
}
catch(any e)
{
WriteLog("rolling back the transaction");
transactionRollback("sp1");
}
}
}
}
WriteDump(q.execute(sql="select * from art where artid = 60").getResult());
transaction
{
WriteLog("deleting the record");
q.execute(sql="delete from art where artid = 60");
WriteDump(q.execute(sql="select * from art where artid = 60").getResult());
}
</cfscript>
<cfscript> q = new query(); q.setDatasource("cfartgallery"); WriteDump(q.execute(sql="select * from art where artid = 60").getResult()); transaction { q.execute(sql="insert into art (artid,artistid,artname,description,price) values (60,3,'tom','tom',2000)"); transactionSetSavePoint('sp1'); WriteDump(q.execute(sql="select * from art where artid = 60").getResult()); transaction { q.execute(sql="update art set artistid=4 where artid = 60"); transactionSetSavePoint('sp2'); WriteDump(q.execute(sql="select * from art where artid = 60").getResult()); transaction { try { q.execute(sql="update art set artistid='badvalue' where artid = 60"); } catch(any e) { WriteLog("rolling back the transaction"); transactionRollback("sp1"); } } } } WriteDump(q.execute(sql="select * from art where artid = 60").getResult()); transaction { WriteLog("deleting the record"); q.execute(sql="delete from art where artid = 60"); WriteDump(q.execute(sql="select * from art where artid = 60").getResult()); } </cfscript>
<cfscript> 
q = new query(); 
q.setDatasource("cfartgallery"); 
WriteDump(q.execute(sql="select * from art where artid = 60").getResult()); 
transaction 
{ 
q.execute(sql="insert into art (artid,artistid,artname,description,price) values (60,3,'tom','tom',2000)"); 
transactionSetSavePoint('sp1'); 
WriteDump(q.execute(sql="select * from art where artid = 60").getResult()); 
transaction 
{ 
q.execute(sql="update art set artistid=4 where artid = 60"); 
transactionSetSavePoint('sp2'); 
WriteDump(q.execute(sql="select * from art where artid = 60").getResult()); 
transaction 
{ 
try 
{ 
q.execute(sql="update art set artistid='badvalue' where artid = 60"); 
} 
catch(any e) 
{ 
WriteLog("rolling back the transaction"); 
transactionRollback("sp1"); 
} 
} 
} 
} 
WriteDump(q.execute(sql="select * from art where artid = 60").getResult()); 
transaction 
{ 
WriteLog("deleting the record"); 
q.execute(sql="delete from art where artid = 60"); 
WriteDump(q.execute(sql="select * from art where artid = 60").getResult()); 
} 
</cfscript>

Get help faster and easier

New user?