Product Documentation

c-treeDB API for C++ - Developers Guide

Previous Topic

Next Topic

CTDB_ON_RECORD_BEFORE_BUILD_KEY

A CTDB_ON_RECORD_BEFORE_BUILD_KEY callback is invoked just before a call to FairCom DB BuildKey() function. The FairCom DB BuildKey() function perform key segment translation from record buffer to target key. This callback is useful to prepare a record buffer just before an index key is built.

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

c-treeDB C API Example


CTDBRET ctdbDECL OnRecordBeforeBuildKey(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