Previous Topic

Next Topic

Allocating a table handle

A table handle is required before most table operations can take place. A table handle is instantiated with ctdbAllocTable() and freed with ctdbFreeTable().

When allocating a table handle you need to provide a handle to a database. At the moment of the table handle allocation, the database handle must be properly allocated by calling ctdbAllocDatabase(), but need not be connected.

CTHANDLE hSession = ctdbAllocSession(CTSESSION_CTDB);
CTHANDLE hDatabase = ctdbAllocDatabase(hSession);
CTHANDLE hTable = ctdbAllocTable(hDatabase);

if (!hSession || !hDatabase || !hTable) {
   printf(“Session, database or table handle allocation failed\n”);
   exit(1);
}

When the table handle is no longer needed it should be released by calling ctdbFreeTable(). A table handle must be allocated and released by ctdbAllocTable() and ctdbFreeTable().

If you release an active table handle, ctdbFreeTable() automatically closes the table and resets all record buffers associated with the table.