SQL Programming Manual for TAL
Dynamic NonStop SQL Operations
HP NonStop SQL Programming Manual for TAL—527887-001
7-14
Dynamically Allocating Memory
•
If there were no input parameters:
! Using a statement name:
EXEC SQL EXECUTE s1;
! Using a statement host variable:
EXEC SQL EXECUTE :statement^hostvar;
7. End the TMF transaction (for both SELECT and other statements):
EXEC SQL COMMIT WORK;
8. If you do not want to reexecute the statement, call PUTPOOL to deallocate the
memory for the SQLDAs and names buffers and for the values.
The following paragraphs describe some of these steps in detail.
Dynamically Allocating Memory
A program can dynamically allocate memory for input parameters and output variables
at run time when the parameters and variables are known. To dynamically allocate
memory, follow these steps:
1. Declare a structure template for the SQLDA by issuing the INCLUDE SQLDA
directive, and for the names buffer by specifying your own template (Refer to page
7-14
.)
2. Declare an SQLSA by issuing the INCLUDE SQLSA directive.
3. PREPARE the input statement.
4. Use the information in the SQLSA to determine the number of input parameters
and output variables in the statement.
5. Allocate space for the required number of SQLDA entries to describe the
parameters and output variables, using the GETPOOL system procedure.
6. Allocate space for the values input to the program or output from the database,
again using GETPOOL.
These steps are described in order on the following pages.
Declaring the SQLDA Structure Template and the Names
Buffer Template
To use the INCLUDE SQLDA directive, you must supply both the number of input
parameters or output variables and a size for the names buffer. You can specify large
numbers to ensure that any data you might obtain at run time will fit. If you are not
concerned about memory use, this is the simplest course to take.
A more memory-efficient method is to use INCLUDE SQLDA to generate a template
for the structure and later allocate memory dynamically both for the SQLDA structure
itself and for the variables and names contained in the input statement.