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

  1. // BDE - (C) Copyright 1995 by Borland International
  2.  
  3. // qbe2.c       
  4. #include "snipit.h"
  5.  
  6. //=====================================================================
  7. //  Function:
  8. //          QBE2();
  9. //
  10. //  Description:
  11. //          This example shows how to query non-SQL tables using the
  12. //          DbiQExec function.  
  13. //=====================================================================
  14. void
  15. QBE2 (void)
  16. {
  17.     DBIResult       rslt;       // Return value from IDAPI functions
  18.     hDBIDb          hDb;        // Handle to the database
  19.     hDBICur         hCur;       // Cursor to the result set
  20.     hDBIStmt        hStrmt;     // Handle to the query
  21.     CHAR            szQry[]     = { // The text of the query
  22.                 "CUST.DBF   | Cust_No | Name  | Phone | State_prov |\r\n"
  23.                 "           |    _x   | Check | Check |  = CA |\r\n"
  24.                 "\r\n"
  25.                 "ORDERS.DB  | Customer No | Ship Date |\r\n"
  26.                 "           |     _x      |   Check   |\r\n"
  27.                                   };
  28.  
  29.     Screen("*** Expanded 'Query by Example' Example ***\r\n");
  30.  
  31.     BREAK_IN_DEBUGGER();
  32.  
  33.     Screen("    Initializing IDAPI...");
  34.     if (InitAndConnect(&hDb) != DBIERR_NONE)
  35.     {                                        
  36.         Screen("\r\n*** End of Example ***");
  37.         return;
  38.     }
  39.                              
  40.     Screen("    Setting the database directory...");
  41.     rslt = DbiSetDirectory(hDb, (pCHAR) szTblDirectory);
  42.     ChkRslt(rslt, "SetDirectory");
  43.  
  44.     Screen("    Perform the following query on the table:\r\n");
  45.     Screen(szQry);
  46.  
  47.     Screen("    Prepare the query command...");
  48.     rslt = DbiQPrepare(hDb, qrylangQBE, szQry, &hStrmt);
  49.     if (ChkRslt(rslt, "QPrepare") != DBIERR_NONE)
  50.     {
  51.         CloseDbAndExit(&hDb);
  52.         Screen("\r\n*** End of Example ***");
  53.         return;
  54.     }
  55.  
  56.     Screen("    Execute the query...");
  57.     rslt = DbiQExec(hStrmt, &hCur);
  58.     if (ChkRslt(rslt, "QExec") != DBIERR_NONE)
  59.     {
  60.         CloseDbAndExit(&hDb);
  61.         Screen("\r\n*** End of Example ***");
  62.         return;
  63.     }
  64.  
  65.     // Check for a valid cursor.
  66.     if (hCur)
  67.     {
  68.         Screen("    Display the first 10 records in the answer table...");
  69.  
  70.         rslt = DbiSetToBegin(hCur);
  71.         ChkRslt(rslt, "SetToBegin");
  72.         DisplayTable(hCur, 10);
  73.  
  74.         Screen("\r\n    Close the cursor to the answer set...");
  75.         rslt = DbiCloseCursor(&hCur);
  76.         ChkRslt(rslt, "CloseCursor");
  77.     }
  78.     else
  79.     {
  80.         Screen("        Could not get cursor to the answer table");
  81.     }
  82.  
  83.     Screen("    Release memory allocated for the query...");
  84.     rslt = DbiQFree(&hStrmt);
  85.     ChkRslt(rslt, "QFree");
  86.     
  87.     Screen("    Close the database and exit IDAPI...");
  88.     CloseDbAndExit(&hDb);
  89.  
  90.     Screen("\r\n*** End of Example ***");
  91. }
  92.  
  93.