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 COBOL—523627-004
10-12
Steps for Using SQL Item Descriptor Areas
Steps for Using SQL Item Descriptor Areas 
Figure 10-1 shows the steps presented within the complete C program. These steps 
are executed in the sample program Example A-4 on page A-8.
Figure 10-1. Using SQL Descriptor Areas in a C Program
EXEC SQL BEGIN DECLARE SECTION;
 char hv_sql_statement[256];
 long in_value;
 short num; 
 /* Declare host variables for item descriptor values. */
 long num_data; 
 char char_data[100]; 
 ...
EXEC SQL END DECLARE SECTION;
... /* Construct the SQL statement from user input. */ 
desc_max = 1;
EXEC SQL ALLOCATE DESCRIPTOR 'in_sqlda' WITH MAX :desc_max; 
desc_max = 6;
EXEC SQL ALLOCATE DESCRIPTOR 'out_sqlda' WITH MAX :desc_max;
EXEC SQL PREPARE sqlstmt FROM :hv_sql_statement;
...
EXEC SQL DESCRIBE INPUT sqlstmt USING SQL DESCRIPTOR 'in_sqlda'; 
EXEC SQL DESCRIBE OUTPUT sqlstmt USING SQL DESCRIPTOR 'out_sqlda';
desc_value = 1;
EXEC SQL SET DESCRIPTOR 'in_sqlda' VALUE :desc_value 
 VARIABLE_DATA = :in_value;
EXEC SQL EXECUTE sqlstmt USING SQL DESCRIPTOR 'in_sqlda'
 INTO SQL DESCRIPTOR 'out_sqlda';
EXEC SQL GET DESCRIPTOR 'out_sqlda' :num = COUNT;
for (i = 1; i<= num; i++) {
 EXEC SQL GET DESCRIPTOR 'out_sqlda' VALUE :i
 :type = TYPE, 
 :length = LENGTH, 
 :name = NAME;
 /* Test type or name to determine the compatible host variable. */
 if ...
 EXEC SQL GET DESCRIPTOR 'out_sqlda' VALUE :i 
 :num_data = VARIABLE_DATA;
 ...
}
... /* Process the values from the item descriptor areas. */
EXEC SQL DEALLOCATE PREPARE sqlstmt; 
EXEC SQL DEALLOCATE DESCRIPTOR 'in_sqlda';
EXEC SQL DEALLOCATE DESCRIPTOR 'out_sqlda';
C
1
2
3
4
5
6
7
8
9










