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

GetFieldValue Method

Applies To

ODynaset

Description

This method obtains the value of a field in the current record of the dynaset.

Usage

oresult GetFieldValue(int index, OValue *val) const

oresult GetFieldValue(const char *fieldname, OValue *val) const

oresult GetFieldValue(int index, char *val, unsigned short maxlen, unsigned short *outlen) const

oresult GetFieldValue(const char *fieldname, char *val, unsigned short maxlen, unsigned short *outlen) const

oresult GetFieldValue(int index, int *val) const

oresult GetFieldValue(const char *fieldname, int *val) const

oresult GetFieldValue(int index, long *val) const

oresult GetFieldValue(const char *fieldname, long *val) const

oresult GetFieldValue(int index, double *val) const

oresult GetFieldValue(const char *fieldname, double *val) const

oresult GetFieldValue(int index, char *buffer, unsigned short maxlen) const

oresult GetFieldValue(const char *fieldname, char *buffer, unsigned short maxlen) const

oresult GetFieldValue(int index, void __huge *blobp, long bloblen, long * blobread) const

oresult GetFieldValue(const char *fieldname, void __huge * blobp, long bloblen, long *blobread) const

oresult GetFieldValue(int index, OBlob *val) const

oresult GetFieldValue(int index, OClob *val) const

oresult GetFieldValue(int index, OBfile *val) const

oresult GetFieldValue(int index, ORef *val) const

oresult GetFieldValue(int index, OObject *val) const

oresult GetFieldValue(int index, OCollection *val) const

oresult GetFieldValue(const char *fieldname, OBlob *val) const

oresult GetFieldValue(const char *fieldname, OClob *val) const

oresult GetFieldValue(const char *fieldname, OBfile *val) const

oresult GetFieldValue(const char *fieldname, ORef *val) const

oresult GetFieldValue(const char *fieldname, OObject *val) const

oresult GetFieldValue(const char *fieldname, OCollection *val) const

Arguments

Arguments
Description
index
The 0-based index of the field. The index is the position of the field in the SQL query that created the current record set.
fieldname
The name of the field, as expressed in the SQL query.
val
A variable, of one of a number of types, that will receive the value.
buffer
A caller-provided buffer that will be filled with a text value.
maxlen
The maximum number of bytes that can be placed in the buffer.
blobp
A caller-provided buffer that will be filled with data from a long or long raw field.
bloblen
The number of bytes to be read into blobp.
blobread
To be set to the number of bytes that were read into blobp.

Remarks

These methods get the value of a particular field specified by index (position in the SQL query) or by fieldname. Simple data can be extracted into any of the following types: int, long, double, and OValue.

If you need to get the value as a string, pass in a pointer to a character buffer. In this case, the length indicated by maxlen should include space for a null terminator, which will be added. Alternatively, you can get the string as an OValue and then cast the OValue to const char *. (See OValue for more information).

You should read data from a raw field into a string. Embedded nulls will be preserved (a null terminator will be added).

You can read data from a long or long raw field as a string if the length is less than 64K. If the length is greater than 64K (or simply if you want to), you can read the field into a buffer that you provide. The number of bytes that is actually read from the database is returned in the blobread argument. You can use the forms of GetFieldValue that read blobs only on fields whose server type is OTYPE_LONGRAW or OTYPE_LONG.

The method attempts to convert from one type to another. For example, asking for the field value as an integer when it is a character string with the value "23" will return the integer 23.

The method returns OSUCCESS if the value could be obtained in the desired type. It fails, and returns OFAILURE, if the current record is invalid, or the indicated field does not exist, or the data cannot be coerced into the desired type.

It is more efficient to ask for the field's value using the index argument than using the fieldname argument. Use the GetFieldIndex method to convert a field name to an index.

Return Value

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

Example An example of a variety of GetFieldValue calls:

// open a database object
ODatabase odb("t:123.45.987.06", "scott", "feline");

// open a dynaset on a table with several field types
ODynaset dyn(odb, "select fchar, fnumber, flong from data");
dyn.MoveFirst();

// declare variables to hold data
int ival;  // integer value
char cval[30]; // character string value
char *blobbuff = new char[80000]; // space for a whole document

// now read some data
dyn.GetFieldValue("fnumber", &ival);  // returns 23
dyn.GetFieldValue("fnumber", cval, 30); // returns "23"
dyn.GetFieldValue("fchar", cval, 30);   // returns the string in fchar
dyn.GetFieldValue("fchar", &ival);  // puts a number in ival, if it can

// get the long piece of text
long nread;  // number of bytes actually read
dyn.GetFieldValue("flong", (void *) blobbuff, 80000, &nread);