Product Documentation

c-treeDB API API for C

Previous Topic

Next Topic

ctdbAllocResource

Allocates a new resource handle.

DECLARATION

CTHANDLE ctdbDECL ctdbAllocResource(CTHANDLE Handle, ULONG type, ULONG number, cpTEXT name);

DESCRIPTION

Allocate a new resource handle. Before any operations can be performed on resources, you are required to allocate a resource handle. Resource handles are opaque handles whose contents are not available to the developer. You must use the set of functions provided by c-treeDB API to set and get properties and to perform operations.

  • Handle is a c-treeDB API table handle.
  • type is the resource type. If the resource type is unknown you may set this parameter to zero.
  • number is the resource number. If the resource number is unknown you may set this parameter to zero.
  • name is the resource name. If you do not know this value in advance, you can set this parameter with a NULL or empty string ("").

RETURN

ctdbAllocResource() returns the resource handle on success. Returns NULL if ctdbAllocResource() fails to allocate handle, in which case you should call ctdbGetError() passing the table Handle to obtain the error code.

EXAMPLE

CTDBRET DisplayAllResources(CTHANDLE hTable)

{

CTDBRET eRet;

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

/* check if resource was allocated */

if (!hRes)

return ctdbGetError(hTable);

/* get the first resource */

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

if ((eRet = ctdbFirstResource(hRes, false)) != CTDBRET_OK)

{

ctdbFreeResource(hRes);

return eRet;

}

/* get the other resources */

do

{

/* display resource type, number and name */

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

if (ctdbGetResourceName(hRes) != NULL)

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

else

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

}

while ((eRet = ctdbNextResource(hRes, false)) != CTDBRET_OK);

ctdbFreeResource(hRes);

return eRet;

}

SEE ALSO

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

TOCIndex