sqldata/sqldb.cpp
// Compare string representations of numbers .5 and 0.50
Compare string representations of numbers .5 and 0.50
Compare string representations of numbers . 5 and 0 . 50
bool SqlDb::ValidateCompareNumbers(SqlCol *s_col, const char *s_string, int s_len, SqlCol *t_col, 
										const char *t_string, int t_len, int *equal)
{
	if(s_col == NULL || s_string == NULL || t_col == NULL || t_string == NULL)
		return false;
	bool num = false;
	bool comp = false;
	if((source_type == SQLDATA_ORACLE && s_col->_native_dt == SQLT_NUM && s_col->_scale != 129 ) || 
		(source_type == SQLDATA_SYBASE && s_col->_native_fetch_dt == CS_CHAR_TYPE &&
			(s_col->_native_dt == CS_NUMERIC_TYPE || s_col->_native_dt == CS_DECIMAL_TYPE || 
			 s_col->_native_dt == CS_MONEY_TYPE || s_col->_native_dt == CS_MONEY4_TYPE)) ||
		(source_type == SQLDATA_INFORMIX && s_col->_native_fetch_dt == SQL_C_CHAR &&
			(s_col->_native_dt == SQL_DECIMAL || s_col->_native_dt == SQL_NUMERIC ||
			 s_col->_native_dt == SQL_REAL || s_col->_native_dt == SQL_DOUBLE)))
	{
		comp = Str::CompareNumberAsString(s_string, s_len, t_string, t_len);
		num = true;
	}
	else
	if((source_type == SQLDATA_ORACLE && s_col->_native_dt == SQLT_NUM && s_col->_scale == 129 ) ||		
		(source_type == SQLDATA_SYBASE && s_col->_native_fetch_dt == CS_CHAR_TYPE &&
		(s_col->_native_dt == CS_REAL_TYPE || s_col->_native_dt == CS_FLOAT_TYPE))) 
	{
		double d1 = 0.0, d2 = 0.0;
		char f1[11], f2[11];
		sprintf(f1, "%%%dlf", s_len);
		sprintf(f2, "%%%dlf", t_len);
		sscanf(s_string, f1, &d1);
		sscanf(t_string, f2, &d2);
		if(d1 == d2)
		{
			comp = true;
			num = true;
		}
	}
	if(equal != NULL)
		*equal = comp ? 0 : -1;
	return num;
}
bool SqlDb :: ValidateCompareNumbers ( SqlCol * s_col , const char * s_string , int s_len , SqlCol * t_col , const char * t_string , int t_len , int * equal ) { if ( s_col == NULL || s_string == NULL || t_col == NULL || t_string == NULL ) return false ; bool num = false ; bool comp = false ; if ( ( source_type == SQLDATA_ORACLE && s_col -> _native_dt == SQLT_NUM && s_col -> _scale != 129 ) || ( source_type == SQLDATA_SYBASE && s_col -> _native_fetch_dt == CS_CHAR_TYPE && ( s_col -> _native_dt == CS_NUMERIC_TYPE || s_col -> _native_dt == CS_DECIMAL_TYPE || s_col -> _native_dt == CS_MONEY_TYPE || s_col -> _native_dt == CS_MONEY4_TYPE ) ) || ( source_type == SQLDATA_INFORMIX && s_col -> _native_fetch_dt == SQL_C_CHAR && ( s_col -> _native_dt == SQL_DECIMAL || s_col -> _native_dt == SQL_NUMERIC || s_col -> _native_dt == SQL_REAL || s_col -> _native_dt == SQL_DOUBLE ) ) ) { comp = Str :: CompareNumberAsString ( s_string , s_len , t_string , t_len ) ; num = true ; } else if ( ( source_type == SQLDATA_ORACLE && s_col -> _native_dt == SQLT_NUM && s_col -> _scale == 129 ) || ( source_type == SQLDATA_SYBASE && s_col -> _native_fetch_dt == CS_CHAR_TYPE && ( s_col -> _native_dt == CS_REAL_TYPE || s_col -> _native_dt == CS_FLOAT_TYPE ) ) ) { double d1 = 0.0 , d2 = 0.0 ; char f1 [ 11 ] , f2 [ 11 ] ; sprintf ( f1 , " " , s_len ) ; sprintf ( f2 , " " , t_len ) ; sscanf ( s_string , f1 , & d1 ) ; sscanf ( t_string , f2 , & d2 ) ; if ( d1 == d2 ) { comp = true ; num = true ; } } if ( equal != NULL ) * equal = comp ? 0 : -1 ; return num ; }
Compare string representations of numbers .5 and 0.50
Compare string representations of numbers . 5 and 0 . 50
// Check is the source data type is a number fetched as string /*floating*/ // Compare numbers // Compare floating point numbers that can be different due to rounding issues // Sybase ASE can return 6.7000000000000002 for value 6.7 /*floating*/ // Get double values