Product Documentation

c-treeDB API for C++ - Developers Guide

Previous Topic

Next Topic

Attach and Detach Open Tables

A c-treeDB table handle or object can be attached and detached to an already open data file. Applications may need to open a table using c-tree ISAM and low level functions and then attach the table to a c-treeDB table handle to take advantage of full c-treeDB functionality.

CTTable::Attach() attaches a c-tree Plus ISAM datno object to a c-treeDB table handle. This function is useful if you have opened a data or index file using one of c- tree’s ISAM open functions and need to attach it to a table handle to use some of the advanced c-treeDB features such as alter table or the record handler.

AttachXtd() attaches a c-tree Plus ISAM datno object to a c-treeDB table handle. This function is useful if you have opened a data and index file using one of c-tree’s ISAM open functions and need to attach it to a table handle to use some of the advanced c-treeDB features such as alter table or the record handler. This extended version allows the user to specify the DODA and IFIL for the table, enabling tables without DODA and/or IFIL to be attached to c-treeDB.

Detach() detaches a c-treeDB table handle from a c-tree data and index files. The table is not closed but the c-treeDB table handle resources are released and the handle re-initialized.

Example

/* DODA */

static DATOBJ doda[] =

{

{"f1", (pTEXT)0, CT_INT4, 4},

{"f2", (pTEXT)4, CT_FSTRING, 10}

};

/* IFIL */

static ISEG iseg = {0, 4, 12};

static IIDX iidx = {4, 0, 0, 0, 0, 1, &iseg, "i311x1", NULL, NULL, NULL};

static IFIL ifil = {"test310", -1, 14, 0, 0, 1, 0, 0, &iidx, "f1", "f2", 0};

CTHANDLE hSession = ctdbAllocSession(CTSESSION_CTREE);

CTHANDLE hTable = ctdbAllocTable(hSession);

CTHANDLE hRecord = ctdbAllocRecord(hTable);

NINT datno, count = 0;

/* logon to c-tree */

ctdbLogon(hSession, SERVER, USER, PASSWD);

/* open the file using c-tree ISAM */

datno = (NINT)OPNRFILX((COUNT) -1, "test309.dat", (COUNT)0, NULL);

/* attach to table */

ctdbAttachTableXtd(hTable, datno, doda, &ifil);

/* read the records */

if (ctdbFirstRecord(hRecord) == CTDBRET_OK)

do

{

count++;

}

while (ctdbNextRecord(hRecord) == CTDBRET_OK);

/* cleanup */

ctdbDetachtable(hTable);

ctdbFreeRecord(hRecord);

ctdbFreeTable(hTable);

ctdbLogout(hSession);

ctdbFreeSession(hSession);

CTDBRET ctdbDetachTable(CTHANDLE Handle);

void CTTable::Detach();

TOCIndex