Host language program mappings with transform functions

This section describes the host language program mappings with transform functions

An application cannot directly select an entire object, although you can select individual attributes of an object into an application. An application usually does not directly insert an entire object, although it can insert the result of an invocation of the constructor function:

   INSERT INTO Employee(Address) VALUES (Address_t());

To exchange whole objects between the server and client applications, or external functions, you must normally write transform functions.

A transform function defines how Db2® converts an object into a well-defined format for accessing its contents, or binds out the object. A different transform function defines how Db2 returns the object to be stored in the database, or binds in the object. Transforms that bind out an object are called FROM SQL transform functions, and transforms that bind in a column object are called TO SQL transforms.

Most likely, there will be different transforms for passing objects to routines, or external UDFs and methods, than those for passing objects to client applications. This is because when you pass the object to an external routine, you decompose the object and pass it to the routine as a list of parameters. With client applications, you must turn the object into a single built-in type, such as a BLOB. This process is called encoding the object. Often these two types of transforms are used together.

Use the SQL statement CREATE TRANSFORM to associate transform functions with a particular structured type. Within the CREATE TRANSFORM statement, the functions are paired into what are called transform groups. This makes it easier to identify which functions are used for a particular transform purpose. Each transform group can contain not more than one FROM SQL transform, and not more than one TO SQL transform, for a particular type.