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 contains 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 when calling ctdbAddResource(). In addition, each Resource can be identified by a Resource Name. A Resource Name is not guaranteed to be unique.
The following steps are required to add a new resource to a table:
To add a new resource you must call the following function:
CTDBRET ctdbDECL ctdbAddResource(CTHANDLE resource, pVOID data, VRLEN size);
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 to 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. FairCom DB does not guarantee unique Resource Names. Names starting with the character sequences "FC!" or "RD!", are reserved for FairCom use.
FairCom DB API C API Add Resource Example
/* return CTDB_ASSIGN_RESOURCE_NUMBER on error */
ULONG AddMyResource(CTHANDLE Handle, ULONG type, pTEXT name, pVOID data, VRLEN size)
{
ULONG number = CTDB_ASSIGN_RESOURCE_NUMBER;
CTHANDLE hRes = ctdbAllocResource(Handle, type, number, name);
CTDBRET eRet;
/* 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);
ctdbFreeResource(hRes);
return eRet;
}
/* retrieve the assigned resource number */
number = ctdbGetResourceNumber(hRes);
/* release the resource handle */
ctdbFreeResource(hRes);
return number;
}