A valid session object is required to perform any session operation. The default parameter of the CTSession constructor is CTSESSION_CTDB.
// create a default CTSession object
CTSession ASession;
try
{
// logon to session using default
// server name, user name and password.
CTSession.Logon();
}
catch (CTException &err)
{
printf("Session logon failed with error %d\n", err.GetErrorCode);
}
If you create a dynamic CTSession object with the new operator, you are required to destroy the object with the delete operator.
// create a dynamic CTSession object
CTSession* pSession = new CTSession;
if (!pSession)
{
printf("CTSession allocation failed\n");
}
... other operations ..
// destroy the CTSession object
delete pSession;
When a session object is created, we can specify the session type. There are three different session types:
CTSESSION_CTREE |
Allocate a new session for logon only. No session or database dictionary files will be used. No database functions can be used with this session mode. You must allocate table handles using the session handle. |
CTSESSION_CTDB |
Allocate a new session making full usage of c-treeDB session and database dictionaries. With this session mode, a Session dictionary file must exist to perform a session logon and you need to connect to a database before attempting to perform operation on tables. |
CTSESSION_SQL |
Allocate a new session for FairCom DB SQL processing. This mode allows changes made at the c-treeDB level to be reflected at the FairCom DB SQL level without requiring an additional table import step; your tables are immediately available with the FairCom DB SQL interface. While this session type is available, limitations still exist. Support for alter table operations are not supported; c-treeDB AlterTable() activities are NOT reflected in the FairCom DB SQL system tables. |
// Create a session object
CTSession ASession(CTSESSION_CTDB);