Skip Headers
Oracle® Objects for OLE C++ Class Library Developer's Guide
10g Release 2 (10.2)

Part Number B14308-01
Go to Documentation Home
Home
Go to Book List
Book List
Go to Table of Contents
Contents
Go to Index
Index
Go to Master Index
Master Index
Go to Feedback page
Contact Us

Commit Method

Applies To

OSession

Description

This method commits the current transaction.

Usage

oresult Commit(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.
Remarks

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. You start a transaction with BeginTransaction. You terminate the transaction either with a Commit or a Rollback. It is an error to call Commit when no transaction is in progress.

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 the changes are discarded with a Rollback. If they all succeed, all the changes are made permanent with a Commit.

// routine to give all employees the same salary
void Transfer(ODynaset empdyn, double salary)
{
    // 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", salary) != OSUCCESS)
            break;
        if (empdyn.Update() != OSUCCESS)
            break;
   
        empdyn.MoveNext();  // go to the next record
    }
    if (!empdyn.IsEOF())
    { // we got out of the loop early. There must be a problem.
      //   Get rid of any changes we made
        empsess.Rollback();
    }
    else
    { // everything worked, so make it all permanent
        empsess.Commit();
    }
    return;
}