SQL Programming Manual for TAL
Dynamic NonStop SQL Operations
HP NonStop SQL Programming Manual for TAL—527887-001
7-16
Dynamically Allocating Memory
Using the SQLSA Structure
After the input statement is dynamically compiled with the PREPARE statement, the
SQLSA contains this information:
•
The number of input parameters in the statement is in
sqlsa.PREPARE.INPUT^NUM; use this information to decide how many parameter
values to solicit from the user.
•
The length of the buffer that is required to contain the names of the input
parameters is in sqlsa.PREPARE.INPUT^NAMES^LEN.
•
The number of output variables in the statement is in
sqlsa.PREPARE.OUTPUT^NUM; use this information to decide how many column
values to report.
•
The length of the buffer that is required to contain the names of the output
variables is in sqlsa.PREPARE.OUTPUT^NAMES^LEN.
•
The type of statement being prepared is in
sqlsa.PREPARE.SQL^STATEMENT^TYPE; use this information to decide what
type of statement was entered. Literals defined for the values are shown with
INCLUDE SQLSA in Table 3-1
on page 3-4.
Because some SQL statements that execute after the PREPARE reset the SQLSA,
you should save the values from the
sqlsa.PREPARE fields in separate variables
immediately after the PREPARE statement. You can pass these values to a procedure
that allocates memory for the required number of input parameters and output
variables as well as for the required input and output names buffer length.
Figure 7-1. Using a PREPARE Statement to Compile a Statement
EXEC SQL BEGIN DECLARE SECTION;
. . .
STRING .statement^buffer[0:511];
. . .
EXEC SQL END DECLARE SECTION;
. . .
--Prompt for a new statement. Pass statement^buffer
--to a procedure that reads and interprets the input.
EXEC SQL PREPARE s1 FROM :statement^buffer;
. . .
VST0701.vsd