Method 4 dynamic descriptors

A dynamic descriptor is a data structure that holds a description of the variables used in a dynamic SQL statement. There are two kinds of dynamic descriptors—SQL descriptors and SQLDA structures. Both are described later in this chapter.

When a cursor opens, it can have an input descriptor associated with it. The input descriptor contains the values to be substituted for the dynamic SQL statement’s parameter markers.

Before the cursor is opened, the user fills in the input descriptor with the appropriate information, including the number of parameters, and, for each parameter, its type, length, precision, scale, indicator, and data.

Associated with the fetch statement is an output descriptor, which holds the resultant data. Adaptive Server fills in the data item’s attributes, including its type and the actual data being returned. If you are using an SQL descriptor, use the get descriptor statement to copy the data into host variables.

Dynamic SQL method 4 performs the following steps:

  1. Prepares the statement for execution.

  2. Associates a cursor with the statement.

  3. Defines and binds the input parameters or descriptor and:

    • If using an input descriptor, allocates it

    • If using an input parameter, associates it with the statement or cursor

  4. Opens the cursor with the appropriate input parameter(s) or descriptor(s).

  5. Allocates the output descriptor if different from the input descriptor and binds the output descriptor to the statement.

  6. Retrieves the data by using fetch cursor and the output descriptor.

  7. Copies data from the dynamic descriptor into host program variables. If you are using an SQLDA, this step does not apply; the data is copied in step 6.

  8. Closes the cursor.

  9. Deallocates the dynamic descriptor(s).

  10. Drops the statement (ultimately, the stored procedure).