Allocating a table handle without database supportIt is possible to create or open a table without database support by passing the session handle when allocating the table handle. Here is an example without error checking: CTHANDLE hSession; CTHANDLE hTable; /* Allocate a new session handle */ hSession = ctdbAllocSession(CTSESSION_CTREE); /* Logon to session */ ctdbLogon(hSession, “FAIRCOMS”, “ADMIN”, “ADMIN”); /* Allocate a new table handle, note the use of a session handle, not a database handle */ hTable = ctdbAllocTable(hSession); /* Without database support, it is necessary to specify the path were the table is located */ ctdbSetTablePath(hTable, “c:\\MyDocuments”); /* Open the table */ ctdbOpenTable(hTable, “mytable”, CTOPEN_NORMAL); Please note from the code above the need to specify the path where the table is located. If no path is specified, c-treeDB will try to open the table from the current directory. The same principle applies when creating a table without database support: CTHANDLE hSession; CTHANDLE hTable; /* Allocate a new session handle without session dictionary support*/ hSession = ctdbAllocSession(CTSESSION_CTREE); /* Logon to session */ ctdbLogon(hSession, “FAIRCOMS”, “ADMIN”, “ADMIN”); /* Allocate a new table handle, note the use of a session handle, not a database handle */ hTable = ctdbAllocTable(hSession); /* add fields to table */ ctdbAddField(hTable, “Field1”, CT_INT2, 2); ctdbAddField(hTable, “Field2”, CT_FSTRING, 30); /* Without database support, it is necessary to specify the path were the table is located */ ctdbSetTablePath(hTable, “c:\\MyDocuments”); /* Create the table */ ctdbCreateTable(hTable, “mytable”, CTCREATE_NORMAL); |
|||