Remarks
The assignment operator makes the object a copy of another object.
For the classes OAdvise, OClient, OConnection, OConnectionCollection, ODatabase, ODynaset, OField, OFieldCollection, OParameter, OParameterCollection, OSession, and OSessionCollection, a copied object becomes another handle that refers to the same underlying
implementation object. Strings owned by the source object are not copied to the
destination object (although the same information - such as database name and
SQL statement - are available from the new object).
Note: For OField, what is being copied is not the value of the field, but the OField handle itself.
ODynasetMark and OValue are simpler objects. The data of the source object is simply copied.
If the object is already open, it is closed before the assignment. As a
result, if the assignment fails, the return value of the operation will be a closed
object.
The work that is done by assigning is the same as for a copy constructor.
OBinder and OBound have operator= defined in the header file, but the operator is not implemented. This is done
so that the compiler's default implementation will not be used (it would be
incorrect). If you want an assignment operator for your OBinder or OBound subclass, you must implement it.
Return Value
The object that was assigned to.
Example
An illustration of the meaning of assignment:
// open an ODatabase
ODatabase odb("ExampleDB", "scott", "tiger");
// open an ODynaset
ODynaset odyn(odb, "select ename, sal, comm from employees");
// get a field on sal and commission
OField salfield = odyn.GetField("sal");
OField commfield = odyn.GetField("comm");
// declare some OValue variables
OValue salval;
OValue commval;
// now look at the values of the first record
odyn.GetFieldValue("sal", &salval);
odyn.GetFieldValue("comm", &commval);
// let us say that salval contains 5000 and commval contains 300
salval = bonusval; // assign commission value to salary
// now salval contains 300
// can we do the same with OFields? NO!
int isal = (int) salfield; // isal is now 5000
int ibonus = (int) commfield; // ibonus is now 300
salfield = commfield; // assign comm OField to salary OField
// NOTE: we have only assigned the OField variable
int isal2 = (int) salfield; // isal2 is 300
/*
isal2 is 300 because salfield is now referring to the field "comm" in the
record.
*/
// now update the record
odyn.StartEdit()
salfield.SetValue(4000);
odyn.Update();
// we have just set the "comm" field to 4000, not the "sal" field