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 Manual691117-004
3-83
Considerations for SET DESCRIPTOR
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) "
" VALUES (cast(? as decimal(3,0) unsigned));");
desc_max = 1;
EXEC SQL ALLOCATE DESCRIPTOR 'in_desc3' 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);
desc_val = 1;
type_val = -301;
strncpy(decimal_3_unsigned, " ",
sizeof(decimal_3_unsigned));
strcpy(decimal_3_unsigned, " 999");
precision = 3;
scale = 0;
length = 5;
EXEC SQL SET DESCRIPTOR 'in_desc3' VALUE :desc_val
TYPE = :type_val,
PRECISION = :precision,
SCALE = :scale,
LENGTH = :length,
DATA = :decimal_3_unsigned;
printf("SQLCODE after SET DESCRIPTOR is %d\n", SQLCODE);
EXEC SQL EXECUTE USING SQL DESCRIPTOR 'in_desc3';
printf("SQLCODE after insert r1 is %d\n", SQLCODE);
Using VARIABLE_POINTER
If the VARIABLE_POINTER value is set in the descriptor area, the type and length of
the host variable pointed to must exactly match the type and length of the
corresponding item in the descriptor area. The type and length of the item in the
descriptor area is set either by executing a DESCRIBE INPUT statement or by setting
the TYPE and LENGTH items in the descriptor area.
If the type and length are not identical, the results can be unpredictable at program
execution time. To avoid this problem, use one of these alternatives: