Name
GET DESCRIPTOR -- get information from an SQL descriptor area
Synopsis
GET DESCRIPTOR descriptor_name :hostvariable = descriptor_header_item [, ... ]
GET DESCRIPTOR descriptor_name VALUE column_number :hostvariable = descriptor_item [, ... ]
Description
GET DESCRIPTOR retrieves information about a query result set from an SQL descriptor area and stores it into host variables. A descriptor area is typically populated using FETCH or SELECT before using this command to transfer the information into host language variables.
This command has two forms: The first form retrieves descriptor "header" items, which apply to the result set in its entirety. One example is the row count. The second form, which requires the column number as additional parameter, retrieves information about a particular column. Examples are the column name and the actual column value.
Parameters
A descriptor name.
A token identifying which header information item to retrieve. Only COUNT, to get the number of columns in the result set, is currently supported.
The number of the column about which information is to be retrieved. The count starts at 1.
A token identifying which item of information about a column to retrieve. See Section 33.7.1 for a list of supported items.
A host variable that will receive the data retrieved from the descriptor area.
Examples
An example to retrieve the number of columns in a result set:
EXEC SQL GET DESCRIPTOR d :d_count = COUNT END-EXEC.
An example to retrieve a data length in the first column:
EXEC SQL GET DESCRIPTOR d VALUE 1 :d_returned_octet_length = RETURNED_OCTET_LENGTH END-EXEC.
An example to retrieve the data body of the second column as a string:
EXEC SQL GET DESCRIPTOR d VALUE 2 :d_data = DATA END-EXEC.
Here is an example for a whole procedure of executing SELECT current_database(); and showing the number of columns, the column data length, and the column data:
EXEC SQL BEGIN DECLARE SECTION END-EXEC. 01 D-COUNT PIC S9(9) COMP-5. 01 D-DATA PIC X(1024). 01 D-RETURNED-OCTET-LENGTH PIC S9(9) COMP. EXEC SQL END DECLARE SECTION END-EXEC. EXEC SQL CONNECT TO testdb AS con1 USER testuser END-EXEC. EXEC SQL ALLOCATE DESCRIPTOR d END-EXEC. * Declare, open a cursor, and assign a descriptor to the cursor EXEC SQL DECLARE cur CURSOR FOR SELECT current_database() END-EXEC. EXEC SQL OPEN cur END-EXEC. EXEC SQL FETCH NEXT FROM cur INTO SQL DESCRIPTOR d END-EXEC. * Get a number of total columns EXEC SQL GET DESCRIPTOR d :D-COUNT = COUNT END-EXEC. DISPLAY "d_count = " D-COUNT. * Get length of a returned column EXEC SQL GET DESCRIPTOR d VALUE 1 :D-RETURNED-OCTET-LENGTH = RETURNED_OCTET_LENGTH END-EXEC. DISPLAY "d_returned_octet_length = " D-RETURNED-OCTET-LENGTH. * Fetch the returned column as a string EXEC SQL GET DESCRIPTOR d VALUE 1 :D-DATA = DATA END-EXEC. DISPLAY "d_data = " D-DATA. * Closing EXEC SQL CLOSE cur END-EXEC. EXEC SQL COMMIT END-EXEC. EXEC SQL DEALLOCATE DESCRIPTOR d END-EXEC. EXEC SQL DISCONNECT ALL END-EXEC.
When the example is executed, the result will look like this:
d_count = +000000001 d_returned_octet_length = +000000006 d_data = testdb
Compatibility
GET DESCRIPTOR is specified in the SQL standard.
See Also