SQL Programming Manual for Pascal

Using Dynamic SQL
HP NonStop SQL Programming Manual for Pascal528614-001
7-30
Handling Output Variables
...
END ;
VAR P : PTR_TEST;
...
P.EXTPTR := SQLDA.SQLVAR[i].VAR_PTR;
IF P.LONG < 0 THEN
{ name does not fit }
Handling Output Variables
To allocate space for output variables, you perform essentially the same set of
operations described for allocating space for input parameters except that the pointers
point to the output SQLDA and names buffer. To get the descriptions of the output
variables into the output SQLDA, you use the DESCRIBE statement instead of
DESCRIBE INPUT:
EXEC SQL DESCRIBE statement or :statement-hostvar
INTO :OUTPUT_SQLDA_PTR^
NAMES INTO :OUTPUT_NAMESBUF_PTR^;
DESCRIBE places the descriptions of the column values to be output from the
database into the location in memory pointed to by OUTPUT_SQLDA_PTR^ and the
names of the columns into the location pointed to by OUTPUT_NAMESBUF_PTR^.
For code to allocate memory, see Allocating Memory for the Values on page 7-22.
Handling Scale
If your program must handle numeric values with scale, you will need to read scale
information from the output SQLDA. DESCRIBE places this information in bits 0
through 7 of the DATA_LEN field in the SQLVAR array. If you can ignore scale, you can
set the DATA_LEN field to 0, causing data truncation; otherwise, you will need to save
the scale information and write a procedure to handle scale.
The same considerations apply if your program must handle precision for date-time,
INTERVAL, FLOAT, or binary numeric values. The precision information is in the
PRECISION field of the SQLVAR entry.
Displaying Output
To display output from the database after the cursor FETCH, you perform the following
tasks:
1. Set pointers to the beginning of the first SQLVAR array and to the beginning of the
names buffer.
2. Get the number of output columns from the SQLDA.
3. Write the column name to the output file using the names buffer pointer (only if you
are doing a repetitive display of the column names).