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

  1. // BDE - (C) Copyright 1995 by Borland International
  2.  
  3. // Aliases.c
  4. #include "snipit.h"
  5.  
  6. //=====================================================================
  7. //  Function:
  8. //          Aliases();
  9. //
  10. //  Description:
  11. //          This example list the aliases available in the current
  12. //          configuration file.
  13. //=====================================================================
  14. void
  15. Aliases (void)
  16. {
  17.     hDBIDb      hDb;            // Handle to the database
  18.     hDBICur     hCur;           // Handle to the table
  19.     DBIResult   rslt;           // Return value from IDAPI functions
  20.     CURProps    TblProps;       // Table properties
  21.     pBYTE       pRecBuf;        // Record buffer
  22.     DBINAME     szDatabase;     // String to contain the driver name
  23.     BOOL        bIsBlank;       // Is the field blank?
  24.     DBDesc      dbDesc;         // Database descriptor
  25.  
  26.     Screen("*** Alias Information Example ***\r\n");
  27.  
  28.     BREAK_IN_DEBUGGER();
  29.  
  30.     Screen("    Initializing IDAPI...");
  31.     if (InitAndConnect(&hDb) != DBIERR_NONE)
  32.     {                                       
  33.         Screen("\r\n*** End of Example ***");
  34.         return;
  35.     }
  36.  
  37.     Screen("    Setting the database directory... ");
  38.     rslt = DbiSetDirectory(hDb, (pCHAR) szTblDirectory);
  39.     ChkRslt(rslt, "SetDirectory");
  40.  
  41.     rslt = DbiOpenDatabaseList(&hCur);
  42.     if (ChkRslt(rslt, "OpenDatabaseList") != DBIERR_NONE)
  43.     {
  44.         CloseDbAndExit(&hDb);
  45.         Screen("\r\n*** End of example ***");
  46.         return;
  47.     }
  48.  
  49.     // Allocate space for the record buffer.
  50.     rslt = DbiGetCursorProps(hCur, &TblProps);
  51.     ChkRslt(rslt, "GetCursorProps");
  52.  
  53.     pRecBuf = (pBYTE) malloc(TblProps.iRecBufSize * sizeof(BYTE));
  54.     if (pRecBuf == NULL)
  55.     {
  56.         Screen("    Error - Could not allocate memory");
  57.         rslt = DbiCloseCursor(&hCur);
  58.         ChkRslt(rslt, "CloseCursor");
  59.         CloseDbAndExit(&hDb);               
  60.         Screen("\r\n*** End of example ***");
  61.         return;
  62.     }
  63.  
  64.     Screen("    Go to the beginning of the table...");
  65.     rslt = DbiSetToBegin(hCur);
  66.     ChkRslt(rslt, "SetToBegin");
  67.  
  68.     // Display information about all available aliases
  69.     //   in the configuration file.
  70.     while (DbiGetNextRecord(hCur, dbiNOLOCK, pRecBuf, NULL) == DBIERR_NONE)
  71.     {
  72.         // Get the name of the driver.
  73.         rslt = DbiGetField(hCur, 1, pRecBuf, (pBYTE) szDatabase, &bIsBlank);
  74.         ChkRslt(rslt, "GetField");
  75.  
  76.         // Get the description of the alias.
  77.         rslt = DbiGetDatabaseDesc(szDatabase, &dbDesc);
  78.         if (ChkRslt(rslt, "GetDriverDesc") == DBIERR_NONE)
  79.         {
  80.             // Display the information about the database.
  81.             Screen("\r\n        Logical Name or Alias: %s", dbDesc.szName);
  82.             Screen("        Physical Name\\Path:    %s", dbDesc.szPhyName);
  83.             Screen("        Database type:         %s", dbDesc.szDbType);
  84.         }
  85.     }
  86.  
  87.     // Clean up.
  88.     
  89.     free(pRecBuf);
  90.     rslt = DbiCloseCursor(&hCur);
  91.     ChkRslt(rslt, "CloseCursor");
  92.  
  93.     Screen("\r\n    Close the database and exit IDAPI...");
  94.     CloseDbAndExit(&hDb);
  95.  
  96.     Screen("\r\n*** End of Example ***");
  97. }
  98.