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

  1. // BDE - (C) Copyright 1995 by Borland International
  2.  
  3. // qbe.c
  4. #include "snipit.h"
  5.  
  6. //=====================================================================
  7. //  Function:
  8. //          QBE();
  9. //
  10. //  Description:
  11. //          This example shows how to do a QBE query on a Paradox table.
  12. //=====================================================================
  13. void
  14. QBE (void)
  15. {
  16.     DBIResult       rslt;   // Return value from IDAPI functions
  17.     hDBIDb          hDb;    // Handle to the database
  18.     hDBICur         hCur;   // Cursor to the result set from the query
  19.     // Query string
  20.     CHAR            szQry[]  = {
  21.                                  "CUSTOMER.DB | Name  | Phone |\r\n"
  22.                                  "            | Check | Check |"
  23.                                };
  24.  
  25.     Screen("*** 'Query by Example' Example ***\r\n");
  26.  
  27.     BREAK_IN_DEBUGGER();
  28.  
  29.     Screen("    Initializing IDAPI...");
  30.     if (InitAndConnect(&hDb) != DBIERR_NONE)
  31.     {                                        
  32.         Screen("\r\n*** End of Example ***");
  33.         return;
  34.     }
  35.  
  36.     Screen("    Setting the database directory...");
  37.     rslt = DbiSetDirectory(hDb, (pCHAR) szTblDirectory);
  38.     ChkRslt(rslt, "SetDirectory");
  39.  
  40.     Screen("    Perform the following query on the table:\r\n");
  41.     Screen(szQry);
  42.  
  43.     // The DbiQExecDirect function sets up the query, executes
  44.     //   the query, and returns a cursor to the answer table.
  45.     Screen("\r\n    Do a direct query of the table...");
  46.  
  47.     rslt = DbiQExecDirect(hDb, qrylangQBE, szQry, &hCur);
  48.     if (ChkRslt(rslt, "QExecDirect") != DBIERR_NONE)
  49.     {
  50.         CloseDbAndExit(&hDb);
  51.         Screen("\r\n*** End of Example ***");
  52.         return;
  53.     }
  54.  
  55.     // Check for a valid cursor.
  56.     if (hCur)
  57.     {
  58.         Screen("    Display the first 10 records in the answer table");
  59.  
  60.         rslt = DbiSetToBegin(hCur);
  61.         ChkRslt(rslt, "SetToBegin");
  62.         DisplayTable(hCur, 10);
  63.  
  64.         Screen("\r\n    Close the cursor to the answer set...");
  65.         rslt = DbiCloseCursor(&hCur);
  66.         ChkRslt(rslt, "CloseCursor");
  67.     }
  68.     else
  69.     {
  70.         Screen("    Error - Could not get cursor to the answer table");
  71.     }
  72.  
  73.     Screen("    Close the database and exit IDAPI...");
  74.     CloseDbAndExit(&hDb);
  75.  
  76.     Screen("\r\n*** End of Example ***");
  77. }
  78.  
  79.