sqldata/sqldatacmd.cpp
// Run the data transfer or validation
Run the data transfer or validation
Run the data transfer or validation
int SqlDataCmd::Run()
{
	_command_start = Os::GetTickCount();
	_total_tables = 0;
	_failed_tables = 0;
	_total_target_ddl = 0;
	_failed_target_ddl = 0;
	_tables_equal = 0;
	_tables_diff = 0;
	_log.Reset();
	_ddl_log.Reset();
	_failed_ddl_log.Reset();
	_failed_tables_log.Reset();
	_failed_tables_list.clear();
	_warnings_tables_list.clear();
	_tables_diff_list.clear();
	int rc = SetParameters();
	if(rc == -1)
		return rc;
	PrintCurrentTimestamp();
	_log.LogFile("\nCurrent directory: %s", Os::CurrentWorkingDirectory());
	_log.LogFile("\nConfiguration file: %s", _parameters.GetConfigFile());
	if(!_parameters.IsCfgReadOk())
		_log.LogFile("\n\nError reading the configuration file: %s", _parameters.GetCfgReadError());
	rc = Connect();
	if(rc == -1)
	{
		SqlDataReply reply;
		reply._cmd = _command;
		reply._cmd_subtype = SQLDATA_CMD_ALL_COMPLETE;
		_sqlData.GetErrors(reply);
		if(_ui_callback != NULL)
			_ui_callback(_ui_callback_object, &reply);
		return -1;
	}
	rc = ReadMetadata();
	if(_total_tables == 0 && _total_objects == 0)
		return 0;
	int workers = (_command != SQLDATA_CMD_TRANSFER_OBJ) ? _sqlData.SetConcurrentSessions(_concurrent_sessions, _total_tables) : 1;
	if(_command == SQLDATA_CMD_TRANSFER)
	{
		rc = DropReferences();
		_log.Log("\n\nTransferring database ");
		_transfer_table_num = 1;
	}
	else
	if(_command == SQLDATA_CMD_TRANSFER_OBJ)
	{
		_log.Log("\n\nTransferring database objects ");
		_transfer_obj_num = 1;
	}
	else
	if(_command == SQLDATA_CMD_VALIDATE)
	{
		if(_command_options == SQLDATA_OPT_ROWCOUNT)
			_log.Log("\n\nValidating table row count ");
		else
		if(_command_options == SQLDATA_OPT_ROWS)
			_log.Log("\n\nValidating table data ");
		_validate_table_num = 1;
	}
	else
	if(_command == SQLDATA_CMD_ASSESS)
	{
		_log.Log("\n\nRunning assessment ");
		_assess_table_num = 1;
	}
	_log.Log("(%d %s):\n", workers, (workers == 1) ? "session" : "concurrent sessions");
	if(rc != -1)
		rc = _sqlData.Run();
	PrintCurrentTimestamp();
	printf("\n");
	return rc;
}
int SqlDataCmd :: Run ( ) { _command_start = Os :: GetTickCount ( ) ; _total_tables = 0 ; _failed_tables = 0 ; _total_target_ddl = 0 ; _failed_target_ddl = 0 ; _tables_equal = 0 ; _tables_diff = 0 ; _log . Reset ( ) ; _ddl_log . Reset ( ) ; _failed_ddl_log . Reset ( ) ; _failed_tables_log . Reset ( ) ; _failed_tables_list . clear ( ) ; _warnings_tables_list . clear ( ) ; _tables_diff_list . clear ( ) ; int rc = SetParameters ( ) ; if ( rc == -1 ) return rc ; PrintCurrentTimestamp ( ) ; _log . LogFile ( " \n " , Os :: CurrentWorkingDirectory ( ) ) ; _log . LogFile ( " \n " , _parameters . GetConfigFile ( ) ) ; if ( ! _parameters . IsCfgReadOk ( ) ) _log . LogFile ( " \n \n " , _parameters . GetCfgReadError ( ) ) ; rc = Connect ( ) ; if ( rc == -1 ) { SqlDataReply reply ; reply . _cmd = _command ; reply . _cmd_subtype = SQLDATA_CMD_ALL_COMPLETE ; _sqlData . GetErrors ( reply ) ; if ( _ui_callback != NULL ) _ui_callback ( _ui_callback_object , & reply ) ; return -1 ; } rc = ReadMetadata ( ) ; if ( _total_tables == 0 && _total_objects == 0 ) return 0 ; int workers = ( _command != SQLDATA_CMD_TRANSFER_OBJ ) ? _sqlData . SetConcurrentSessions ( _concurrent_sessions , _total_tables ) : 1 ; if ( _command == SQLDATA_CMD_TRANSFER ) { rc = DropReferences ( ) ; _log . Log ( " \n \n " ) ; _transfer_table_num = 1 ; } else if ( _command == SQLDATA_CMD_TRANSFER_OBJ ) { _log . Log ( " \n \n " ) ; _transfer_obj_num = 1 ; } else if ( _command == SQLDATA_CMD_VALIDATE ) { if ( _command_options == SQLDATA_OPT_ROWCOUNT ) _log . Log ( " \n \n " ) ; else if ( _command_options == SQLDATA_OPT_ROWS ) _log . Log ( " \n \n " ) ; _validate_table_num = 1 ; } else if ( _command == SQLDATA_CMD_ASSESS ) { _log . Log ( " \n \n " ) ; _assess_table_num = 1 ; } _log . Log ( " \n " , workers , ( workers == 1 ) ? " " : " " ) ; if ( rc != -1 ) rc = _sqlData . Run ( ) ; PrintCurrentTimestamp ( ) ; printf ( " \n " ) ; return rc ; }
Run the data transfer or validation
Run the data transfer or validation
// Start writing new log files // Read and validate parameters // Command line or parameters error // Check status for configuration file reading // Connect to the database to read metadata // Notify UI on error completion // Read the database catalog to define objects and metadata // No tables selected // Remove foreign keys for selected tables if DROP or TRUNCATE options are set // Process tables or objects