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

  1. // BDE - (C) Copyright 1995 by Borland International
  2.  
  3. // addalias.c
  4. #include "snipit.h"
  5.  
  6. //=====================================================================
  7. //  Function:
  8. //          AddAlias();
  9. //
  10. //  Description:
  11. //          This example shows how to add an alias to the BDE
  12. //          configuration file.
  13. //=====================================================================
  14. void
  15. AddAlias (void)
  16. {
  17.     hDBIDb      hDb;            // Handle to the database
  18.     hDBICur     hCur;           // Handle to a table
  19.     DBIResult   rslt;           // Return value from IDAPI functions
  20.     DBINAME     szAlias;        // Name of the alias
  21.     CHAR        szParams[200];  // Parameters to the alias
  22.  
  23.     Screen("*** Adding aliases to the configuration file ***\r\n");
  24.  
  25.     BREAK_IN_DEBUGGER();
  26.  
  27.     Screen("    Initializing IDAPI...");
  28.     rslt = DbiInit(NULL);
  29.     if (ChkRslt(rslt, "Init"))
  30.     {
  31.         return;
  32.     }
  33.  
  34.     // Enable trace information if the debug layer is enabled.
  35.     rslt = DbiDebugLayerOptions(DEBUGON | OUTPUTTOFILE, "SNIPIT.INF");
  36.     ChkRslt(rslt, "DebugLayerOptions");
  37.  
  38.     strcpy(szAlias, "SNIPTEST");
  39.     // szTblDirectory is set within SNIPIT to contain the fully
  40.     //   qualified path to the examples table directory, by default,
  41.     //   c:\bde\examples\tables.
  42.     strcpy(szParams, "PATH:");
  43.     strcat(szParams, szTblDirectory);
  44.  
  45.     // Add an alias for local tables.
  46.     Screen("    Add an Alias to IDAPI.CFG.");
  47.     rslt = DbiAddAlias(NULL, szAlias, szPARADOX, szParams, TRUE);
  48.     if (ChkRslt(rslt, "AddAlias") != DBIERR_NONE)
  49.     {
  50.         Screen("\r\n    Could not add alias to IDAPI.CFG.");
  51.     }
  52.     else
  53.     {
  54.         Screen("\r\n    Alias added to IDAPI.CFG.");
  55.     }
  56.  
  57.     // Open a database using this alias.
  58.     Screen("\r\n    Open a database using the created alias...");
  59.     rslt = DbiOpenDatabase(szAlias, NULL, dbiREADONLY, dbiOPENSHARED,
  60.                            NULL, NULL, NULL, NULL, &hDb);
  61.     ChkRslt(rslt, "OpenDatabase");
  62.  
  63.     // Notice that we do not have to specify the directory and that
  64.     //   DbiSetDirectory was not called - the directory information was set
  65.     //   in the alias.
  66.     Screen("\r\n    Open the vendors table using the created alias...");
  67.     rslt = DbiOpenTable(hDb, "vendors.db", NULL, NULL, NULL, 0, dbiREADONLY,
  68.                         dbiOPENSHARED, xltFIELD, FALSE, NULL, &hCur);
  69.     ChkRslt(rslt, "OpenTable");
  70.  
  71.     Screen("\r\n    Display the table...");
  72.     DisplayTable(hCur, 10);
  73.  
  74.     Screen("\r\n    Close the Database...");
  75.     rslt = DbiCloseDatabase(&hDb);
  76.     ChkRslt(rslt, "DeleteAlias");
  77.  
  78.     Screen("\r\n    Delete the alias...");
  79.     rslt = DbiDeleteAlias(NULL, szAlias);
  80.     ChkRslt(rslt, "DeleteAlias");
  81.  
  82.     // Shut down trace file
  83.     DbiDebugLayerOptions(0, NULL);
  84.  
  85.     Screen("\r\n    Exit IDAPI...");
  86.     DbiExit();
  87.  
  88.     Screen("\r\n*** End of Example ***");
  89. }
  90.