// BDE - (C) Copyright 1995 by Borland International // qbe2.c #include "snipit.h" //===================================================================== // Function: // QBE2(); // // Description: // This example shows how to query non-SQL tables using the // DbiQExec function. //===================================================================== void QBE2 (void) { DBIResult rslt; // Return value from IDAPI functions hDBIDb hDb; // Handle to the database hDBICur hCur; // Cursor to the result set hDBIStmt hStrmt; // Handle to the query CHAR szQry[] = { // The text of the query "CUST.DBF | Cust_No | Name | Phone | State_prov |\r\n" " | _x | Check | Check | = CA |\r\n" "\r\n" "ORDERS.DB | Customer No | Ship Date |\r\n" " | _x | Check |\r\n" }; Screen("*** Expanded 'Query by Example' 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, "SetDirectory"); Screen(" Perform the following query on the table:\r\n"); Screen(szQry); Screen(" Prepare the query command..."); rslt = DbiQPrepare(hDb, qrylangQBE, szQry, &hStrmt); if (ChkRslt(rslt, "QPrepare") != DBIERR_NONE) { CloseDbAndExit(&hDb); Screen("\r\n*** End of Example ***"); return; } Screen(" Execute the query..."); rslt = DbiQExec(hStrmt, &hCur); if (ChkRslt(rslt, "QExec") != DBIERR_NONE) { CloseDbAndExit(&hDb); Screen("\r\n*** End of Example ***"); return; } // Check for a valid cursor. if (hCur) { Screen(" Display the first 10 records in the answer table..."); rslt = DbiSetToBegin(hCur); ChkRslt(rslt, "SetToBegin"); DisplayTable(hCur, 10); Screen("\r\n Close the cursor to the answer set..."); rslt = DbiCloseCursor(&hCur); ChkRslt(rslt, "CloseCursor"); } else { Screen(" Could not get cursor to the answer table"); } Screen(" Release memory allocated for the query..."); rslt = DbiQFree(&hStrmt); ChkRslt(rslt, "QFree"); Screen(" Close the database and exit IDAPI..."); CloseDbAndExit(&hDb); Screen("\r\n*** End of Example ***"); }