![]() | Programming Guide | ![]() |
Sets aliases for a declared or default
SELECTcursor
DBMS [WITH CURSORcursor] ALIAS [columnpantherVar[,columnpantherVar...]]DBMS [WITH CURSORcursor] ALIAS [pantherVar[,pantherVar...]]
WITH CURSORcursor- Name of a declared
SELECTcursor. If the clause is not used, Panther uses the defaultSELECTcursor.column- Name of column in the database table.
pantherVar- Name of Panther variable to contain the data.
By default, database values are written to Panther variables with the same names as the selected database columns. Use
DBMS ALIASto map a database column or value to any Panther variable.If a column name is given, it is associated with the variable name that follows it. For example:
DBMS ALIAS name title, film_minutes lengthIf the database column
nameis selected with the default cursor, its value is written to the Panther variabletitle. If the columnfilm_minutesis selected with the default cursor, its value is written to the Panther variablelength. For all other columns selected with the default cursor, the column's value is written to a variable with the same (unqualified) name as the selected column.If
columncontains characters not permitted in Panther identifiers, enclosecolumnin quotes to ensure correct parsing. For example:DBMS ALIAS "last-name" last_nameThe case of
columnneeds to match the setting of the case flag used to initialize the database engine. For example, if the case flag isDM_FORCE_TO_LOWER_CASE,columnmust be entered in lower case. The case ofpantherVarmust be the case used to name the Panther variable. IfpantherVardoes not exist, Panther ignores the column when it executes theSELECT. Refer to "Database Drivers" for details of case setting for each database engine.If no
columnarguments are given, the association is positional. For example:DBMS ALIAS title_var, , abcWhen the above statement is executed, each time values are selected with the default cursor, Panther writes the values of the first and third columns to the Panther variables
title_varandabc, respectively. For all other columns selected with the default cursor, Panther writes to a variable with the same (unqualified) name as the selected column. The order of column names in theselectstatement determines the mapping. Named and positional aliases cannot be assigned in a single statement.Only one
DBMS ALIASstatement is allowed for each cursor. The lastDBMS ALIASstatement called is the one currently in effect.If aliases are declared for a
CATQUERYcursor with theHEADING ONoption, Panther uses the aliases rather than the column names to build the heading. The alias for a column selected with aCATQUERYcursor can be enclosed in quotes. This permits a column heading to use embedded spaces. For example:DBMS DECLARE t_cursor CURSOR FOR \
SELECT title_id, name, pricecat FROM titles
DBMS WITH CURSOR t_cursor CATQUERY TO FILE t_list
DBMS WITH CURSOR t_cursor ALIAS \
"Title ID", Name, "Price Category"
DBMS WITH CURSOR t_cursor EXECUTEAliasing for a cursor is turned off by executing the
DBMS ALIAScommand with no arguments. Closing a cursor also turns off aliasing. If a cursor is redeclared without being closed, the cursor keeps the aliases. Aliases do not affectINSERT,UPDATE, orDELETEstatements.The
ALIAScommand is necessary if the name of a selected column is not a valid Panther variable name, if the application is selecting values from different tables which use the same column name for different values, or if a selection is not a column value, but the value of an aggregate function or select expression.
// Assign named aliases for a declared cursor.DBMS DECLARE x CURSOR FOR \
SELECT title_id, copy_num, status FROM tapes
DBMS WITH CURSOR x ALIAS \
title_id code, copy_num copy, status current_status
DBMS WITH CURSOR x EXECUTE
DBMS WITH CURSOR x ALIAS// Set a positional alias for the 2nd and 4th columns.
// Use automatic mapping for the 1st and 3rd columns.DBMS ALIAS , var_x, , var_y
DBMS QUERY SELECT title_id, name, genre_code, release_date \
FROM titles// Panther will write
// column title_id to variable title_id,
// column name to variable var_x,
// column genre_code to variable genre_code, and
// column release_date to variable var_y.// Note how the mappings change when the columns are
// listed in another order.DBMS QUERY SELECT name, genre_code, release_date, title_id \
FROM titles// Panther will write
// column name to variable name,
// column genre_code to variable var_x,
// column release_date to variable release_date, and
// column title_id to variable var_y.