sqldata/sqldatacmd.cpp
// Read the database catalog to define objects and metadata
Read the database catalog to define objects and metadata
Read the database catalog to define objects and metadata
int SqlDataCmd::ReadMetadata()
{
	size_t start = GetTickCount();
	_sqlData.SetCallback((void*)this, SqlDataCmd::CallbackS);
	std::list<std::string> avail_tables;
	int rc = -1; 
	if(!_t.empty() || !_tf.empty())
	{
		_log.Log("\n\nReading the database schema");
		if(!_t.empty())
		{
			if(_command != SQLDATA_CMD_TRANSFER_OBJ)
				rc = _sqlData.GetAvailableTables(_t, _texcl, avail_tables); 
			else
				rc = 0;
		}
		else
		if(!_tf.empty())
			rc = GetObjectsFromFile(avail_tables);
	}
	else
	if(!_qf.empty())
	{
		_log.Log("\n\nDefining queries to transfer data");
		rc = GetQueriesFromFile(_qf, _queries);
	}
	if(rc == -1)
	{
		SqlDataReply reply;
		reply._cmd = _command;
		reply._cmd_subtype = SQLDATA_CMD_ALL_COMPLETE;
		_sqlData.GetErrors(reply);
		if(reply._s_rc == -1 && *reply.s_native_error_text)
			_log.Log("\n\t%s", reply.s_native_error_text);
		if(reply._t_rc == -1 && *reply.t_native_error_text)
			_log.Log("\n\t%s", reply.t_native_error_text);
		if(_ui_callback != NULL)
			_ui_callback(_ui_callback_object, &reply);
		return -1;
	}
	_total_tables = (int)avail_tables.size();
	if(!_qf.empty())
	{
		_total_tables = (int)_queries.size();
		_sqlData.SetQueries(&_queries);
		_log.Log(" (%d %s)", _total_tables, SUFFIX2(_total_tables, "query", "queries"));
	}
	else
	if(_command != SQLDATA_CMD_TRANSFER_OBJ)
	{
		for(std::list<std::string>::iterator i = avail_tables.begin(); i != avail_tables.end(); i++)
			_tables.push_back(*i);
		_sqlData.SetTables(&_tables);
		std::string meta_filter = _t;
		if(_t.empty())
		{
			int c = 0;
			for(std::list<std::string>::iterator i = avail_tables.begin(); i != avail_tables.end(); i++)
			{
				if(c > 0)
					meta_filter += ",";
				meta_filter += (*i);
				c++;
			}
		}
		_sqlData.CreateMetadataQueues(meta_filter, _texcl);
		char time_fmt[21];
		Str::FormatTime(GetTickCount() - start, time_fmt);
		_log.Log(" (%d table%s, %s)", _total_tables, SUFFIX(_total_tables), time_fmt);
		if(_ui_callback != NULL)
		{
			SqlDataReply reply;
			reply._cmd = _command;
			reply._cmd_subtype = SQLDATA_CMD_NUMBER_OF_TABLES;
			reply._int1 = _total_tables;
			_ui_callback(_ui_callback_object, &reply);
		}
	}
	else
	if(_command == SQLDATA_CMD_TRANSFER_OBJ)
	{
		_sqlData.CreateObjectQueue(_t, _texcl, &_total_objects, &_total_object_lines, &_total_object_bytes);
		char time_fmt[21];
		Str::FormatTime(GetTickCount() - start, time_fmt);
		char bytes_fmt[21];
		Str::FormatByteSize((double)_total_object_bytes, bytes_fmt);
		_log.Log(" (%d object%s, %d line%s, %s, %s)", _total_objects, SUFFIX(_total_objects), _total_object_lines, SUFFIX(_total_object_lines), 
			bytes_fmt, time_fmt);
	}
	return 0;
}
int SqlDataCmd :: ReadMetadata ( ) { size_t start = GetTickCount ( ) ; _sqlData . SetCallback ( ( void * ) this , SqlDataCmd :: CallbackS ) ; std :: list < std :: string > avail_tables ; int rc = -1 ; if ( ! _t . empty ( ) || ! _tf . empty ( ) ) { _log . Log ( " \n \n " ) ; if ( ! _t . empty ( ) ) { if ( _command != SQLDATA_CMD_TRANSFER_OBJ ) rc = _sqlData . GetAvailableTables ( _t , _texcl , avail_tables ) ; else rc = 0 ; } else if ( ! _tf . empty ( ) ) rc = GetObjectsFromFile ( avail_tables ) ; } else if ( ! _qf . empty ( ) ) { _log . Log ( " \n \n " ) ; rc = GetQueriesFromFile ( _qf , _queries ) ; } if ( rc == -1 ) { SqlDataReply reply ; reply . _cmd = _command ; reply . _cmd_subtype = SQLDATA_CMD_ALL_COMPLETE ; _sqlData . GetErrors ( reply ) ; if ( reply . _s_rc == -1 && * reply . s_native_error_text ) _log . Log ( " \n \t " , reply . s_native_error_text ) ; if ( reply . _t_rc == -1 && * reply . t_native_error_text ) _log . Log ( " \n \t " , reply . t_native_error_text ) ; if ( _ui_callback != NULL ) _ui_callback ( _ui_callback_object , & reply ) ; return -1 ; } _total_tables = ( int ) avail_tables . size ( ) ; if ( ! _qf . empty ( ) ) { _total_tables = ( int ) _queries . size ( ) ; _sqlData . SetQueries ( & _queries ) ; _log . Log ( " " , _total_tables , SUFFIX2 ( _total_tables , " " , " " ) ) ; } else if ( _command != SQLDATA_CMD_TRANSFER_OBJ ) { for ( std :: list < std :: string > :: iterator i = avail_tables . begin ( ) ; i != avail_tables . end ( ) ; i ++ ) _tables . push_back ( * i ) ; _sqlData . SetTables ( & _tables ) ; std :: string meta_filter = _t ; if ( _t . empty ( ) ) { int c = 0 ; for ( std :: list < std :: string > :: iterator i = avail_tables . begin ( ) ; i != avail_tables . end ( ) ; i ++ ) { if ( c > 0 ) meta_filter += " " ; meta_filter += ( * i ) ; c ++ ; } } _sqlData . CreateMetadataQueues ( meta_filter , _texcl ) ; char time_fmt [ 21 ] ; Str :: FormatTime ( GetTickCount ( ) - start , time_fmt ) ; _log . Log ( " " , _total_tables , SUFFIX ( _total_tables ) , time_fmt ) ; if ( _ui_callback != NULL ) { SqlDataReply reply ; reply . _cmd = _command ; reply . _cmd_subtype = SQLDATA_CMD_NUMBER_OF_TABLES ; reply . _int1 = _total_tables ; _ui_callback ( _ui_callback_object , & reply ) ; } } else if ( _command == SQLDATA_CMD_TRANSFER_OBJ ) { _sqlData . CreateObjectQueue ( _t , _texcl , & _total_objects , & _total_object_lines , & _total_object_bytes ) ; char time_fmt [ 21 ] ; Str :: FormatTime ( GetTickCount ( ) - start , time_fmt ) ; char bytes_fmt [ 21 ] ; Str :: FormatByteSize ( ( double ) _total_object_bytes , bytes_fmt ) ; _log . Log ( " " , _total_objects , SUFFIX ( _total_objects ) , _total_object_lines , SUFFIX ( _total_object_lines ) , bytes_fmt , time_fmt ) ; } return 0 ; }
Read the database catalog to define objects and metadata
Read the database catalog to define objects and metadata
// Set callback function // Get list of tables available in the source database // For non-table objects source code will be read later // Get list from file // Get queries from a file // Notify UI on error completion // Queries from file // Tables // Add all tables to the list // Create queues to transfer schema metadata // Notify UI about the number of tables // Non-table objects