| Home | Master Index | New Book |
DataBlade Module Example DescriptionsThis section describes the example DataBlade modules provided with the DataBlade Developers Kit. Topic-to-Example TableThe following table lists topics, in alphabetical order, covered by the example DataBlade modules provided with the DataBlade Developers Kit.
Example DescriptionsThe following example DataBlade modules are provided in the dbdk\examples directory:
Most of these examples have a BladeSmith project file (.ibs) and source code, SQL registration scripts for use with BladeManager, simple installation files for use with BladePack, and functional tests. Compiled binaries for the examples are not included and must be rebuilt using the source files. To set up example DataBlade modules, read the readme.txt file in the dbdk\examples directory. The DataBlade module names are links to its main source code file. The Business DataBlade module illustrates how to perform arithmetic calculations with the following user-defined functions:
The udr.c file contains the source code for these user-defined routines. The Circle DataBlade module illustrates representing two-dimensional coordinates and circles with two opaque types (Pnt and Circ). The Circ data type contains the Pnt data type as one of its members. The DataBlade module provides the Contains() function for calculating the distance between two points and the Distance() function for testing whether a circle contains a given point. The following files contain the source code for the Circle DataBlade module: The Color DataBlade module consists of a server project and a client project. The server project defines the Color opaque type, its support routines, and its accessor methods for execution on the server. The client project provides the code that allows Microsoft Visual Basic to instantiate the server opaque type as a client-side ActiveX value object; it also provides the ActiveX custom methods and interfaces with which Visual Basic and the client application developer can access the ActiveX value object. The client program connects to an Informix database table that contains a Color opaque type column, retrieves a row from that table, and then makes use of the ActiveX client project to visualize (display) the data as a color in Visual Basic. The Color data type represents standard RGB color codes. The Color data type has three members: one each for red, green, and blue. The readme.txt file in the dbdk\examples\Types\ActiveX\AxColorDemo directory describes:
The AxColorCommon.cpp and AxColorServer.cpp files contain the editable source code for the Color DataBlade module. The DataBladeAPI DataBlade module illustrates the use of DataBlade API calls and query processing from within a server user-defined routine. It queries for a column in a table and returns the values as a set. It provides the CIter function and a table. The udr.c file contains the source code for the CIter() function. For more information, read the readme.txt file in the dbdk\examples\Routines\dapi\QueryData directory. The FuzzyMatch DataBlade module illustrates:
The FuzzyMatch DataBlade module was designed for a clothing manufacturer that must store information about the clothing it manufactures and retrieve that information based on color. The table holding the clothing data is a typed table based on a row type called ClothingType. The ClothingType row type includes an opaque type called ColorType, which holds color information. Custom handling of a color description is handled by the Input routine ColorTypeInput. This routine assumes that a color description is supplied as a number or a name. The number is an RGB color triplet with each color appearing in the range 0 through 255. If, while reading the color description, ColorTypeInput detects a leading character, rather than a digit, it looks up the name in an external file, called color.map, and uses the associated numeric color value. To locate data based on color, the FuzzyMatch() function checks to see if two colors are in close proximity by computing the distance between two colors using a Euclidean metric on the RGB color values. The value is normalized and examined to see if it is less than the value 0-1, as specified by the SQL user. If so, a match is made, and the clothing data is displayed. The ColorType.c file contains the source code for the ColorType data type support routines. The udr.c file contains the source code for the FuzzyMatch() function. The Matrix DataBlade module illustrates storing and retrieving two-dimensional matrixes, as opaque data types, to and from the database. In addition, it provides user-defined routines that perform arithmetic operations between matrixes of compatible dimensions. The Matrix2d.c file contains the source code for the Matrix2d data type support routines, including the arithmetic functions. The MMX Image DataBlade module illustrates using an opaque data type to store Windows bitmap images and using user-defined functions to enlarge and reduce them. On computers with Intel MMX processors, these functions use MMX instructions to rescale the images. This example is for Windows NT only. The Image.c file contains the source code for the Image data type support routines. The udr.c file contains the source code for the user-defined functions. The MMX Matrix DataBlade module illustrates using MMX technologies with a user-defined function from within a DataBlade module to multiply a matrix by a vector to produce another vector. The VxMmx() function uses MMX code to multiply a matrix and a vector to produce another vector. The udr.c file contains the source code for the VxMmx() function. MMX String Search DataBlade Module The MMX String Search DataBlade module illustrates using MMX technologies with a user-defined function from within a DataBlade module to test for the presence of one string within another. The strstrmmx() function uses MMX assembly code to match the two strings. The udr.c file contains the source code for the strstrmmx() function. The Multirep DataBlade module illustrates using multirepresentational data, which is stored in different ways based on its size. This DataBlade module uses an sbspace to store data too large to fit in a database table row. IMPORTANT: You cannot currently create this DataBlade module using BladeSmith; for information on how to install it, read the Readme.html file in the dbdk\examples\Types\dapi\MultirepLO directory. This DataBlade module creates a variable-length opaque data type, MyUdt, containing an internal array of double-precision floating-point values, support functions for MyUdt, and user-defined routines. These functions are provided:
The myblade.c file contains the source code for the MyUdt data type support routines and the user-defined routines. Parts Explosion DataBlade Module The Parts Explosion DataBlade module provides a simple solution to a parts explosion problem, which finds all dependent child objects for a given parent object. For example, you could find all parts that must be ordered to build the engine of a particular model of automobile. The assumption for this module is that all objects (parts) are stored in one table. This table has at least two columns:
This implementation requires that both the key column and the pointer column be of type INTEGER. Typically, the table also has a description of the object, its price, and so on. This parts explosion solution is limited in that it assumes that an object can be the child of only one parent. This example DataBlade module demonstrates the use of SQL statements within a DataBlade module, how to return a set of results, and the use of the MI_FPARAM structure to return multiple rows. The results of the parts explosion are stored in a linked list in memory allocated by the function before they are returned to the caller. The udr.c file contains the source code for the user-defined routines. The Shapes DataBlade module illustrates how to implement the necessary functionality for an opaque type to support an R-tree index on a column of that type. It contains four opaque data types: MyShape, MyPoint, MyBox, and MyCircle. The MyShape type implements the behavior of all these types; the MyPoint, MyBox, and MyCircle types delegate to the MyShape functions for their functionality. The source code for the Shapes DataBlade module is contained in the following files:
The Strings DataBlade module illustrates GLS support in user-defined routines that manipulate character strings. This DataBlade module also illustrates the creation of custom Input and Output support functions for the CompressedStr data type, an opaque data type containing compressed character data. These functions compress data as it is written to the server and uncompress it as it is written out using Huffman encoding. The Strings DataBlade module has a cast to convert numeric values to a character string: for example, the number 117 is cast to the string "one hundred seventeen." The CompressedStr.c file contains the source code for the CompressedStr data type support routines. The udr.c file contains the source code for the string-manipulation routines. The TopK Terms DataBlade module illustrates taking a set as an argument and returning a set with a user-defined iterator function. The TopK() function finds the top k integer terms from a set of integers. The udr.c file contains the source code for the TopK() function. The UDTExporter DataBlade module illustrates the use of extended data types on an ESQL/C and a C++ client. The UDTExporter DataBlade module contains row data types, collection data types, an opaque data type (ComplexNumber), qualified data types, and distinct data types. Two additional programs are provided: an ESQL/C program, udtexpo.ec, in the dbdk\examples\Client\esqlc\UDTExporter directory; and a C++ program, cppclient.cpp, in the dbdk\examples\Client\c++api\UDTExporter directory. These programs illustrate:
For information on how to run the client programs, see the readme.txt file for ESQL/C client and the readme.txt file for C++. For the ESQL/C program, the ComplexNumber.c file is the source code for the ComplexNumber data type support routines. For the C++ program, the ComplexNumber.c file is the source code for the ComplexNumber data type support routines. |