SQL Programming Manual for TAL
Dynamic NonStop SQL Operations
HP NonStop SQL Programming Manual for TAL—527887-001
7-20
Dynamically Allocating Memory
Allocating Memory for the Values.
After the descriptions of the input parameters and output variables are specified, the
program must allocate space for the actual values. The user might enter these values
for input parameters, or the system might return them for columns (output variables).
The following paragraphs describe how to handle input parameters.
The program uses the DESCRIBE INPUT statement to fill in the SQLDA and names
buffer with the descriptions of the input parameters in the SQL statement. If you specify
NAMES INTO, the names of the parameters are also returned in the names buffer.
The DESCRIBE INPUT statement is as follows. Notice that the names are placed in
the STRING field of the names buffer template declared for dynamic memory
allocation.
EXEC SQL
DESCRIBE INPUT : statement or :statement-hostvar
INTO :isqlda^ptr
NAMES INTO :inamesbuf^ptr.namestr;
The DESCRIBE INPUT statement places the descriptions for the parameters into the
location pointed to by ISQLDA^PTR, (the input SQLDA) and the names of the
parameters into the location pointed to by INAMESBUF^PTR.
Immediately after DESCRIBE INPUT executes, the VAR^PTR field in the SQLDA
points to the first entry in the names buffer. You can use VAR^PTR to read the names
from the names buffer only if you access the names buffer immediately following
DESCRIBE INPUT. After you have set VAR^PTR to point to the data, you can no
longer use VAR^PTR to access the names buffer and must loop through the names
buffer to get the names.
The program can now allocate memory for the parameter values to be entered.
Handling Scale. If your program must handle numeric values with scale, you will need
to read scale information from the input SQLDA structure. The DESCRIBE INPUT
statement places this information in bits 0 through 7 of the DATA^LEN field in the
SQLVAR array. For handling input parameters, these possibilities exist:
•
The program can ignore scale entirely: set bits 0 through 7 of DATA^LEN to 0 and
send integers to SQL.
•
The program can ignore scale but accept scaled values from the user: set bits 0
through 7 of DATA^LEN to 0, truncate digits to the right of the decimal point in the
user-entered value, and send the resulting integers to SQL.
•
The program can handle scale: write a procedure that scales the user-entered
value to match the value in bits 0 through 7 of DATA^LEN.
Similar considerations apply if your program must handle precision for date-time,
INTERVAL, FLOAT, or binary numeric values. The precision information is in the
PRECISION field of the SQLVAR entry.