/* ** Title: FuzzyMatch ** SCCSid: %W% %E% %U% ** CCid: %W% %E% %U% ** Author: Informix Software, Inc. ** Created: 06/11/1998 14:50 ** Description: This is the generated 'C' file for the FuzzyMatch DataBlade. ** Comments: Generated for project FuzzyMatch.3.6 */ /* ** The following is placed here to insure ** that name "mangling" does not occur. */ #ifdef __cplusplus extern "C" { #endif /* Standard library includes. */ #include #include #include #include #include /* Used by Informix GLS routines. */ #include /* Include when accessing the Informix API. */ #include /* This is the project include file. */ #include "FuzzyMatch.h" /**************************************************************** ** ** Function name: ** ** UnPackRow ** ** Description: ** ** Special Comments: ** ** Entrypoint for the SQL routine FuzzyMatch (row,ColorType,double precision,lvarchar) returns boolean. ** ** Parameters: ** ** MI_ROW * Row ** Clothing_t * RowData ** ** Return value: ** ** void ** ** History: ** ** Jul 15, 1997 - Written. ** ***************************************************************** */ void UnPackRow ( MI_ROW * Row, /* The row data. */ Clothing_t * RowData /* Place the data here. */ ) { MI_ROW_DESC * RowDesc; /* The current row descriptor. */ mi_integer NumCols; /* Number of columns in the row. */ mi_integer ColumnIndex; /* Index over columns. */ void * ColValue; /* The unpacked column value. */ mi_integer ColLen; /* The size of the unpacked column. */ /* Get a handle to the data. */ RowDesc = mi_get_row_desc( Row ); /* Determine the number of columns in the row. */ NumCols = mi_column_count( RowDesc ); /* Unpack each data item. */ for( ColumnIndex = -1;++ColumnIndex < NumCols; ) { switch( mi_value( Row, ColumnIndex, &ColValue, &ColLen ) ) { case MI_ERROR: /* Check for error. */ break; case MI_NULL_VALUE: /* Check for a NULL value. */ break; case MI_NORMAL_VALUE: /* Check for an ordinary data value. */ switch( ColumnIndex ) { case 0: /* Unpack the clothing name. */ strcpy( RowData->ClothingName, (char *)mi_get_vardata((mi_lvarchar *)ColValue)); break; case 1: /* Unpack the clothing type. */ strcpy( RowData->ClothingType, (char *)mi_get_vardata((mi_lvarchar *)ColValue)); break; case 2: /* Unpack the size of the garment. */ RowData->Size = (int)ColValue; break; case 3: /* Get the garment's color. */ RowData->Color = (ColorType *)ColValue; break; case 4: /* 'M'ale or 'F'emale. */ RowData->Sex = (int)ColValue; break; case 5: /* Unpack the factory design code. */ RowData->Design = (int)ColValue; break; } } } } #define ABSV(x) (x < 0 ? (x * -1) : x) #define SQRD(x) (x)*(x) /* {{FUNCTION(a9e91f5c-f895-11d0-8885-00a0c9255cf3) (MergeSection) */ /**************************************************************** ** ** Function name: ** ** FuzzyMatch ** ** Description: ** ** Special Comments: ** ** Entrypoint for the SQL routine FuzzyMatch (Clothing_t,ColorType) returns integer. ** ** Parameters: ** ** Return value: ** ** mi_integer ** ** History: ** ** 06/30/1998 - Generated by BladeSmith Version 3.60.630 . ** ** Identification: ** ** NOTE: ** ** BladeSmith will add and remove parameters from the function ** prototype, and will generate tracing calls. ONLY EDIT code ** in blocks marked Your_
. Any other modifications ** will require manual merging. ** ***************************************************************** */ UDREXPORT mi_integer FuzzyMatch ( MI_ROW * Name, ColorType * Color, MI_FPARAM * Gen_fparam /* Standard info - see DBDK docs.*/ ) { MI_CONNECTION * Gen_Con; /* The connection handle. */ mi_integer Gen_RetVal; /* The return value. */ /* ------ {{Your_Declarations (PreserveSection) BEGIN ------ */ Clothing_t RowData; mi_double_precision ColorDistance; /* The distance between two colors. */ mi_integer ReturnValue; /* The distance between two colors. */ /* ------ }}Your_Declarations (#0000) END ------ */ /* Use the NULL connection. */ Gen_Con = NULL; /* ------ {{Your_Code (PreserveSection) BEGIN ------ */ /* Retrieve the data from the current row. */ UnPackRow( Name, &RowData ); /* ** Now that the data has been unpacked, ** determine if the row matches. */ /* Compute the distance between color values. */ ColorDistance = sqrt( SQRD(Color->Red - RowData.Color->Red) + SQRD(Color->Green - RowData.Color->Green) + SQRD(Color->Blue - RowData.Color->Blue) ); /* Normalize between 0 and 100. */ ReturnValue = (int)(ColorDistance / 4.42); Gen_RetVal = ReturnValue; /* ------ }}Your_Code (#L1C9) END ------ */ /* Return the function's return value. */ return Gen_RetVal; } /* }}FUNCTION (#P3M80U5T) */ #ifdef __cplusplus } #endif