Product Documentation

c-treeDB API API for C

Previous Topic

Next Topic

CTDB_ON_RECORD_AFTER_WRITE

A CTDB_ON_RECORD_AFTER_WRITE callback is invoked just after a record is written with one of the FairCom DB record writing or updating functions. This callback is useful to adjust a record buffer just after data is written to disk.

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

c-treeDB API C API Example


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