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
Feedback

OField Method

Applies To

OField

Description

OField constructor

Usage

OField(void)

OField(const OField &otherfield)

Arguments

otherfield
Another OField object that you are copying.
Remarks

These methods construct a new OField instance.

The default constructor constructs an unopened OField object. It cannot fail.

The copy constructor copies another OField object. If that other OField object is open - which means it is a handle on an implementation field object - the new OField object becomes a handle to that same field object. The copy constructor copies the reference to the field object but does not copy any strings that the source OField may own. The copy constructor can fail; check whether the new OField is open after the constructor call.

There is no Open method for the OField class. To get an open OField, call one of the GetField methods.

Example

This method sums all the salaries of employees.

// open the employee database

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

// open a dynaset on the employee's table
ODynaset odyn(odb, "select sal, comm from employees");

// get a field on the salary for speed
OField salf = odyn.GetField("sal");
/*
By using the = operator in the declaration of salf we are invoking the copy
constructor. It is copying the temporary object that is returned by the GetField
method.
*/

// sum the salaries
double sumsal = 0.0;
odyn.MoveFirst();
while (!odyn.IsEOF())
{
    sumsal += (double) salf;
    odyn.MoveNext();
}

// of course, we could have done the same thing (faster) with:
ODatabase odb("ExampleDB", "scott", "tiger");
ODynaset odyn(odb, "select sum(sal) from employees");
odyn.GetFieldValue(0, &sumsal);
// the server is good at that kind of bulk calculation