Transform functions and transform groups

Transform functions are used to exchange structured type values with host language programs and with external functions and methods.

Transform functions naturally occur in pairs: one FROM SQL transform function, and one TO SQL transform function. The FROM SQL function converts a structured type object into a type that can be exchanged with an external program, and the TO SQL function constructs the object.

When you create transform functions, you put each logical pair of transform functions into a group.

The transform group name uniquely identifies a pair of these functions for a given structured type.

Before you can use a transform function, you must use the CREATE TRANSFORM statement to associate the transform function with a group name and a type. The CREATE TRANSFORM statement identifies one or more existing functions and causes them to be used as transform functions. The following example names two pairs of functions to be used as transform functions for the type Address_t. The statement creates two transform groups, func_group and client_group, each of which consists of a FROM SQL transform and a TO SQL transform.

   CREATE TRANSFORM FOR Address_t
      func_group ( FROM SQL WITH FUNCTION addresstofunc,
         TO SQL WITH FUNCTION functoaddress )
      client_group ( FROM SQL WITH FUNCTION stream_to_client,
         TO SQL WITH FUNCTION stream_from_client ) ;

You can associate additional functions with the Address_t type by adding more groups on the CREATE TRANSFORM statement. To alter the transform definition, you must reissue the CREATE TRANSFORM statement with the additional functions.

Use the SQL statement DROP TRANSFORM to disassociate transform functions from types. After you run the DROP TRANSFORM statement, the functions will still exist, but they will no longer be used as transform functions for this type. The following example disassociates the specific group of transform functions func_group for the Address_t type, and then disassociates all transform functions for the Address_t type:

   DROP TRANSFORMS func_group FOR Address_t;

   DROP TRANSFORMS ALL FOR Address_t;

To alter the transform definition, you must reissue the CREATE TRANSFORM statement with the additional functions. For example, you might want to customize your client functions for different host language programs, such as having one for C and one for Java™. To optimize the performance of your application, you might want your transforms to work only with a subset of the object attributes. Or you might want one transform that uses VARCHAR as the client representation for an object and one transform that uses BLOB.