SQL/MP Programming Manual for C

Dynamic SQL Operations
HP NonStop SQL/MP Programming Manual for C429847-008
10-14
Input Parameters and Output Variables
4. The program enters a loop to prompt the user to supply values for successive
execution of the statement:
/* Beginning of loop */
/* Prompt the user for a value using the parameter */
/* name from the names buffer */
...
/* Store the value in a buffer pointed to by in_sqlda */
/* Run the statement using each successive value */
EXEC SQL EXECUTE exec_stmt USING DESCRIPTOR :in_sqlda;
/* end of loop */
Using the Names Buffer for Parameter Values
When you use the names buffer to prompt the user for parameter values, the names
buffer contains the names of parameters. When you use the names buffer to display
column values, the names buffer contains the names of columns.
If you specify NAMES INTO in the DESCRIBE INPUT statement, the names buffer
contains the names of parameters that you can use to prompt the user for parameter
values. The data returned to the names buffer is in this form:
length_1 name_1 length_2 name_2 ... length_n name_n
where name_1 is the first name, name_2 the second name, and name_n the last
name.
The name length information is a 2-byte integer (SQL data type PIC S9(4) COMP,
C data type int). All names with a length of an odd number of characters are padded
with a blank to make the length an even number. When you display the names, you
might want to check for this blank padding. Expressions appear as a null string with a
length of 0.
For the program to determine the names in the names buffer, you can write a routine to
return the names structure when given the address of the column information desired.
After the DESCRIBE INPUT or DESCRIBE statement runs, the information for each
parameter or column is in the SQLVAR array; the var_ptr field contains the address
of the length field for each parameter or column name in the names buffer.
You can use var_ptr to read the names from the names buffer only if you access the
names buffer immediately following DESCRIBE INPUT or DESCRIBE. After you have
set var_ptr to point to the data, you can no longer use var_ptr to access the
names buffer and must loop through the names buffer to get the names.