Product Documentation

FairCom Direct SQL for C and C++

Previous Topic

Next Topic

Done

When an application and/or process has completed operations with the database, it must release resources by closing the open files and disconnecting from the database engine.

Below is the code for Done():

/*

* Done()

*

* This function handles the housekeeping of closing connection and

* freeing of associated memory

*/

void Done(void)

{

CTSQLRET rc;

printf("DONE\n");

/* re-enable autocommit */

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

Handle_Error( "ctsqlSetAutoCommit()");

Delete_Tables();

/* disconnect from server */

printf("\tLogout...\n");

if ((rc = ctsqlDisconnect(hConn)) != CTSQLRET_OK)

Handle_Error("ctsqlDisconnect()");

/* free command handle */

if (hCmd)

ctsqlFreeCommand(hCmd);

/* free connection handle */

ctsqlFreeConnection(hConn);

}

/*

* Delete_Tables()

*

* This function removes all existing tables

*/

void Delete_Tables(void)

{

CTSQLRET rc;

if ((rc = ctsqlExecuteDirect(hCmd, CT_STRING_LITERAL("DROP TABLE ordritem"))) != CTSQLRET_OK)

Handle_Error("ctsqlExecuteDirect(DROP TABLE)");

if ((rc = ctsqlExecuteDirect(hCmd, CT_STRING_LITERAL("DROP TABLE custordr"))) != CTSQLRET_OK)

Handle_Error("ctsqlExecuteDirect(DROP TABLE)");

if ((rc = ctsqlExecuteDirect(hCmd, CT_STRING_LITERAL("DROP TABLE custmast"))) != CTSQLRET_OK)

Handle_Error("ctsqlExecuteDirect(DROP TABLE)");

if ((rc = ctsqlExecuteDirect(hCmd, CT_STRING_LITERAL("DROP TABLE itemmast"))) != CTSQLRET_OK)

Handle_Error("ctsqlExecuteDirect(DROP TABLE)");

}

TOCIndex