Working with BDE Aliases
Go Up to Managing database sessions Index
Each database component associated with a session has a BDE alias (although optionally a fully qualified path name may be substituted for an alias when accessing Paradox and dBASE tables). A session can create, modify, and delete aliases during its lifetime.
The AddAlias method creates a new BDE alias for a SQL database server. AddAlias takes three parameters: a string containing a name for the alias, a string that specifies the SQL Links driver to use, and a string list populated with parameters for the alias. For example, the following statements use AddAlias to add a new alias for accessing an InterBase server to the default session:
var AliasParams: TStringList; begin AliasParams := TStringList.Create; try with AliasParams do begin Add('OPEN MODE=READ'); Add('USER NAME=TOMSTOPPARD'); Add('SERVER NAME=ANIMALS:/CATS/PEDIGREE.GDB'); end; Session.AddAlias('CATS', 'INTRBASE', AliasParams); ... finally AliasParams.Free; end; end;
TStringList *AliasParams = new TStringList(); try { AliasParams->Add("OPEN MODE=READ"); AliasParams->Add("USER NAME=TOMSTOPPARD"); AliasParams->Add("SERVER NAME=ANIMALS:/CATS/PEDIGREE.GDB"); Session->AddAlias("CATS", "INTRBASE", AliasParams); . . . } catch (...) { delete AliasParams; throw; } delete AliasParams;
AddStandardAlias creates a new BDE alias for Paradox, dBASE, or ASCII tables. AddStandardAlias takes three string parameters: the name for the alias, the fully qualified path to the Paradox or dBASE table to access, and the name of the default driver to use when attempting to open a table that does not have an extension. For example, the following statement uses AddStandardAlias to create a new alias for accessing a Paradox table:
AddStandardAlias('MYDBDEMOS', 'C:\TESTING\DEMOS\', 'Paradox');
Session->AddStandardAlias("MYBCDEMOS", "C:\\TESTING\\DEMOS\\", "Paradox");
When you add an alias to a session, the BDE stores a copy of the alias in memory, where it is only available to this session and any other sessions with cfmPersistent included in the ConfigMode property. ConfigMode is a set that describes which types of aliases can be used by the databases in the session. The default setting is cmAll, which translates into the set [cfmVirtual, cfmPersistent, cfmSession]. If ConfigMode is cmAll, a session can see all aliases created within the session (cfmSession), all aliases in the BDE configuration file on a user's system (cfmPersistent), and all aliases that the BDE maintains in memory (cfmVirtual). You can change ConfigMode to restrict what BDE aliases the databases in a session can use. For example, setting ConfigMode to cfmSession restricts a session's view of aliases to those created within the session. All other aliases in the BDE configuration file and in memory are not available.
To make a newly created alias available to all sessions and to other applications, use the session's SaveConfigFile method. SaveConfigFile writes aliases in memory to the BDE configuration file where they can be read and used by other BDE-enabled applications.
After you create an alias, you can make changes to its parameters by calling ModifyAlias. ModifyAlias takes two parameters: the name of the alias to modify and a string list containing the parameters to change and their values. For example, the following statements use ModifyAlias to change the OPEN MODE
parameter for the CATS alias to READ/WRITE in the default session:
var List: TStringList; begin List := TStringList.Create; with List do begin Clear; Add('OPEN MODE=READ/WRITE'); end; Session.ModifyAlias('CATS', List); List.Free; ...
TStringList *List = new TStringList(); List->Clear(); List->Add("OPEN MODE=READ/WRITE"); Session->ModifyAlias("CATS", List); delete List;
To delete an alias previously created in a session, call the DeleteAlias method. DeleteAlias takes one parameter, the name of the alias to delete. DeleteAlias makes an alias unavailable to the session.
Session components provide five methods for retrieving information about a BDE aliases, including parameter information and driver information. They are:
- GetAliasNames, to list the aliases to which a session has access.
- GetAliasParams, to list the parameters for a specified alias.
- GetAliasDriverName, to return the name of the BDE driver used by the alias.
- GetDriverNames, to return a list of all BDE drivers available to the session.
- GetDriverParams, to return driver parameters for a specified driver.
For more information about using a session's informational methods, see Using transactions with the BDE.