SQL Programming Manual for TAL

NonStop SQL Statements and Directives
HP NonStop SQL Programming Manual for TAL527887-001
3-16
DESCRIBE and DESCRIBE INPUT
You can refer to a static SQL cursor only in the compilation unit where the cursor is
declared. Thus, for static SQL programs, the DELETE WHERE CURRENT, DECLARE
CURSOR, OPEN, FETCH, and CLOSE statements that refer to the cursor must be in
the same compilation unit. If a program exits a procedure with an open cursor,
procedures that execute later can still refer to the cursor, provided the procedures are
in the same compilation unit.
For a dynamic SQL cursor, all statements referring to the cursor must appear in the
procedure where the cursor is defined. However, if you open the cursor and use it in a
call to the procedure where it is defined, you can still use the cursor in subsequent
calls without opening the cursor again.
DESCRIBE and DESCRIBE INPUT
The DESCRIBE statement returns information about output variables (usually SELECT
columns) associated with a previously prepared dynamic SQL statement. DESCRIBE
fills in an SQLDA structure and the names buffer with the descriptions and names of
the columns.
The DESCRIBE INPUT statement returns information about the input parameters
associated with a previously prepared SQL statement.
Follow these guidelines when you use a DESCRIBE or DESCRIBE INPUT statement:
A DESCRIBE or DESCRIBE INPUT statement must appear in the same procedure
as the PREPARE, EXECUTE, or cursor SQL statements (DECLARE CURSOR,
OPEN, FETCH, CLOSE) that process the dynamic SQL input statement.
Both DESCRIBE and DESCRIBE INPUT set the SQLDA NULL^INFO field
depending on whether the prepared SQL statement includes a null indicator and
not whether the column actually allows a null value. To determine whether a
column allows a null value, check the NULLALLOWED column in the COLUMNS
table for the catalog where the particular table is registered. To determine the
catalog for a table, use the FILEINQUIRE procedure.
If a program declares an SQLSA structure, the DESCRIBE and DESCRIBE INPUT
statements return the same compilation statistics that PREPARE returns for the
OUTPUT^NUM, OUTPUT^NAMES^LEN, INPUT^NUM, and INPUT^NAMES^LEN
fields. For more information see the description of the SQLSA structure in
Section 6, Error and Status Processing
.
The following example dynamically executes a SELECT statement, but it does not
know the actual text of the statement. The example uses a SELECT statement in the
host variable :INTEXT and prepares the statement in DYNASTATEMENT. The
DESCRIBE statement uses the SQLDA structure and the names buffer generated by
the INCLUDE SQLDA directive.