DataBlade Developers Kit Tutorial |
Tutorial Exercise 3Creating Distinct Data Types and CastsThis exercise demonstrates how to create distinct data types and the casts that convert them. The Mercury DataBlade module contains distinct data types to represent Fahrenheit and Celsius temperatures and casts to convert between the two. You create the distinct data type hierarchy, beginning with the temperature distinct data type, which is based on the built-in double-precision data type. Then you create the CTemp and FTemp types that inherit from temperature, as shown in the following diagram. The Mercury DataBlade module ensures that users cannot enter temperatures below absolute zero in the CTemp and FTemp types. If a user attempts to insert an incorrect value, the INSERT statement fails and returns an error. The DataBlade module uses user-defined support routines and casts to check the input value. Using CastsThe Mercury DataBlade module uses casts in two ways:
The temperature data type is implemented to reduce the number of casts you need to define. If you defined casts from integer and decimal for both CTemp and FTemp, you would create a total of six casts. Instead, you add integer and decimal casts only to the temperature type; the CTemp and FTemp types inherit the casts. This approach reduces the number of casts you have to define from six to four. DataBlade Module ObjectsThe Mercury DataBlade module creates the following user-defined objects.
Tutorial StepsThis exercise consists of 16 steps. It takes approximately one hour to complete.
Start BladeSmith from the Informix program group and choose Project New. Enter the following information into the New Project wizard.
Choose Project Save; create a new directory called Mercury in a convenient place on your hard drive and save your project in this directory as a file called Mercury.ibs.
Copyright © 1998, Informix Software, Inc. All rights reserved. |