home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Total C++ 2
/
TOTALCTWO.iso
/
borland
/
32snipit.pak
/
NAVIGATE.C
< prev
next >
Wrap
C/C++ Source or Header
|
1997-05-06
|
4KB
|
110 lines
// BDE32 3.x - (C) Copyright 1996 by Borland International
// navigate.c
#include "snipit.h"
// Name of table to be created.
static const char szTblName[] = "customer";
// Table type to use.
static const char szTblType[] = szPARADOX;
//========================================================================
// Function:
// Navigate();
//
// Description:
// This sample code will open the customer database and
// navigate through it, doing operations such as getting and
// displaying the current record, getting the next record,
// getting the previous record, and getting the record relative
// to the offset given.
//========================================================================
void
Navigate (void)
{
hDBIDb hDb = 0; // Handle to the database
hDBICur hCur = 0; // Handle to the table
DBIResult rslt; // Value returned from IDAPI functions
Screen("*** Cursor Navigation Example ***\r\n");
BREAK_IN_DEBUGGER();
Screen(" Initializing IDAPI...");
if (InitAndConnect(&hDb) != DBIERR_NONE)
{
Screen("\r\n*** End of Example ***");
return;
}
Screen(" Setting the database directory...");
rslt = DbiSetDirectory(hDb, (pCHAR)szTblDirectory);
ChkRslt(rslt, "SetDirectorry");
Screen(" Opening the %s table...", szTblName);
rslt = DbiOpenTable(hDb, (pCHAR)szTblName, (pCHAR)szTblType, NULL, NULL,
NULL, dbiREADWRITE, dbiOPENSHARED, xltFIELD, FALSE,
NULL, &hCur);
if (ChkRslt(rslt, "OpenTable") != DBIERR_NONE)
{
CloseDbAndExit(&hDb);
Screen("\r\n*** End of Example ***");
return;
}
Screen(" Display the first ten records in the table...");
DisplayInMemoryTable(hCur, 10);
Screen("\r\n Set the current record to the first record in the"
" table");
rslt = DbiSetToBegin(hCur);
ChkRslt(rslt, "SetToBegin");
// We need to display the next record as we are currently at the BOF crack.
DisplayNextRecord(hCur);
Screen("\r\n Change to the next record...");
rslt = DbiGetNextRecord(hCur, dbiNOLOCK, NULL, 0);
ChkRslt(rslt, "GetNextRecord");
Screen(" New current record:");
DisplayCurrentRecord(hCur);
// Skip 3 records. We will be passing the function a NULL
// record buffer as we only want to skip and we don't want to fill
// a record buffer.
Screen("\r\n Getting the 3rd record relative to the current record...");
Screen(" New Current record:");
rslt = DbiGetRelativeRecord(hCur, 3, dbiNOLOCK, NULL, 0);
ChkRslt(rslt, "GetRelativeRecord");
DisplayCurrentRecord(hCur);
Screen("\r\n Set the cursor to the previous record...");
Screen(" New Current record:");
rslt = DbiGetPriorRecord(hCur, dbiNOLOCK, NULL, 0);
ChkRslt(rslt, "GetPriorRecord");
DisplayCurrentRecord(hCur);
Screen("\r\n Set the current record to the last record in the"
" table");
Screen(" New Current record:");
// Set the cursors current record pointer to EOF
rslt = DbiSetToEnd(hCur);
ChkRslt(rslt, "SetToEnd");
// Set the cursors to the last record in the table.
rslt = DbiGetRelativeRecord(hCur, -1, dbiNOLOCK, NULL, 0);
ChkRslt(rslt, "GetRelativeRecord");
DisplayCurrentRecord(hCur);
Screen("\r\n Close the database and exit IDAPI...");
CloseDbAndExit(&hDb);
Screen("\r\n*** End of Example ***");
}