sqldata/sqldb.cpp
// Check whether we need to drop, create or truncate the table 
Check whether we need to drop, create or truncate the table
Check whether we need to drop create or truncate the table
int SqlDb::PrepareTransfer(SqlCol *s_cols, const char *s_table, const char *t_table, size_t col_count, int options, SqlDataReply &reply)
{
	if(s_table == NULL || t_table == NULL || _target_ca.db_api == NULL || s_cols == NULL)
		return -1;
	int rc = 0;
	size_t time_spent = 0;
	if(options & SQLDATA_OPT_DROP)
	{
		std::string drop_stmt;
		rc = _target_ca.db_api->DropTable(t_table, &time_spent, drop_stmt);
		if(_callback != NULL)
		{
			reply._cmd_subtype = SQLDATA_CMD_DROP;
			reply.rc = rc;
			reply._int1 = (int)time_spent;
			reply.t_sql = drop_stmt.c_str();
			if(rc != 0)
			{
				reply.t_error = _target_ca.db_api->GetError();
				strcpy(reply.t_native_error_text, _target_ca.db_api->GetNativeErrorText());
			}
			_callback(_callback_object, &reply);
		}
		if(rc == -1 && reply.t_error != SQL_DBAPI_NOT_EXISTS_ERROR)
			return rc;
	}
	if(options & SQLDATA_OPT_TRUNCATE)
	{
		std::string command = "TRUNCATE TABLE ";
		command += t_table;
		rc = _target_ca.db_api->ExecuteNonQuery(command.c_str(), &time_spent);
		if(_callback != NULL)
		{
			reply._cmd_subtype = SQLDATA_CMD_TRUNCATE;
			reply.rc = rc;
			reply._int1 = (int)time_spent;
			reply.t_sql = command.c_str();
			if(rc != 0)
			{
				reply.t_error = _target_ca.db_api->GetError();
				strcpy(reply.t_native_error_text, _target_ca.db_api->GetNativeErrorText());
			}
			_callback(_callback_object, &reply);
		}
	}
	if(options & SQLDATA_OPT_CREATE)
	{
		std::string command;
		GenerateCreateTable(s_cols, s_table, t_table, (int)col_count, command);
		rc = _target_ca.db_api->ExecuteNonQuery(command.c_str(), &time_spent);
		if(_callback != NULL)
		{
			reply._cmd_subtype = SQLDATA_CMD_CREATE;
			reply.rc = rc;
			reply._int1 = (int)time_spent;
			reply.t_sql = command.c_str();
			if(rc != 0)
			{
				reply.t_error = _target_ca.db_api->GetError();
				strcpy(reply.t_native_error_text, _target_ca.db_api->GetNativeErrorText());
			}
			_callback(_callback_object, &reply);
		}
	}
	return rc;
}
int SqlDb :: PrepareTransfer ( SqlCol * s_cols , const char * s_table , const char * t_table , size_t col_count , int options , SqlDataReply & reply ) { if ( s_table == NULL || t_table == NULL || _target_ca . db_api == NULL || s_cols == NULL ) return -1 ; int rc = 0 ; size_t time_spent = 0 ; if ( options & SQLDATA_OPT_DROP ) { std :: string drop_stmt ; rc = _target_ca . db_api -> DropTable ( t_table , & time_spent , drop_stmt ) ; if ( _callback != NULL ) { reply . _cmd_subtype = SQLDATA_CMD_DROP ; reply . rc = rc ; reply . _int1 = ( int ) time_spent ; reply . t_sql = drop_stmt . c_str ( ) ; if ( rc != 0 ) { reply . t_error = _target_ca . db_api -> GetError ( ) ; strcpy ( reply . t_native_error_text , _target_ca . db_api -> GetNativeErrorText ( ) ) ; } _callback ( _callback_object , & reply ) ; } if ( rc == -1 && reply . t_error != SQL_DBAPI_NOT_EXISTS_ERROR ) return rc ; } if ( options & SQLDATA_OPT_TRUNCATE ) { std :: string command = " " ; command += t_table ; rc = _target_ca . db_api -> ExecuteNonQuery ( command . c_str ( ) , & time_spent ) ; if ( _callback != NULL ) { reply . _cmd_subtype = SQLDATA_CMD_TRUNCATE ; reply . rc = rc ; reply . _int1 = ( int ) time_spent ; reply . t_sql = command . c_str ( ) ; if ( rc != 0 ) { reply . t_error = _target_ca . db_api -> GetError ( ) ; strcpy ( reply . t_native_error_text , _target_ca . db_api -> GetNativeErrorText ( ) ) ; } _callback ( _callback_object , & reply ) ; } } if ( options & SQLDATA_OPT_CREATE ) { std :: string command ; GenerateCreateTable ( s_cols , s_table , t_table , ( int ) col_count , command ) ; rc = _target_ca . db_api -> ExecuteNonQuery ( command . c_str ( ) , & time_spent ) ; if ( _callback != NULL ) { reply . _cmd_subtype = SQLDATA_CMD_CREATE ; reply . rc = rc ; reply . _int1 = ( int ) time_spent ; reply . t_sql = command . c_str ( ) ; if ( rc != 0 ) { reply . t_error = _target_ca . db_api -> GetError ( ) ; strcpy ( reply . t_native_error_text , _target_ca . db_api -> GetNativeErrorText ( ) ) ; } _callback ( _callback_object , & reply ) ; } } return rc ; }
Check whether we need to drop, create or truncate the table
Check whether we need to drop create or truncate the table
// Check for necessity to DROP existing table // If failed with the error other than table does not exist, then exit // Check truncate command // Check for necessity to create table // Generate SQL CREATE TABLE statement