home *** CD-ROM | disk | FTP | other *** search
- // BDE - (C) Copyright 1995 by Borland International
-
- // dbio.c
- #include "snipit.h"
-
- #define iNUMDB 5
-
- //=====================================================================
- // Function:
- // DatabaseIOSample();
- //
- // Description:
- // This example shows how to open a number of databases and get
- // information about those databases.
- //=====================================================================
- void
- DatabaseIOSample (void)
- {
- DBIResult rslt; // Value returned from IDAPI functions
- hDBIDb hDb[iNUMDB]; // Array of handles to databases
- hDBICur hCur; // Handle to the table
- DBIPATH szDir; // String to hold the directory
- CHAR szMessage[20]; // String to hold messages
- // (expected size <20)
- UINT16 iOpenedDatabases; // Count of the opened databases
- UINT16 iLoop; // 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;
- }
-
- // Turn on trace information if the debug layer is anabled (DLLSWAP.EXE).
- DbiDebugLayerOptions(DEBUGON | OUTPUTTOFILE, "SNIPIT.INF");
-
- // Specify where temporary files are placed.
- rslt = DbiSetPrivateDir(szPrivDirectory);
- ChkRslt(rslt, "SetPrivateDir");
-
- // Open up to iNUMDB databases.
- for (iOpenedDatabases=0; iOpenedDatabases < iNUMDB; iOpenedDatabases++)
- {
- Screen(" Open database #%i", iOpenedDatabases + 1);
- rslt = DbiOpenDatabase("", 0, dbiREADWRITE, dbiOPENSHARED,
- NULL, NULL, NULL, NULL,
- &hDb[iOpenedDatabases]);
- if (rslt != DBIERR_NONE)
- {
- // Know how to deal with running out of database handles.
- if (rslt == DBIERR_DBLIMIT)
- {
- break;
- }
-
- ChkRslt(rslt, "OpenDatabase");
-
- DbiDebugLayerOptions(0, NULL);
- 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 (iLoop = 0; iLoop < iOpenedDatabases; iLoop++)
- {
- Screen(" Close database #%i", iLoop + 1);
- wsprintf(szMessage, "CloseDatabase #%i", iLoop + 1);
-
- rslt = DbiCloseDatabase(&hDb[iLoop]);
- ChkRslt(rslt, szMessage);
- }
-
- // Turn off trace information.
- DbiDebugLayerOptions(0, NULL);
-
- Screen("\r\n Clean up IDAPI");
- rslt = DbiExit();
- ChkRslt(rslt, "Exit");
-
- Screen("\r\n*** End of Example ***");
- }
-