Retrieves attribute information about dynamic parameter markers and select column list attributes and data from a SQL descriptor.
For a list of SQL descriptor datatype codes, see Table 10-5.
exec sql get descriptor descriptor_name {:host_variable = count | value item_number :host_variable = item_name [, :host_variable = item_name]…};
The name of the SQL descriptor that contains information about the dynamic parameter markers or return columns in a prepared statement.
A variable defined in a declare section.
The number of dynamic parameters retrieved.
A number specifying the nth dynamic parameter marker or select column for which get descriptor retrieves information.
The name of an attribute to be retrieved. See Table Table 10-3.:
Value |
Description |
---|---|
data |
Value for the dynamic parameter marker or target associated with the specified SQL descriptor. If indicator is negative, this field is undefined. |
indicator |
Value for the indicator parameter associated with the dynamic parameter marker or target. |
length |
The length, in characters, of the dynamic parameter marker of target for the specified SQL descriptor. |
name |
The name of the specified SQL descriptor containing information about the dynamic parameter markers. |
nullable |
Equals 0 if the dynamic parameter marker can accept a null value; otherwise, equals 1. |
precision |
An integer specifying the total number of digits of precision for the CS_NUMERIC variable. |
returned_length |
The length of character types of the values from the select column list. |
scale |
An integer specifying the total number of digits after the decimal point for the CS_NUMERIC variable. |
type |
The datatype of this column (item number) in the row. For values, see SQL descriptor datatype codes. |
exec sql begin declare section;
int numcols, colnum, type, intbuf;
char charbuf[100];
exec sql end declare section;
...
exec sql allocate descriptor big_desc
with max 1000;
exec sql prepare dynstmt from "select * from \
huge_table";
exec sql execute dynstmt into sql descriptor
big_desc;
exec sql get descriptor big_desc :numcols = count;
for (colnum = 1; colnum <= numcols; colnum++)
{
exec sql get descriptor big_desc value :colnum :type = type;
if (type == 4)
{
exec sql get descriptor big_desc value :colnum :intbuf = data;
/* Display intbuf. */
...
}
else if (type == 1)
{
big_desc value :colnum :charbuf = data;
/* Display charbuf. */
...
}
}
exec sql deallocate descriptor big_desc;
...
The get descriptor statement returns information about the number or attributes of dynamic parameters specified or the select list columns in a prepared statement.
This statement should be executed after a describe input, describe output, execute, or fetch (dynamic) statement has been issued.
It is not possible to retrieve data, indicator, or returned_length until the data associated with the descriptor is retrieved from the server by an execute statement or a fetch statement.
describe input, describe output, fetch, set descriptor