SQL Programming Manual for TAL
Dynamic NonStop SQL Operations
HP NonStop SQL Programming Manual for TAL—527887-001
7-6
Using the SQLDA and Names Buffer
Before DESCRIBE INPUT or DESCRIBE:
•
Set the EYE^CATCHER field to the literal SQLDA^EYE^CATCHER.
•
Set NUM^ENTRIES to the number of SQLVAR entries allocated in the SQLDA (the
number of input parameters or output columns expected). If you do not know this
number in advance, you can get it from the INPUT^NUM or OUTPUT^NUM fields
of the SQLSA after the PREPARE statement executes.
After DESCRIBE INPUT or DESCRIBE:
•
Set VAR^PTR to point to the input or output data buffers.
•
Set IND^PTR to point to any indicator variables. If your program does not process
null values, set IND^PTR to an invalid address such as the one shown in the
detailed dynamic SQL program in Appendix C.
•
In some cases, your program might change the contents of the DATA^TYPE,
DATA^LEN, or PRECISION fields. Two cases are when the data type of the input
parameter or output variable you declared is compatible with but not the same as
the data type SQL uses, or when you want to manipulate the scale information in
the first byte of the DATA^LEN field.
For input parameter handling, the FETCH or EXECUTE operation usually references
the same SQLDA structure used for DESCRIBE INPUT. Similarly, for output variable
handling, the FETCH or EXECUTE operation references the same SQLDA structure
used for DESCRIBE.
If the program will execute a statement using input parameters, you declare an SQLDA
to describe the input parameters. If the program will execute a dynamic SELECT
statement or an INSERT statement with the RETURNING LASTSYSKEY option, you
declare a second SQLDA to describe the output variables (SELECT columns or
system-defined primary key).
The names buffer stores the names of the input parameters (after DESCRIBE INPUT)
or the names of selected columns (after DESCRIBE). For an expression, the names
buffer contains a null string. If you will need to prompt the user for parameter values or
display column names for output to the user, you should declare one or more names
buffers.
You can generate an SQLDA template and allocate a names buffer by entering the
INCLUDE SQLDA directive. The generated SQLDA template has the format shown
with INCLUDE SQLDA in Section 6, Error and Status Processing
To process the SELECT statement
SELECT EMPNUM, SALARY FROM =EMPLOYEE WHERE SALARY > ?SAL