DB_STATUS adt_tupcmp( ADF_CB *adf_scb, i4 adt_natts, /* # of attrs in each tuple. */ DB_ATTS *adt_atts, /* Ptr to vector of DB_ATTS, ** 1 for each attr in tuple, and ** in attr order. */ char *adt_tup1, /* Ptr to 1st tuple. */ char *adt_tup2, /* Ptr to 2nd tuple. */ i4 *adt_cmp_result) /* Place to put cmp result. */ { DB_STATUS status; DB_ATTS *atr; /* Ptr to current DB_ATTS */ *adt_cmp_result = 0; status = E_DB_OK; /* Note we always skip 0th entry in DB_ATTS array */ /* As long as there are attributes and they're equal... */ while ( adt_natts-- > 0 && *adt_cmp_result == 0 && status == E_DB_OK ) { atr = ++adt_atts; *adt_cmp_result = adt_compare(adf_scb, atr, adt_tup1 + atr->offset, adt_tup2 + atr->offset, &status); } return(status); }
i4 adt_sortcmp( ADF_CB *adf_scb, DB_CMP_LIST *adt_atts, /* Ptr to vector of DB_CMP_LIST, ** 1 for each attr in tuple, and ** in attr order. */ i4 adt_natts, /* # of attrs in each tuple. */ char *adt_tup1, /* Ptr to 1st tuple. */ char *adt_tup2, /* Ptr to 2nd tuple. */ i4 dif_ret_value) /* ** Value to return if difference found ** is of type DB_DIF_TYPE */ { i4 adt_cmp_result; /* Place to put cmp result. */ DB_STATUS status; /* Used to catch return status ** from the adc_compare() call, ** if the call is made. */ i4 cur_cmp; /* Result of latest attr cmp */ DB_CMP_LIST *atr; /* Ptr to current atts list */ /********************************/ char *d1; /* Ptrs to data in data records */ char *d2; /* for current attributes */ /********************************/ i4 atr_bdt; /* Base datatype of attr */ i4 atr_len; /* Length of cur attribute */ i4 natts = adt_natts; DB_ATTS Datt; for (atr = adt_atts; --natts >= 0; atr++) { d1 = (char *)adt_tup1 + atr->cmp_offset; d2 = (char *)adt_tup2 + atr->cmp_offset; atr_len = atr->cmp_length; if ( (atr_bdt = atr->cmp_type) < 0) { /* Nullable datatype */ i4 d1_isnull = (*((char *)d1 + atr_len - 1) & ADF_NVL_BIT); i4 d2_isnull = (*((char *)d2 + atr_len - 1) & ADF_NVL_BIT); if ( !d1_isnull && !d2_isnull ) { /* Neither is the Null value, look at data */ atr_bdt = -atr_bdt; atr_len--; } else if (d1_isnull && d2_isnull) { continue; /* both are Null values; 1st = 2nd */ } else if (d1_isnull) { /* 1st is Null value; 1st > 2nd */ adt_cmp_result = adt_natts - natts; if (atr->cmp_direction) return (-adt_cmp_result); return (adt_cmp_result); } else if (d2_isnull) { /* 2nd is Null value; 1st < 2nd */ adt_cmp_result = natts - adt_natts; if (atr->cmp_direction) return (-adt_cmp_result); return (adt_cmp_result); } } if ( atr_bdt == DB_DIF_TYPE ) { if ( dif_ret_value ) return(dif_ret_value); continue; } /* Construct a (non-null) DB_ATTS for adt_compare */ Datt.type = atr_bdt; Datt.length = atr_len; Datt.precision = atr->cmp_precision; Datt.collID = atr->cmp_collID; if ( cur_cmp = adt_compare(adf_scb, &Datt, d1, d2, &status) ) { adt_cmp_result = adt_natts - natts; if (cur_cmp < 0) adt_cmp_result = -adt_cmp_result; if (atr->cmp_direction) return (-adt_cmp_result); return (adt_cmp_result); } } return (0); }