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
- Declare a variable to hold the address of an sqlda structure.
For more information, see Define an sqlda structure.
- 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.
- Use the DESCRIBE...INTO statement to perform two tasks:
- 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 ids_esqlc_0586.html#ids_esqlc_0586.
- 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.
- 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.
- Deallocate any memory you allocated to the sqlda structure.
For more information, see Free memory allocated to an sqlda structure.