SQL Programming Manual for Pascal
Using Dynamic SQL
HP NonStop SQL Programming Manual for Pascal—528614-001
7-18
Dynamically Allocating Memory
Once at the beginning of the array, you can use the following statement repeatedly to
position to subsequent SQLVAR records:
SQLVAR_PTR.INT32_FIELD :=
SQLVAR_PTR.INT32_FIELD + SIZEOF(SQLVAR_TYPE);
Accessing the SQLDA and Names Buffer. You can declare host variables for
SQLDA and names buffer pointers in the main variable declarations as shown in
Figure 7-2. MAXCHARS is a constant declared elsewhere in the program:
You can declare the names buffer by declaring pointers to an input names buffer and
an output names buffer and passing the pointers to the appropriate memory allocation
procedure.
Declaring the SQLSA
To declare an SQLSA, issue the INCLUDE SQLSA directive:
EXEC SQL INCLUDE SQLSA ;
Compiling the Input Statement with PREPARE
Use PREPARE to dynamically compile the statement that was input to the program.
Figure 7-3 on page 7-19 gives an overview of the sequence you can follow. The
statement is prepared with the name S1.
Figure 7-2. Declaring SQLDA and Names Buffer Pointers
Note. To give the DESCRIBE INPUT and DESCRIBE statements a size to use before the
memory is actually allocated, you must declare the names buffer to be an arbitrarily large
number (this example uses 4096). You should estimate a number that is greater than any
possible size your names buffer could be; otherwise, DESCRIBE INPUT and DESCRIBE might
stop describing parameters or variables too soon.
EXEC SQL BEGIN DECLARE SECTION;
VAR
INPUT_SQLDA_PTR : SQLDA_HEADER_PTR;
OUTPUT_SQLDA_PTR : SQLDA_HEADER_PTR;
INPUT_NAMESBUF_PTR : CHAR_BUF_TYPE;
OUTPUT_NAMESBUF_PTR : CHAR_BUF_TYPE;
. . .
EXEC SQL END DECLARE SECTION;
CONST
MAXCHARS = 4096;
TYPE
SQLDA_HEADER_PTR = ^SQLDA_HEADER_TYPE;
{ SQLDA_HEADER_TYPE previously declared with the SQLDA }
CHAR_BUF = PACKED ARRAY[1..MAXCHARS] OF CHAR;
CHAR_BUF_TYPE = ^CHAR_BUF;
. . .
VST0702.vsd