The SQL CREATE TYPE command is used to create a user-defined object type, which is stored in the Advanced Server database.
These user-defined types can then be referenced within SPL procedures, SPL functions, and .NET programs.
The basic object type is created with the CREATE TYPE AS OBJECT command along with optional usage of the CREATE TYPE BODY command.
An example that demonstrates using an object type is shown in the following section.
Using an Object Type
To use an object type, you must first create the object type in the Advanced Server database. Object type addr_object_type defines the attributes of an address:
Object type emp_obj_typ defines the attributes of an employee. Note that one of these attributes is object type ADDR_OBJECT_TYPE as previously described. The object type body contains a method that displays the employee information:
The following listing is a complete .NET program that uses these user-defined object types:
The following .NET types are defined to map to the types in Advanced Server:
A call to EDBConnection.GlobalTypeMapper.MapComposite maps the .NET type to the Advanced Server types:
A call to EDBCommandBuilder.DeriveParameters() gets parameter information for a stored procedure. This allows you to just set the parameter values and call the stored procedure:
The value of the parameter is set by creating an object of the .NET type and assigning it to the Value property of the parameter:
A call to cmd.ExecuteNonQuery() executes the call to the display_emp() method: