Opening a table
To access your dBase tables you should add Alchemy DBF Access files to your
project and add the code that opens your DBF table:
DBF_Error_Code DBFOpen(const char *fName, DBFTable* pDBFTable);
Navigating thrue records
You can move the record pointer up and down thrue the data table:
DBF_Error_Code DBFTop(DBFTable *pDBFTable);
DBF_Error_Code DBFBottom(DBFTable *pDBFTable);
DBF_Error_Code DBFSkip(DBFTable *pDBFTable, long count);
DBF_Error_Code DBFGoTo(DBFTable *pDBFTable, long recno);
DBF_Error_Code DBFGoToNonDeletedRecord(DBFTable *pDBFTable, long recno);
Reading data from the current record
Alchemy DBF Access allows you to read data from the table using various
formats:
DBF_Error_Code DBFGetIntByName
(
DBFTable *pDBFTable,
const char *pszFieldName,
int *fieldValue
);
DBF_Error_Code DBFGetLogicalByName
(
DBFTable *pDBFTable,
const char *pszFieldName,
int *fieldValue
);
DBF_Error_Code DBFGetDoubleByName
(
DBFTable *pDBFTable,
const char *pszFieldName,
double *fieldValue
);
DBF_Error_Code DBFGetCharacterByName
(
DBFTable *pDBFTable,
const char *pszFieldName,
int *fieldValue,
int maxlen
);
DBF_Error_Code DBFGetDateByName
(
DBFTable *pDBFTable,
const char *pszFieldName,
DBFDate *fieldValue
);
Writing data to the record
To write data to the current database record you should open the current record
for editing, write data to the table and then post written data to the database:
DBF_Error_Code DBFEdit(DBFTable *pDBFTable);
DBF_Error_Code DBFPutIntByName
(
DBFTable *pDBFTable,
const char *pszFieldName,
int fieldValue
);
DBF_Error_Code DBFPutLogicalByName
(
DBFTable *pDBFTable,
const char *pszFieldName,
int fieldValue
);
DBF_Error_Code DBFPutDoubleByName
(
DBFTable *pDBFTable,
const char *pszFieldName,
double fieldValue
);
DBF_Error_Code DBFPutCharacterByName
(
DBFTable *pDBFTable,
const char *pszFieldName,
const char* fieldValue
);
DBF_Error_Code DBFPutDateByName
(
DBFTable *pDBFTable,
const char *pszFieldName,
const DBFDate *fieldValue
);
DBF_Error_Code DBFPost(DBFTable *pDBFTable);
Insert/delete operations
You can insert and delete records from/to the table. Since deleted record in
DBase table is not immediatelly deleted from the file, you can either recall it
later or physically delete deleted records from the table with the help of the
pack operation:
DBF_Error_Code DBFAppend(DBFTable *pDBFTable);
DBF_Error_Code DBFDelete(DBFTable *pDBFTable);
DBF_Error_Code DBFRecall(DBFTable *pDBFTable);
DBF_Error_Code DBFPack(DBFTable *pDBFTable);
Closing the table
After you've finished working with CDBFTable, release allocated resources and
close opened table by calling:
DBF_Error_Code DBFClose(DBFTable *pDBFTable);
Resume
As you probably noted, Alchemy DBF Access provides extremely clear
and simple way for manipulating database tables; it does not require any
additional DLLs and adds only few kilobytes to your program. Just
download it and you can bring database power to your programs!