
Dynamic SQL Operations
HP NonStop SQL/MP Programming Manual for C—429847-008
10-29
Allocate Memory for the SQLDA Structures and
Names Buffers
Allocate Memory for the SQLDA Structures and Names Buffers
To allocate memory for the SQLDA structures and names buffers for the input and
output variables, use the
malloc
function. The
malloc(n)
function allocates a block
of memory,
n
bytes long, and returns the address of that block. The function returns a
pointer to
void
, which is compatible with any pointer type. However, to enhance
readability, specify the intended type using a cast operator. To include the
malloc
function in the
stdlibh
library, specify:
#include <stdlibh>
The program calls
malloc
and puts the values returned by
malloc
into pointers to
the SQLDA structure and names buffer variables defined earlier in the program.
Initialize the
eye_catcher
and
ind_ptr
Fields
When you allocate the SQLDA, you must explicitly initialize the
eye_catcher
and
ind_ptr
fields. You must initialize
ind_ptr
even if your program is not using
indicator variables to handle null values.
When you issue INCLUDE SQLDA to create the SQLDA template, the C compiler
creates a
#define
for SQLDA_EYE_CATCHER, which you then use to initialize the
eye_catcher
field:
sqlda_name.eye_catcher = SQLDA_EYE_CATCHER;
Initialize the
ind_ptr
and
var_ptr
fields for each SQLVAR entry to NULL:
for (i = 0; i < num_entries; i++)
sqlda-name -> sqlvar[i].ind_ptr = NULL;
sqlda-name -> sqlvar[i].var_ptr = NULL;
Prepare to Allocate the SQLDA Structure and Names Buffer
In preparation for allocating memory to store the SQLDA structure, get the number of
input parameters or output variables from the SQLSA structure. Similarly, to allocate
memory for the names buffer, get the length of the input or output names buffer from
the SQLSA structure.
num_input_vars = sqlsa.u.prepare.input_num;
if (num_input_vars > 0)
allocate_sqlda(num_input_vars);
...
in_nameslen = sqlsa.u.prepare.input_names_len;
if (in_nameslen > 0)
allocate_namesbuf(in_nameslen);
Содержание NonStop SQL/MP
Страница 4: ......
Страница 14: ...Contents HP NonStop SQL MP Programming Manual for C 429847 008 x ...
Страница 34: ...Introduction HP NonStop SQL MP Programming Manual for C 429847 008 1 8 SQL MP Version Management ...
Страница 60: ...Host Variables HP NonStop SQL MP Programming Manual for C 429847 008 2 26 VARCHAR Data Type ...
Страница 68: ...SQL MP Statements and Directives HP NonStop SQL MP Programming Manual for C 429847 008 3 8 Finding Information ...
Страница 156: ...Explicit Program Compilation HP NonStop SQL MP Programming Manual for C 429847 008 6 40 SQL Program Files ...
Страница 264: ...Dynamic SQL Operations HP NonStop SQL MP Programming Manual for C 429847 008 10 66 Detailed Dynamic SQL Program ...
Страница 294: ...SQL MP Sample Database HP NonStop SQL MP Programming Manual for C 429847 008 A 6 ...
Страница 300: ...Memory Considerations HP NonStop SQL MP Programming Manual for C 429847 008 B 6 Avoiding Memory Stack Overflows ...
Страница 304: ...Maximizing Local Autonomy HP NonStop SQL MP Programming Manual for C 429847 008 C 4 Skipping Unavailable Partitions ...