SQL/MX Programming Manual for C and COBOL (G06.24+, H06.03+)

Dynamic SQL With Descriptor Areas
HP NonStop SQL/MX Programming Manual for C and COBOL523627-004
10-17
Set Explicit Input Values
Setting the Parameter Values
After user input, you can set the VARIABLE_DATA or VARIABLE_POINTER value in
the item descriptor area. For limitations on using the VARIABLE_POINTER item, see
using the VARIABLE POINTER in the SQL/MX Reference Manual.
Example
desc_value = 1;
EXEC SQL SET DESCRIPTOR 'in_sqlda' VALUE :desc_value
VARIABLE_DATA = :in_empnum;
Setting Null
If the user can enter null, set the INDICATOR_DATA value to indicate null in the
VARIABLE_DATA field in the item descriptor area.
Example
desc_value = 1;
EXEC SQL SET DESCRIPTOR 'in_sqlda' VALUE :desc_value
INDICATOR_DATA = -1;
In this case, the actual value of VARIABLE_DATA is irrelevant and is not verified.
Setting Parameter Values by Position
If you have more than one dynamic parameter, you can identify and set values for the
parameters by their position in the prepared SQL statement.
Example
strcpy (hv_sql_statement, "UPDATE employee"
" SET salary = salary * 1.1"
" WHERE jobcode = CAST(? AS NUMERIC(4) UNSIGNED)"
" AND salary < CAST(? AS NUMERIC(8,2) UNSIGNED)");
...
desc_max = 2;
EXEC SQL ALLOCATE DESCRIPTOR 'in_sqlda' WITH MAX :desc_max;
...
EXEC SQL PREPARE sqlstmt FROM :hv_sql_statement;
...
EXEC SQL DESCRIBE INPUT sqlstmt
USING SQL DESCRIPTOR 'in_sqlda';
...
... /* Input the values for the jobcode and salary parms. */
desc_value = 1;
EXEC SQL SET DESCRIPTOR 'in_sqlda' VALUE :desc_value
VARIABLE_DATA = :in_jobcode;
desc_value = 2;
EXEC SQL SET DESCRIPTOR 'in_sqlda' VALUE :desc_value
VARIABLE_DATA = :in_salary;
C
C
C