SQL Programming Manual for TAL

Dynamic NonStop SQL Operations
HP NonStop SQL Programming Manual for TAL527887-001
7-15
Dynamically Allocating Memory
Dynamic allocation of the names buffer is somewhat different, because INCLUDE
SQLDA causes an actual string (not a template) to be declared for the names buffer. If
you want to allocate this memory dynamically, you should omit the name-string-size
parameter from the INCLUDE SQLDA statement. You can then declare a names buffer
template with a large value, and use the template to allocate memory.
In the names buffer template, use a number that is greater than any possible size your
names buffer could be; otherwise, DESCRIBE INPUT and DESCRIBE might stop
describing parameter or variable names too soon. Remember also that indicator
variable names appear in the names buffer; if the names are long and you use many
indicator variables, you will need to accommodate the indicator variable names.
To estimate the names buffer size, use this formula, also accounting for indicator
variable names:
size = (name-string-size + 11) * sqlvar-count
To access the SQLDA, you declare pointers that you later pass to a procedure that
allocates the memory. Sample declarations are:
EXEC SQL BEGIN DECLARE SECTION;
INT .EXT isqlda^ptr (sqlda^type);
INT .EXT osqlda^ptr (sqlda^type);
EXEC SQL END DECLARE SECTION;
After GETPOOL executes, ISQLDA^PTR will point to the memory for the input SQLDA
structure, and OSQLDA^PTR will point to the memory for the output SQLDA structure.
Declaring the SQLSA Structure
Declare an SQLSA structure using the INCLUDE SQLSA directive:
EXEC SQL INCLUDE SQLSA;
Compiling the Input Statement with PREPARE
Use PREPARE to dynamically compile the statement that was input to the program.
The code shown in Figure 7-1
gives an overview of the sequence you can follow. The
statement is prepared with the name S1.