Preparing the record buffer and retrieving field descriptors

<< Click to Display Table of Contents >>

Navigation:  »No topics above this level«

Preparing the record buffer and retrieving field descriptors

Return to chapter overview

A successful call to DbiOpenTable returns a cursor handle to the application. Before it can use the cursor handle to access data in the table, the application must prepare the record buffer. Preparing the record buffer includes allocating memory for it and, in some cases, initializing it.

The application can also set up an array in which to retrieve the field descriptors for each field contained in the table. To determine the required sizes of the record buffer and the array of field descriptors, the application calls DbiGetCursorProps. This call is usually made immediately after the DbiOpenTable call, and returns the required information in the CURProps structure.

Example

The following code sample gets the cursor properties, allocates the record buffer, sets up an array for the field descriptors, and gets the field descriptors:

DBIResult   rslt;

pCHAR       pRecBuf;

CURProps    curProps;

pFLDDesc    pFldArray;

// Get the table properties

rslt = DbiGetCursorProps(hCursor, &curProps);

if (rslt == DBIERR_NONE)

{

 // Allocate the record buffer

 pRecBuf = malloc(curProps.iRecBufSize);

 // Check result of malloc

 …

 // Get an array of field descriptors

 pFldArray = (pFLDDesc) malloc(sizeof(FLDDesc) * curProps.iFields);

 // Check result of malloc

 …

 rslt = DbiGetFieldDescs(hCursor, pFldArray);

 …

 free(pFldArray);

 free(pRecBuf);

}

Getting the cursor properties

When the application calls DbiGetCursorProps, the cursor properties CURProps structure is returned with information describing the most commonly used cursor properties. CURProps contains the following fields:

Type

Name

Description

DBITBLNAME

szName

Table name (no extension, if it can be derived)

UINT16

iFNameSize

Full file name size

DBINAME

szTableType

Table type

UINT16

iFields

Number of fields in table

UINT16

iRecSize

Record size (logical record)

UINT16

iRecBufSize

Record size (physical record)

UINT16

iKeySize

Key size

UINT16

iIndexes

Number of currently available indexes

UINT16

iValChecks

Number of validity checks

UINT16

iRefIntChecks

Number of referential integrity constraints

UINT16

iBookMarkSize

Bookmark size

BOOL

bBookMarkStable

TRUE, if the cursor supports stable bookmarks

DBIOpenMode

eOpenMode

dbiREADWRITE, dbiREADONLY

DBIShareMode

eShareMode

dbiOPENSHARED, dbiOPENEXCL

BOOL

bIndexed

TRUE, if the index is active

INT16

iSeqNums

1: Has sequence numbers (Paradox);

0: Has record numbers (dBASE, FoxPro);

< 0 (-1, -2. . .): None (SQL and Access)

BOOL

bSoftDeletes

TRUE, if the cursor supports soft deletes (dBASE and FoxPro only)

BOOL

bDeletedOn

TRUE, if deleted records are seen

UINT16

iRefRange

If > 0, has active refresh

XLTMode

exltMode

Translate mode: xltNONE (physical types), xltFIELD (logical types)

UINT16

iRestrVersion

Restructure version number

BOOL

bUniDirectional

TRUE, if the cursor is unidirectional (SQL only)

PRVType

eprvRights

Table-level rights

UINT16

iFmlRights

Family rights (Paradox only)

UINT16

iPasswords

Number of auxiliary passwords (Paradox only)

UINT16

iCodePage

Code page; if unknown, set to 0

BOOL

bProtected

TRUE, if the table is protected by password

UINT16

iTblLevel

Driver-dependent table level

DBINAME

szLangDriver

Symbolic name of language driver

BOOL

bFieldMap

TRUE, if a field map is active

UINT16

iBlockSize

Data block size in bytes, if any

BOOL

bStrictRefInt

TRUE, if strict referential integrity is in place

UINT16

iFilters

Number of filters

BOOL

bTempTable

TRUE, if the table is temporary

 

Memory allocation elements

The following elements are significant when allocating memory:

iFields
Specifies the number of fields in the table. Use this number to allocate an array to receive the field descriptors for the table. The size of the array is:

 iFields * sizeof(FLDDesc)

 

iRecSize
Specifies the record size, depending on the translation mode for the cursor. If the translation mode is xltFIELD, iRecSize specifies the logical record size. In other words, it is the size of the record if all fields were represented as BDE logical types. If the translation mode is xltNONE, iRecSize specifies the physical record size, which is the same as iRecBufSize.

iRecBufSize
Specifies the physical record size. This is the size of the record buffer that you must allocate in order to retrieve the records by using DbiGetNextRecordefq.7b, DbiGetPriorRecord, and other functions. For example,

 pRecBuf = (pBYTE)malloc(curProps.iRecBufSize);

Initializing the record buffer

Initialize the record buffer with a call to DbiInitRecord if a new record is to be inserted. This function initializes each field in the record buffer, including BLOB fields, to blanks based on the data type defined. For Paradox tables, default values are used to initialize the fields if default values are specified in the table.

Getting the field descriptors

After memory has been allocated for the array of field descriptors, the application can retrieve the field descriptors with a call to DbiGetFieldDescs. The field descriptors provide the application with information that it needs to address and manipulate each field within the record buffer. DbiGetFieldDescs returns an array of FLDDesc structures, with information describing each field in the table:

Type

Name

Description

UINT16

iFldNum

Field number (1 to n)

DBINAME

szName

Field name

UINT16

iFldType

Field type

UINT16

iSubType

Field subtype (if applicable)

UINT16

iUnits1

Number of characters or units

UINT16

iUnits2

Decimal places

UINT16

iOffset

Offset in the record (computed)

UINT16

iLen

Length in bytes (computed)

UINT16

iNullOffset

For NULL bits (computed)

FLDVchk

efldvVchk

Field has validity checks (computed)

FLDRights

efldrRights

Field rights (computed)

iFldNum


Specifies a driver-specific field ID. For most drivers, this value is from 1 to curProps.iFields, except for Paradox tables, which can use an invariant field ID For more information about invariant field IDs, refer to DbiDoRestructure

Note:For consistency across drivers, use the ordinal position of the field in the descriptor array. Both DbiGetField and DbiPutField use an ordinal number from 1 to n.

szName
Specifies the name of the field.

iFldType
Specifies the type of the field. Depending on the translate mode property of this cursor the field type returned could be physical or logical. If the translate mode is xltFIELD, the field type returned is a BDE logical type; if the mode is xltNONE, the field type returned is the driver's corresponding physical type. For more information about physical and logical data types, see Using the function reference and Data structures.

iSubType
Specifies the subtype of the field. This could be a BDE logical subtype or a driver physical subtype, depending on the translate mode.

iUnits1
Specifies the number of characters, digits, and so on. For logical field types, this number is consistent across drivers. For physical field types, the interpretation of this field can be dependent on the driver and also on the specific field type. For most drivers, if the field is of the numeric type, iUnits1 is the precision and iUnits2 is the scale.

iUnits2
Specifies the number of decimal places, and so on. For logical field types, this number is consistent across drivers. For physical field types, the interpretation of this field can depend on the driver and also on the specific field type. For most drivers, if the field is of the numeric type, iUnits1 is the precision and iUnits2 is the scale.

The following three fields together specify the layout of the record buffer:

iOffset
Specifies the offset of this field in the record buffer. The offset depends on the translation mode. If the mode is xltFIELD, it is the offset of the field within a logical record.

iLen
Specifies the length of this field. The length depends on the translation mode; that is, it could be the length of the logical or physical representation of the field. The application developer uses this value to allocate a buffer in which to retrieve the field value.

iNullOffset
Specifies the offset of the NULL indicator for this field in the record buffer. If zero, there is no NULL indicator. Otherwise, iNullOffset is the offset to an INT16 value, which is -1 if the field is NULL (SQL only).

efldvVchk
Specifies whether or not validity checks are associated with this field (Paradox and SQL drivers only).

efldrRights
Specifies the field level rights for this field.

 

 Preparing to access a table%!AL(`preparingtoaccess')

 Accessing and updating tables%!AL(`accessingtables')