SQL Programming Manual for TAL
Dynamic NonStop SQL Operations
HP NonStop SQL Programming Manual for TAL—527887-001
7-10
Overview of a Dynamic SQL Program
Use the information returned to the SQLSA structure after the PREPARE statement
executes in the next procedure.
Handling the Input Parameters
If sqlsa.PREPARE.INPUT^NUM is 0, skip these steps.
1. Get the number of input parameters and the length of the names buffer (for
parameter names) from the SQLSA structure (sqlsa.PREPARE.INPUT^NUM and
sqlsa.PREPARE.INPUT^NAMES^LEN).
2. Allocate memory for the input SQLDA (and names buffer, if needed). This example
uses the procedure ALLOCATE^SQLDA. The GETPOOL procedure returns a
pointer to the SQLDA in ISQLDA^PTR.
3. Initialize the SQLDA header fields (SQLDA^EYE^CATCHER is defined by the TAL
compiler):
isqlda^ptr.eye^catcher ':=' SQLDA^EYE^CATCHER;
isqlda^ptr.num^entries := sqlsa.PREPARE.INPUT^NUM;
4. Specify a DESCRIBE INPUT statement to access input parameters:
! Using a statement name:
EXEC SQL DESCRIBE INPUT s1
INTO :isqlda^ptr
NAMES INTO :inamesbuf^ptr.namestr;
! Using a statement host variable:
EXEC SQL DESCRIBE INPUT :statement^hostvar
INTO :isqlda^ptr
NAMES INTO :inamesbuf^ptr.namestr;
5. Loop through the SQLVAR array in the input SQLDA. Loop n times, where n is the
number of parameters from
sqlsa.PREPARE.INPUT^NUM). On each iteration:
•
Check the DATA^TYPE field. If necessary, adjust the data type and reset
DATA^LEN and PRECISION accordingly.
•
Allocate a data buffer with size equal to DATA^LEN for the parameter. Use
GETPOOL to allocate the memory.
•
DATA^LEN is used differently for different data types. For example, for a binary
numeric item the upper byte contains the scale, so you must ignore the upper
byte if you are not handling scale. For more information, see Table 6-4
on
page 6-17.
•
Set VAR^PTR to point to the memory.
If you are not allocating memory dynamically, you will have declared a variable
for each input parameter value, and put the address of the variable in
VAR^PTR.










