SQL/MX 3.2.1 Reference Manual (H06.26+, J06.15+)
Embedded-Only SQL/MX Statements
HP NonStop SQL/MX Release 3.2.1 Reference Manual—691117-004
3-82
Considerations for SET DESCRIPTOR
Null values and SET DESCRIPTOR
If you use SET DESCRIPTOR to set a column's value to be a null value, you must
initialize the host variable to a number with INDICATE_DATA = -1. Otherwise,
NonStop SQL/MX issues an error. For example:
unsigned DECIMAL(3,3) data_pic_2;
strncpy(data_pic_2, " ", sizeof(data_pic_2));
strcpy(data_pic_2, " 000");
col_num = 1;
data_ind = -1;
EXEC SQL SET DESCRIPTOR :upd_desc VALUE :col_num
INDICATOR_DATA = :data_ind,
VARIABLE_DATA = :data_pic_2;
printf("SQLCODE after SET DESCRIPTOR is %d \n", SQLCODE);
EXEC SQL EXECUTE P_UPD USING SQL DESCRIPTOR :upd_desc;
printf("SQLCODE after EXECUTE = %ld\n", SQLCODE);
DECIMAL Data Types and SET DESCRIPTOR
When a host variable is defined as the DECIMAL data type in an embedded program,
there are two ways to set the descriptor:
•
Set with the DECRIBE statement:
strncpy(insert_buf, " ", sizeof(insert_buf));
strcpy(insert_buf, "INSERT INTO t ( decimal_3_unsigned)
values (cast (? as decimal(3,0) unsigned));");
strncpy(decimal_3_unsigned, " ",
sizeof(decimal_3_unsigned));
strcpy(decimal_3_unsigned, " 382");
desc_max = 1;
EXEC SQL ALLOCATE DESCRIPTOR 'in_desc2' WITH MAX
:desc_max;
printf("SQLCODE after allocate descriptor is %d\n",
SQLCODE);
EXEC SQL PREPARE FROM :insert_buf;
printf("SQLCODE after prepare is %d\n", SQLCODE);
EXEC SQL DESCRIBE INPUT USING SQL DESCRIPTOR 'in_desc2';
printf("SQLCODE after descriptor is %d\n", SQLCODE);
desc_val = 1;
type_val = -301;
EXEC SQL SET DESCRIPTOR 'in_desc2' VALUE :desc_val
DATA = :decimal_3_unsigned;
printf("SQLCODE after SET DESCRIPTOR is %d\n",
SQLCODE);










