USING Clause

Function:

The USING clause is used to provide references to host variables for use in either a dynamic FETCH, OPEN or EXECUTE statement.

Invocation:

The USING clause is part of dynamic EXECUTE, FETCH or OPEN statements.

 

Syntax:



using_clause.bmp
 

 

host_variable_specification

A valid host variable specification and must have been defined in an application program. The host variable specification may reference a structure.

host_variable_identifier

A valid single host variable identifier and which must be the address of an SQL descriptor area (SQLDA).

 

Description:

The USING clause defines a set of host variables for use either as value sources in a dynamic OPEN or EXECUTE statement or as target receptors in a dynamic FETCH statement.

A host variable specification, which references a host variable structure is equivalent to individual host variable specifications which reference all the elements of the structure singularly.

For a dynamic OPEN or EXECUTE statement, if the associated prepared statement contained host variable markers, i.e., `?' then these markers must be satisfied by use of a USING clause. Prior to use the referenced host variables must have been assigned appropriate values. Each referenced host variable provides a value for its corresponding host variable marker. The user must make sure that the host variables are supplied with the correct values and formats in the correct order.

For a dynamic FETCH statement, the host variables provided are intended to receive the results of the statement.

Host variables within the USING clause can be provided in two ways:

  • by explicitly specifying a list of host variables. The number, type and order of the required host variables must be known at compilation time of the host program.

  • by providing an SQL descriptor area. This facility enables a more dynamic approach to be adopted. The DESCRIBE statement provides the necessary information in the SQLDA for each host variable marker or derived column. The user must then provide a pointer in each field description which references an appropriate host variable. The number, type and order of the host variables can be completely unknown at compilation time of the host program. An SQL descriptor area is identified by means of a host variable which contains the address of the SQLDA.

A host variable specification which references a host variable structure is equivalent to individual host variable specifications which reference all the elements of a structure singularly.

Limitations:

None.

ANSI Specifics:

The USING clause is not part of the Standard.

Adabas SQL Gateway Embedded SQL Specifics:

This is an Adabas SQL Gateway Embedded SQL extension.

 

Example:

The following example provides values for an an EXECUTE statement which requires the input of three values, for example, 'SELECT * FROM contract WHERE price IN ( ?, ?, ? ). The USING clause provides these values.

 

USING :hv1, :hv2, :hv3;