Product Documentation

FairCom Direct SQL for C and C++

Previous Topic

Next Topic

Define

Define() establishes specific data definitions. This involves defining columns/fields and creating the tables/files with optional indexes.

Below is the code for Define():

/*

* Define()

*

* Create the tables

*/

void Define(void)

{

printf("DEFINE\n");

Create_CustomerMaster_Table();

Create_CustomerOrders_Table();

Create_OrderItems_Table();

Create_ItemMaster_Table();

}

/*

* Create_CustomerMaster_Table()

*

* Create the CustomerMaster

*/

void Create_CustomerMaster_Table(void)

{

CTSQLRET rc;

/* define table CustomerMaster */

printf("\ttable CustomerMaster\n");

if ((rc = ctsqlExecuteDirect(hCmd,

"CREATE TABLE custmast ( \

cm_custnumb CHAR(4), \

cm_custzipc CHAR(9), \

cm_custstat CHAR(2), \

cm_custrtng CHAR(1), \

cm_custname VARCHAR(47), \

cm_custaddr VARCHAR(47), \

cm_custcity VARCHAR(47))"

)) != CTSQLRET_OK)

Handle_Error("ctsqlExecuteDirect(CREATE TABLE)");

if ((rc = ctsqlExecuteDirect(hCmd,

"CREATE UNIQUE INDEX cm_custnumb_idx ON custmast (cm_custnumb)"

)) != CTSQLRET_OK)

Handle_Error("ctsqlExecuteDirect(CREATE INDEX)");

}

/*

* Create_CustomerOrders_Table()

*

* Create the table CustomerOrders

*/

void Create_CustomerOrders_Table(void)

{

CTSQLRET rc;

/* define table CustomerOrders */

printf("\ttable CustomerOrders\n");

if ((rc = ctsqlExecuteDirect(hCmd,

"CREATE TABLE custordr ( \

co_ordrdate DATE, \

co_promdate DATE, \

co_ordrnumb CHAR(6), \

co_custnumb CHAR(4))"

)) != CTSQLRET_OK)

Handle_Error("ctsqlExecuteDirect(CREATE TABLE)");

if ((rc = ctsqlExecuteDirect(hCmd,

"CREATE UNIQUE INDEX co_ordrnumb_idx ON custordr (co_ordrnumb)"

)) != CTSQLRET_OK)

Handle_Error("ctsqlExecuteDirect(CREATE INDEX)");

if ((rc = ctsqlExecuteDirect(hCmd,

"CREATE INDEX co_custnumb_idx ON custordr (co_custnumb)"

)) != CTSQLRET_OK)

Handle_Error("ctsqlExecuteDirect(CREATE INDEX)");

}

/*

* Create_OrderItems_Table()

*

* Create the table OrderItems

*/

void Create_OrderItems_Table(void)

{

CTSQLRET rc;

/* define table OrderItems */

printf("\ttable OrderItems\n");

if ((rc = ctsqlExecuteDirect(hCmd,

"CREATE TABLE ordritem ( \

oi_sequnumb SMALLINT, \

oi_quantity SMALLINT, \

oi_ordrnumb CHAR(6), \

oi_itemnumb CHAR(5))"

)) != CTSQLRET_OK)

Handle_Error("ctsqlExecuteDirect(CREATE TABLE)");

if ((rc = ctsqlExecuteDirect(hCmd,

"CREATE UNIQUE INDEX oi_ordrnumb_idx ON ordritem (oi_ordrnumb, oi_sequnumb)"

)) != CTSQLRET_OK)

Handle_Error("ctsqlExecuteDirect(CREATE INDEX)");

if ((rc = ctsqlExecuteDirect(hCmd,

"CREATE INDEX oi_itemnumb_idx ON ordritem (oi_itemnumb)"

)) != CTSQLRET_OK)

Handle_Error("ctsqlExecuteDirect(CREATE INDEX)");

}

/*

* Create_ItemMaster_Table()

*

* Create the table ItemMaster

*/

void Create_ItemMaster_Table(void)

{

CTSQLRET rc;

/* define table ItemMaster */

printf("\ttable ItemMaster\n");

if ((rc = ctsqlExecuteDirect(hCmd,

"CREATE TABLE itemmast ( \

im_itemwght INTEGER, \

im_itempric MONEY, \

im_itemnumb CHAR(5), \

im_itemdesc VARCHAR(47))"

)) != CTSQLRET_OK)

Handle_Error("ctsqlExecuteDirect(CREATE TABLE)");

if ((rc = ctsqlExecuteDirect(hCmd,

"CREATE UNIQUE INDEX im_itemnumb_idx ON itemmast (im_itemnumb)"

)) != CTSQLRET_OK)

Handle_Error("ctsqlExecuteDirect(CREATE INDEX)");

}

TOCIndex