
Dynamic SQL Operations
HP NonStop SQL/MP Programming Manual for C—429847-008
10-32
Allocate Memory for the SQLDA Structures and
Names Buffers
Example 10-5
allocates memory for input parameter values. You can use the same
code later to allocate memory for output variables.
Example 10-5. Allocating Memory for Parameters and Columns
int setupvarbuffers (sqlda_ptr)
sqldaptr sqlda_ptr; /* pointer to input or output SQLDA */
{
int num_entries; /* # of input parameters/output columns*/
int mem_reqd; /* buffer size to be allocated */
int i; /* loop counter */
/* Pass the SQLDA pointer to a function to handle any */
/* unsupported data types and scale (code omitted here).*/
/* If you do not need to handle the scale, you can set */
/* scale to 0. */
num_entries = sqlda_ptr->num_entries;
for (i = 0; i < num_entries; i++)
{
switch ( sqlda_ptr->sqlvar[i].data_type )
{
case _SQLDT_ASCII_F : /* char type */
mem_reqd = sqlda_ptr->sqlvar[i].data_len;
break;
case _SQLDT_ASCII_V: /* varchar type */
mem_reqd = sqlda_ptr->sqlvar[i].da 2;
break;
...
/* For the numeric data types, either save the */
/* scale information found in bits 0:7, or set */
/* these bits to 0. Then extract the length */
/* from bits 8:15: */
case _SQLDT_16BIT_S:
case _SQLDT_16BIT_U:
...
/* Set scale information to zero: */
sqlda_ptr->sqlvar[i].data_len =
sqlda_ptr->sqlvar[i].data_len & 0377;
/* extract length from bits 8:15: */
mem_reqd = sqlda_ptr->sqlvar[i].data_len & 0377;
break;
... /* If data type is unsupported, return -1
} /* end of switch statement; check data type */
/* Allocate memory for the parameter or column; assign */
/* address to the var_ptr field in the input SQLDA. */
sqlda_ptr->sqlvar[i].var_ptr=(long) malloc (mem_reqd);
} /* end of loop for memory for each parameter value */
/* or column value */
return (0);
}
Содержание 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 ...