Home | Previous Page | Next Page   DataBlade Module Concepts > DataBlade Module Components >

Data Types

The database server uses data types to determine how to store and retrieve different kinds of data.

The following table lists the categories of data types available to you when you create a DataBlade module. You must define some of these data types; others you can use just as they are.

Data Type You Define? Code Needed? Description
Built-in No No A native Informix data type that comes with the database server
Qualified built-in Yes No A built-in data type that takes one or more qualifications, such as storage size, range of values, or precision
Opaque Yes Yes (the basic code needed to implement an opaque type is generated by BladeSmith) A structured data type whose internal members cannot be accessed directly using SQL statements
Distinct Yes No A unique name for an existing built-in or extended type
Collection Yes No A group of elements of the same data type
Row Yes No A structured data type whose internal members can be directly accessed through SQL statements

An extended data type is a data type that is not built into your Informix database server. Extended data types include opaque data types, distinct data types, collection data types, and row data types. Extended data types are described in the IBM Informix: User-Defined Routines and Data Types Developer's Guide.

Collection and row data types are extended data types built from a combination of other data types; their components are accessed through SQL statements.

Built-in Data Types

Built-in data types include character, numeric, time, large object, and Boolean data types. You can use built-in data types as building blocks in opaque, distinct, row, and collection data types.

Built-in data types are automatically included in your DataBlade module project file as imported objects.

For a complete list and descriptions of built-in data types, see the IBM Informix: Guide to SQL Reference manual.

Qualified Built-in Data Types

A qualified data type is a built-in data type that has an added qualification that specifies information about the storage size, range of values, or precision of the type. For example, the DECIMAL(p,s) data type can take qualifiers for precision (the total number of digits) and scale (the total number of digits to the right of the decimal point).

You must define a qualified data type by specifying its qualifications.

Example

The DECIMAL(6,3) data type has six digits, with three digits to the right of the decimal point; for example, 123.456.

More Information

For a complete list of qualified data types and their parameters, see the IBM Informix: Guide to SQL Reference manual.

Distinct Data Types

A distinct data type is an existing data type to which you assign a unique name. The distinct data type inherits all routines from the source data type, but it cannot be directly compared to the source data type without an explicit cast.

Why Use a Distinct Data Type? Use a distinct data type if you want to create routines that do not work on the source data type. You can use a distinct data type to control how the data type is cast, or converted, to other data types.

You can use distinct data types to create inheritance hierarchies, which allow you to write very selective routines. A distinct data type can be passed to all routines defined for the source; however, the source data type cannot be passed to routines defined for the distinct data type.

Example

You can create two distinct data types based on the MONEY type: lira and us_dollar. To determine the dollar value of a specified lira value, you can create an explicit cast between lira and us_dollar by writing a function that multiplies the value of lira by the exchange rate. Using the cast allows you to perform arithmetic operations involving both distinct data types and to return a meaningful result.

More Information

For a description of distinct data types, see the IBM Informix: User-Defined Routines and Data Types Developer's Guide.

Collection Data Types

A collection data type is a group of values of a single data type in a column. Each value is referred to as an element. A collection data type is defined using a type constructor and an element data type. Type constructors determine whether the database server checks for duplicate elements or orders the elements. The following table describes the collection type constructors.

Type Constructor Duplicates Allowed? Ordered?
SET No No
MULTISET Yes No
LIST Yes Yes

For a SET, the database server prevents insertion of duplicate elements. For a MULTISET, the database server takes no special actions. For a LIST, the database server orders the elements.

Elements can be almost any data type, including other extended data types and built-in data types such as smart large objects. You can access any element in a collection individually through SQL statements.

The number of elements in a collection is not mandated. You can change the number of elements in a collection without reinserting it into a table, and different rows can have different numbers of elements in their collections.

What Does a Collection Look Like? The following diagram illustrates a collection data type using a SET constructor and the LVARCHAR data type in a column called Dependents.

Figure 2. Sample Collection Data Type
begin figure description - This figure is described in the surrounding text. - end figure description

Instead of putting information on dependents in a separate table, all the information is contained in one row, using a collection data type. You can add or remove elements without altering the table's columns.

Why Use a Collection Data Type? You can use collection data types to reconfigure a table with awkwardly long rows by grouping data into a single column. Use a collection if you have data of the same data type that can be naturally grouped into a single column. You can group data even further by creating a collection of row types or other collections.

Collections are also useful as returned values: for example, a group of values from many rows in a column or fields in a row type. For example, if you want to obtain a list of every city in which your employees live from the sample collection data type in Figure 2, you could create a collection on the Location column to return a set of values.

The following function types can return collections:

More Information

For a description of collection data types, see the IBM Informix: Guide to SQL Tutorial.

Row Data Types

A row data type can be thought of as a row of columns, of varying data types, stored in a single database table column. Row data types follow essentially the same rules as database tables. The columns within a row data type are called fields. They can be almost any data type, including other extended data types and built-in data types, such as smart large objects. You can access fields individually using SQL statements.

To create a row data type, you specify:

What Does a Row Data Type Look Like? The following diagram illustrates a row type named address_t in a column named Address.

Figure 3. Sample Row Data Type
begin figure description - This figure is described in the surrounding text. - end figure description

Instead of having additional columns in the Address table, the row data type groups data that is most often accessed together in one column. The table Address consists of the columns Name(LVARCHAR(30)), Address(address_t), and Dependents(SET(LVARCHAR)). The row data type address_t consists of the named fields Street(LVARCHAR(20)), City(LVARCHAR(20)), State(CHAR(2)), and Zip_code(INTEGER).

Why Use a Row Data Type? Like collection data types, row data types allow you to reconfigure your database table. Use a row type if you have data of differing data types that group naturally into a single column. You can further group your data if you include a collection or another row data type as a field within your row data type.

Row data types can be useful for handling smart large objects. For example, if a row data type has a field that is an opaque data type containing an image in a smart large object, the other fields of the row data type could contain additional information about the image.

For best performance, use row data types if most user queries access all or most of the row data type's fields.

You can use row data types to create inheritance hierarchies, allowing you to write very selective routines. A child row data type inherits its parent's fields and can be passed to all routines defined for the parent; however, the parent data type cannot be passed to routines defined for the child data type.

More Information

For a discussion on row data types, see the IBM Informix: Guide to SQL Tutorial.

Opaque Data Types

An opaque data type is a user-defined data structure. To successfully interpret opaque data types, the database server requires that the DataBlade module provide opaque data type support routines. You must provide support routines for your opaque data type.

BladeSmith generates boilerplate code for opaque data type support routines. You can write additional code in C or Java to implement the functionality your opaque data type requires. If you provide ActiveX value objects as a client-side interface to your opaque data types, you can write the underlying support routines for the opaque data type in C++. See Opaque Data Type Support Routines for more information.

Opaque data types typically contain more than one member, so they are similar to row data types, except that the database server can only operate on the individual components with support routines you define in the DataBlade module.

What Does an Opaque Data Type Look Like? The following diagram illustrates an opaque data type called circle, based on a structure called circle_t, in a column called circle_col.

Figure 4. Sample Opaque Type
begin figure description - This figure is described in the surrounding text. - end figure description

The table circle_tab consists of the columns circle_id(SERIAL), color(VARCHAR(15)), and circle_col(circle). The opaque data type circle is defined as a C structure, circle_t, which contains a radius member and another structure, point_t. The point_t structure contains x and y members. To the database server, however, the whole circle_t structure is indivisible, unless you provide accessor functions.

Why Use an Opaque Data Type? Use an opaque type to extend SQL to address fundamentally new data types and allow operations on them. Such data types are typically indivisible or made up of components to which you want to control access.

For example, geographic data and many sorts of rich media data (images, audio, text, and so on) are have been represented by the use of opaque types. Opaque data types often contain smart large objects. Smart large objects are logically stored in a column in a database table but physically stored in a file. For example, an opaque data type for images could have a smart large object member containing the image and other members containing metadata about the image.

Opaque types require more work to create than other data types because you must write all the routines that support them.

Opaque Data Type Support Routines

BladeSmith enables you to generate support routine code for opaque data types. You might have to add code to implement the functionality your opaque data type requires.

The following table describes the support routines you can create and indicates the categories of opaque types for which they are recommended.

Function Recommended for Description
Text input and output All opaque types Convert between external and internal representations.
Send and receive All opaque types Convert between internal representation on the database server and client computers. Not available for Java.
Text import and export All opaque types Process opaque types for bulk loading and unloading as textual data to and from a file.
Import binary and export binary All opaque types Process opaque types for bulk loading and unloading as binary data to and from a file. Not available for Java.
Assign() and Destroy() Large objects and multi-
representational types
Stores or deletes data on disk just before a commit: for example, to ensure proper reference counting on smart large objects. Not available for ActiveX.
LOhandles() Large objects and multi-
representational types
Returns the large object handle or list of large-object handles in opaque types that contain smart large objects. Not available for ActiveX.
Compare() Opaque data types sorted by a B-tree or R-tree index Sorts opaque type data within SQL statements and supports the B-tree and R-tree access method.
Statistics support All opaque types Compile information about the values in an opaque data type column that the optimizer can use to create a query plan. Not available for Java or ActiveX.
More Information

For a description of creating opaque types and their support routines, see the IBM Informix: DataBlade Developer's Kit User's Guide or IBM Informix: User-Defined Routines and Data Types Developer's Guide.

Home | [ Top of Page | Previous Page | Next Page | Contents | Index ]