Product Documentation

FairCom DB API for C

Previous Topic

Next Topic

CTDB_ON_RECORD_AFTER_BUILD_KEY

A CTDB_ON_RECORD_AFTER_BUILD_KEY callback is invoked just after a call to the FairCom DB BuildKey() function. The FairCom DB BuildKey() function performs key segment translation from record buffer to target key. This callback is useful to adjust a record buffer just after a target key was built.

The handle passed as a parameter with 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 OnRecordAfterBuildKey(CTHANDLE Handle)

{

CTDBRET Retval = CTDBRET_OK;

pCTDBRECORD pRecord = (pCTDBRECORD)Handle;

if (!pRecord)

Retval = CTDBRET_NOTRECORD;

else

{

/* change any CT_DATE dates to C time_t dates */

pUTEXT recptr = pRecord->recbuf;

int i;

for (i = 0; (i < pRecord->fields_count && Retval == CTDBRET_OK); i++)

{

if (pRecord->fields[i].ftype == CT_DATE)

{

struct tm m;

CTDATE* dateptr;

/* get the CTDB date */

dateptr = (CTDATE*)&recptr[pRecord->fields[i].offset];


/* convert a CT_DATE date to a C time_t date */

if ((Retval = ctdbDateUnpack(*dateptr, &m.tm_year, &m.tm_mon, &m.tm_mday)) == CTDBRET_OK)

{

time_t* tptr = (time_t*)&recptr[pRecord->fields[i].offset];

m.tm_year -= 1900;

m.tm_mon--;

m.tm_sec = 0;

m.tm_min = 0;

m.tm_hour = 0;

m.tm_isdst = 0;

*t = mktime(&m);

}

}

}

}

return Retval;

}

TOCIndex