SQL Programming Manual for Pascal
Using Dynamic SQL
HP NonStop SQL Programming Manual for Pascal—528614-001
7-29
Using the Names Buffer
VAR_PTR and Names
If a parameter name or column name does not fit in the names buffer, SQL sets the 
VAR_PTR field in the SQLDA to a value less than 0. To determine whether this 
occurred, you must treat VAR_PTR as a signed integer of the appropriate size before 
doing the comparison. For example, the following comparison would not work:
IF SQLDA.SQLVAR[i].VAR_PTR < 0
Because VAR_PTR is defined as type EXTADDR, the comparison would fail. To 
correctly perform the comparison, use the RETYPE function as shown in the following 
example:
IF RETYPE (SQLDA.SQLVAR[i].VAR_PTR, LONGINT ) < 0 THEN
 { name does not fit }
Alternatively, you could use a record variant as follows:
TYPE PTR_TEST = RECORD
 CASE INTEGER OF
 0 : (EXTPTR : EXTADDR);
 1 : (LONG : LONGINT);
 ...
other types as needed
Figure 7-8. Getting Parameter Values
PROCEDURE PROMPT_USER(VAR NAMESBUF_PTR : PTR_TO_ANY);
VAR
COUNT : INTEGER;
LEN  : INTEGER:
 { loop counter                        }
{ length of a parameter name            }
BEGIN
{ Read the length of the first parameter name:          }
LEN := NAMESBUF_PTR.INT32_FIELD^;
{ Set the pointer past the length field and onto the        }
{ name field :                       }
NAMESBUF_PTR.INT32_FIELD :=
NAMESBUF_PTR.INT32_FIELD + SIZEOF(INT16);
{ 2 on NonStop system            }
WRITE('Please enter a value for ');
FOR COUNT := 1 TO LEN DO
BEGIN
WRITE(NAMESBUF_PTR.CHAR_FIELD^);
NAMESBUF_PTR.INT32_FIELD :=
NAMESBUF_PTR.INT32_FIELD + SIZEOF (CHAR);
{ 1 on NonStop system            }
END;
WRITELN(' :');
END; { PROMPT_USER }
VST0708.vsd










