Progress
Language Reference
CREATE ALIAS Statement
Creates an alias for a database. Once an alias is created, it can be used in place of the database’s logical name.
NOTE: A database can have more than one alias, but each alias refers to one and only one database.SYNTAX
alias-string | value ( expression )
An unquoted string, quoted string, or CHARACTER expression that represents an alias for the database.
FOR DATABASE logical-name-string | value ( expression )
An unquoted string, quoted string, or CHARACTER expression that represents the logical name of the database.
NOTE: The logical name must already be set.NO-ERROR
Tells Progress to allow the alias to be created even if the database is not connected.
If you CREATE ALIAS for a database that is not connected and omit NO-ERROR, Progress reports a run time error.
NOTE: The NO-ERROR option of the CREATE ALIAS statement behaves differently from the NO-ERROR option of other 4GL elements. EXAMPLEThis procedure creates the alias myalias for database mydb.
NOTES
- The first Progress database connected during a given session receives the DICTDB alias.
- The first database connected that has an
_menu
file automatically receives the alias FTDB. You can reassign the FTDB alias to any other FAST
TRACK
database.- If there is already a database connected with logical name equal to alias, CREATE ALIAS fails.
- If there is an existing alias equal to alias, the existing alias is replaced by the new alias.
- If you want to use an expression for an alias name or logical name, you must use CREATE ALIAS VALUE (expression) FOR DATABASE VALUE (expression).
- When a given database is disconnected, the existing aliases that refer to it are not erased, but remain in the session alias table. Later in the same session, if you connect to a database with the same logical name, the same alias is used again.
- Aliases allow a general purpose application (such as the Progress Data Dictionary) to expect a specific database name. The Dictionary only works on databases with logical name or alias “DICTDB”. The end user or the application can use CREATE ALIAS to provide the correct alias, in case it is inconvenient to connect the database using the correct logical name. Also, if there are several connected databases, the application can ask the user which one to select, then set the alias accordingly. The Data Dictionary does this when you choose Select Working Database.
- Suppose you connect to a database with logical name MYNAME and compile a procedure that accesses that database. Normally, the saved r-code file contains references to MYNAME.
In a later session, when you want to use the precompiled program, you can connect to your database with the same logical name (MYNAME), or you can connect with a different logical name and set up an alias with the statement CREATE ALIAS “MYNAME” FOR DATABASE logical name.
- Usually, any alias that exists during the session when you compile a procedure has no effect on the resulting r-code file. When a procedure is compiled, the logical name of the database that is accessed within the procedure is put into the r-code file, not an existing alias. If a procedure accesses more than one database, all of the logical names of accessed databases are placed into the r code file.
However, any file reference that is qualified with an alias (as opposed to a logical name) generates a new instance of the file for the compilation. This new instance causes the r-code to have the alias reference and not the logical database name reference. Subsequent unqualified references to that same file within the same block, or nested blocks, will resolve to the new alias instance following the usual rules for qualifying. Unqualified references to different files in the same database do not get the alias name, but get the logical name. Anonymous references to a file, previously referenced using the alias qualifier, in a different, non-nested block get the logical name instead of the alias name.
It simpler to just connect to a database with the desired logical name, leave all references unqualified, not create an alias, and then compile the application. However, sometimes you cannot precompile. In those cases, if you want to compile a procedure so that only the alias gets into the r-code file, then explicitly qualify all file references using the alias. You might want only the alias to get into the r-code file, so you can compile and distribute procedures that will run against any database whose logical name has been assigned the alias contained in the r-code file.
- Changes made to an alias do not take effect within the current procedure. In the next example, alias1.p fails to compile when it reaches the FOR EACH statement, because alias myalias has not been created during the compilation.
To solve this problem, split r-alias1.p into two procedures.
CREATE ALIAS affects only subsequent compilations; currently executing procedures are not affected.
- Be careful when using shared buffers with aliases. If you reference a shared buffer after changing the alias that initially was used in defining it, Progress returns a run-time error. See the following example procedures for details.
Once procedure
r-main.p
is run, it callsr-makebf.p
, which callsr-disp6.p
. The alias myalias is created inr-main.p
, with reference to database sports. Inr-makebf.p
, the shared buffer mybuf is defined for myalias.customer. Then, in the next line, myalias is changed, so that it now refers to database sports2. When an attempt is made to reference shared buffer mybuf in procedurer-disp6.p
, a run-time error occurs, with the message: “r-disp6.p Unable to find shared buffer for mybuf.”
SEE ALSO
ALIAS Function, CONNECT Statement, CONNECTED Function, CREATE DATABASE Statement, DATASERVERS Function, DBCODEPAGE Function, DBCOLLATION Function, DBRESTRICTIONS Function, DBTYPE Function, DBVERSION Function, DELETE ALIAS Statement, DISCONNECT Statement, ERROR-STATUS System Handle, FRAME-DB Function, LDBNAME Function, NUM-DBS Function, PDBNAME Function, SDBNAME Function
Copyright © 2004 Progress Software Corporation www.progress.com Voice: (781) 280-4000 Fax: (781) 280-4095 |