Product Documentation

c-treeDB API API for C

Previous Topic

Next Topic

ctdbFindResource

Locate and retrieve a resource by type and number.

Declaration

CTDBRET ctdbDECL ctdbFindResource(CTHANDLE resource, ULONG type, ULONG number, CTBOOL lock)

Description

ctdbFindResource() locates and retrieves a resource in a table based on type and number. resource is a handle allocated with ctdbAllocHandle(). type and number identify the resource and lock is used to indicate if the resource should be locked, if it is found.

Return

ctdbFindResource() returns CTDBRET_OK on success. If the specified resource is not in the table, ctdbFindResource() returns RNOT_ERR (408).

Example

/* display a particular resource */

CTDBRET DisplayResource(CTHANDLE hTable, ULONG type, ULONG number)

{

CTDBRET eRet;

CTHANDLE hRes = ctdbAllocResource(hTable, 0, 0, NULL);

/* check if resource was allocated */

if (!hRes)

return ctdbGetError(hTable);

/* note that no resource locks are acquired since we are not changing the resources */

if ((eRet = ctdbFindResource(hRes, type, number, NO)) == CTDBRET_OK)

{

printf("Resource type: %u, number: %u", ctdbGetResourceType(hRes), ctdbGetResourceNumber(hRes));

if (ctdbGetResourceName(hRes) != NULL)

printf(", name: \"\"\n", ctdbGetResourceName(hRes));

else

printf(", name: NULL"\n");

}

ctdbFreeResource(hRes);

return eRet;

}

See also

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

TOCIndex