Skip Headers

Oracle® Objects for OLE C++ Class Library Developer's Guide
10g Release 1 (10.1)

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

DuplicateRecord Method

Applies To

OBinder

ODynaset

Description

This method creates a new record that is a duplicate of the current record. The current record must be valid.

Usage

oresult DuplicateRecord(void)

Remarks

This method works the same way that AddNewRecord does, and has the same side effects. OADVISE_ADDNEW messages are sent to all attached advisories and, for OBinders, the PreAdd and PostAdd triggers are called. The only difference is that after the record has been added, the values of the previously current record are used to fill the fields of the new record.

To use this method with an ODynaset, you must call AddNewRecord and then Update to save the changes. When you use OBinder you do not need to call Update; the OBinder machinery does that for you.

Depending on the options that were used to create the database to which this dynaset is attached, the Oracle database may or may not be called to fill values into some of the fields. See the ODATABASE_ORAMODE under ODatabase.

Note: A call to StartEdit, AddNewRecord, DuplicateRecord, or DeleteRecord, will cancel any outstanding StartEdit, AddNewRecord or DuplicateRecord calls before proceeding. Any outstanding changes not saved using Update will be lost during the cancellation.

When duplicating records, the order of events is as follows:

  1. ActionRequest on advisories for add and PreAdd trigger (for OBinders) in undefined order.
  2. Then the new record is added.
  3. Then the ActionNotify advisory is called.
  4. Then the values are copied.
  5. Then the PostAdd trigger (for OBinders) is called.
Return Value

An oresult indicating whether the operation succeeded (OSUCCESS) or not (OFAILURE).

Example

This example duplicates an order.

// open the database

ODatabase odb("ExampleDB", "scott", "tiger");

// open a dynaset on the orders table

ODynaset orderdyn(odb, "select * from ord");

// navigate somewhere in the orders dynaset

MoveToInterestingOrder(orderdyn);

/*

Note that although we are passing the orderdyn by value, when

the routine MoveToInterestingOrder navigates the dynaset, the

current record that we see will be changed.

*/

// duplicate the current order record

orderdyn.DuplicateRecord();

// we need to set a new id (because it must be unique)

orderdyn.SetFieldValue("ordid", orderidseed++);

// save the new record

orderdyn.Update();