| DataBlade Developers Kit Tutorial |
Exercise 5: Creating Opaque Data Types, continued
See " Generating Code" for detailed instructions. BladeSmith generates the basic C code and SQL scripts necessary for your DataBlade module to run:
The BladeSmith portion of this exercise is complete; you can exit BladeSmith.
BladeSmith generates four source code files for the Circle DataBlade module:
For each of the support routine types you selected in the New Opaque Type wizard, BladeSmith generates the following functions for the Pnt and Circ data types.
#include <math.h> Because the rciContains() function calls the rciDistance() function, you must have a definition of the rciDistance() function in the udr.c file before the code for the rciContains() function.
UDREXPORT mi_double_precision *Distance ( Pnt * Pnt1, Pnt * Pnt2, MI_FPARAM * Gen_fparam );
To implement the Distance() function
1. Following the comment containing /* ** TO DO: Remove this comment and call to ** mi_db_error_raise after implementing ** this function. */ mi_db_error_raise( Gen_Con, MI_EXCEPTION, "Function Distance has not been implemented." );
2. Find the comment *Gen_RetVal = sqrt((Pnt1->x - Pnt2->x) * (Pnt1->x - Pnt2->x) + (Pnt1->y - Pnt2->y) * (Pnt1->y - Pnt2->y) );
To implement the Contains() function
1. Between the comments double * dist;
2. Replace the code between the comment /* ** Computes the distance between ** the center of the circle and ** the point. */ dist = Distance( Pnt1, &Circ1->center, Gen_fparam ); /* Is the distance within the radius? */ if( (*dist - Circ1->radius) <= 0 ) { Gen_RetVal = 1; } else { Gen_RetVal = 0; } BladeSmith makes the return value of Contains() an mi_integer, which is the closest available C data type to the SQL Boolean return type you defined. To determine whether the point is contained within the circle, the Contains() function first uses the Distance() function to calculate the distance between the center of the circle and the point. Then the Contains() function subtracts the radius from the distance. If the result is negative, the point is contained by the circle; if the result is positive, the point is outside the circle.
Copyright © 1998, Informix Software, Inc. All rights reserved. |