A CTDB_ON_RECORD_AFTER_READ callback is invoked just after a record is read by one of the FairCom DB record reading functions. This callback is useful to adjust a record buffer just after data is read.
The handle passed as parameter for this callback is a record handle and you can safely typecast the handle parameter to a pCTDBRECORD structure pointer.
The following CTDBRECORD structure members keep information regarding the record buffer kept by the record handle:
CTDBRECORD Structure Member |
Explanation |
---|---|
pUTEXT recbuf |
record buffer |
VRLEN recbuf_size |
size in bytes of memory allocated for record buffer |
VRLEN recbuf_len |
actual length of data in record buffer |
FairCom DB API C API Example
CTDBRET ctdbDECL OnRecordAfterRead(CTHANDLE Handle)
{
CTDBRET Retval = CTDBRET_OK;
pCTDBRECORD pRecord = (pCTDBRECORD)Handle;
if (!pRecord)
Retval = CTDBRET_NOTRECORD;
else
{
/* swap the record buffer with the localTag */
pUTEXT recptr = pRecord->recbuf;
int i;
pRecord->recbuf = pRecord->localTag;
pRecord->localTag = (pVOID)recptr;
/* make any CT_DATE field compatible with FairCom DB API */
for (i = 0; (i < pRecord->fields_count && Retval == CTDBRET_OK); i++)
{
if (pRecord->fields[i].ftype == CT_DATE)
{
time_t* t;
struct tm* ptr;
CTDATE date;
/* get the non standard date into t */
t = (time_t*)&recptr[pRecord->fields[i].offset];
/* convert a C time_t date into CT_DATE */
if ((ptr = gmtime(t)) != NULL)
{
if ((Retval = ctdbDatePack(&date, (ptr->tm_year + 1900), (ptr->tm_mon + 1), ptr->tm_mday)) == CTDBRET_OK
{
/* put converted CTDB date back into record buffer */
memcpy(&pRecord->recptr[pRecord->fields[i].offset], &date, sizeof(CTDATE));
}
}
else
Retval = CTDBRET_INVDATE;
}
}
}
return Retval;
}