BDE Aliases
by Ken Mayer [dBVIPS]

Creating a BDE Alias

When using local (.dbf) tables, a BDE alias does not point at a particular table or tables, but at a particular folder. On the contrary, a database in a SQL database is not specifically a folder: it can be, for example, a single file that contains a set of tables. This is why the folder concept for BDE Aliases is really only pertinent to local tables.

To work with tables in a path, use a BDE Alias. Below are the steps. The instructions given here are for dB2K, but very similar instructions can be used for the 16-bit version (which is what Visual dBASE 5.x uses).

A BDE Alias is used in two ways. If you are working with SQL Server databases (Interbase, Oracle, etc.), you use the BDE Alias as a pointer to that database. If you are using local tables, you use the BDE Alias to treat those local tables as if they were a SQL Server database.

Why would you want to use a BDE alias? The following are a few reasons, and there are probably others…

Setting Up An Alias

The first step is to actually create a BDE alias. To do this, you must bring up the BDE Administrator (there should be an icon in the folder for dB2K — double click on it) or go to the menu item Start|Settings|Control Panel and double-click the BDE Administrator icon.

In the BDE Administrator, click on the Databases tab. The treeview may appear as closed, so click on the “+”. Depending on your setup, you may or may not see a bunch of aliases already set in the Administrator. When you install dB2K several aliases are created for you, for example “Contax” and “dB2KSample”. Click on “Contax” if it is there.

On the right side of the screen you should see four entries:

Type: Standard
DEFAULT DRIVER: DBASE
ENABLE BCD: false
PATH: C:\Program Files\dB2K\Samples\contax\data
This is the important information for your alias. The “Type” should be “Standard” for local tables, and you may see (depending on your installation) other types if you check other aliases — these refer to the table’s server and/or the driver. If you are using dBASE tables, make sure the default driver is “DBASE”. You probably don’t need BCD, so don’t worry about it (check online help if you are curious). The “Path” is the actual location of the tables.

Note: If the “Type” is something other than “Standard”, there are a bunch of other options that may appear — you will need to examine those and have some idea what they mean for that specific server or driver.

To create a new alias, on the left half of the BDE Administrator screen, right click and select New… Select Standard unless you need to select, say, “Interbase” (note, if you are using local InterBase and dConnections, use the driver named “INTRBASE”), and click “OK”.

Set the Default Driver to “DBASE” (unless you are using PARADOX tables), and then click on the “…” button for the path. This will bring up a standard path dialog… select the path to your tables. You will probably want to give this a different name — on the left side of the screen, click on “STANDARD1” and type a new name there (like MyAlias).

At this point, you have the alias created in the BDE Administrator. However, you will want to “Apply” it (Ctrl+A) and then exit the Administrator. This saves the information to your .CFG file for the BDE.

If dB2K was up at the time you did this, you should exit it and restart it… otherwise the new alias will not appear.

Using a BDE Alias

To use a BDE Alias, you start dB2K, and in the Navigator select the Tables tab. In the Look In combobox, select your new alias. (If it is selected, the image will show a green “spot” in the database image.)

Instead of using the mouse, you could accomplish the same task by typing in the Command window:
 
 
In XDML:
OPEN DATABASE MyApp
SET DATABASE TO MyApp

In OODML:
d = new Database("MyApp")
set database to MyApp  // There is no OOP equivalent

   

From this point on, while developing, you will be automatically using this alias. When that's the case, the name of your alias is always shown in the “Look in:” field when the Tables tab is selected.  Sometimes when dB2K or an application crashes, the database closes and without knowing it, you're no longer using the database. So be sure that the name of the Alias is shown in the “Look in:” field.

Once a BDE Alias has been selected, if you drag'n drop a table from the Navigator unto a form in the Form designer, dBASE will automatically add the following lines of code to that form:
 
 
Without a BDE Alias:
   this.MY_TABLE1 = new QUERY()
   this.MY_TABLE1.parent = this
   with (this.MY_TABLE1)
      left = 100
      top = 100
      sql = 'select * from "My_Table.DBF"'
      active = true
   endwith
 

With a BDE Alias:
   this.MYAPP1 = new DATABASE()
   this.MYAPP1.parent = this
   with (this.MYAPP1)
      left = 100
      top = 100
      databaseName = "MYAPP"
      active = true
   endwith

   this.MY_TABLE1 = new QUERY()
   this.MY_TABLE1.parent = this
   with (this.MY_TABLE1)
      left = 150
      top = 150
      database = form.myapp1
      sql = "select * from My_Table.dbf"
      active = true
   endwith

   

A few suggestions


Note: The author would like to thank Steve Hawkins and David L. Stone, my proof-readers, for the improvements they brought to this text.