You use GET DESCRIPTOR to read the values from the fields in an SQL descriptor area.
You must create the descriptor with ALLOCATE DESCRIPTOR, and it must be supplied with values before you call GET DESCRIPTOR.
GET DESCRIPTOR GLOBAL
descriptor
{ :
host_variable =COUNT |
VALUE
item_number :
host_variable =
field_id
[,
host_variable =
field_id ]...}
item_number ::= {
integer | :
host_variable }
field_id ::=
{
REPETITIONS |
TYPE |
DATETIME_INTERVAL_CODE |
PRECISION |
SCALE |
LENGTH |
INDICATOR |
DATA |
OCTET_LENGTH |
NULLABLE |
NAME |
UNNAMED
}
descriptor
Name of the SQL descriptor area whose item descriptors are to be read.
host_variable=COUNT
Host variable of the type SMALLINT into which the value of the COUNT field is entered.
item_number
Number of the item descriptor in the SQL descriptor area containing the fields to be read. The items in the descriptor area are numbered sequentially starting with 1. You can specify an integer or a host variable for item_number, where:
1 <= item_number <= defined maximum number of item descriptors
If item_number > COUNT, an appropriate SQLSTATE is set, which can be handled with WHENEVER NOT FOUND.
host_variable=field_id
Host variable into which the value of the specified field of the item descriptor item_number is entered. The SQL data type of the variable depends on the specified field identifier.
field_id
Field in the item descriptor item_number that is to be read. The descriptor area fields are described in the section "Descriptor area fields". You may specify a field_id more than once in a GET DESCRIPTOR statement.
If a value is transferred from a descriptor area field to a host variable, the host variable must be of the type SMALLINT for all of the fields except NAME and DATA.
If the value of the NAME field is to be transferred, the host variable must be of the SQL data type CHAR(n) or VARCHAR(n), where n >= 128.
If the value of the DATA field is to be transferred to a host variable, the host variable must have exactly the same SQL data type indicated by the fields TYPE, DATETIME_INTERVAL_CODE, LENGTH, PRECISION, SCALE of the same item (see section "Transferring values between host variables and a descriptor area").
Except for the DATA and INDICATOR fields, no vectors can be specified. If DATA and INDICATOR are specified, both must be atomic values or vectors with the same number of elements.
If a vector with several elements is specified, the item numbers for exactly the same number of subsequent items must be <= the defined maximum number of item descriptors. If item numbers > COUNT, an appropriate SQLSTATE is set, which can be handled with WHENEVER NOT FOUND.
GET DESCRIPTOR reads the last value set for the specified field. If the value of the field is undefined, the value returned is also undefined.
The following applies to the DATA field: If the value of the INDICATOR field of the same item < 0, the GET DESCRIPTOR statement must also include the INDICATOR field and only the INDICATOR field is assigned a value.
If vectors are specified, the appropriate number of items are read starting with item_number.
Examples
Read the name, data type and length in bytes of the third item descriptor in the SQL descriptor area DEMO_DESC:
Query the number of item descriptors in the SQL descriptor area:
|
See also
ALLOCATE DESCRIPTOR, DEALLOCATE DESCRIPTOR, DESCRIBE, SET DESCRIPTOR