Allocate memory for the fetch arrays
The DESCRIBE...INTO statement allocates memory for the sqlda structure and its sqlvar_struct structures. However, it does not allocate memory for the sqldata field of the sqlvar_struct structures. The sqldata field holds the fetch array for a retrieved column. Therefore, you must allocate sufficient memory to each sqldata field to hold the elements of the fetch array.
A new global variable, FetArrSize, indicates the number
of rows to be returned per FETCH statement. This variable is defined
as a C language short integer data type. It has a default value of
zero, which disables the fetch array feature. You can set FetArrSize to
any integer value in the following range:
0 <= FetArrSize <= MAXSMINT
The MAXSMINT value is the maximum amount of the data type that can retrieve. Its value is 32767 bytes (32 KB). If the size of the fetch array is greater than MAXSMINT, automatically reduces its size to 32 KB.
You can use the following calculation to determine the appropriate
size of the fetch array:
(fetch-array size) = (fetch-buffer size) / (row size)
The preceding equation uses the following information:
- fetch-array size
- The size of the fetch array, which the FetArrSize global variable indicates
- fetch-buffer size
- The size of the fetch buffer, which the FetBufSize and BigFetBufSize global variables indicate. For information about the size of the fetch buffer, see Optimize cursor execution.
- row size
- The size of the row to be fetched. To determine the size of the row to be fetched, call the rtypmsize() function for each column of the row. This function returns the number of bytes that are needed to store the data type. For more information about the rtypmsize() function, see HCL OneDB ESQL/C data types.
However, if you set FetArrSize so that the following relationship
is true,
(FetArrSize * row size) > FetBufSize
automatically
adjusts the size of the fetch buffer (FetBufSize) as follows
to hold the size of the fetch array:
FetBufSize = FetArrSize * row size
If the result is greater than 32 KB (MAXSMINT), sets FetBufSize to
32 KB and FetArrSize as follows:
FetArrSize = MAXSMINT / (row size)
Important: The FetArrSize global variable
can be used in thread-safe applications.