home *** CD-ROM | disk | FTP | other *** search
/ C Programming Starter Kit 2.0 / SamsPublishing-CProgrammingStarterKit-v2.0-Win31.iso / bde / snipit.pak / NAVIGATE.C < prev    next >
Encoding:
C/C++ Source or Header  |  1997-07-24  |  3.6 KB  |  111 lines

  1. // BDE - (C) Copyright 1995 by Borland International
  2.  
  3. // navigate.c
  4. #include "snipit.h"
  5.  
  6. static const char szTblName[] = "customer";
  7. static const char szTblType[] = szPARADOX;
  8.  
  9. //========================================================================
  10. //  Function:
  11. //          Navigate();
  12. //
  13. //  Description:
  14. //          This sample code will open the Customer table and 
  15. //          navigate through it, doing operations such as getting and 
  16. //          displaying the current record, getting the next record,
  17. //          getting the previous record, and getting the record relative
  18. //          to the offset given.
  19. //========================================================================
  20. void
  21. Navigate (void)
  22. {
  23.     DBIResult   rslt;   // Return value from IDAPI functions
  24.     hDBIDb      hDb;    // Handle to the database
  25.     hDBICur     hCur;   // Handle to the table
  26.  
  27.     Screen("*** Cursor Navigation Example ***\r\n");
  28.  
  29.     BREAK_IN_DEBUGGER();
  30.  
  31.     Screen("    Initializing IDAPI...");
  32.     if (InitAndConnect(&hDb) != DBIERR_NONE)
  33.     {                                        
  34.         Screen("\r\n*** End of Example ***");
  35.         return;
  36.     }
  37.  
  38.     Screen("    Setting the database directory...");
  39.     rslt = DbiSetDirectory(hDb, (pCHAR) szTblDirectory);
  40.     ChkRslt(rslt, "SetDirectorry");
  41.  
  42.     Screen("    Opening the %s table...", szTblName);
  43.     rslt = DbiOpenTable(hDb, (pCHAR) szTblName, (pCHAR) szTblType,
  44.                         NULL, NULL, NULL, dbiREADWRITE, dbiOPENSHARED,
  45.                         xltFIELD, FALSE, NULL, &hCur);
  46.     if (ChkRslt(rslt, "OpenTable") != DBIERR_NONE)
  47.     {
  48.         CloseDbAndExit(&hDb);
  49.         Screen("\r\n*** End of Example ***");
  50.         return;
  51.     }
  52.  
  53.     Screen("    Display the first ten records in the table...");
  54.     DisplayInMemoryTable(hCur, 10);
  55.  
  56.     Screen("\r\n    Set the current record to the first record in the"
  57.            " table...");
  58.     rslt = DbiSetToBegin(hCur);
  59.     ChkRslt(rslt, "SetToBegin");
  60.  
  61.     // We need to display the next record as we are currently at the
  62.     //   BOF crack.
  63.     DisplayNextRecord(hCur);
  64.  
  65.     Screen("\r\n    Change to the next record...");
  66.     rslt = DbiGetNextRecord(hCur, dbiNOLOCK, NULL, 0);
  67.     ChkRslt(rslt, "GetNextRecord");
  68.  
  69.     Screen("    New current record:");
  70.     DisplayCurrentRecord(hCur);
  71.  
  72.     // Skip 3 records.  We will be passing the function a NULL
  73.     //   record buffer as we only want to skip and we don't want to fill
  74.     //   a record buffer.
  75.     Screen("\r\n    Getting the third record relative to the current"
  76.            " record...\r\n    New current record:");
  77.  
  78.     rslt = DbiGetRelativeRecord(hCur, 3, dbiNOLOCK, NULL, 0);
  79.     ChkRslt(rslt, "GetRelativeRecord");
  80.     DisplayCurrentRecord(hCur);
  81.  
  82.  
  83.     Screen("\r\n    Set the cursor to the previous record...");
  84.     Screen("    New current record:");
  85.  
  86.     rslt = DbiGetPriorRecord(hCur, dbiNOLOCK, NULL, 0);
  87.     ChkRslt(rslt, "GetPriorRecord");
  88.     DisplayCurrentRecord(hCur);
  89.  
  90.     Screen("\r\n    Set the current record to the last record in the"
  91.            " table...");
  92.     Screen("    New current record:");
  93.  
  94.     // Set the cursors current record pointer to EOF.
  95.     rslt = DbiSetToEnd(hCur);
  96.     ChkRslt(rslt, "SetToEnd");
  97.  
  98.     // Set the cursors to the last record in the table. 
  99.     rslt = DbiGetRelativeRecord(hCur, -1, dbiNOLOCK, NULL, 0);
  100.     ChkRslt(rslt, "GetRelativeRecord");
  101.  
  102.     DisplayCurrentRecord(hCur);
  103.  
  104.     Screen("\r\n    Close the database and exit IDAPI...");
  105.     CloseDbAndExit(&hDb);
  106.  
  107.     Screen("\r\n*** End of Example ***");
  108. }
  109.  
  110.  
  111.