Progress
Embedded SQL-92
Guide and Reference


Explicit Data Comparison Using tpe_compare_data( )

Use the SQL-92 API function tpe_compare_data to compare two data values of the same type. The syntax for tpe_compare_data is:

SYNTAX
tpe_status_t
tpe_compare_data (dtype, buf1len, buf1, buf2len, buf2, result)
 
int dtype;
int buf1len;
void *buf1;
int buf2len;
void *buf2;
int *result ; 

dtype

Data type of the two values that are being compared.

buf1len

Length of the buffer containing the first value.

buf

A pointer to the buffer containing the first value.

buf2len

Length of the buffer containing the second value.

buf2

A pointer to the buffer containing the second value.

result

An integer that points to a location for returning the result. Table 13–1 shows the range of integer values returned by the tpe_compare_data function into result.

Table 13–1: Values Returned by tpe_compare_data()   
Integer Value
Meaning of Integer Value Returned by tpe_compare_data()
1
First data value is greater than the second data value.
-1
First data value is less than the second data value.
0
The two data values are equal.

dtype

Must be one of the data type symbolic names defined in $DLC/include/sql_lib.h. The defined symbolic names include:

The tpe_compare_data function returns a 0 if the compare operation succeeds. If the compare operation is not successful, the function returns a non-zero status code.

EXAMPLE

The following code fragment shows the comparison of two NUMERIC data elements. This example compares val1_v and val2_v and returns the result in the result_v variable:

EXEC SQL BEGIN DECLARE SECTION ;
     numeric val1_v ;
     numeric val2_v ;
     numeric result_v ;
EXEC SQL END DECLARE SECTION ;
   .
   .
   .
status = tpe_compare_data (TPE_DT_NUMERIC, sizeof(tpe_num_t),
        (void *)&val1_v, sizeof(tpe_num_t), (void *)&val2_v,
        &result_v) ;
if (status == 0)
{
     if (result_v > 0)
          printf("val1_v > val2_v ") ;
     else
          if (result_v < 0)
               printf("val1_v < val2_v ") ;
          else
               printf("val1_v = val2_v ") ;
}
/*
** Error handling logic here, for unsuccessful tpe_compare_data operation.
*/ 


Copyright © 2004 Progress Software Corporation
www.progress.com
Voice: (781) 280-4000
Fax: (781) 280-4095