GEOS SDK TechDocs|
|
5 String Search |
7 Timestamping DataStoreFieldEnum(), DataStoreRecordEnum()
DataStoreFieldEnum()
enumerates through fields of a record. This routine uses a Boolean callback to determine whether to continue enumeration. If the callback returns TRUE, enumeration stops.
DataStoreRecordEnum()
enumerates through records of a datastore in storage order, starting at the specified
RecordNum
in the specified direction. This routine uses a Boolean callback routine to determine whether to continue enumeration. If the callback returns TRUE, enumeration ends; if FALSE, enumeration continues until the callback returns TRUE or until the routine reaches the last record.
There are two
DataStoreRecordEnumFlags
that can be passed in this routine:
The following example enumerates through the a datastore looking for the maximum value in a particular field.
Code Display 9-7 Enumerating Through a Datastore
/* data to be passed to the callback routine */ FloatNum enumData = 0;
/* record at which to start enumeration */ RecordNum rec = 0;
/*
* Open the datastore. For this example, assume dsToken
* is a global variable.
*/
if(DataStoreOpen("Exchange Rates", oself, 0, &dsToken) == DSE_NO_ERROR)
{
/*
* Enumerate through the datastore starting at the first record
* (so pass zero in the flags parameter);
* find the maximum value of the "exchange rate" field.
*/
if(DataStoreRecordEnum(dsToken, &rec, 0, &enumData, EnumCallback)
== DSE_NO_MORE_RECORDS)
{
/* do something with the value */
}
DataStoreClose(dsToken);
}
/* * The callback compares the data in the "exchange rate" field to the value * passed in with enumData. If the field data is greater than that of * enumData, copy the field's data to enumData. */
Boolean EnumCallback(RecordHeader *record, void *enumData)
{
/* parameters for getting field data */
FloatNum rateBuffer, *pRateBuffer;
FieldType type;
word size;
if(DataStoreGetFieldPtr(dsToken, record, 3, (void **)&pRateBuffer,
&type, &size) == DSDE_NO_ERROR)
{
if(*pRateBuffer > *((FloatNum *)enumData))
{
*((FloatNum *)enumData) = *pRateBuffer;
}
}
return FALSE; /* FALSE to continue enumeration */
}
If the routine returns DSE_NO_MORE_RECORDS, it has reached the last record in the file. If it returns DSE_NO_ERROR, it writes the
RecordNum
of the last record examined in the startRecord parameter.
GEOS SDK TechDocs|
|
5 String Search |
7 Timestamping