sqldata/sqldb.cpp
// Get the target column name and type
Get the target column name and type
Get the target column name and type
void SqlDb::MapColumn(const char *s_table, const char *s_name, std::string &t_name, std::string &t_type)
{
	if(s_table == NULL || s_name == NULL)
		return;
	bool name_mapped = false;
	if(_column_map != NULL && _column_map->size() > 0)
	{
		std::string schema;
		std::string table;
		SqlApiBase::SplitQualifiedName(s_table, schema, table);
		for(std::list<SqlColMap>::iterator i = _column_map->begin(); i != _column_map->end(); i++)
		{
			if(_stricmp((*i).schema.c_str(), schema.c_str()) == 0 && 
				_stricmp((*i).table.c_str(), table.c_str()) == 0 && _stricmp((*i).name.c_str(), s_name) == 0)
			{
				if((*i).t_name.empty() == false)
				{
					t_name = (*i).t_name;
					name_mapped = true;
				}
				t_type = (*i).t_type;			
				break;
			}
		}
	}
	if(name_mapped)
		return;
	if(target_type == SQLDATA_SQL_SERVER)
	{
		t_name += '[';
		t_name += s_name;
		t_name += "]";
	}
	else
	if(target_type == SQLDATA_ORACLE)
	{
		bool resword = _target_ca.db_api->IsReservedWord(s_name);
		bool space = strchr(s_name, ' ') != NULL ? true : false;
		if(resword || space)
			t_name += '"';
		t_name += s_name;
		if(resword || space)
			t_name += '"';
		if(resword == false)
		{
			size_t len = t_name.size();
			if(len > 30)
			{
				std::string trimmed;
				Str::TrimToAbbr(t_name, trimmed, 30);
				t_name = trimmed;
			}
		}
	}
	else
	if(target_type == SQLDATA_POSTGRESQL)
	{
		if(IsSpecialIdentifier(s_name) == true)
		{
			t_name += '"';
			t_name += s_name;
			t_name += "\"";
		}
		else
			t_name += s_name;
	}
	else
	if(target_type == SQLDATA_MYSQL)
	{
		t_name += '`';
		t_name += s_name;
		t_name += "`";
	}
	else
		t_name += s_name;
}
void SqlDb :: MapColumn ( const char * s_table , const char * s_name , std :: string & t_name , std :: string & t_type ) { if ( s_table == NULL || s_name == NULL ) return ; bool name_mapped = false ; if ( _column_map != NULL && _column_map -> size ( ) > 0 ) { std :: string schema ; std :: string table ; SqlApiBase :: SplitQualifiedName ( s_table , schema , table ) ; for ( std :: list < SqlColMap > :: iterator i = _column_map -> begin ( ) ; i != _column_map -> end ( ) ; i ++ ) { if ( _stricmp ( ( * i ) . schema . c_str ( ) , schema . c_str ( ) ) == 0 && _stricmp ( ( * i ) . table . c_str ( ) , table . c_str ( ) ) == 0 && _stricmp ( ( * i ) . name . c_str ( ) , s_name ) == 0 ) { if ( ( * i ) . t_name . empty ( ) == false ) { t_name = ( * i ) . t_name ; name_mapped = true ; } t_type = ( * i ) . t_type ; break ; } } } if ( name_mapped ) return ; if ( target_type == SQLDATA_SQL_SERVER ) { t_name += ' ' ; t_name += s_name ; t_name += " " ; } else if ( target_type == SQLDATA_ORACLE ) { bool resword = _target_ca . db_api -> IsReservedWord ( s_name ) ; bool space = strchr ( s_name , ' ' ) != NULL ? true : false ; if ( resword || space ) t_name += ' ' ; t_name += s_name ; if ( resword || space ) t_name += ' ' ; if ( resword == false ) { size_t len = t_name . size ( ) ; if ( len > 30 ) { std :: string trimmed ; Str :: TrimToAbbr ( t_name , trimmed , 30 ) ; t_name = trimmed ; } } } else if ( target_type == SQLDATA_POSTGRESQL ) { if ( IsSpecialIdentifier ( s_name ) == true ) { t_name += ' ' ; t_name += s_name ; t_name += " \" " ; } else t_name += s_name ; } else if ( target_type == SQLDATA_MYSQL ) { t_name += ' ' ; t_name += s_name ; t_name += " " ; } else t_name += s_name ; }
Get the target column name and type
Get the target column name and type
// Check is column name mapping is set // Find mapping record for this table and column // Target column name is optional // Target data type is optional // Enclose column names to prevent reserved word conflicts // Check for a reserved word in the target database // Check for space (Sybase ASE, ASA i.e. return unqouted identifier when space inside) // The length must not exceed 30 characters