5. Embedded QUEL : Host Language Variables : Variable Usage and Dynamic Operation of EQUEL Statements
 
Share this page                  
Variable Usage and Dynamic Operation of EQUEL Statements
EQUEL allows you to use host language variable to specify many and various parts of EQUEL statements. This powerful feature enables you to write applications that have a great deal of runtime flexibility.
Of course, the data type and use of the host language variable must make sense in the context of the EQUEL statement.
The following are general rules and guidelines:
Host variables can be used to receive values from tables and status information obtained from the DBMS Server.
Host variables can be used to specify the following portions of EQUEL statements:
Portion of Statement
Description
Values of constants within expressions
A variable can contain a value to be matched in a database qualification (where clause), a value to be stored in a database column or an operand in a complex expression. The variable must contain a single value of an appropriate data type, and must not be a string containing multiple operands or operators.
Qualifications
A string variable can be used to specify an entire qualification (where clause), including names of range variables and columns, values to be matched, and QUEL functions. This string variable must not contain names of host language functions or other host language variables which are not understood by the database management system. This feature allows considerable flexibility in programs, permitting applications to construct a "where clause" from parameters that the user specifies at runtime.
Names of database objects
The general rule when using variable substitution for database object names, (such as range variables, tables, and columns) is that one variable can substitute for one name in a statement: for example, you cannot assign a string variable a value such as "e.salary"; you must specify the range variable e and the column salary using separate host variables. When using a variable to specify a database name, you can use a single string variable to specify both the network node and database name.
Miscellaneous arguments
In general, constant values for statement arguments can be specified using host variables of the appropriate data type. For example, the components of a with clause on the index and copy statements, and the items in a define permit or a save statement, can be represented by host variables. In the sort clause of a retrieve statement, the sort keys can be specified individually using string variables containing the name of a result column. A string variable can be used to specify the entire target_list on the create, copy, define view and declare cursor statements.
Host variables of short integer types can be used as null indicator variables as described in this chapter.
Host variables cannot be substituted for keywords in EQUEL statements. For details about the parameters that can be specified using host variables, see QUEL and EQUEL Statements.
In the following example, the retrieve statement makes use of host variables. The two host variables are "name" and "sal".
## retrieve (name = e.empname, sal = e.salary)
##            where e.empnum = 23
In the following example, the variable "eno" is used as an expression in the where clause.
## retrieve (ename = e.empname, sal = e.salary)
##            where e.empnum = eno
If an embedded retrieve statement returns no rows, the contents of the host variables are not be modified.