home *** CD-ROM | disk | FTP | other *** search
/ QBasic & Borland Pascal & C / Delphi5.iso / C / BC_502 / 32SNIPIT.PAK / ALIASES.C < prev    next >
Encoding:
C/C++ Source or Header  |  1997-05-06  |  3.3 KB  |  101 lines

  1. // BDE32 3.x - (C) Copyright 1996 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 = 0;        // Handle to the database
  18.     hDBICur     hCur = 0;       // 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) // Terminate example if
  32.     {                                        // initialization fails
  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.     // Get the size of the record buffer
  50.     rslt = DbiGetCursorProps(hCur, &TblProps);
  51.     ChkRslt(rslt, "GetCursorProps");
  52.  
  53.     // Allocate space for the record buffer
  54.     pRecBuf = (pBYTE) malloc(TblProps.iRecBufSize * sizeof(BYTE));
  55.     if (pRecBuf == NULL)
  56.     {
  57.         Screen("    Error - Could not allocate memory");
  58.         rslt = DbiCloseCursor(&hCur);
  59.         ChkRslt(rslt, "CloseCursor");
  60.  
  61.         CloseDbAndExit(&hDb);
  62.         Screen("\r\n*** End of example ***");
  63.         return;
  64.     }
  65.  
  66.     Screen("    Go to the beginning of the table...");
  67.     rslt = DbiSetToBegin(hCur);
  68.     ChkRslt(rslt, "SetToBegin");
  69.  
  70.     // Display information about all available aliases
  71.     // in the configuration file.
  72.     while (DbiGetNextRecord(hCur, dbiNOLOCK, pRecBuf, NULL) == DBIERR_NONE)
  73.     {
  74.         // Get the name of the driver
  75.         rslt = DbiGetField(hCur, 1, pRecBuf, (pBYTE)szDatabase, &bIsBlank);
  76.         ChkRslt(rslt, "GetField");
  77.  
  78.         // Get the description of the alias
  79.         rslt = DbiGetDatabaseDesc(szDatabase, &dbDesc);
  80.         if (ChkRslt(rslt, "GetDriverDesc") == DBIERR_NONE)
  81.         {
  82.             // Display the information about the database
  83.             Screen("\r\n        Logical Name or Alias: %s", dbDesc.szName);
  84.             Screen("        Physical Name\\Path:    %s", dbDesc.szPhyName);
  85.             Screen("        Database type:         %s", dbDesc.szDbType);
  86.         }
  87.     }
  88.  
  89.     // Free the record buffer
  90.     free(pRecBuf);
  91.  
  92.     // Close the table
  93.     rslt = DbiCloseCursor(&hCur);
  94.     ChkRslt(rslt, "CloseCursor");
  95.  
  96.     Screen("\r\n    Close the database and exit IDAPI...");
  97.     CloseDbAndExit(&hDb);
  98.  
  99.     Screen("\r\n*** End of Example ***");
  100. }
  101.