Home | Previous Page | Next Page   Creating DataBlade Objects Using BladeSmith > Creating DataBlade Module Objects >

Creating Casts

A cast is a conversion from one data type to another. The cast accepts the source data type as its argument and returns the target data type.

The following table describes the properties you specify when you create a cast.

Property Default Value Description
Cast from type None The source data type.

See Source and Target Data Types for more information.

Cast to type None The target data type. The source and target data types cannot both be built-in or qualified types.

See Source and Target Data Types for more information.

Implicit cast Yes The kind of cast. Implicit casts are automatically called by the database server. Explicit casts are called by the users.

See Implicit and Explicit Casts for more information.

Support routine Yes
typeCast
If the source and target data types do not have the same binary representation, you must write a routine to support the cast.

See Cast Support Functions for more information.

Language (if you choose to create a support function) C Which language to use for the cast support function: C or Java.

You must set server compatibility to 9.2 or later to generate code for Java projects.

You need the J/Foundation upgrade to IBM Informix Dynamic Server to enable Java services.

See the IBM Informix: Guide to SQL Tutorial for general information on casts.

The following sections describe properties of casts.

Source and Target Data Types

You cannot create a cast between two built-in or qualified data types.

You also cannot create a cast that includes any of the following data types as either the source type or target type for the cast:

Implicit and Explicit Casts

You can specify whether a cast is called for implicit conversions. Implicit conversions allow the database server to use the cast when it is not called explicitly in an SQL statement.

For example, if you call the Plus() function with a DOLLAR argument, the database server searches for an implicit cast from DOLLAR to a data type for which the Plus() function is defined. If an implicit cast exists, the database server calls the conversion function and then calls the Plus() function without error. If no cast is specified with implicit conversion, the Plus() function call results in an error message from the database server.

In this example, you create an implicit cast from DOLLAR to DOUBLE PRECISION to permit the database server to execute all functions defined for DOUBLE PRECISION on DOLLAR values. However, if you define a cast from DOLLAR to INTEGER, you do not want that cast to be implicit, because the conversion function truncates dollar values, resulting in inaccurate results.

See IBM Informix: User-Defined Routines and Data Types Developer's Guide for more information on implicit and explicit casts.

Cast Support Functions

If the source and target data types do not have the same binary representation, the database server calls a cast support function to perform the conversion. If the two types have the same binary representation, a cast support function might not be needed. You can also create a cast support function to perform other types of conversions, such as applying a mathematical formula. For example, you could create a cast support function to convert temperature between Fahrenheit and Celsius.

See IBM Informix: User-Defined Routines and Data Types Developer's Guide for more information on creating cast support functions.

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