Product Documentation

FairCom Direct SQL for C and C++

Previous Topic

Next Topic

Init

First we need to open a connection to a database by providing the FairCom Database Engine with a user name, password and the database name.

Below is the code for Initialize():

/*

* Initialize()

*

* Perform the minimum requirement of logging onto the c-tree Server

*/

void Initialize (void)

{

CTSQLRET rc;

printf("INIT\n");

/* allocate connection handle */

if ((hConn = ctsqlNewConnection()) == NULL)

Handle_Error("ctsqlNewConnection()");

/* allocate command handle */

if ((hCmd = ctsqlNewCommand(hConn)) == NULL)

Handle_Error("ctsqlNewCommand()");

/* connect to server */

printf("\tLogon to server...\n");

if ((rc = ctsqlConnect(hConn, CT_STRING_LITERAL("6597@localhost:ctreeSQL"), CT_STRING_LITERAL("admin"), CT_STRING_LITERAL("ADMIN"))) != CTSQLRET_OK)

Handle_Error( "ctsqlConnect()");

/* enable autocommit */

if ((rc = ctsqlSetAutoCommit(hConn, CTSQL_TRUE)) != CTSQLRET_OK)

Handle_Error( "ctsqlSetAutoCommit()");

}

TOCIndex