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

Embedded-Only SQL/MX Statements
HP NonStop SQL/MX Reference Manual540440-003
3-82
Considerations for SET DESCRIPTOR
" 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:
Use arguments in an EXECUTE statement rather than descriptor areas. For more
information about dynamic SQL, see the SQL/MX Programming Manual for C and
COBOL.
If descriptor areas are used, use VARIABLE_DATA rather than
VARIABLE_POINTER.
Use VARIABLE_POINTER to efficiently retrieve individual values from a large buffer.
For more information on retrieving multiple values from a large buffer, see the SQL/MX
Programming Manual for C and COBOL.