Example 10-4. Allocating The Sqlda Structure - HP NonStop SQL/MP Programming Manual

For c
Table of Contents

Advertisement

Dynamic SQL Operations
Example 10-4
the output SQLDA structure. This function initializes the eye_catcher and ind_ptr
fields.

Example 10-4. Allocating the SQLDA Structure

/* in main code:
/*
typedef struct SQLDA_TYPE *sqldaptr;
/* sqlda_type and sqlvar_type are generated by INCLUDE SQLDA
*/
sqldaptr allocate_sqlda (num_entries)
int num_entries;
{
sqldaptr sqlda_ptr;
int mem_reqd;
short i;
sqlda_ptr = NULL;
mem_reqd = sizeof( struct SQLDA_TYPE ) +
( (num_entries - 1) * sizeof( struct SQLVAR_TYPE )
...
/* call malloc to allocate memory (error checking omitted */
sqlda_ptr
sqlda_ptr->num_entries = num_entries;
...
/* Initialize eye_catcher and ind_ptr
...
/* return the pointer to newly allocated memory:
return(sqlda_ptr);
}
To allocate memory for the names buffer, call malloc and pass in_nameslen. You
specify an arbitrarily large size for the space required because SQL must have
advance information about the space where to store the names. The program still
allocates only the memory that is actually needed for the names, and SQL ignores any
unused memory.
In this call, input_namesbuf_ptr is a pointer to the memory allocated for an input
names buffer:
typedef char (*arrayptr) [1000];
...
if (in_nameslen > 0)
input_namesbuf_ptr = (arrayptr) malloc(in_nameslen);
HP NonStop SQL/MP Programming Manual for C—429847-008
shows the allocate_sqlda function, which is also called to allocate
/* number of input or output variables */
/* pointer to be returned
/* number of bytes required for SQLDA
/* loop counter
= (sqldaptr)malloc (mem_reqd);
Allocate Memory for the SQLDA Structures and
10-30
Names Buffers
*/
*/
*/
*/
);
*/
*/

Advertisement

Table of Contents
loading

Table of Contents