示例#1
0
II_EXTERN II_VOID
IIapi_cnvtGDV2Descr
(	
    IIAPI_ENVHNDL	*envHndl,
    IIAPI_DT_ID		gcaDataType,
    i4			gcaLength,
    i4			gcaPrecision,
    IIAPI_DESCRIPTOR	*descriptor
)
{
    descriptor->ds_columnType = IIAPI_COL_TUPLE;
    descriptor->ds_dataType = abs( gcaDataType );
    descriptor->ds_nullable = gcaDataType < 0;
    descriptor->ds_length = IIapi_getAPILength( envHndl, gcaDataType,
    						gcaLength, NULL );

    if ( descriptor->ds_dataType == IIAPI_DEC_TYPE )
    {
	descriptor->ds_precision = DB_P_DECODE_MACRO( gcaPrecision );
	descriptor->ds_scale = DB_S_DECODE_MACRO( gcaPrecision );
    }
    else
    {
	descriptor->ds_precision = gcaPrecision;
        descriptor->ds_scale = 0;
    }

    descriptor->ds_columnName = NULL;
    return;
}
示例#2
0
VOID
adu_2prvalue(
i4		    (*fcn)(char *, ...),
DB_DATA_VALUE      *db_dv)
{
    char			num_buf[64];
    i2				flt_wid;
    f8				f8_tmp;
    AD_DTUNION			*dp;
    DB_TAB_LOGKEY_INTERNAL  	*tab_logkey;
    DB_OBJ_LOGKEY_INTERNAL  	*obj_logkey;
    DB_DT_ID			bdt;
    i4				blen;
    i4				prec;
    char			*data;
    char			fmt[16];
    i4			tmp;
    i4			tcnt;
    i4				i;
    i4				res_wid;
    i8				i8_tmp;
    f4				f4_tmp;
    i4				i4_tmp;
    i2				i2_tmp, i2_tmp2;
    i1				i1_tmp;
    char			stbuf[2048];


    if (db_dv == NULL)
    {
	(*fcn)(STprintf(stbuf,"< Pointer to DB_DATA_VALUE is NULL >\n"));
	return;
    }

    bdt  = abs(db_dv->db_datatype);
    blen = db_dv->db_length - (db_dv->db_datatype < 0);
    prec = db_dv->db_prec;
    data = db_dv->db_data;
    dp = (AD_DTUNION*)data;

    if (data == NULL)
    {
	(*fcn)(STprintf(stbuf,"< pointer to data is NULL >\n"));
    }
    else if (ADI_ISNULL_MACRO(db_dv))
    {
	(*fcn)(STprintf(stbuf,"< NULL >\n"));
    }
    else
    {
	switch (bdt)
	{
	  case DB_LOGKEY_TYPE:

	    obj_logkey = (DB_OBJ_LOGKEY_INTERNAL *) data;

	    (*fcn)(STprintf(stbuf, "olk_db_id = %x\tolk_rel_id = %x\n",
		    obj_logkey->olk_db_id, obj_logkey->olk_rel_id));
	    (*fcn)(STprintf(stbuf, "olk_high_id = %x\tolk_low_id = %x\n",
		    obj_logkey->olk_high_id, obj_logkey->olk_low_id));
	    
	    break;

	  case DB_TABKEY_TYPE:

	    tab_logkey = (DB_TAB_LOGKEY_INTERNAL *) data;

	    (*fcn)(STprintf(stbuf, "tlk_high_id = %x\ttlk_low_id = %x\n",
		    tab_logkey->tlk_high_id, tab_logkey->tlk_low_id));

	    break;

	  case DB_CHA_TYPE:
	  case DB_CHR_TYPE:
	  case DB_BYTE_TYPE:
	    if (blen == 0)
	    {
	        (*fcn)(STprintf(stbuf,"''"));
		break;
	    }
	    (*fcn)(STprintf(stbuf, "'%*s'", blen, (u_char *) data));
	    break;

	  case DB_DTE_TYPE:
	    (*fcn)(STprintf(stbuf,
		      "dn_status = %x\tdn_highday = %d\tdn_time = %d\n",
		      dp->ing_date.dn_status, dp->ing_date.dn_highday, dp->ing_date.dn_time));
	    (*fcn)(STprintf(stbuf,
		      "dn_year = %d\tdn_month = %d\tdn_lowday = %d",
		      dp->ing_date.dn_year, dp->ing_date.dn_month, dp->ing_date.dn_lowday));
	    break;

	  case DB_ADTE_TYPE:
	    (*fcn)(STprintf(stbuf,"dn_year = %d\tdn_month = %d\tdn_day = %d\n",
		      dp->adate.dn_year, dp->adate.dn_month, dp->adate.dn_day));
	    break;

	  case DB_TMWO_TYPE:
	  case DB_TMW_TYPE:
	  case DB_TME_TYPE:
	    (*fcn)(STprintf(stbuf,"dn_seconds = %d\tdn_nsecond = %d\n",
		      dp->atime.dn_seconds, dp->atime.dn_nsecond));
	    (*fcn)(STprintf(stbuf,"dn_tzoffset = %d\n",
		      AD_TZ_OFFSET(&dp->atime)));
	    break;

	  case DB_INYM_TYPE:
	    (*fcn)(STprintf(stbuf,"dn_years = %d\tdn_months = %d\n",
		      dp->aintym.dn_years, dp->aintym.dn_months));
	    break;

	  case DB_INDS_TYPE:
	    (*fcn)(STprintf(stbuf,"dn_days = %d\tdn_seconds = %d\tdn_nseconds = %d\n",
		      dp->aintds.dn_days, dp->aintds.dn_seconds, dp->aintds.dn_nseconds));
	    break;

	  case DB_TSWO_TYPE:
	  case DB_TSW_TYPE:
	  case DB_TSTMP_TYPE:
	    (*fcn)(STprintf(stbuf,"dn_year = %d\tdn_month = %d\tdn_day = %d\n",
		      dp->atimestamp.dn_year, dp->atimestamp.dn_month, dp->atimestamp.dn_day));
	    (*fcn)(STprintf(stbuf,"dn_seconds = %d\tdn_nsecond = %d\n",
		      dp->atimestamp.dn_seconds, dp->atimestamp.dn_nsecond));
	    (*fcn)(STprintf(stbuf,"dn_tzoffset = %d\n",
		      AD_TZ_OFFSET(&dp->atimestamp)));
	    break;

	  case DB_DEC_TYPE:
	    CVpka(data,
		(i4)DB_P_DECODE_MACRO(prec),
		(i4)DB_S_DECODE_MACRO(prec),
		'.',
		(i4)DB_P_DECODE_MACRO(prec) + 5,
		(i4)DB_S_DECODE_MACRO(prec),
		CV_PKLEFTJUST,
		num_buf,
		&res_wid);
		
	    tmp = res_wid;
	    i = 0;
	    fmt[i++] = '%';
	    if (tmp >= 10)
	    {
		fmt[i++] = (tmp / 10) + '0';
		tmp = tmp % 10;
	    }
	    fmt[i++] = tmp + '0';
	    fmt[i++] = 's';
	    fmt[i] = EOS;
	    (*fcn)(STprintf(stbuf, fmt, num_buf));
	    break;
	    
	  case DB_FLT_TYPE:
	    if (blen == 4)
	    {
		F4ASSIGN_MACRO(*data, f4_tmp);
		f8_tmp = f4_tmp;
	    }
	    else
		F8ASSIGN_MACRO(*data, f8_tmp);

	    CVfa(f8_tmp, (i4) sizeof(num_buf), (i4) 4, 'f', '.', num_buf, &flt_wid);
	    (*fcn)(STprintf(stbuf, "%*s", flt_wid, (u_char *)num_buf));
	    break;

	  case DB_INT_TYPE:
	    if (blen == 4)
	    {
		I4ASSIGN_MACRO(*data, i4_tmp);
	    }
	    else if (blen == 2)
	    {
		I2ASSIGN_MACRO(*data, i2_tmp);
		i4_tmp = i2_tmp;
	    }
	    else if (blen == 1)
	    {
		i4_tmp = I1_CHECK_MACRO(*(i1 *)data);
	    }
	    else /* blen == 8 */
	    {
		/* Depending on host, printing i8's might be %ld (lp64)
		** or %lld (lpi32).  Avoid issues by converting to string.
		*/
		I8ASSIGN_MACRO(*data,i8_tmp);
		CVla8(i8_tmp,&num_buf[0]);
		(*fcn)(num_buf);
		break;
	    }
	    (*fcn)(STprintf(stbuf, "%d", i4_tmp));
	    break;

	  case DB_MNY_TYPE:
	    f8_tmp = ((AD_MONEYNTRNL *) data)->mny_cents / 100.0;
	    CVfa(f8_tmp, 32, 2, 'f', '.', num_buf, &flt_wid);
	    tmp = flt_wid;
	    i = 0;
	    fmt[i++] = '%';
	    if (flt_wid >= 100)
	    {
		fmt[i++] = (tmp / 100) + '0';
		tmp = tmp % 100;
	    }
	    if (flt_wid >= 10)
	    {
		fmt[i++] = (tmp / 10) + '0';
		tmp = tmp % 10;
	    }
	    fmt[i++] = tmp + '0';
	    fmt[i++] = 's';
	    fmt[i] = EOS;
	    (*fcn)(STprintf(stbuf, fmt, num_buf));
	    break;

	  case DB_VCH_TYPE:
	  case DB_TXT_TYPE:
	  case DB_LTXT_TYPE:
	  case DB_VBYTE_TYPE:
	    I2ASSIGN_MACRO(((DB_TEXT_STRING *)data)->db_t_count, i2_tmp);
	    if (i2_tmp == 0)
	    {
	        (*fcn)(STprintf(stbuf,"''"));
		break;
	    }
	    (*fcn)(STprintf(stbuf, "'%*s'", i2_tmp, ((DB_TEXT_STRING *) data)->db_t_text));
	    break;

	  case DB_BOO_TYPE:
	    if (*((bool *) data))
	        (*fcn)(STprintf(stbuf,"TRUE"));
	    else
	        (*fcn)(STprintf(stbuf,"FALSE"));
	    break;

	  case DB_NCHR_TYPE:
	    for(i=0; i< blen/2; i++)
	    {
                I2ASSIGN_MACRO(data[2*i], i2_tmp);
                i4_tmp = i2_tmp;
                (*fcn)(STprintf(stbuf,"%x ", i4_tmp));
	     }
             break;

          case DB_NVCHR_TYPE:
          case DB_PAT_TYPE:
            I2ASSIGN_MACRO(((DB_NVCHR_STRING *)data)->count, i2_tmp);
	    if (bdt == DB_PAT_TYPE)
		i2_tmp = 4;
	    for(i=0; i< i2_tmp; i++)
            {
                I2ASSIGN_MACRO(((DB_NVCHR_STRING *)data)->element_array[i], i2_tmp2);
                i4_tmp = i2_tmp2;
		(*fcn)(STprintf(stbuf,"%x ", i4_tmp));
             }
             break;

	  case DB_LVCH_TYPE:
  	  case DB_LBYTE_TYPE:
  	  case DB_GEOM_TYPE:
          case DB_POINT_TYPE:
          case DB_MPOINT_TYPE:
          case DB_LINE_TYPE:
          case DB_MLINE_TYPE:
          case DB_POLY_TYPE:
          case DB_MPOLY_TYPE:
          case DB_GEOMC_TYPE:
	  case DB_LNVCHR_TYPE:
	    {
		ADP_PERIPHERAL	    *p = (ADP_PERIPHERAL *) data;
		ADP_COUPON	    *cpn;
		
		(*fcn)(STprintf(stbuf, "%s/length = (%d., %0d.):  ",
			(p->per_tag == ADP_P_COUPON ? "ADP_P_COUPON" :
				    "ADP_P_DATA"),
			p->per_length0, p->per_length1));
		if (p->per_tag == ADP_P_COUPON)
		{
		    cpn = &p->per_value.val_coupon;
		    
#if defined(axp_osf) || defined(ris_u64) || defined(LP64) || \
    defined(axp_lnx)
		    (*fcn)(STprintf(stbuf, "(%d.,%d.,%d.,%d.,%d.,%d.)",
			cpn->cpn_id[0],cpn->cpn_id[1],
			cpn->cpn_id[2],cpn->cpn_id[3],
			cpn->cpn_id[4],cpn->cpn_id[5]));
#else
		    (*fcn)(STprintf(stbuf, "(%d.,%d.,%d.,%d.,%d.)",
			cpn->cpn_id[0],cpn->cpn_id[1],
			cpn->cpn_id[2],cpn->cpn_id[3],
			cpn->cpn_id[4]));
#endif
		}
		else
		{
		    (*fcn)(STprintf(stbuf, "(first %d. of value) '%t'",
			    min(100, p->per_length1),
			    min(100, p->per_length1),
			    p->per_value.val_value));
		}
			
	    }
	    break;
	  default:
	    (*fcn)(STprintf(stbuf,
		    "< unknown type: don't know how to interpret data >"));
	    break;
	}
    }

    return;
}
示例#3
0
VOID
adu_prdv(
DB_DATA_VALUE      *db_dv)
{
    DB_DT_ID	dt;
    DB_DT_ID	bdt;
    i4		len;
    i4		blen;
    PTR		data;

    if (db_dv == NULL)
    {
	TRdisplay("< Pointer to DB_DATA_VALUE is NULL >\n");
	return;
    }

    dt   = bdt  = db_dv->db_datatype;
    len  = blen = db_dv->db_length;
    data        = db_dv->db_data;
    if (dt < 0)
    {
	bdt = -dt;
	blen--;
    }

    TRdisplay("type: %d (", (i4) dt);
    adu_prtype(db_dv);
    TRdisplay(");    prec: [%d,%d]   length: %d\n",
		(i4)DB_P_DECODE_MACRO(db_dv->db_prec),
		(i4)DB_S_DECODE_MACRO(db_dv->db_prec),
		(i4) len);

    if (data == NULL)
    {
	TRdisplay("< pointer to data is NULL >\n");
    }
    else if (ADI_ISNULL_MACRO(db_dv))
    {
	TRdisplay("value: < NULL >\n");
    }
    else
    {
	switch (bdt)
	{
	  case DB_CHA_TYPE:
	  case DB_CHR_TYPE:
	  case DB_DEC_TYPE:
	  case DB_FLT_TYPE:
	  case DB_INT_TYPE:
	  case DB_MNY_TYPE:
	  case DB_BOO_TYPE:
	  case DB_LOGKEY_TYPE:
	  case DB_TABKEY_TYPE:
	  case DB_BYTE_TYPE:
	  case DB_NCHR_TYPE:
	    TRdisplay("value: ");
	    break;

	  case DB_VCH_TYPE:
	    TRdisplay("varchar count: %d\n", 
				((DB_TEXT_STRING *) data)->db_t_count);
	    break;

	  case DB_VBYTE_TYPE:
	    TRdisplay("varbyte count: %d\n", 
				((DB_TEXT_STRING *) data)->db_t_count);
	    break;

	  case DB_PAT_TYPE:
	    TRdisplay("pattern length: %d\n",
				((DB_TEXT_STRING *) data)->db_t_count);
	    break;

	  case DB_TXT_TYPE:
	    TRdisplay("text count: %d\n",
				((DB_TEXT_STRING *) data)->db_t_count);
	    break;

	  case DB_LTXT_TYPE:
	    TRdisplay("longtext count: %d\n", 
				((DB_TEXT_STRING *) data)->db_t_count);
	    break;

	case DB_NVCHR_TYPE:
	    TRdisplay("nvarchar count: %d\n",
                                ((DB_NVCHR_STRING *) data)->count);

	  case DB_DTE_TYPE:
	  case DB_ADTE_TYPE:
	  case DB_TMWO_TYPE:
	  case DB_TMW_TYPE:
	  case DB_TME_TYPE:
	  case DB_TSWO_TYPE:
	  case DB_TSW_TYPE:
	  case DB_TSTMP_TYPE:
	  case DB_INYM_TYPE:
	  case DB_INDS_TYPE:
	  default:
	    break;
	}

	adu_prvalue(db_dv);
	TRdisplay("\n");
    }

    return;
}
示例#4
0
STATUS
adu_sc930prtdataval(
i4 msg_type,
char *parameter_name,
i4 parameter_no,
DB_DATA_VALUE      *db_dv,
ADF_CB *tzcb,
PTR file)
{
    char			num_buf[64];
    i2				flt_wid;
    f8				f8_tmp;
    AD_NEWDTNTRNL		dateval;
    AD_NEWDTNTRNL		*datep=&dateval;
    DB_TAB_LOGKEY_INTERNAL  	*tab_logkey;
    DB_OBJ_LOGKEY_INTERNAL  	*obj_logkey;
    DB_DT_ID			bdt;
    DB_STATUS			db_stat;
    i4				blen;
    i4				prec;
    char			*data;
    char			fmt[16];
    i4			tmp;
    i4			tcnt;
    i4				i;
    i4				res_wid;
    f4				f4_tmp;
    i4				i4_tmp;
    i2				i2_tmp, i2_tmp2;
    i1				i1_tmp;
    u_char 			u_tmp_i1;
    char			stbuf[SC930_DATAVAL_BUFSIZE];
    AD_DTUNION			*dp;
    i8				i8_tmp;
    char			*c_tmp,*c_buf_end;


    if (db_dv == NULL)
    {
	SIfprintf(file, "< Pointer to DB_DATA_VALUE is NULL >\n");
	return E_DB_ERROR;
    }

    if (parameter_name)
    {
	    STprintf(stbuf,"%d:%d(%s)=",
		db_dv->db_datatype,
		parameter_no,
	        parameter_name);
    } else
    {
	    STprintf(stbuf,"%d:%d=",
		db_dv->db_datatype,
	        parameter_no);
    }

    /* output the PARM/PARMEXEC 'header' to the trace file */
    switch (msg_type)
    {
	    case SC930_LTYPE_PARM:
		    SIfprintf(file,"PARM:%s",stbuf);
		    break;
	    case SC930_LTYPE_PARMEXEC:
		    SIfprintf(file,"PARMEXEC:%s",stbuf);
		    break;
	    default:
		    SIfprintf(file,"UNKNOWN:%s",stbuf);
    }

    bdt  = abs(db_dv->db_datatype);
    blen = db_dv->db_length - (db_dv->db_datatype < 0);
    prec = db_dv->db_prec;
    data = db_dv->db_data;

    if (data == NULL)
    {
	SIfprintf(file, "< pointer to data is NULL >\n");
	return E_DB_ERROR;
    }
    else if (ADI_ISNULL_MACRO(db_dv))
    {
	SIfprintf(file, "< NULL >\n");
	return OK;
    }
    else
    {
	switch (bdt)
	{
	  case DB_LOGKEY_TYPE:

	    obj_logkey = (DB_OBJ_LOGKEY_INTERNAL *) data;

	    SIfprintf(file, "olk_high_id = %x\tolk_low_id = %x\t"
				   "olk_rel_id = %d\tolk_db_id = %d\n" ,
		    obj_logkey->olk_high_id, obj_logkey->olk_low_id,
		    obj_logkey->olk_rel_id, obj_logkey->olk_db_id);
	    
	    break;

	  case DB_TABKEY_TYPE:

	    tab_logkey = (DB_TAB_LOGKEY_INTERNAL *) data;

	    SIfprintf(file, "tlk_high_id = %x\ttlk_low_id = %x\n",
		    tab_logkey->tlk_high_id, tab_logkey->tlk_low_id);

	    break;

	  case DB_CHA_TYPE:
	  case DB_CHR_TYPE:
	    if (blen == 0)
		SIfprintf(file, "''\n");
	    else
	        SIfprintf(file, "'%*s'\n", blen, (u_char *) data);

	    break;

	  case DB_DTE_TYPE:
	    db_stat = adu_6to_dtntrnl (tzcb, db_dv, datep);

	    if (datep->dn_status == 0)
	    {
		SIfprintf(file, "''\n");
		break;
	    }

	    SIfprintf(file,
		"(%s) %d/%d/%d %d:%d:%d.%.3d (%d)\n",
		(datep->dn_status & AD_DN_ABSOLUTE)?
		    ((datep->dn_status & AD_DN_TIMESPEC)?"DATETIME":"DATE")
		    :"INTERVAL",
		(i2)datep->dn_year,(i2)datep->dn_month,datep->dn_day,
		datep->dn_seconds / AD_39DTE_ISECPERHOUR,
		(datep->dn_seconds / AD_10DTE_ISECPERMIN) % 60,
		datep->dn_seconds % 60,
		(datep->dn_nsecond % AD_29DTE_NSPERMS), AD_TZ_OFFSETNEW(datep));
	    break;

	  case DB_ADTE_TYPE:
	    dp = (AD_DTUNION*)data;
	    SIfprintf(file,"%d/%d/%d\n",
		dp->adate.dn_year, dp->adate.dn_month, dp->adate.dn_day);
	    break;

	  case DB_TMWO_TYPE:
	  case DB_TMW_TYPE:
	  case DB_TME_TYPE:
	    dp = (AD_DTUNION*)data;
	    SIfprintf(file,"%d,%d +/- %d\n",
		dp->atime.dn_seconds, dp->atime.dn_nsecond,
		AD_TZ_OFFSET(&dp->atime));
	    break;

	  case DB_INYM_TYPE:
	    dp = (AD_DTUNION*)data;
	    SIfprintf(file,"%d %d\n",dp->aintym.dn_years, dp->aintym.dn_months);
	    break;

	  case DB_INDS_TYPE:
	    dp = (AD_DTUNION*)data;
	    SIfprintf(file,"%d %d %d\n", dp->aintds.dn_days,
		dp->aintds.dn_seconds, dp->aintds.dn_nseconds);
	    break;

	  case DB_TSWO_TYPE:
	  case DB_TSW_TYPE:
	  case DB_TSTMP_TYPE:
	    dp = (AD_DTUNION*)data;
	    SIfprintf(file,"%d/%d/%d %d %d (%d)\n",
		dp->atimestamp.dn_year, dp->atimestamp.dn_month,
		dp->atimestamp.dn_day,
		dp->atimestamp.dn_seconds, dp->atimestamp.dn_nsecond,
		AD_TZ_OFFSET(&dp->atimestamp));
	    break;
	  
	  case DB_DEC_TYPE:
	    CVpka(data,
		(i4)DB_P_DECODE_MACRO(prec),
		(i4)DB_S_DECODE_MACRO(prec),
		'.',
		(i4)DB_P_DECODE_MACRO(prec) + 5,
		(i4)DB_S_DECODE_MACRO(prec),
		CV_PKLEFTJUST,
		num_buf,
		&res_wid);
		
	    tmp = res_wid;
	    i = 0;
	    fmt[i++] = '%';
	    if (tmp >= 10)
	    {
		fmt[i++] = (tmp / 10) + '0';
		tmp = tmp % 10;
	    }
	    fmt[i++] = tmp + '0';
	    fmt[i++] = 's';
	    fmt[i++] = '\n';
	    fmt[i] = EOS;
	    SIfprintf(file, fmt, num_buf);
	    break;
	    
	  case DB_FLT_TYPE:
	    if (blen == 4)
	    {
		F4ASSIGN_MACRO(*data, f4_tmp);
		f8_tmp = f4_tmp;
	    }
	    else
		F8ASSIGN_MACRO(*data, f8_tmp);

	    CVfa(f8_tmp, (i4) sizeof(num_buf), (i4) 4, 'f', '.', num_buf, &flt_wid);
	    SIfprintf(file, "%*s\n", flt_wid, (u_char *) num_buf);
	    break;

	  case DB_INT_TYPE:
	    if (blen == 4)
	    {
		I4ASSIGN_MACRO(*data, i4_tmp);
	    }
	    else if (blen == 2)
	    {
		I2ASSIGN_MACRO(*data, i2_tmp);
		i4_tmp = i2_tmp;
	    }
	    else if (blen == 1)
	    {
		i4_tmp = I1_CHECK_MACRO(*(i1 *)data);
	    } else /* blen == 8 */
	    {
		I8ASSIGN_MACRO(*data,i8_tmp);
		CVla8(i8_tmp,num_buf);
	        SIfprintf(file, "%s\n", num_buf);
		break;
	    }
	    SIfprintf(file, "%d\n", i4_tmp);
	    break;

	  case DB_MNY_TYPE:
	    f8_tmp = ((AD_MONEYNTRNL *) data)->mny_cents / 100.0;
	    CVfa(f8_tmp, 32, 2, 'f', '.', num_buf, &flt_wid);
	    tmp = flt_wid;
	    i = 0;
	    fmt[i++] = '%';
	    if (flt_wid >= 100)
	    {
		fmt[i++] = (tmp / 100) + '0';
		tmp = tmp % 100;
	    }
	    if (flt_wid >= 10)
	    {
		fmt[i++] = (tmp / 10) + '0';
		tmp = tmp % 10;
	    }
	    fmt[i++] = tmp + '0';
	    fmt[i++] = 's';
	    fmt[i++] = '\n';
	    fmt[i] = EOS;
	    SIfprintf(file, fmt, num_buf);
	    break;

	  case DB_VCH_TYPE:
	  case DB_TXT_TYPE:
	  case DB_LTXT_TYPE:
	    I2ASSIGN_MACRO(((DB_TEXT_STRING *)data)->db_t_count, i2_tmp);
	    if (i2_tmp == 0)
	    {
		SIfprintf(file, "''\n");
	    }
	    else
	    {
	        SIfprintf(file, "'%*s'\n", i2_tmp, ((DB_TEXT_STRING *) data)->db_t_text);
	    }

	    break;

	  case DB_BOO_TYPE:
	    if (*((bool *) data))
		SIfprintf(file,"TRUE\n");
	    else
		SIfprintf(file,"FALSE\n");
	    break;

	  case DB_VBYTE_TYPE:
            I2ASSIGN_MACRO(((DB_TEXT_STRING *)data)->db_t_count, i2_tmp);
	    blen=i2_tmp;
	    data = ((DB_TEXT_STRING *)data)->db_t_text;

	  case DB_BYTE_TYPE:
	    c_tmp=stbuf;
	    c_buf_end=c_tmp + SC930_DATAVAL_BUFSIZE - 10;
	    STprintf(c_tmp,"%d:",blen);
	    c_tmp += STlength(c_tmp);
	    for(i=0; i< blen; i++)
	    {
                u_tmp_i1=(u_char) data[i];
                STprintf(c_tmp,"%02x ", u_tmp_i1);
		c_tmp += 3;
		if (c_tmp > c_buf_end )
		{
		  SIfprintf(file,stbuf);
		  c_tmp=stbuf;
		  stbuf[0]=EOS;
		}

	    }
            SIfprintf(file,"%s\n",stbuf);
            break;

	  case DB_NCHR_TYPE:
	    stbuf[0] = EOS;
	    c_tmp = stbuf;
	    c_buf_end=c_tmp + SC930_DATAVAL_BUFSIZE - 10;
	    for(i=0; i< blen/2; i++)
	    {
                I2ASSIGN_MACRO(data[2*i], i2_tmp);
                i4_tmp = i2_tmp;
                STprintf(c_tmp,"%x ", i4_tmp);
		c_tmp += STlength(c_tmp);
		if (c_tmp > c_buf_end )
		{
		  SIfprintf(file,stbuf);
		  c_tmp=stbuf;
		  stbuf[0]=EOS;
		}
	     }
             SIfprintf(file,"%s\n",stbuf);
             break;

          case DB_NVCHR_TYPE:
            I2ASSIGN_MACRO(((DB_NVCHR_STRING *)data)->count, i2_tmp);
	    stbuf[0] = EOS;
	    c_tmp = stbuf;
	    c_buf_end=c_tmp + SC930_DATAVAL_BUFSIZE - 10;
	    for(i=0; i< i2_tmp; i++)
            {
                I2ASSIGN_MACRO(((DB_NVCHR_STRING *)data)->element_array[i], i2_tmp2);
                i4_tmp = i2_tmp2;
                STprintf(c_tmp,"%x ", i4_tmp);
		c_tmp += STlength(c_tmp);
		if (c_tmp > c_buf_end )
		{
		  SIfprintf(file,stbuf);
		  c_tmp=stbuf;
		  stbuf[0]=EOS;
		}
             }
             SIfprintf(file,"%s\n",stbuf);
             break;

	  case DB_LVCH_TYPE:
  	  case DB_LBYTE_TYPE:
  	  case DB_GEOM_TYPE:
          case DB_POINT_TYPE:
          case DB_MPOINT_TYPE:
          case DB_LINE_TYPE:
          case DB_MLINE_TYPE:
          case DB_POLY_TYPE:
          case DB_MPOLY_TYPE:
          case DB_GEOMC_TYPE:
	  case DB_LNVCHR_TYPE:
	    {
		ADP_PERIPHERAL	*p = (ADP_PERIPHERAL *) data;
		ADP_COUPON	*cpn;
		DB_DATA_VALUE	dv_work;
		char tmp_val[DB_MAXSTRING + 1] = {0};
		i4 i;
		
		dv_work.db_datatype = DB_CHA_TYPE;
		dv_work.db_length = DB_MAXSTRING;
		dv_work.db_data = tmp_val;

		adu_lvch_move(tzcb, db_dv, &dv_work);

		i = DB_MAXSTRING;
		while (dv_work.db_data[i] == ' ')
			dv_work.db_data[i--] = EOS;

		SIfprintf(file, "(%d/%d):'%s'\n",p->per_length0,p->per_length1,
			dv_work.db_data);
	    }
	    break;

	  default:
            SIfprintf(file,
	        "< unknown type: don't know how to interpret data >\n");
            return E_DB_ERROR;
	}
    }

    return OK;
}
示例#5
0
DB_STATUS
adu_copascii(
ADF_CB		*adf_scb,
DB_DATA_VALUE	*dv1,
DB_DATA_VALUE	*rdv)
{
    register char       *p;
    char		temp[ADI_OUTMXFIELD];
    i4			leftfill;
    i4			plen;
    i4			str_len;
    i2			out_width;

    p = temp;

    switch(dv1->db_datatype)
    {
      case DB_INT_TYPE:
        if (dv1->db_length == 8)
        {
            CVla8(*(i8 *) dv1->db_data, p);
        }
        else if (dv1->db_length == 4)
        {
            CVla(*(i4 *) dv1->db_data, p);
        }
        else if (dv1->db_length == 2)
        {
            CVla((i4) *(i2 *) dv1->db_data, p);
        }
        else
        {
            CVla(I1_CHECK_MACRO(*(i1 *) dv1->db_data), p);
        }

        break;

      case DB_DEC_TYPE:
	{
	    i4		pr = DB_P_DECODE_MACRO(dv1->db_prec);
	    i4		sc = DB_S_DECODE_MACRO(dv1->db_prec);
	    i4		available_width = rdv->db_length;
	    char	decimal = (adf_scb->adf_decimal.db_decspec
					? (char) adf_scb->adf_decimal.db_decimal
					: '.'
				  );
				  
	    if (    rdv->db_datatype == DB_VCH_TYPE
		||  rdv->db_datatype == DB_TXT_TYPE
		||  rdv->db_datatype == DB_LTXT_TYPE
	       )
		available_width -= DB_CNTSIZE;

	    /* now convert to ascii: use formula from lenspec for length, get
	    ** scale # of digits after decimal point, use left-justify
	    */
	    if (CVpka((PTR)dv1->db_data, pr, sc, decimal,
		    AD_PS_TO_PRN_MACRO(pr, sc), sc, CV_PKLEFTJUST, p, &str_len)
		== CV_OVERFLOW)
	    {
		/* this should never happen */
		return(adu_error(adf_scb, E_AD9999_INTERNAL_ERROR, 0));
	    }

	    if (str_len > available_width)
		return(adu_error(adf_scb, E_AD1030_F_COPY_STR_TOOSHORT, 0));
	}
        break;

      case DB_FLT_TYPE:
	{
	    char    decimal = (adf_scb->adf_decimal.db_decspec ?
				(char) adf_scb->adf_decimal.db_decimal : '.');
	    i4	    available_width = rdv->db_length;


	    if (    rdv->db_datatype == DB_VCH_TYPE
		||  rdv->db_datatype == DB_TXT_TYPE
		||  rdv->db_datatype == DB_LTXT_TYPE
	       )
		available_width -= DB_CNTSIZE;

	    if (dv1->db_length == 4)
	    {
		f8 f8tmp = (f8) *(f4 *) dv1->db_data;

                /*  BUG : b119968
		**
		**  CVfa is a utility routine for both f8 and f4 floats.
		**  In the f4 case, the value is converted to f8 prior 
		**  to call (as here).
		**
		**  This works well except for the boundary case, where 
		**  the f4 is FLT_MAX. In this case, an effective 
		**  rounding up of the f8 that occurs as we convert to 
		**  a string (eventually through fcvt) "overflows" the 
		**  original f4 value.
		**
		**  We bump down the last sig bit of the f4, and then
		**  we have no problems.
		*/
		if ( f8tmp == FLT_MAX )
		{
		    f8tmp = FLT_MAX_ROUND;
		} 
                else if ( f8tmp == -FLT_MAX ) 
		{
		    f8tmp = -FLT_MAX_ROUND;
		} 
		CVfa(f8tmp,
		     adf_scb->adf_outarg.ad_f4width,
		     adf_scb->adf_outarg.ad_f4prec,
		     adf_scb->adf_outarg.ad_f4style,
		     decimal, p, &out_width);

		if (out_width > available_width)
		    return(adu_error(adf_scb, E_AD1030_F_COPY_STR_TOOSHORT, 0));
	    }
	    else
	    {
		CVfa(*(f8 *)dv1->db_data,
		     adf_scb->adf_outarg.ad_f8width,
		     adf_scb->adf_outarg.ad_f8prec,
		     adf_scb->adf_outarg.ad_f8style,
		     decimal, p, &out_width);

		if (out_width > available_width)
		    return(adu_error(adf_scb, E_AD1030_F_COPY_STR_TOOSHORT, 0));
	    }
	}
	break;

      default:
	return(adu_error(adf_scb, E_AD5002_BAD_NUMBER_TYPE, 0));
    }

    while (*p == ' ')
        p++;

    /*
    ** TEXT, VARCHAR, and LONGTEXT are variable length copies,
    ** so no need to pad on the left.
    */
    if (    rdv->db_datatype == DB_TXT_TYPE
	||  rdv->db_datatype == DB_VCH_TYPE
	||  rdv->db_datatype == DB_LTXT_TYPE
       )	
    {
        return(adu_movestring(adf_scb, (u_char *) p, 
				(i4) STlength(p), dv1->db_datatype, rdv));
    }

    /*
    ** At this point the result type can be C or CHAR
    */
    plen     = min(STlength(p), rdv->db_length);
    leftfill = rdv->db_length - plen;

    MEfill(leftfill, ' ', rdv->db_data);
    MEcopy((PTR)p, plen, (PTR)((char *)rdv->db_data + leftfill));

    return(E_DB_OK);
}
示例#6
0
DB_STATUS
adu_ascii(
ADF_CB			*adf_scb,
register DB_DATA_VALUE	*dv1,
DB_DATA_VALUE		*rdv)
{
    DB_STATUS           db_stat = E_DB_OK;
    register char       *p;
    char		temp[ADI_OUTMXFIELD]; /* could probably be smaller */
    u_char		*str_addr;
    i4			str_len;
    i2			reswidth;
    bool		char_text = FALSE;
    i8			i8_tmp = 0;

    p = temp;

    switch(dv1->db_datatype)
    {
      case DB_INT_TYPE:
        if (dv1->db_length == 8)
	{
            CVla8(*(i8 *) dv1->db_data, p);
	}
        else if (dv1->db_length == 4)
        {
            CVla(*(i4 *) dv1->db_data, p);
        }
        else if (dv1->db_length == 2)
        {
            CVla((i4) (*(i2 *) dv1->db_data), p);
        }
        else
        {
            CVla(I1_CHECK_MACRO(*(i1 *) dv1->db_data), p);
        }

        break;

      case DB_BOO_TYPE:
        if (((DB_ANYTYPE *)dv1->db_data)->db_booltype == DB_FALSE)
            STcopy("FALSE", p);
        else
            STcopy("TRUE", p);
        break;

      case DB_VCH_TYPE:
      case DB_CHA_TYPE:
      case DB_CHR_TYPE:
      case DB_TXT_TYPE:
      case DB_LTXT_TYPE:
      case DB_BYTE_TYPE:
      case DB_VBYTE_TYPE:
	if ((db_stat = adu_3straddr(adf_scb, dv1, (char **) &str_addr)))
	    return(db_stat);
	if ((db_stat = adu_size(adf_scb, dv1, &str_len)))
	    return(db_stat);
        if ((db_stat = adu_movestring(adf_scb, str_addr, str_len, 
					dv1->db_datatype, rdv)))
	    return(db_stat);
        char_text = TRUE;

        break;

      case DB_DEC_TYPE:
	{
	    i4		pr = DB_P_DECODE_MACRO(dv1->db_prec);
	    i4		sc = DB_S_DECODE_MACRO(dv1->db_prec);
	    char	decimal = (adf_scb->adf_decimal.db_decspec
					? (char) adf_scb->adf_decimal.db_decimal
					: '.'
				  );
				  
	    /* now convert to ascii: use formula from lenspec for length, get
	    ** scale # of digits after decimal point, use left-justify option
	    */
	    if (CVpka((PTR)dv1->db_data, pr, sc, decimal,
		    AD_PS_TO_PRN_MACRO(pr, sc), sc, CV_PKLEFTJUST, p, &str_len)
		== CV_OVERFLOW)
	    {
		/* this should never happen */
		return(adu_error(adf_scb, E_AD9999_INTERNAL_ERROR, 0));
	    }
	}
        break;

      case DB_FLT_TYPE:
	{
	    char    decimal = (adf_scb->adf_decimal.db_decspec ?
				(char) adf_scb->adf_decimal.db_decimal : '.');
	    
	    if (dv1->db_length == 4)
	    {
		CVfa((f8) *(f4 *) dv1->db_data,
		     adf_scb->adf_outarg.ad_f4width,
		     adf_scb->adf_outarg.ad_f4prec,
		     adf_scb->adf_outarg.ad_f4style,
		     decimal, p, &reswidth);
	    }
	    else
	    {
		CVfa(*(f8 *)dv1->db_data,
		     adf_scb->adf_outarg.ad_f8width,
		     adf_scb->adf_outarg.ad_f8prec,
		     adf_scb->adf_outarg.ad_f8style,
		     decimal, p, &reswidth);
	    }
	}
        break;

      case DB_DTE_TYPE:
      case DB_ADTE_TYPE:
      case DB_TMWO_TYPE:
      case DB_TMW_TYPE:
      case DB_TME_TYPE:
      case DB_TSWO_TYPE:
      case DB_TSW_TYPE:
      case DB_TSTMP_TYPE:
      case DB_INYM_TYPE:
      case DB_INDS_TYPE:
	return( adu_6datetostr( adf_scb, dv1, rdv));
	       
      case DB_MNY_TYPE:
	return( adu_9mnytostr( adf_scb, dv1, rdv));

      case DB_LVCH_TYPE:
      case DB_LBYTE_TYPE:
      case DB_GEOM_TYPE:
      case DB_POINT_TYPE:
      case DB_MPOINT_TYPE:
      case DB_LINE_TYPE:
      case DB_MLINE_TYPE:
      case DB_POLY_TYPE:
      case DB_MPOLY_TYPE:
      case DB_GEOMC_TYPE:
      case DB_LNVCHR_TYPE:
      case DB_LCLOC_TYPE:
      case DB_LBLOC_TYPE:
      case DB_LNLOC_TYPE:
	return( adu_lvch_move( adf_scb, dv1, rdv));
	
      case DB_BIT_TYPE:
      case DB_VBIT_TYPE:
	return( adu_bit2str( adf_scb, dv1, rdv));
	
      case DB_LOGKEY_TYPE:
      case DB_TABKEY_TYPE:
	return( adu_3logkeytostr( adf_scb, dv1, rdv));

      default:
	return(adu_error(adf_scb, E_AD2090_BAD_DT_FOR_STRFUNC, 0));
    }

    if (!char_text)
    {
        if ((db_stat = adu_movestring(adf_scb, (u_char *) p,
				      (i4) STlength(p), 
				      dv1->db_datatype, rdv))
	    != E_DB_OK
	   )
	    return(db_stat);
    }

    return(E_DB_OK);
}
示例#7
0
/*{
** Name: adt_compare() - Compare 2 data values.
**
** Description:
**	This routine compares two data values.  This will tell the caller if the
**	supplied values are equal, or if not, which one is "greater than" the
**	other.
**
**	This routine exists as a performance boost for DMF.  DMF is not allowed
**	to know how to compare data values for the various datatypes.
**	Therefore, if this routine did not exist, DMF would have to make a
**	function call to "adc_compare()" for every attribute in the tuples
**	being compared.  Even though tuples are constructs that seem a level
**	above what ADF logically handles, the performance improvement in this
**	case justifies this routine.
**
**	To avoid the overhead of an adc_compare call,
**	this routine has built into it the semantics for
**	comparing several of the most common datatypes supported by INGRES.
**
**	If the routine does run across a datatype that is not in this list, it
**	will call the general routine "adc_compare()", thereby guaranteeing
**	that it will function (perhaps slower), for ALL datatypes, even future
**	user defined ADTs.
**
**	When NULL values are involved, this routine will use the same semantics
**	that "adc_compare()" uses:  a NULL value will be considered greater
**	than any other value, and equal to another NULL value.
**
**	PLEASE NOTE:  As with "adc_compare()", no pattern matching for
**	-----------   the string datatypes is done within this routine.
**
**
** Inputs:
**	adf_scb				Pointer to an ADF session control block.
**	    .adf_errcb			ADF_ERROR struct.
**		.ad_ebuflen		The length, in bytes, of the buffer
**					pointed to by ad_errmsgp.
**		.ad_errmsgp		Pointer to a buffer to put formatted
**					error message in, if necessary.
**      atr                             Pointer to DB_ATTR.
**      d1                        	Pointer to first value.
**      d2                              Pointer to second value.
**
** Outputs:
**	adf_scb				Pointer to an ADF session control block.
**	    .adf_errcb			ADF_ERROR struct.  If an
**					error occurs the following fields will
**					be set.  NOTE: if .ad_ebuflen = 0 or
**					.ad_errmsgp = NULL, no error message
**					will be formatted.
**		.ad_errcode		ADF error code for the error.
**		.ad_errclass		Signifies the ADF error class.
**		.ad_usererr		If .ad_errclass is ADF_USER_ERROR,
**					this field is set to the corresponding
**					user error which will either map to
**					an ADF error code or a user-error code.
**		.ad_emsglen		The length, in bytes, of the resulting
**					formatted error message.
**		.adf_errmsgp		Pointer to the formatted error message.
**      status                          Status returned from
**					adc_compare(), if called.
**	
**	    The following DB_STATUS codes may be returned by adc_compare():
**	    E_DB_OK, E_DB_WARN, E_DB_ERROR, E_DB_SEVERE, E_DB_FATAL
**
**	    If a DB_STATUS code other than E_DB_OK is returned, the caller
**	    can look in the field adf_scb.adf_errcb.ad_errcode to determine
**	    the ADF error code.  The following is a list of possible ADF error
**	    codes that can be returned by this routine:
**
**          E_AD0000_OK                 Operation succeeded.
**          E_AD2004_BAD_DTID           Datatype id unknown to ADF.
**          E_AD2005_BAD_DTLEN          Internal length is illegal for
**					the given datatype.
**		(Others not yet defined)
**
** Returns:
**      i4  < 0   if 1st < 2nd
**          = 0   if 1st = 2nd
**          > 0   if 1st > 2nd
**
** Exceptions:
**       none
**
** Side Effects:
**       none
**
** History:
**      10-Feb-86 (thurston)
**          Initial creation.
**	03-apr-86 (thurston)
**	    Initial coding.  Also, added two more return statuses (stati?):
**          E_AD2004_BAD_DTID and E_AD2005_BAD_DTLEN.
**      11-jun-86 (jennifer)
**          Fixed bug compare result asigned to adt_cmp_result instead
**          of indirect through this pointer, i.e. *adt_cmp_result.
**      11-jun-86 (jennifer)
**	    Fixed bug where the first entry of attribute array (0)
**          was being used.  This entry is always garbage since 
**          attributes are numbered from 1.
**      27-jul-86 (ericj)
**	    Converted for new ADF error handling.
**	19-nov-86 (thurston)
**	    Fixed the comparison for text.
**	22-sep-88 (thurston)
**	    Added bit representation check as a first pass on each attr.  Also,
**	    added code to deal with nullable types here ... this could be a big
**	    win, since all nullable types were going through adc_compare(), now
**	    they need not.  Also, added cases for CHAR and VARCHAR.
**	21-oct-88 (thurston)
**	    Got rid of all of the `#ifdef BYTE_ALIGN' stuff by using the
**	    appropriate [I2,I4,F4,F8]ASSIGN_MACROs.  This also avoids a bunch
**	    of MEcopy() calls on BYTE_ALIGN machines.
**	21-Apr-89 (anton)
**	    Added local collation support
**	17-Jun-89 (anton)
**	    Moved local collation routines to ADU from CL
**	25-jul-89 (jrb)
**	    Added support for decimal datatype.
**	02-jan-90 (jrb)
**	    Fix alignment problem.
**	08-aug-91 (seg)
**	    "d1" and "d2" are dereferenced too often with the assumption
**	    that (PTR) == (char *) to fix.  Made them (char *).
**	28-mar-2001 (abbjo03)
**	    Add support for DB_NCHR_TYPE and DB_NVCHR_TYPE.
**	16-dec-04 (inkdo01)
**	    Add collation ID parm to aduucmp() calls.
**	02-Feb-2005 (jenjo02)
**	    Consolidated from the nine adt functions which duplicated
**	    this "compare" code. Runs the most optimal compare
**	    based on datatype for a single attribute.
**
**	    Optimized CHA/VCH compares to use MEcmp rather than
**	    CMcmpcase loop when possible.
**
**	    Replace giant switch statement with if-then-else
**	    ordered most likely to least likely, more or less.
**	    The switch was consuming 27% of the CPU used by this
**	    function.
**
**	    Added DB_STATUS *status as a function parameter so
**	    if adc_compare returns an error, it will be returned
**	    to the caller rather than as a bogus compare "result".
**	27-Apr-2005 (jenjo02 for stial01)
**	    Replaced computing compare value using arithmetic
**	    (d1 - d2) with logical compares ( d1 < d2...) as
**	    the arithmetic may over/underflow and return the
**	    wrong result.
**	13-May-2005 (thaju02)
**	    For differing length vchar, return value based on 
**	    comparison of longer length vchar to blank. (B114514)
**	19-Jun-2006 (gupsh01)
**	    Added support for new date/time types.
**	3-may-2007 (dougi)
**	    Tweak slightly to allow MEcmp() on collation/double byte
**	    if they're bytewise equal.
**	10-may-2007 (dougi)
**	    Add logic to handle ordering of c/text/char/varchar in UTF8
**	    server.
**	25-jul-2007 (gupsh01)	
**	    Although UTF8 is multibyte it is meant to be processed through
**	    UTF8 comparison code utilizing unicode comparison.
**	17-Aug-2007 (gupsh01)
**	    Fix the UTF8 handling.
*/
i4
adt_compare(
ADF_CB		    *adf_scb,
DB_ATTS		    *atr,		/* Attribute in question */
char		    *d1,		/* Ptr to 1st value */
char		    *d2,		/* Ptr to 2nd value */
DB_STATUS	    *status)		/* Status from adc_compare */

{
    i4			cur_cmp;	/* Result of latest attr cmp */
    i4			vi1, vi2;	/* Temp i4's used to cmp ints */
    i8			lli1, lli2;	/* Compare i8's */
    f8			vf1, vf2;	/* Temp f8's used to cmp flts */
    u_char	        *lc1, *lc2;
    u_char	        blank;
    i4			atr_bdt;	/* Base datatype of attr */
    i2			atr_len;	/* Length of cur attribute */
    i4			d1_isnull, d2_isnull;
    DB_DATA_VALUE	dv1, dv2;	/* Data value structs for call
					** to adc_compare(), if that is
					** necessary.
					*/
    u_char		*tc1, *tc2;	/* Temps used for string compare */
    u_char		*endtc1, *endtc2;
    UCS2		*tn1, *tn2;	/* Temps used for Nstring compare */
    UCS2		*endtn1, *endtn2;
	/*
	**  The following four lines provide temp storage to solve
	**  byte allignment problems on some archictectures.
	*/
    i2			i2_t1, i2_t2;
    i4			i4_t1, i4_t2;
    f4			f4_t1, f4_t2;
    f8			f8_t1, f8_t2;

#define	ADT_LT	(i4)-1
#define ADT_EQ	(i4)0
#define	ADT_GT	(i4)1

    *status = E_DB_OK;

    atr_len = atr->length;

    if ( (atr_bdt = atr->type) < 0 )
    {
	/* Nullable datatype */

	d1_isnull = (*((char *)d1 + atr_len - 1) & ADF_NVL_BIT);
	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)
	    return(ADT_EQ);   /* both are Null values; 1st = 2nd */
	else if (d1_isnull)
	    return(ADT_GT);   /* 1st is Null value; 1st > 2nd */
	else
	    return(ADT_LT);  /* 2nd is Null value; 1st < 2nd */
    }

    /* "if then else" consumes ~27% less CPU than "switch" */

    if ( atr_bdt == DB_INT_TYPE )
    {
	/* If both operands aligned... */
	/* Extra casts to shut up compilers -- only care about low bits */
	if ( (((i4)(SCALARP)d1 | (i4)(SCALARP)d2) & atr_len-1) == 0 )
	{
	    if ( atr_len == 4 )
	    {
		if      (*(i4*)d1 < *(i4*)d2)	return(ADT_LT);
		else if (*(i4*)d1 > *(i4*)d2)	return(ADT_GT);
		else			  	return(ADT_EQ);
	    }
	    if ( atr_len == 8 )
	    {
		if      (*(i8*)d1 < *(i8*)d2)	return(ADT_LT);
		else if (*(i8*)d1 > *(i8*)d2)	return(ADT_GT);
		else			  	return(ADT_EQ);
	    }
	    if ( atr_len == 2 )
	    {
		if      (*(i2*)d1 < *(i2*)d2)	return(ADT_LT);
		else if (*(i2*)d1 > *(i2*)d2)	return(ADT_GT);
		else			  	return(ADT_EQ);
	    }
	
	    if      (*(i1*)d1 < *(i1*)d2)	return(ADT_LT);
	    else if (*(i1*)d1 > *(i1*)d2)	return(ADT_GT);
	    else			  	return(ADT_EQ);
	}
	/* One or both not aligned... */
	if (atr_len == 4)
	{
	    I4ASSIGN_MACRO(*d1, i4_t1);
	    I4ASSIGN_MACRO(*d2, i4_t2);
	    if      (i4_t1 < i4_t2)	return(ADT_LT);
	    else if (i4_t1 > i4_t2)	return(ADT_GT);
	    else			return(ADT_EQ);
	}
	if (atr_len == 8)
	{
	    I8ASSIGN_MACRO(*d1, lli1);
	    I8ASSIGN_MACRO(*d2, lli2);
	    if      (lli1 < lli2)	return(ADT_LT);
	    else if (lli1 > lli2)	return(ADT_GT);
	    else		  	return(ADT_EQ);
	}
	if (atr_len == 2)
	{
	    I2ASSIGN_MACRO(*d1, i2_t1);
	    I2ASSIGN_MACRO(*d2, i2_t2);
	    if      (i2_t1 < i2_t2)	return(ADT_LT);
	    else if (i2_t1 > i2_t2)	return(ADT_GT);
	    else			return(ADT_EQ);
	}
	if      (*(i1*)d1 < *(i1*)d2)	return(ADT_LT);
	else if (*(i1*)d1 > *(i1*)d2)	return(ADT_GT);
	else			  	return(ADT_EQ);
    }

    if ( atr_bdt == DB_FLT_TYPE || atr_bdt == DB_MNY_TYPE )
    {
	/* If both operands aligned... */
	/* Extra casts to shut up compilers, only care about low bits */
	if ( (((i4)(SCALARP)d1 | (i4)(SCALARP)d2) & atr_len-1) == 0 )
	{
	    if ( atr_len == 8 )
	    {
		if      (*(f8*)d1 < *(f8*)d2) return(ADT_LT);
		else if (*(f8*)d1 > *(f8*)d2) return(ADT_GT);
		else                  	  return(ADT_EQ);
	    }
	    if      (*(f4*)d1 < *(f4*)d2) return(ADT_LT);
	    else if (*(f4*)d1 > *(f4*)d2) return(ADT_GT);
	    else                  	  return(ADT_EQ);
	}

	/* One or both not aligned... */
	if ( atr_len == 8 )
	{
	    F8ASSIGN_MACRO(*d1, f8_t1);
	    F8ASSIGN_MACRO(*d2, f8_t2);
	    if      (f8_t1 < f8_t2) return(ADT_LT);
	    else if (f8_t1 > f8_t2) return(ADT_GT);
	    else   		    return(ADT_EQ);
	}
	F4ASSIGN_MACRO(*d1, f4_t1);
	F4ASSIGN_MACRO(*d2, f4_t2);
	if      (f4_t1 < f4_t2) return(ADT_LT);
	else if (f4_t1 > f4_t2) return(ADT_GT);
	else   		        return(ADT_EQ);
    }

    if ( atr_bdt == DB_BYTE_TYPE || atr_bdt == DB_TABKEY_TYPE ||
	      atr_bdt == DB_LOGKEY_TYPE )
    {
	return(MEcmp(d1, d2, atr_len));
    }

    if ( atr_bdt == DB_CHA_TYPE || atr_bdt == DB_VCH_TYPE )
    {
	if ( atr_bdt == DB_CHA_TYPE )
	{
	    /* Try the turbo compare. */
	    cur_cmp = MEcmp(d1, d2, atr_len);

	    /* If not equal and UTF8-enabled ... */
	    if (cur_cmp && (adf_scb->adf_utf8_flag & AD_UTF8_ENABLED))
		return(adt_utf8comp(adf_scb, atr, atr_bdt, atr_len, 
							d1, d2, status));

	    /* If neither collation nor doublebyte or if byte-wise equal ... */
	    if ( !(adf_scb->adf_collation || 
		   Adf_globs->Adi_status & ADI_DBLBYTE) || cur_cmp == 0)
	    {
		return(cur_cmp);
	    }

	    tc1    = (u_char *) d1;
	    tc2    = (u_char *) d2;
	    endtc1 = tc1 + atr_len;
	    endtc2 = tc2 + atr_len;
	}
	else
	{
	    I2ASSIGN_MACRO(((DB_TEXT_STRING *)d1)->db_t_count, i2_t1);
	    I2ASSIGN_MACRO(((DB_TEXT_STRING *)d2)->db_t_count, i2_t2);
	    tc1 = (u_char *)d1 + DB_CNTSIZE;
	    tc2 = (u_char *)d2 + DB_CNTSIZE;

	    /* Try the turbo compare on the prefix. */
	    cur_cmp = MEcmp((char *)tc1, (char *)tc2, min(i2_t1, i2_t2));

	    /* If neither collation nor doublebyte... */
	    if ( !(adf_scb->adf_collation || 
		   Adf_globs->Adi_status & ADI_DBLBYTE) || 
			(adf_scb->adf_utf8_flag & AD_UTF8_ENABLED))
	    {
		i2	diff = i2_t1 - i2_t2;
	    
		/* If not equal or lengths differ and UTF8-enabled ... */
		if ((diff || cur_cmp) && 
			(adf_scb->adf_utf8_flag & AD_UTF8_ENABLED))
		    return(adt_utf8comp(adf_scb, atr, atr_bdt, atr_len, 
							d1, d2, status));

		/* If short compare produces inequality or lengths are
		** the same ... */
		if ( cur_cmp || diff == 0 )
		{
		    return(cur_cmp);
		}

		/*
		** Equal for shorter length.
		** If longer trails all blanks, they're equal
		*/
		if ( diff > 0 )
		{
		    /* tc1 is longer */
		    tc1 += i2_t2;
		    while ( *(tc1++) == MIN_CHAR && --diff > 0 );

		    if (!diff)
			return( ADT_EQ );
		    else
		    {
			tc1--;
			if (*tc1 > MIN_CHAR)
			    return(ADT_GT);
			else
			    return(ADT_LT);
		    }
		}
		else
		{
		    /* tc2 is longer */
		    tc2 += i2_t1;
		    while ( *(tc2++) == MIN_CHAR && ++diff < 0 );

		    if (!diff)
			return( ADT_EQ );
		    else
		    {
			tc2--;
			if (MIN_CHAR > *tc2)
			    return(ADT_GT);
			else 
			    return(ADT_LT);
		    }
		}

	    }
	    else if (i2_t1 == i2_t2 && cur_cmp == 0)
		return(cur_cmp);	/* byte wise compare returns "=" */

	    endtc1 = tc1 + i2_t1;
	    endtc2 = tc2 + i2_t2;
	}

	if (adf_scb->adf_collation)
	    return(adugcmp((ADULTABLE *)adf_scb->adf_collation,
			 ADUL_BLANKPAD, tc1, endtc1, tc2, endtc2));

	/* Doublebyte is rather more tedious */
	blank = (u_char)MIN_CHAR;
	cur_cmp = ADT_EQ;
	
	while ( cur_cmp == ADT_EQ )
	{
	    if (tc1 < endtc1)
	    {
		lc1 = tc1;
		CMnext(tc1);
	    }
	    else
	    {
		lc1 = &blank;
	    }
	    
	    if (tc2 < endtc2)
	    {
		lc2 = tc2;
		CMnext(tc2);
	    }
	    else
	    {
		lc2 = &blank;
	    }
	    
	    /* if both pointing to blank or we happen to be comparing
	    ** a string to itself then break
	    */
	    if (lc1 == lc2)
		break;
	    
	    cur_cmp = CMcmpcase(lc1, lc2);
	}
	return(cur_cmp);
    }

    if ( atr_bdt == DB_NCHR_TYPE || atr_bdt == DB_NVCHR_TYPE )
    {
	if ( atr_bdt == DB_NCHR_TYPE )
	{
	    tn1 = (UCS2 *)d1;
	    tn2 = (UCS2 *)d2;
	    endtn1 = tn1 + atr_len / sizeof(UCS2);
	    endtn2 = tn2 + atr_len / sizeof(UCS2);
	}
	else
	{
	    tn1 = ((DB_NVCHR_STRING *)d1)->element_array;
	    tn2 = ((DB_NVCHR_STRING *)d2)->element_array;
	    I2ASSIGN_MACRO(((DB_NVCHR_STRING *)d1)->count, i2_t1);
	    I2ASSIGN_MACRO(((DB_NVCHR_STRING *)d2)->count, i2_t2);
	    endtn1 = tn1 + i2_t1;
	    endtn2 = tn2 + i2_t2;
	}
      
	*status = aduucmp(adf_scb, ADUL_BLANKPAD,
	    tn1, endtn1, tn2, endtn2, &cur_cmp, atr->collID);
	return (cur_cmp);
    }

    if ( atr_bdt == DB_CHR_TYPE )
    {
	if (adf_scb->adf_utf8_flag & AD_UTF8_ENABLED)
	    return(adt_utf8comp(adf_scb, atr, atr_bdt, atr_len, 
							d1, d2, status));

	if (adf_scb->adf_collation)
	    return(adugcmp((ADULTABLE *)adf_scb->adf_collation,
			     ADUL_SKIPBLANK, (u_char *)d1,
			     atr_len + (u_char *)d1, (u_char *)d2,
			     atr_len + (u_char *)d2));
	return(STscompare((char *)d1, atr_len, (char *)d2, atr_len));
    }

    if ( atr_bdt == DB_TXT_TYPE )
    {
	if (adf_scb->adf_utf8_flag & AD_UTF8_ENABLED)
	    return(adt_utf8comp(adf_scb, atr, atr_bdt, atr_len, 
							d1, d2, status));

	I2ASSIGN_MACRO(((DB_TEXT_STRING *)d1)->db_t_count, i2_t1);
	I2ASSIGN_MACRO(((DB_TEXT_STRING *)d2)->db_t_count, i2_t2);
	tc1 = (u_char *)d1 + DB_CNTSIZE;
	tc2 = (u_char *)d2 + DB_CNTSIZE;
	endtc1 = tc1 + i2_t1;
	endtc2 = tc2 + i2_t2;

	if (adf_scb->adf_collation)
	    return(adugcmp((ADULTABLE *)adf_scb->adf_collation,
			     0, tc1, endtc1, tc2, endtc2));

	cur_cmp = ADT_EQ;
	while (cur_cmp == ADT_EQ && tc1 < endtc1  &&  tc2 < endtc2)
	{
	    if ( (cur_cmp = CMcmpcase(tc1, tc2)) == ADT_EQ )
	    {
		CMnext(tc1);
		CMnext(tc2);
	    }
	}
	
	/* If equal up to shorter, short strings < long */
	return( (cur_cmp) ? cur_cmp : (endtc1 - tc1) - (endtc2 - tc2) );
    }

    if ( atr_bdt == DB_DEC_TYPE )
    {
	/*  See if the bit representation is identical. */
	if ( MEcmp(d1, d2, atr_len) )
	{
	    i4	    pr;
	    i4	    sc;

	    pr = DB_P_DECODE_MACRO(atr->precision);
	    sc = DB_S_DECODE_MACRO(atr->precision);
	    return(MHpkcmp((PTR)d1, pr, sc, (PTR)d2, pr, sc));
	}
	return(ADT_EQ);
    }

    /* Bit-equivalent dates we can handle here */
    if (( atr_bdt == DB_DTE_TYPE || 
	 atr_bdt == DB_ADTE_TYPE ||
	 atr_bdt == DB_TMWO_TYPE ||
	 atr_bdt == DB_TMW_TYPE ||
	 atr_bdt == DB_TME_TYPE ||
	 atr_bdt == DB_TSWO_TYPE ||
	 atr_bdt == DB_TSW_TYPE ||
	 atr_bdt == DB_TSTMP_TYPE ||
	 atr_bdt == DB_INYM_TYPE ||
	 atr_bdt == DB_INDS_TYPE ) &&
	MEcmp(d1, d2, (u_i2)atr_len) == 0 )
    {
	return(ADT_EQ);
    }

    /* Will have to do it the slow way */
    dv1.db_datatype = dv2.db_datatype = (DB_DT_ID)atr_bdt;
    dv1.db_prec = dv2.db_prec = atr->precision;
    dv1.db_length = dv2.db_length = atr_len;
    dv1.db_collID = dv2.db_collID = atr->collID;
    dv1.db_data = d1;
    dv2.db_data = d2;
    *status = adc_compare(adf_scb, &dv1, &dv2, &cur_cmp);

    return(cur_cmp);
}