SQL Programming Manual for Pascal

Using Dynamic SQL
HP NonStop SQL Programming Manual for Pascal528614-001
7-16
Dynamically Allocating Memory
Example 1
To position a pointer past the header and onto the first SQLVAR record:
1. Make an INT32 version of the contents of SQLVAR_PTR to allow pointer
arithmetic:
T := RETYPE (SQLVAR_PTR, INT32);
2. Position SQLVAR_PTR past the header:
T := T + SIZEOF(SQLDA_HEADER_TYPE);
SQLVAR_PTR := RETYPE (T, SQLVAR_PTR_TYPE);
Example 2
To allocate memory for an SQLDA, you could use RETYPE to make the output from
MALLOC consistent with the pointer type:
SQLDA_HEADER_PTR := RETYPE (MALLOC(SIZE_TO_ALLOCATE),
SQLDA_HEADER_PTR_TYPE);
See the Pascal Reference Manual for details on RETYPE syntax. For more information
about positioning in the SQLVAR array and using MALLOC, see Allocating Memory for
the SQLDAs and Names Buffers on page 7-20.
Explicitly Declaring the SQLDA
To use the INCLUDE SQLDA directive, you must supply a size for the SQLDA and for
the names buffer. You can specify the largest possible size to ensure that any data you
might obtain at run time will fit. If you are not concerned about memory use, this is the
simplest course to take. Details about using INCLUDE SQLDA appear in Section 6.
A more memory-efficient method is to explicitly declare the fields in the SQLDA and
later allocate memory dynamically for the variables and names contained in the input
statement. Figure 7-1 on page 7-17 shows one way you might explicitly declare the
SQLDA.