home *** CD-ROM | disk | FTP | other *** search
- // BDE32 3.x - (C) Copyright 1996 by Borland International
-
- // dbio.c
- #include "snipit.h"
-
- #define NUMDB 5
- #define MSG_LEN 30
-
- //=====================================================================
- // Function:
- // DatabaseIOSample();
- //
- // Description:
- // This example shows how to open a number of databases and get
- // information about those databases.
- //=====================================================================
- void
- DatabaseIOSample (void)
- {
- hDBIDb hDb[NUMDB]; // Array of handles to databases
- hDBICur hCur = 0; // Handle to the table
- DBIResult rslt; // Value returned from IDAPI functions
- DBIPATH szDir; // String to hold the directory
- CHAR szMessage[MSG_LEN]; // String to hold messages
- UINT16 uOpenedDatabases; // Count of the opened databases
- UINT16 uLoop; // Loop variable
- DBDesc DbDesc; // Information about the databases
-
- Screen("*** Database Manipulation Example ***\r\n");
-
- BREAK_IN_DEBUGGER();
-
- Screen(" Initializing IDAPI...\r\n");
- rslt = DbiInit(NULL);
- if (ChkRslt(rslt, "Init") != DBIERR_NONE)
- {
- Screen("\r\n*** End of Example ***");
- return;
- }
-
- // Open up to iNUMDB databases
- for (uOpenedDatabases=0; uOpenedDatabases < NUMDB; uOpenedDatabases++)
- {
- Screen(" Open database #%i", uOpenedDatabases + 1);
- rslt = DbiOpenDatabase(NULL, "STANDARD", dbiREADWRITE, dbiOPENSHARED,
- NULL, NULL, NULL, NULL, &hDb[uOpenedDatabases]);
- if (rslt != DBIERR_NONE)
- {
- // Know how to deal with running out of database handles.
- if (rslt == DBIERR_DBLIMIT)
- {
- break;
- }
-
- ChkRslt(rslt, "OpenDatabase");
-
- rslt = DbiExit();
- ChkRslt(rslt, "Exit");
-
- Screen("\r\n*** End of Example ***");
- return;
- }
- }
-
- Screen("\r\n Get the default directory for the first database...");
- rslt = DbiGetDirectory(hDb[0], FALSE, szDir);
- ChkRslt(rslt, "GetDirectory");
-
- Screen(" The working directory: %s", szDir);
-
- Screen(" Change the directory which the first database uses...");
- rslt = DbiSetDirectory(hDb[0], (pCHAR)szTblDirectory);
- ChkRslt(rslt, "SetDirectory");
-
- // Display information about the available databases.
- // Note that this example reads the data from the schema table
- // directly into a structure defined in IDAPI.H. This should
- // only be done with schema tables.
- rslt = DbiOpenDatabaseList(&hCur);
- if (ChkRslt(rslt, "OpenDatabaseList") == DBIERR_NONE)
- {
- Screen("\r\n Display information about the available databases:");
- while ((rslt = DbiGetNextRecord(hCur, dbiNOLOCK, (pBYTE)&DbDesc, NULL))
- == DBIERR_NONE)
- {
- Screen("\r\n Logical Name: %s", DbDesc.szName);
- Screen(" Description: %s", DbDesc.szText);
- Screen(" Physical name/path: %s", DbDesc.szPhyName);
- Screen(" Database type: %s", DbDesc.szDbType);
- }
-
- // Trap for unexpected errors....
- if (rslt != DBIERR_EOF)
- {
- ChkRslt(rslt, "GetNextRecord");
- }
- }
-
- // Place an empty line in the output edit control
- Screen("");
-
- // Clean up and return
- for (uLoop = 0; uLoop < uOpenedDatabases; uLoop++)
- {
- Screen(" Close database #%i", uLoop + 1);
- wsprintf(szMessage, "CloseDatabase #%i", uLoop + 1);
-
- rslt = DbiCloseDatabase(&hDb[uLoop]);
- ChkRslt(rslt, szMessage);
- }
-
- Screen("\r\n Clean up IDAPI");
- rslt = DbiExit();
- ChkRslt(rslt, "Exit");
-
- Screen("\r\n*** End of Example ***");
- }
-