Oracle® Objects for OLE C++ Class Library Developer's Guide 10g Release 2 (10.2) Part Number B14308-01 |
|
Applies To
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:
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();