allocate descriptor

Description

Allocates a SQL descriptor.

Syntax

exec sql allocate descriptor descriptor_name 
 [with max [host_variable | integer_literal]] 
 end-exec

Parameters

descriptor_name

The name of the SQL descriptor that will contain information about the dynamic parameter markers in a prepared statement.

with max

The maximum number of columns in the SQL descriptor.

host_variable

An integer host variable defined in a declare section.

integer_literal

A numeric value representing the size, in number of occurrences, of the SQL descriptor.

Examples

Example 1

 EXEC SQL BEGIN DECLARE SECTION END-EXEC.
                 01    COLTYPE           PIC S9(9) COMP.
                 01    NUMCOLS           PIC S9(9) COMP.
                 01    COLNUM            PIC S9(9) COMP.
     EXEC SQL END DECLARE SECTION END-EXEC.
 
               ...
 
     EXEC SQL ALLOCATE DESCRIPTOR big_desc WITH MAX 1000 END-EXEC.
 
     EXEC SQL PREPARE dynstmt FROM "select * from huge_table" END-EXEC.
 
    *  Assume that the select returns only 1 row.
     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 DESCRIPTOR big_desc END-EXEC.
     EXEC SQL DEALLOCATE PREPARE dynstmt END-EXEC.
         ...
 
     GET-DESC-LOOP.
         EXEC SQL GET DESCRIPTOR big_desc VALUE
                 :COLNUM :COLTYPE = TYPE END-EXEC.
         DISPLAY "COLUMN ",COLNUM," IS OF TYPE ", COLTYPE.
         ADD 1 TO COLNUM.

Usage

See also

deallocate descriptor, get descriptor, set descriptor