Field-level access

<< Click to Display Table of Contents >>

Navigation:  Application development > Accessing and updating tables >

Field-level access

Previous pageReturn to chapter overviewNext page

An application usually accesses data in a record at the field level. The BDE functions DbiGetField and DbiPutField let the application retrieve and update the data within each field in a record buffer. These functions allow field access without the need to know the structure of a record buffer.

Field-level access is done through a record buffer:

Reading a record
--> Table [DbiGetRecord] --> Record buffer [DbiGetField] -->  Field

Updating a record
--> Field [DbiPutField] --> Record buffer [DbiModifyRecord] --> Table

Retrieving field values

To retrieve a field within the record buffer, the application calls the BDE function DbiGetField, supplying the ordinal number of the field and a buffer to hold the data contents of the field. (The ordinal number is the position of the FLDDesc in the array returned by DbiGetFieldDesc, 1 to n.) Optionally, a Boolean can be returned indicating if the field is blank.

Updating field values

To update a field in the record buffer, the application calls the BDE function DbiPutField, supplying the ordinal number of the field, and a buffer containing the field contents to be written to the record. (The ordinal number is the position of the FLDDesc in the array returned by DbiGetFieldDescs, 1 to n.)

DbiPutField can also be used to set a field to blank, by passing a NULL pointer as the field buffer parameter.

Logical types versus physical types

As a general rule, the application should always use field translation mode xltFIELD. This parameter is set when the table is opened. If the table has already been opened and the translation mode is not set to xltFIELD, it can be changed with the DbiSetProp call.

When field translation mode is in effect, BDE automatically translates a field's data contents. When the field is retrieved, BDE translates the data in the record buffer from the native data type into a generic logical data type. When the field is written back to the record buffer, BDE translates the data back into the native physical data type.

When field translation mode is not in effect, BDE performs no translation of data to logical types. The application must be prepared to accept data from BDE using the data types native to the database system managing the table.

BDE type

C equivalent

Description

fldZSTRING

char[ ]

Zero terminated array of chars

fldUINT16

unsigned int

16-bit unsigned integer

fldINT16

int

16-bit integer

fldUINT32

unsigned long

32-bit unsigned long integer

fldINT32

long

32-bit long integer

fldFLOAT

double

64-bit floating point

fldFLOATIEEE

long double

80-bit floating point

fldBOOL

int

16-bit quantity, TRUE==1; FALSE==0

fldBYTES

unsigned char[ ]

Fixed size (independent of row) array of bytes

fldVARBYTES

unsigned char[ ]

Length-prefixed array of bytes