SQL Programming Manual for Pascal
Using Dynamic SQL
HP NonStop SQL Programming Manual for Pascal—528614-001
7-19
Dynamically Allocating Memory
Using the SQLSA
After the input statement is dynamically compiled with the PREPARE statement, the 
SQLSA contains the following 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 Section 3, NonStop SQL Statements and Directives
.
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-3. Using PREPARE to Compile a Statement
CONST
MAXCMD = 256;
. . .
EXEC SQL BEGIN DECLARE SECTION;
VAR STATEMENT_BUFFER : STRING(MAXCMD);
EXEC SQL END DECLARE SECTION;
. . .
WRITELN('Enter a new SQL statement:');
READLN(STATEMENT_BUFFER);
. . .
STATEMENT_HOSTVAR := 'S1';
. . .
EXEC SQL PREPARE :STATEMENT_HOSTVAR FROM :STATEMENT_BUFFER;
VST0703.vsd










