SQL/MX 2.x Reference Manual (H06.04+)

Embedded-Only SQL/MX Statements
HP NonStop SQL/MX Reference Manual540440-003
3-81
Considerations for SET DESCRIPTOR
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);
EXEC SQL EXECUTE USING SQL DESCRIPTOR
'in_desc2';
printf("SQLCODE after insert is %d\n", SQLCODE);
Set without the DECRIBE statement. You must set LENGTH or the descriptor will
receive a numeric overflow error.
strncpy(insert_buf, " ", sizeof(insert_buf));
strcpy(insert_buf, "INSERT INTO t1 (decimal_3_unsigned) "