You can use an sqlda structure to save values that
a dynamically executed user-defined function returns.
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:
- 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:
- 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.
- 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.
- 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.
- 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.