Hi
I have this old C code and is wondering if Powerbasic can do what this code is doing. The C code reads/writes from/to the DOS version of Navision accounting system.
/*******************************************************************************
* Database C-Library Test application. *
* *
* (c) 1996 Navision Software a/s. *
*******************************************************************************/
#ifdef __TURBOC__
extern int _stklen = 0x4000;
#endif
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <dbl.h>
#define RECORDCOUNT 500
typedef struct {
DBL_U8 FieldNo;
DBL_S16 FieldType;
DBL_S16 FieldSize;
char *FieldName;
} FieldDefinitionType;
FieldDefinitionType fieldsstruct[] = {
{1, DBL_Type_S16 , 2, "Counter"},
{2, DBL_Type_STR , 31, "Text"},
{3, DBL_Type_BYTE , 1, "SelectionField"}
};
void verifyTables(void)
{
DBL_S16 TableNo;
DBL_HTABLE hTable;
for (TableNo = 0 ; 0 != (TableNo = DBL_NextTable(TableNo))
{
DBL_Allow(DBL_Err_TableNotFound);
if (!DBL_OpenTable(&hTable, TableNo))
{
printf("Table No %d Not Found Error !\n",TableNo);
return;
}
if (TableNo != DBL_TableNo(DBL_TableName(hTable)))
{
printf("Table No %d Name Error !\n",TableNo);
return;
}
DBL_BWT();
DBL_LockTable(hTable,DBL_LockNoWait);
DBL_AWT();
DBL_CloseTable(hTable);
}
printf("OK\n");
}
int verifyTableSetup(DBL_HTABLE hTable)
{
DBL_U8 FieldNo;
DBL_U8 DBL_FAR *Keys;
DBL_U8 DBL_FAR *ByteSet;
DBL_S16 i;
printf("Verifying the table layout ..");
if (DBL_FieldCount(hTable) != sizeof(fieldsstruct)/sizeof(FieldDefinitionType))
{
printf("Field count\nError !");
return(-1);
}
for (FieldNo = 0,i = 0; 0 != (FieldNo = DBL_NextField(hTable,FieldNo)); i++)
{
if (FieldNo != fieldsstruct[i].FieldNo)
{
printf("Unknown fieldNo %d in table\nError !",FieldNo);
return(-1);
}
if (DBL_FieldClass(hTable, FieldNo) == DBL_Class_Calculated)
{
printf("FieldNo %d was a calculated field\nError !",FieldNo);
return(-1);
}
if (DBL_FieldClass(hTable, FieldNo) != DBL_Class_Ordinary)
{
printf("FieldNo %d was not a normal field\nError !",FieldNo);
return(-1);
}
if (DBL_FieldType(hTable,FieldNo) != fieldsstruct[i].FieldType)
{
printf("FieldType error FieldNo %d was %d, expected %d\nError !",FieldNo,DBL_FieldType(hTable,FieldNo),fieldsstruct[i].FieldType);
return(-1);
}
if (DBL_FieldSize(hTable,FieldNo) != fieldsstruct[i].FieldSize)
{
printf("FieldSize error FieldNo %d was %d, expected %d\nError !",FieldNo,DBL_FieldSize(hTable, FieldNo),fieldsstruct[i].FieldSize);
return(-1);
}
if (strcmp((char*)DBL_FieldName(hTable,FieldNo),fieldsstruct[i].FieldName))
{
printf("Fieldname error FieldNo %d was %s, expected %s\nError !", FieldNo,DBL_FieldName(hTable,FieldNo),fieldsstruct[i].FieldName);
return(-1);
}
if ((ByteSet = DBL_FieldOptionStr(hTable,FieldNo)) != NULL)
if (strcmp((char*)ByteSet,"Selection 1, Selection 2, Selection 3") != 0)
{
printf("ByteSet error was %s,expected %s\nError !",ByteSet,"Selection 1, Selection 2, Selection 3");
return(-1);
}
}
if (DBL_KeyCount(hTable) != 1)
{
printf("Key count\nError !");
return(-1);
}
Keys = DBL_NextKey(hTable,NULL);
if ((*Keys != 1) && (strlen((char*)Keys) != 1))
{
printf("Key field\nError !");
return(-1);
}
printf("OK\n");
return(0);
}
void deleteAllRecords(DBL_HTABLE hTable)
{
void DBL_FAR *Rec;
printf("Deleting all records ..");
DBL_AllocRec(hTable,&Rec);
DBL_BWT();
DBL_Allow(DBL_Err_RecordNotFound);
while (DBL_FindRec(hTable,Rec,(DBL_U8 DBL_FAR*)"-"))
{
DBL_DeleteRec(hTable,Rec);
DBL_Allow(DBL_Err_RecordNotFound);
}
DBL_EWT();
DBL_FreeRec(Rec);
printf("OK\n");
}
void DBL_FAR * RecFieldAddr(DBL_HTABLE hTable,
void DBL_FAR *Rec,
DBL_U8 FieldNo)
{
return(((DBL_U8 DBL_FAR *)Rec) + DBL_FieldOffset(hTable,FieldNo));
}
void AssignRecField(DBL_HTABLE hTable,
void DBL_FAR *Rec,
DBL_U8 FieldNo,
void *Val)
{
memcpy(RecFieldAddr(hTable,Rec,FieldNo),Val,DBL_FieldSize(hTable,FieldNo));
}
int createTestData(DBL_HTABLE hTable)
{
DBL_S16 i;
void DBL_FAR *Rec;
char s[100];
printf("Creating test data ..");
DBL_AllocRec(hTable,&Rec);
DBL_BWT();
for (i = 0 ; i < RECORDCOUNT ; i++ )
{
DBL_InitRec(hTable,Rec);
sprintf(s,"This is record number %d",i);
AssignRecField(hTable,Rec,1,&i);
AssignRecField(hTable,Rec,2,s);
DBL_Allow(DBL_Err_RecordExists);
if (!DBL_InsertRec(hTable,Rec))
{
printf("Record %d was allready present in database\nError !!\n",i);
DBL_AWT();
DBL_FreeRec(Rec);
return(-1);
}
}
DBL_EWT();
DBL_FreeRec(Rec);
printf("OK\n");
return(0);
}
int verifyTestData(DBL_HTABLE hTable)
{
DBL_S16 i;
char s[100];
void DBL_FAR *Rec;
printf("Verifying test data ..");
DBL_AllocRec(hTable,&Rec);
for (i = 0 ; i < RECORDCOUNT ; i++ )
{
DBL_InitRec(hTable,Rec);
AssignRecField(hTable,Rec,1,&i);
DBL_Allow(DBL_Err_RecordNotFound);
if (!DBL_FindRec(hTable,Rec,(DBL_U8 DBL_FAR*)"="))
{
printf("Record %d not found\nError !!\n",i);
DBL_FreeRec(Rec);
return(-1);
}
if (memcmp(RecFieldAddr(hTable,Rec,1),&i,sizeof(i)))
{
printf("Counter field differs %d\nError !!\n",i);
DBL_FreeRec(Rec);
return(-1);
}
sprintf(s,"This is record number %d",i);
if (memcmp(RecFieldAddr(hTable,Rec,2),s,strlen(s)+1))
{
printf("Tekst field differs %s\nError !!\n",s);
DBL_FreeRec(Rec);
return(-1);
}
}
DBL_FreeRec(Rec);
printf("OK\n");
return(0);
}
int verifyModifiedTestData(DBL_HTABLE hTable)
{
DBL_S16 i;
void DBL_FAR *Rec;
char s[100];
printf("Verifying modified test data ..");
DBL_AllocRec(hTable,&Rec);
if (DBL_FieldNo(hTable,DBL_FieldName(hTable,1)) != 1)
{
printf("%s FieldName is not field no 1\n",DBL_FieldName(hTable,1));
DBL_FreeRec(Rec);
return(-1);
}
DBL_BWT();
DBL_InitRec(hTable,Rec);
i = 256;
sprintf(s,"%d modified",i);
AssignRecField(hTable,Rec,1,&i);
AssignRecField(hTable,Rec,2,s);
DBL_Allow(DBL_Err_RecordNotFound);
if (!DBL_ModifyRec(hTable,Rec))
{
printf("Record %d not found\nError !!\n",i);
DBL_AWT();
DBL_FreeRec(Rec);
return(-1);
}
DBL_EWT();
DBL_Allow(DBL_Err_RecordNotFound);
if (!DBL_FindRec(hTable,Rec,(DBL_U8 DBL_FAR*)"="))
{
printf("Record %d not found\nError !!\n",i);
DBL_FreeRec(Rec);
return(-1);
}
if (memcmp(RecFieldAddr(hTable,Rec,1),&i,sizeof(i)))
{
printf("Counter field differs %d\nError !!\n",i);
DBL_FreeRec(Rec);
return(-1);
}
if (memcmp(RecFieldAddr(hTable,Rec,2),s,strlen(s)+1))
{
printf("Tekst field differs %s\nError !!\n",s);
DBL_FreeRec(Rec);
return(-1);
}
DBL_FreeRec(Rec);
printf("OK\n");
return(0);
}
int verifySetFilter(DBL_HTABLE hTable)
{
char s[80];
DBL_U16 MinValue;
DBL_U16 MaxValue;
printf("Testing filter functions ..");
DBL_SetFilter(hTable,1,(DBL_U8 DBL_FAR*)">100&<200","",NULL);
if (DBL_RecCount(hTable) != 99)
{
printf("Error\n");
DBL_SetFilter(hTable,1,(DBL_U8 DBL_FAR*)"",NULL);
return(-1);
}
DBL_GetFilter(hTable,1,(DBL_U8 DBL_FAR*)s,sizeof(s)-1);
if (strcmp(s,">100&<200") != 0)
{
printf("Error\n");
DBL_SetFilter(hTable,1,(DBL_U8 DBL_FAR*)"",NULL);
return(-1);
}
MinValue = 100;
MaxValue = 200;
DBL_SetRange(hTable,1,&MinValue,&MaxValue);
MinValue = 0;
MaxValue = 0;
DBL_GetRange(hTable, 1,&MinValue, &MaxValue);
if ((MinValue != 100) || (MaxValue != 200))
{
printf("Error\n");
DBL_SetFilter(hTable,1,(DBL_U8 DBL_FAR*)"",NULL);
return(-1);
}
DBL_SetFilter(hTable,1,(DBL_U8 DBL_FAR*)"",NULL);
printf("OK\n");
return(0);
}
int verifyKeyFunctions(DBL_HTABLE hTable)
{
DBL_U8 DBL_FAR *Key;
DBL_U8 DBL_FAR *SumFields;
printf("Testing key functions ..");
Key = DBL_NextKey(hTable,NULL);
if (Key == NULL)
{
printf("Error\n");
return(-1);
}
if (*Key != 1)
{
printf("Error\n");
return(-1);
}
DBL_Allow(DBL_Err_KeyNotFound);
if (!DBL_SetCurrentKey(hTable,Key))
{
printf("Error\n");
return(-1);
}
Key = DBL_GetCurrentKey(hTable);
if (Key == NULL)
{
printf("Error\n");
return(-1);
}
if (*Key != 1)
{
printf("Error\n");
return(-1);
}
SumFields = DBL_KeySumFields(hTable,Key);
if (SumFields == NULL)
{
printf("Error\n");
return(-1);
}
if (*SumFields != 0)
{
printf("Error\n");
return(-1);
}
printf("OK\n");
return(0);
}
void verifySumFunctions(DBL_HTABLE hTable)
{
DBL_U8 DBL_FAR *Key;
DBL_U8 DBL_FAR *SumFields;
void DBL_FAR *Rec;
printf("Testing sum functions ..");
DBL_AllocRec(hTable,&Rec);
Key = DBL_NextKey(hTable,NULL);
SumFields = DBL_KeySumFields(hTable,Key);
DBL_CalcSums(hTable,Rec,SumFields);
DBL_FreeRec(Rec);
printf("OK\n");
}
void DBL_PASCAL DBL_FAR DBL_LOADDS My_ExceptionHandler(DBL_U8 DBL_FAR * DBL_FAR *texts)
{
while (*texts)
{
printf("%s\n",*texts);
texts++;
}
fflush(stdout);
}
void main(int argc, DBL_U8 *argv[], DBL_U8 *envp[])
{
DBL_S16 ServerNo = 0;
DBL_U8 *NetType = (DBL_U8*)"tcpi";
DBL_U8 *DatabaseName = (DBL_U8*)"CTOOLKIT";
DBL_S16 ExceptionHandlerTest = 0;
DBL_HTABLE hMainTable;
DBL_U8 DBL_FAR *CompanyNamePtr;
if (DBL_Init(argc, argv, envp) != 0)
{
printf("DBL_Init failed\n");
return;
}
for (argc--,argv++;argc;argc--,argv++)
{
if (argv[0][0] == '-')
switch (argv[0][1])
{
case 'd': DatabaseName = argv[0] + 2; continue;
case 's': ServerNo = atoi((char*)(argv[0] + 2)); continue;
case 'n': NetType = argv[0] + 2; continue;
case 't': ExceptionHandlerTest = 1; continue;
}
printf("Invalid Command line option\n\r [-d[DATABASENAME], [-s[SERVERNUMBER], -n[NETTYPE], -t (Exception Handler test)]\n\r");
return;
}
if (ServerNo)
DBL_ConnectServer(ServerNo,NetType);
else
#ifdef DOS
DBL_OpenDatabase(DatabaseName,20, 0);
#else
DBL_OpenDatabase(DatabaseName,1000, 100);
#endif
for (CompanyNamePtr = NULL ; 0 != (CompanyNamePtr = DBL_NextCompany(CompanyNamePtr)); )
printf("Company present %s\n",CompanyNamePtr);
DBL_OpenCompany((DBL_U8 DBL_FAR*)"C-TOOLKIT");
printf("Testing some table functions ..");
verifyTables();
DBL_OpenTable(&hMainTable,1000);
if (strcmp("C-TOOLKIT",(char*)DBL_TableName(hMainTable)) != 0)
{
printf("C-TOOLKIT account not found\n");
goto Error;
}
if (verifyTableSetup(hMainTable) != 0) goto Error;
deleteAllRecords(hMainTable);
if (createTestData(hMainTable) != 0) goto Error;
if (verifyTestData(hMainTable) != 0) goto Error;
if (verifyModifiedTestData(hMainTable) != 0) goto Error;
if (verifySetFilter(hMainTable) != 0) goto Error;
if (verifyKeyFunctions(hMainTable) != 0) goto Error;
verifySumFunctions(hMainTable);
if (ExceptionHandlerTest)
{
printf("Exception Handler test\n");
DBL_SetExceptionHandler(My_ExceptionHandler);
DBL_OpenTable(&hMainTable,2000);
printf("Exception Handler test failed\n");
}
Error:
DBL_CloseCompany();
if (ServerNo)
DBL_DisconnectServer();
else
DBL_CloseDatabase();
DBL_Exit();
printf("Database test ended\n");
}
I have this old C code and is wondering if Powerbasic can do what this code is doing. The C code reads/writes from/to the DOS version of Navision accounting system.
/*******************************************************************************
* Database C-Library Test application. *
* *
* (c) 1996 Navision Software a/s. *
*******************************************************************************/
#ifdef __TURBOC__
extern int _stklen = 0x4000;
#endif
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <dbl.h>
#define RECORDCOUNT 500
typedef struct {
DBL_U8 FieldNo;
DBL_S16 FieldType;
DBL_S16 FieldSize;
char *FieldName;
} FieldDefinitionType;
FieldDefinitionType fieldsstruct[] = {
{1, DBL_Type_S16 , 2, "Counter"},
{2, DBL_Type_STR , 31, "Text"},
{3, DBL_Type_BYTE , 1, "SelectionField"}
};
void verifyTables(void)
{
DBL_S16 TableNo;
DBL_HTABLE hTable;
for (TableNo = 0 ; 0 != (TableNo = DBL_NextTable(TableNo))

{
DBL_Allow(DBL_Err_TableNotFound);
if (!DBL_OpenTable(&hTable, TableNo))
{
printf("Table No %d Not Found Error !\n",TableNo);
return;
}
if (TableNo != DBL_TableNo(DBL_TableName(hTable)))
{
printf("Table No %d Name Error !\n",TableNo);
return;
}
DBL_BWT();
DBL_LockTable(hTable,DBL_LockNoWait);
DBL_AWT();
DBL_CloseTable(hTable);
}
printf("OK\n");
}
int verifyTableSetup(DBL_HTABLE hTable)
{
DBL_U8 FieldNo;
DBL_U8 DBL_FAR *Keys;
DBL_U8 DBL_FAR *ByteSet;
DBL_S16 i;
printf("Verifying the table layout ..");
if (DBL_FieldCount(hTable) != sizeof(fieldsstruct)/sizeof(FieldDefinitionType))
{
printf("Field count\nError !");
return(-1);
}
for (FieldNo = 0,i = 0; 0 != (FieldNo = DBL_NextField(hTable,FieldNo)); i++)
{
if (FieldNo != fieldsstruct[i].FieldNo)
{
printf("Unknown fieldNo %d in table\nError !",FieldNo);
return(-1);
}
if (DBL_FieldClass(hTable, FieldNo) == DBL_Class_Calculated)
{
printf("FieldNo %d was a calculated field\nError !",FieldNo);
return(-1);
}
if (DBL_FieldClass(hTable, FieldNo) != DBL_Class_Ordinary)
{
printf("FieldNo %d was not a normal field\nError !",FieldNo);
return(-1);
}
if (DBL_FieldType(hTable,FieldNo) != fieldsstruct[i].FieldType)
{
printf("FieldType error FieldNo %d was %d, expected %d\nError !",FieldNo,DBL_FieldType(hTable,FieldNo),fieldsstruct[i].FieldType);
return(-1);
}
if (DBL_FieldSize(hTable,FieldNo) != fieldsstruct[i].FieldSize)
{
printf("FieldSize error FieldNo %d was %d, expected %d\nError !",FieldNo,DBL_FieldSize(hTable, FieldNo),fieldsstruct[i].FieldSize);
return(-1);
}
if (strcmp((char*)DBL_FieldName(hTable,FieldNo),fieldsstruct[i].FieldName))
{
printf("Fieldname error FieldNo %d was %s, expected %s\nError !", FieldNo,DBL_FieldName(hTable,FieldNo),fieldsstruct[i].FieldName);
return(-1);
}
if ((ByteSet = DBL_FieldOptionStr(hTable,FieldNo)) != NULL)
if (strcmp((char*)ByteSet,"Selection 1, Selection 2, Selection 3") != 0)
{
printf("ByteSet error was %s,expected %s\nError !",ByteSet,"Selection 1, Selection 2, Selection 3");
return(-1);
}
}
if (DBL_KeyCount(hTable) != 1)
{
printf("Key count\nError !");
return(-1);
}
Keys = DBL_NextKey(hTable,NULL);
if ((*Keys != 1) && (strlen((char*)Keys) != 1))
{
printf("Key field\nError !");
return(-1);
}
printf("OK\n");
return(0);
}
void deleteAllRecords(DBL_HTABLE hTable)
{
void DBL_FAR *Rec;
printf("Deleting all records ..");
DBL_AllocRec(hTable,&Rec);
DBL_BWT();
DBL_Allow(DBL_Err_RecordNotFound);
while (DBL_FindRec(hTable,Rec,(DBL_U8 DBL_FAR*)"-"))
{
DBL_DeleteRec(hTable,Rec);
DBL_Allow(DBL_Err_RecordNotFound);
}
DBL_EWT();
DBL_FreeRec(Rec);
printf("OK\n");
}
void DBL_FAR * RecFieldAddr(DBL_HTABLE hTable,
void DBL_FAR *Rec,
DBL_U8 FieldNo)
{
return(((DBL_U8 DBL_FAR *)Rec) + DBL_FieldOffset(hTable,FieldNo));
}
void AssignRecField(DBL_HTABLE hTable,
void DBL_FAR *Rec,
DBL_U8 FieldNo,
void *Val)
{
memcpy(RecFieldAddr(hTable,Rec,FieldNo),Val,DBL_FieldSize(hTable,FieldNo));
}
int createTestData(DBL_HTABLE hTable)
{
DBL_S16 i;
void DBL_FAR *Rec;
char s[100];
printf("Creating test data ..");
DBL_AllocRec(hTable,&Rec);
DBL_BWT();
for (i = 0 ; i < RECORDCOUNT ; i++ )
{
DBL_InitRec(hTable,Rec);
sprintf(s,"This is record number %d",i);
AssignRecField(hTable,Rec,1,&i);
AssignRecField(hTable,Rec,2,s);
DBL_Allow(DBL_Err_RecordExists);
if (!DBL_InsertRec(hTable,Rec))
{
printf("Record %d was allready present in database\nError !!\n",i);
DBL_AWT();
DBL_FreeRec(Rec);
return(-1);
}
}
DBL_EWT();
DBL_FreeRec(Rec);
printf("OK\n");
return(0);
}
int verifyTestData(DBL_HTABLE hTable)
{
DBL_S16 i;
char s[100];
void DBL_FAR *Rec;
printf("Verifying test data ..");
DBL_AllocRec(hTable,&Rec);
for (i = 0 ; i < RECORDCOUNT ; i++ )
{
DBL_InitRec(hTable,Rec);
AssignRecField(hTable,Rec,1,&i);
DBL_Allow(DBL_Err_RecordNotFound);
if (!DBL_FindRec(hTable,Rec,(DBL_U8 DBL_FAR*)"="))
{
printf("Record %d not found\nError !!\n",i);
DBL_FreeRec(Rec);
return(-1);
}
if (memcmp(RecFieldAddr(hTable,Rec,1),&i,sizeof(i)))
{
printf("Counter field differs %d\nError !!\n",i);
DBL_FreeRec(Rec);
return(-1);
}
sprintf(s,"This is record number %d",i);
if (memcmp(RecFieldAddr(hTable,Rec,2),s,strlen(s)+1))
{
printf("Tekst field differs %s\nError !!\n",s);
DBL_FreeRec(Rec);
return(-1);
}
}
DBL_FreeRec(Rec);
printf("OK\n");
return(0);
}
int verifyModifiedTestData(DBL_HTABLE hTable)
{
DBL_S16 i;
void DBL_FAR *Rec;
char s[100];
printf("Verifying modified test data ..");
DBL_AllocRec(hTable,&Rec);
if (DBL_FieldNo(hTable,DBL_FieldName(hTable,1)) != 1)
{
printf("%s FieldName is not field no 1\n",DBL_FieldName(hTable,1));
DBL_FreeRec(Rec);
return(-1);
}
DBL_BWT();
DBL_InitRec(hTable,Rec);
i = 256;
sprintf(s,"%d modified",i);
AssignRecField(hTable,Rec,1,&i);
AssignRecField(hTable,Rec,2,s);
DBL_Allow(DBL_Err_RecordNotFound);
if (!DBL_ModifyRec(hTable,Rec))
{
printf("Record %d not found\nError !!\n",i);
DBL_AWT();
DBL_FreeRec(Rec);
return(-1);
}
DBL_EWT();
DBL_Allow(DBL_Err_RecordNotFound);
if (!DBL_FindRec(hTable,Rec,(DBL_U8 DBL_FAR*)"="))
{
printf("Record %d not found\nError !!\n",i);
DBL_FreeRec(Rec);
return(-1);
}
if (memcmp(RecFieldAddr(hTable,Rec,1),&i,sizeof(i)))
{
printf("Counter field differs %d\nError !!\n",i);
DBL_FreeRec(Rec);
return(-1);
}
if (memcmp(RecFieldAddr(hTable,Rec,2),s,strlen(s)+1))
{
printf("Tekst field differs %s\nError !!\n",s);
DBL_FreeRec(Rec);
return(-1);
}
DBL_FreeRec(Rec);
printf("OK\n");
return(0);
}
int verifySetFilter(DBL_HTABLE hTable)
{
char s[80];
DBL_U16 MinValue;
DBL_U16 MaxValue;
printf("Testing filter functions ..");
DBL_SetFilter(hTable,1,(DBL_U8 DBL_FAR*)">100&<200","",NULL);
if (DBL_RecCount(hTable) != 99)
{
printf("Error\n");
DBL_SetFilter(hTable,1,(DBL_U8 DBL_FAR*)"",NULL);
return(-1);
}
DBL_GetFilter(hTable,1,(DBL_U8 DBL_FAR*)s,sizeof(s)-1);
if (strcmp(s,">100&<200") != 0)
{
printf("Error\n");
DBL_SetFilter(hTable,1,(DBL_U8 DBL_FAR*)"",NULL);
return(-1);
}
MinValue = 100;
MaxValue = 200;
DBL_SetRange(hTable,1,&MinValue,&MaxValue);
MinValue = 0;
MaxValue = 0;
DBL_GetRange(hTable, 1,&MinValue, &MaxValue);
if ((MinValue != 100) || (MaxValue != 200))
{
printf("Error\n");
DBL_SetFilter(hTable,1,(DBL_U8 DBL_FAR*)"",NULL);
return(-1);
}
DBL_SetFilter(hTable,1,(DBL_U8 DBL_FAR*)"",NULL);
printf("OK\n");
return(0);
}
int verifyKeyFunctions(DBL_HTABLE hTable)
{
DBL_U8 DBL_FAR *Key;
DBL_U8 DBL_FAR *SumFields;
printf("Testing key functions ..");
Key = DBL_NextKey(hTable,NULL);
if (Key == NULL)
{
printf("Error\n");
return(-1);
}
if (*Key != 1)
{
printf("Error\n");
return(-1);
}
DBL_Allow(DBL_Err_KeyNotFound);
if (!DBL_SetCurrentKey(hTable,Key))
{
printf("Error\n");
return(-1);
}
Key = DBL_GetCurrentKey(hTable);
if (Key == NULL)
{
printf("Error\n");
return(-1);
}
if (*Key != 1)
{
printf("Error\n");
return(-1);
}
SumFields = DBL_KeySumFields(hTable,Key);
if (SumFields == NULL)
{
printf("Error\n");
return(-1);
}
if (*SumFields != 0)
{
printf("Error\n");
return(-1);
}
printf("OK\n");
return(0);
}
void verifySumFunctions(DBL_HTABLE hTable)
{
DBL_U8 DBL_FAR *Key;
DBL_U8 DBL_FAR *SumFields;
void DBL_FAR *Rec;
printf("Testing sum functions ..");
DBL_AllocRec(hTable,&Rec);
Key = DBL_NextKey(hTable,NULL);
SumFields = DBL_KeySumFields(hTable,Key);
DBL_CalcSums(hTable,Rec,SumFields);
DBL_FreeRec(Rec);
printf("OK\n");
}
void DBL_PASCAL DBL_FAR DBL_LOADDS My_ExceptionHandler(DBL_U8 DBL_FAR * DBL_FAR *texts)
{
while (*texts)
{
printf("%s\n",*texts);
texts++;
}
fflush(stdout);
}
void main(int argc, DBL_U8 *argv[], DBL_U8 *envp[])
{
DBL_S16 ServerNo = 0;
DBL_U8 *NetType = (DBL_U8*)"tcpi";
DBL_U8 *DatabaseName = (DBL_U8*)"CTOOLKIT";
DBL_S16 ExceptionHandlerTest = 0;
DBL_HTABLE hMainTable;
DBL_U8 DBL_FAR *CompanyNamePtr;
if (DBL_Init(argc, argv, envp) != 0)
{
printf("DBL_Init failed\n");
return;
}
for (argc--,argv++;argc;argc--,argv++)
{
if (argv[0][0] == '-')
switch (argv[0][1])
{
case 'd': DatabaseName = argv[0] + 2; continue;
case 's': ServerNo = atoi((char*)(argv[0] + 2)); continue;
case 'n': NetType = argv[0] + 2; continue;
case 't': ExceptionHandlerTest = 1; continue;
}
printf("Invalid Command line option\n\r [-d[DATABASENAME], [-s[SERVERNUMBER], -n[NETTYPE], -t (Exception Handler test)]\n\r");
return;
}
if (ServerNo)
DBL_ConnectServer(ServerNo,NetType);
else
#ifdef DOS
DBL_OpenDatabase(DatabaseName,20, 0);
#else
DBL_OpenDatabase(DatabaseName,1000, 100);
#endif
for (CompanyNamePtr = NULL ; 0 != (CompanyNamePtr = DBL_NextCompany(CompanyNamePtr)); )
printf("Company present %s\n",CompanyNamePtr);
DBL_OpenCompany((DBL_U8 DBL_FAR*)"C-TOOLKIT");
printf("Testing some table functions ..");
verifyTables();
DBL_OpenTable(&hMainTable,1000);
if (strcmp("C-TOOLKIT",(char*)DBL_TableName(hMainTable)) != 0)
{
printf("C-TOOLKIT account not found\n");
goto Error;
}
if (verifyTableSetup(hMainTable) != 0) goto Error;
deleteAllRecords(hMainTable);
if (createTestData(hMainTable) != 0) goto Error;
if (verifyTestData(hMainTable) != 0) goto Error;
if (verifyModifiedTestData(hMainTable) != 0) goto Error;
if (verifySetFilter(hMainTable) != 0) goto Error;
if (verifyKeyFunctions(hMainTable) != 0) goto Error;
verifySumFunctions(hMainTable);
if (ExceptionHandlerTest)
{
printf("Exception Handler test\n");
DBL_SetExceptionHandler(My_ExceptionHandler);
DBL_OpenTable(&hMainTable,2000);
printf("Exception Handler test failed\n");
}
Error:
DBL_CloseCompany();
if (ServerNo)
DBL_DisconnectServer();
else
DBL_CloseDatabase();
DBL_Exit();
printf("Database test ended\n");
}
Comment