SQL Programming Manual for Pascal

Using Dynamic SQL
HP NonStop SQL Programming Manual for Pascal528614-001
7-27
Using the Names Buffer
Using the Names Buffer
If you specified NAMES INTO in your DESCRIBE INPUT statement, the names buffer
contains the names of the parameters, which you can use to prompt the user for
parameter values. If indicator parameters were specified, the names of the indicator
parameters are also in the names buffer (see Handling Null Values on page 7-36).
The data returned to the names buffer is in the following form:
len-1 name-1 len-2 name-2 ... len- n name- n
where name-1 represents the first name, name-2 the second, and name-n the last. The
name length information is a 2-byte integer (SQL data type PIC S9(4) COMP; Pascal
data type INT16). All names with a length of an odd number of characters are padded
with a blank to make the length an even number. When you display the names, you
Figure 7-7. Allocating Memory for Values (page 2 of 2)
{ Initialize the loop counter; get NUM_INPUT_VARS from the }
{ SQLSA: }
NUM_INPUT_VARS := SQLSA.PREPARE.INPUT_NUM;
COUNT := NUM_INPUT_VARS;
WHILE COUNT > 0 DO
BEGIN
COUNT := COUNT - 1;
{ Pass the name stored in the names buffer to a }
{ procedure that uses the name to prompt the user for a }
{ parameter value: }
ASK_FOR_VALUE (NAMESPTR)
{ Allocate the memory for the value and store a pointer }
{ to the memory in the VAR_PTR field of the SQLVAR entry}
{ for this input parameter: }
PARAM_PTR.EXTADDR_FIELD :=
MALLOC(SQLVAR_PTR.EXTADDR_FIELD^.DATA_LEN);
SQLVAR_PTR.SQLVAR_FIELD^.VAR_PTR
:= PARAM_PTR.SQLVAR_FIELD ;
{ Use an IF statement to check the data type and read the }
{ parameter value into the appropriate version of }
{ PARAM_PTR (code is not included here). }
{ Determine the data type for this input parameter: }
DATA_TYPE := SQLVAR_PTR.SQLVAR_FIELD^.DATA_TYPE
{ Even if the program does not handle null values, you }
{ must initialize the IND_PTR field: }
SQLVAR_PTR.SQLVAR_FIELD^.IND_PTR := RETYPE (NIL,EXTADDR);
{ Move the pointer to the next input parameter: }
SQLVAR_PTR.INT32_FIELD :=
SQLVAR_PTR.INT32_FIELD + SQLVAR_SIZE;
END;
VST0707.vsd