sqldata/sqldb.cpp
// Compare datetime values featched as strings
Compare datetime values featched as strings
Compare datetime values featched as strings
bool SqlDb::ValidateCompareDatetimes(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 datetime = false;
	int comp = -1;
	if((source_type == SQLDATA_ORACLE && s_col->_native_dt == SQLT_TIMESTAMP) ||
		(source_type == SQLDATA_SYBASE && (s_col->_native_dt == CS_DATETIME_TYPE || s_col->_native_dt == CS_DATETIME4_TYPE || s_col->_native_dt == CS_DATE_TYPE))
		&& (target_type == SQLDATA_MYSQL))
	{
		int s_len_new = s_len;
		int t_len_new = t_len;
		if(source_type == SQLDATA_SYBASE)
		{
			if(s_col->_native_dt == CS_DATE_TYPE)
				s_len_new = 10;
			else
			if(s_col->_native_dt == CS_DATETIME4_TYPE)
				s_len_new = 19;
		}
		if(_validation_datetime_fraction != -1)
		{
			if(s_len_new > 20 + _validation_datetime_fraction)
				s_len_new = 20 + _validation_datetime_fraction;
			if(t_len_new > 19 + _validation_datetime_fraction)
				t_len_new = 20 + _validation_datetime_fraction;
		}
		if(s_len_new != t_len_new)
		{
			int l_len = s_len_new;
			int m_len = t_len_new;
			const char *m_string = t_string;
			if(s_len_new > t_len_new) 
			{
				l_len = t_len_new;
				m_len = s_len_new;
				m_string = s_string;
			}
			comp = memcmp(s_string, t_string, (size_t)l_len);	
			if(!comp)
			{
				for(int i = l_len; i < m_len; i++)
				{
					if(m_string[i] != '0')
					{
						comp = -1;
						break;
					}
				}
			}
		}
		else
			comp = memcmp(s_string, t_string, (size_t)s_len_new);				
		datetime = true;
	}
	if(equal != NULL)
		*equal = comp;
	return datetime;
}
bool SqlDb :: ValidateCompareDatetimes ( 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 datetime = false ; int comp = -1 ; if ( ( source_type == SQLDATA_ORACLE && s_col -> _native_dt == SQLT_TIMESTAMP ) || ( source_type == SQLDATA_SYBASE && ( s_col -> _native_dt == CS_DATETIME_TYPE || s_col -> _native_dt == CS_DATETIME4_TYPE || s_col -> _native_dt == CS_DATE_TYPE ) ) && ( target_type == SQLDATA_MYSQL ) ) { int s_len_new = s_len ; int t_len_new = t_len ; if ( source_type == SQLDATA_SYBASE ) { if ( s_col -> _native_dt == CS_DATE_TYPE ) s_len_new = 10 ; else if ( s_col -> _native_dt == CS_DATETIME4_TYPE ) s_len_new = 19 ; } if ( _validation_datetime_fraction != -1 ) { if ( s_len_new > 20 + _validation_datetime_fraction ) s_len_new = 20 + _validation_datetime_fraction ; if ( t_len_new > 19 + _validation_datetime_fraction ) t_len_new = 20 + _validation_datetime_fraction ; } if ( s_len_new != t_len_new ) { int l_len = s_len_new ; int m_len = t_len_new ; const char * m_string = t_string ; if ( s_len_new > t_len_new ) { l_len = t_len_new ; m_len = s_len_new ; m_string = s_string ; } comp = memcmp ( s_string , t_string , ( size_t ) l_len ) ; if ( ! comp ) { for ( int i = l_len ; i < m_len ; i ++ ) { if ( m_string [ i ] != ' ' ) { comp = -1 ; break ; } } } } else comp = memcmp ( s_string , t_string , ( size_t ) s_len_new ) ; datetime = true ; } if ( equal != NULL ) * equal = comp ; return datetime ; }
Compare datetime values featched as strings
Compare datetime values featched as strings
// Oracle TIMESTAMP compared with MySQL DATETIME without fraction // All datetime data types are fetched with 26 length from Sybase ASE, so we need to correct the length // Sybase ASE DATE that fetched with 00:00:00.000000 time part // Sybase ASE SMALLDATETIME contains minutes only, seconds always 00 // Number of fractional digits to compare // If length are not equal allow only difference in number of 0s in fractional part, so consider .0 and .000 equal // Common part is equal // Larger part must contain 0s