Oracle® Objects for OLE C++ Class Library Developer's Guide 10g Release 1 (10.1) Part Number B10119-01 |
|
Applies To
Description
This method rolls back the current transaction.
Usage
oresult Rollback(oboolean startnew = FALSE)
Arguments
startnew |
If TRUE a new transaction is begun (as if BeginTransaction had been called). If FALSE, no additional work is done after the transaction is committed. |
A database transaction is a way to group database operations so that they all either succeed or fail together. Please see "Transactions" for more details. BeginTransaction starts a transaction. You can terminate the transaction either with a Commit or a Rollback. It is an error to call Rollback when no transaction is in progress.
Calling Rollback results in OADVISE_ROLLBACK messages being sent to all advisories attached to all dynasets within this session. Any OBinder or OBound objects within the session will have PreRollback and PostRollback triggers called.
Return Value
An oresult indicating whether the operation succeeded (OSUCCESS) or not (OFAILURE).
Example
This example starts a transaction and begins a long sequence of operations. If an error occurs along the way, all changes are discarded with a Rollback. If they all succeed, the changes are made permanent with a Commit.
// routine to give all employees the same salary
void Transfer(ODynaset empdyn, double newsal)
{
// get the session of this dynaset
OSession empsess = empdyn.GetSession();
// start a transaction
empsess.BeginTransaction();
// edit every record (with StartEdit, SetFieldValue, Update)
empdyn.MoveFirst();
while (!empdyn.IsEOF())
{
if (empdyn.StartEdit() != OSUCCESS)
break;
if (empdyn.SetFieldValue("sal", newsal) != OSUCCESS)
break;
if (empdyn.Update() != OSUCCESS)
break;
empdyn.MoveNext(); // go to the next record
}
if (!empdyn.IsEOF())
{ // we got out of the loop early. Get rid of
// any changes we made
empsess.Rollback();
}
else
{ // everything worked. Make it all permanent
empsess.Commit();
}
return;
}