Define
The Define() step is where specific data definitions are established by your application and/or process. This involves defining columns/fields and creating the tables/files with optional indices. Below is the code for Define(): // // Define() // // Open the table, if it exists. Otherwise create and open the table // VOID Define(VOID) {
CTBOOL do_create = NO; printf("DEFINE\n");
try {
printf("\tOpen table...\n");
MyTable.Open("custmast", CTOPEN_NORMAL);
} catch (...) {
// table does not exist. Try to create it do_create = YES; } if (do_create) {
// create the table printf("\tAdd fields...\n");
try {
MyTable.AddField("cm_custnumb", CT_FSTRING, 4);
MyTable.AddField("cm_custzipc", CT_FSTRING, 9);
MyTable.AddField("cm_custstat", CT_FSTRING, 2);
MyTable.AddField("cm_custrtng", CT_FSTRING, 1);
MyTable.AddField("cm_custname", CT_STRING, 47);
MyTable.AddField("cm_custaddr", CT_STRING, 47);
MyTable.AddField("cm_custcity", CT_STRING, 47);
printf("\tCreate table...\n");
MyTable.Create("custmast", CTCREATE_NORMAL);
MyTable.Open("custmast", CTOPEN_NORMAL);
} catch (CTException E) {
Handle_Exception(E); } } else Check_Table_Mode(MyTable); }
{
try {
// get table create mode CTCREATE_MODE mode = table.GetCreateMode(); // check if table is under transaction processing control if ((mode & CTCREATE_TRNLOG)) {
// change file mode to disable transaction processing mode ^= CTCREATE_TRNLOG; table.UpdateCreateMode(mode); } } catch (CTException E) {
Handle_Exception(E); } } |
|||