Passing structured type parameters to external routines
When you pass structured type parameters to an external routine, you should pass a parameter for each attribute. You must pass a null indicator for each parameter and a null indicator for the structured type itself.
About this task
The following example accepts the structured type Address_t
and
returns a base type:
CREATE FUNCTION stream_to_client (Address_t)
RETURNS VARCHAR(150) ...
The external routine must
accept the null indicator for the instance of the Address_t
type
(address_ind) and one null indicator for each of the attributes of
the Address_t
type. There is also a null indicator
for the VARCHAR output parameter. The following code represents the
C language function headers for the functions that implement the UDFs:
void SQL_API_FN stream_to_client(
/* decomposed address */
SQLUDF_VARCHAR *street,
SQLUDF_CHAR *number,
SQLUDF_VARCHAR *city,
SQLUDF_VARCHAR *state,
/* VARCHAR output */
SQLUDF_VARCHAR *output,
/* null indicators for type attributes */
SQLUDF_NULLIND *street_ind,
SQLUDF_NULLIND *number_ind,
SQLUDF_NULLIND *city_ind,
SQLUDF_NULLIND *state_ind,
/* null indicator for instance of the type */
SQLUDF_NULLIND *address_ind,
/* null indicator for the VARCHAR output */
SQLUDF_NULLIND *out_ind,
SQLUDF_TRAIL_ARGS)
Suppose that the routine accepts two different structured type parameters, st1 and st2, and returns another structured type of st3:
CREATE FUNCTION myudf (int, st1, st2)
RETURNS st3
ST1 | ST2 | ST3 |
---|---|---|
st1_att1 VARCHAR | st2_att1 VARCHAR | st3_att1 INTEGER |
st2_att2 INTEGER | st2_att2 CHAR | st3_att2 CLOB |
st2_att3 INTEGER |
The following code represents the C language headers for routines that implement the UDFs. The arguments include variables and null indicators for the attributes of the decomposed structured type and a null indicator for each instance of a structured type, as follows:
void SQL_API_FN myudf(
SQLUDF_INTEGER *INT,
/* Decomposed st1 input */
SQLUDF_VARCHAR *st1_att1,
SQLUDF_INTEGER *st1_att2,
/* Decomposed st2 input */
SQLUDF_VARCHAR *st2_att1,
SQLUDF_CHAR *st2_att2,
SQLUDF_INTEGER *st2_att3,
/* Decomposed st3 output */
SQLUDF_VARCHAR *st3_att1out,
SQLUDF_CLOB *st3_att2out,
/* Null indicator of integer */
SQLUDF_NULLIND *INT_ind,
/* Null indicators of st1 attributes and type */
SQLUDF_NULLIND *st1_att1_ind,
SQLUDF_NULLIND *st1_att2_ind,
SQLUDF_NULLIND *st1_ind,
/* Null indicators of st2 attributes and type */
SQLUDF_NULLIND *st2_att1_ind,
SQLUDF_NULLIND *st2_att2_ind,
SQLUDF_NULLIND *st2_att3_ind,
SQLUDF_NULLIND *st2_ind,
/* Null indicators of st3_out attributes and type */
SQLUDF_NULLIND *st3_att1_ind,
SQLUDF_NULLIND *st3_att2_ind,
SQLUDF_NULLIND *st3_ind,
/* trailing arguments */
SQLUDF_TRAIL_ARGS
)