home *** CD-ROM | disk | FTP | other *** search
- // BDE - (C) Copyright 1995 by Borland International
-
- // addalias.c
- #include "snipit.h"
-
- //=====================================================================
- // Function:
- // AddAlias();
- //
- // Description:
- // This example shows how to add an alias to the BDE
- // configuration file.
- //=====================================================================
- void
- AddAlias (void)
- {
- hDBIDb hDb; // Handle to the database
- hDBICur hCur; // Handle to a table
- DBIResult rslt; // Return value from IDAPI functions
- DBINAME szAlias; // Name of the alias
- CHAR szParams[200]; // Parameters to the alias
-
- Screen("*** Adding aliases to the configuration file ***\r\n");
-
- BREAK_IN_DEBUGGER();
-
- Screen(" Initializing IDAPI...");
- rslt = DbiInit(NULL);
- if (ChkRslt(rslt, "Init"))
- {
- return;
- }
-
- // Enable trace information if the debug layer is enabled.
- rslt = DbiDebugLayerOptions(DEBUGON | OUTPUTTOFILE, "SNIPIT.INF");
- ChkRslt(rslt, "DebugLayerOptions");
-
- strcpy(szAlias, "SNIPTEST");
- // szTblDirectory is set within SNIPIT to contain the fully
- // qualified path to the examples table directory, by default,
- // c:\bde\examples\tables.
- strcpy(szParams, "PATH:");
- strcat(szParams, szTblDirectory);
-
- // Add an alias for local tables.
- Screen(" Add an Alias to IDAPI.CFG.");
- rslt = DbiAddAlias(NULL, szAlias, szPARADOX, szParams, TRUE);
- if (ChkRslt(rslt, "AddAlias") != DBIERR_NONE)
- {
- Screen("\r\n Could not add alias to IDAPI.CFG.");
- }
- else
- {
- Screen("\r\n Alias added to IDAPI.CFG.");
- }
-
- // Open a database using this alias.
- Screen("\r\n Open a database using the created alias...");
- rslt = DbiOpenDatabase(szAlias, NULL, dbiREADONLY, dbiOPENSHARED,
- NULL, NULL, NULL, NULL, &hDb);
- ChkRslt(rslt, "OpenDatabase");
-
- // Notice that we do not have to specify the directory and that
- // DbiSetDirectory was not called - the directory information was set
- // in the alias.
- Screen("\r\n Open the vendors table using the created alias...");
- rslt = DbiOpenTable(hDb, "vendors.db", NULL, NULL, NULL, 0, dbiREADONLY,
- dbiOPENSHARED, xltFIELD, FALSE, NULL, &hCur);
- ChkRslt(rslt, "OpenTable");
-
- Screen("\r\n Display the table...");
- DisplayTable(hCur, 10);
-
- Screen("\r\n Close the Database...");
- rslt = DbiCloseDatabase(&hDb);
- ChkRslt(rslt, "DeleteAlias");
-
- Screen("\r\n Delete the alias...");
- rslt = DbiDeleteAlias(NULL, szAlias);
- ChkRslt(rslt, "DeleteAlias");
-
- // Shut down trace file
- DbiDebugLayerOptions(0, NULL);
-
- Screen("\r\n Exit IDAPI...");
- DbiExit();
-
- Screen("\r\n*** End of Example ***");
- }
-