get descriptor

Description

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 9-5.

Syntax

exec sql get descriptor descriptor_name 
 {:host_variable = count | 
 value item_number :host_variable = item_name
[, :host_variable = item_name]...} end-exec

Parameters

descriptor_name

The name of the SQL descriptor that contains information about the dynamic parameter markers or return columns in a prepared statement.

host_variable

A variable defined in a declare section.

count

The number of dynamic parameters retrieved.

item_number

A number specifying the nth dynamic parameter marker or select column, for which get descriptor is to retrieve information.

item_name

The name of an attribute to be retrieved. See Table 9-3 for details.

Table 9-3: Valid item_name values

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 Table 9-5.

Examples

Example 1

     EXEC SQL BEGIN DECLARE SECTION END-EXEC.
           01     QUERY         PIC X(100).
           01     CHARBUF       PIC X(100).
           01     NUMCOLS       PIC S9(9) COMP.
           01     COLNUM        PIC S9(9) COMP.
           01     COLTYPE       PIC S9(9) COMP.
           01     INTBUF        PIC S9(9).
      EXEC SQL END DECLARE SECTION END-EXEC.
 
           ...
 
      DISPLAY "ENTER A SELECT STATEMENT :"
      ACCEPT QUERY.
      EXEC SQL ALLOCATE DESCRIPTOR big_desc WITH MAX 256 END-EXEC.
      EXEC SQL PREPARE  dynstmt FROM :QUERY END-EXEC.
      EXEC SQL EXECUTE dynstmt INTO SQL DESCRIPTOR big_desc END-EXEC.
      EXEC SQL GET DESCRIPTOR big_desc :NUMCOLS = COUNT END-EXEC.
 
      MOVE 1 TO COLNUM.
      PERFORM GET-DESC-LOOP UNTIL COLNUM > NUMCOLS.
      EXEC SQL DEALLOCATE PREPARE dynstmt END-EXEC.
      EXEC SQL DEALLOCATE DESCRIPTOR big_desc END-EXEC.
 
           ...
 
 
      GET-DESC-LOOP.
           EXEC SQL GET DESCRIPTOR big_desc 
                     VALUE :COLNUM
                     :COLTYPE = TYPE END-EXEC
  * Check the type data returned and store in appropriate host variables.
           IF COLTYPE = 4
                DISPLAY "INTEGER DATA! "
                EXEC SQL GET DESCRIPTOR big_desc
                     VALUE :COLNUM :INTBUF = DATA END-EXEC
           ELSE
                IF COLTYPE = 1
                        DISPLAY "CHARACTER DATA! "
                     EXEC SQL GET DESCRIPTOR big_desc
                     VALUE :COLNUM :CHARBUF = DATA END-EXEC
 
   * Handle other data types accordingly or store them all as characters.
                ...
 
           ADD 1 TO COLUMN.
      END-GET-DESC-LOOP.

Usage

See also

describe input, describe output, fetch, set descriptor