Allocating a Database handleA database handle is required before most database operations can take place. A database handle is instantiated with ctdbAllocDatabase() and freed with ctdbFreeDatabase(). When allocating a database handle you need to provide a properly allocated session handle. The session does not need to be logged in, only allocated, before the database can be allocated. CTHANDLE hSession = ctdbAllocSession(CTSESSION_CTDB); CTHANDLE hDatabase = ctdbAllocDatabase(hSession); if (!hSession || !hDatabase) {
printf(“Session or database handle allocation failed\n”); exit(1); } When the database handle is no longer needed, release it with ctdbFreeDatabase(). A database handle must be allocated or released by ctdbAllocDatabase() and ctdbFreeDatabase(). If you release an active database handle, ctdbFreeDatabase() automatically closes all tables associated with the database and disconnect the database from the session before releasing any database handle resources. |
|||