SQL Programming Manual for Pascal
Using Dynamic SQL
HP NonStop SQL Programming Manual for Pascal—528614-001
7-8
Overview of a Dynamic SQL Program
•
Run-time memory allocation
This subsection 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 in this subsection 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.
Names for functions, such as ALLOCATE_SQLDA, and variables, such as
INPUT_NAMESBUF_PTR, are arbitrarily chosen.
Setting Up the Environment
1. Specify SQL and XMEM directives:
?SQL
?XMEM
2. Copy any required external declarations. Some of these declarations are shown
below; however, your application might need additional declarations.
?SOURCE $SYSTEM.SYSTEM.PEXTDECS(TYPES, SQLCADISPLAY,
SQLDT);
3. Declare the SQLCA and SQLSA data structures:
EXEC SQL INCLUDE SQLCA;
EXEC SQL INCLUDE SQLSA;
4. Declare the SQLDA (for dynamic memory allocation, you declare the SQLDA
explicitly instead of using INCLUDE SQLDA).
5. Copy in external procedures for using the large memory model:
?SOURCE $SYSTEM.SYSTEM.PASEXT
6. Declare the SQLCODE variable and any host variables:
EXEC SQL BEGIN DECLARE SECTION;
VAR
SQLCODE : INTEGER;... { error checking variable }
INPUT_SQLDA_PTR... { pointer to input SQLDA }
Note. This discussion is intended to demonstrate some possible ways to code for dynamic
SQL; it is not intended to show the best or only way for you to develop your particular
application.