SQL Programming Manual for TAL
Dynamic NonStop SQL Operations
HP NonStop SQL Programming Manual for TAL—527887-001
7-7
Using Dynamic SQL Programming Techniques
The program performs these tasks:
•
Issues the PREPARE statement to dynamically compile the SELECT statement.
•
Declares an input SQLDA and an output SQLDA. If needed, the program also
declares corresponding input and output names buffers.
•
Uses the DESCRIBE INPUT statement to retrieve the description for the input
parameter ?SAL into an input SQLDA. The input SQLDA will need at least one
SQLVAR entry for the parameter.
•
Uses the DESCRIBE statement to retrieve the ENUM and SALARY descriptions
for an output SQLDA. The output SQLDA will need at least two SQLVAR entries,
one for each column.
•
Sets the VAR^PTR fields in the SQLDAs to point to the input and output data
buffers. Sets the IND^PTR fields to the addresses of any associated indicator
variables or to a null address.
Using Dynamic SQL Programming Techniques
The simplest dynamic SQL program does not have any input parameters or output
variables. This program processes statements such as CREATE TABLE or DROP
INDEX, which do not require input parameters. A dynamic SQL program that executes
a dynamic SELECT statement is more complex; it does not know the number of
SELECT columns and input parameters until run time.
This section describes programming techniques for dynamic SQL programs that
include:
•
Input parameters and output variables
•
Run-time memory allocation
This section shows several methods to use dynamic SQL statements; it does not show
the most efficient or only method to develop a particular application.
Appendix C, Examples of Dynamic NonStop SQL Programs
provides program
examples that use dynamic SQL operations.
Overview of a Dynamic SQL Program
The following paragraphs describe a dynamic SQL program that handles any SQL
statement and allocates memory at run time. The examples use host variables to store
the cursor name and statement name. Using host variables allows the program to
dynamically compile multiple statements and have all the statements simultaneously
available for execution.
The names for functions, such as ALLOCATE^SQLDA, and variables, such as
IMNAMESBUB^PTR, are arbitrarily chosen.