Handling unknown return values

You can use an sqlda structure to save values that a dynamically executed user-defined function returns.

About this task

For an introduction on how to handle unknown return values from a user-defined function, see Determine return values dynamically.

To use an sqlda structure to handle unknown-function return values:

Procedure

  1. Declare a variable to hold the address of an sqlda structure.

    For more information, see Define an sqlda structure.

  2. Assemble and prepare an EXECUTE FUNCTION statement.

    The EXECUTE FUNCTION statement cannot contain the INTO clause. For more information, see Assemble and prepare the SQL statement.

  3. Use the DESCRIBE...INTO statement to perform two tasks:
    1. Allocate an sqlda structure.
      The address of the allocated structure is stored in the sqlda pointer that you declare. For more information, see Allocate memory for the sqlda structure.
    2. Determine the number and data types of function return values.
      The DESCRIBE statement fills an sqlvar_struct structure for each return value. For more information, see Initialize the sqlda structure.
  4. After the DESCRIBE statement, you can test the SQLCODE variable (sqlca.sqlcode) for the defined constant SQ_EXECPROC to check for a prepared EXECUTE FUNCTION statement.

    The SQ_EXECPROC constant is defined in the sqlstype.h header file. For more information, see Determine the statement type.

  5. Examine the sqltype and sqllen fields of sqlda for each return value to determine the amount of memory that is required to allocate for the data.
    For more information, see Allocate memory for column data.
  6. Execute the EXECUTE FUNCTION statement and store the return values in the sqlda structure.

    The statement you use to execute a user-defined function depends on whether the function is a noncursor function or a cursor function.

  7. Deallocate any memory you allocated to the sqlda structure.