Product Documentation

c-treeDB API API for C

Previous Topic

Next Topic


Add a new resource to a table.


CTDBRET ctdbDECL ctdbAddResource(CTHANDLE resource, pVOID data, VRLEN size);


ctdbAddResource() add a new resource to a table. When adding a Resource to a table, a special variable-length record is written to the table, containing the information from the Resource Data Block. This is done even if a data file uses fixed-length records. Every Resource is identified by a unique combination of a Resource Type and a Resource Number. The Resource Number can optionally be assigned by FairCom DB during the call to ctdbAddResource(). In addition, each Resource can be identified by a Resource Name. The Resource Name is not guaranteed to be unique.

The Resource Type must be a value greater than 65536. 0 through 65536 are reserved for FairCom use. If the Resource Number is a value of CTDB_ASSIGN_RESOURCE_NUMBER (0xffffffff), FairCom DB assigns this Resource the next available Resource Number for this Resource Type in the specified data file. The assigned number can be retrieved by calling ctdbGetResourceNumber() before the resource handle is released. The Resource Name is optional. Names starting with "FC!" or "RD!", are reserved for FairCom use.

Resource is a handle allocated by ctdbAllocResource(). data is any collection of data that you wish to store as a Resource. It can be a character string, a structure, or any variable type. size indicate the number of bytes occupied by data.


ctdbAddResource() returns CTDBRET_OK on success.


/* return CTDB_ASSIGN_RESOURCE_NUMBER on error */

ULONG AddMyResource(CTHANDLE Handle, ULONG type, pTEXT name, pVOID data, VRLEN size)



CTHANDLE hRes = ctdbAllocResource(Handle, type, number, name);


/* check if resource handle was allocated */

if (!hRes)


printf("ctdbAllocResource failed with error %d\n", ctdbGetError(Handle));

return number;


/* Add the resource */

if ((eRet = ctdbAddResource(hRes, data, size)) != CTDBRET_OK)


printf("ctdbAddResource failed with error %d\n", eRet);


return eRet;


/* retrieve the assigned resource number */

number = ctdbGetResourceNumber(hRes);

/* release the resource handle */


return number;



ctdbAllocResource(), ctdbFreeResource(), ctdbDeleteResource(), ctdbUpdateResource(), ctdbFirstResource(), ctdbNextResource(), ctdbFindResource(), ctdbFindResourceByName(), ctdbGetResourceType(), ctdbSetResourceType(), ctdbGetResourceNumber(), ctdbSetResourceNumber(), ctdbGetResourceName(), ctdbSetResourceName(), ctdbGetResourceDataLength(), ctdbGetResourceData(), ctdbSetResourceData(), ctdbIsResourceLocked(), ctdbUnlockResource()