library/src/blockclass/BP-BlockClass.cc
// Update a proxy db entry in the database.  Requires a valid proxy db entry item.
Update a proxy db entry in the database.  Requires a valid proxy db entry item.
Update a proxy db entry in the database . Requires a valid proxy db entry item .
BP_ERROR_T Block::updateProxyDBEntryInDB(P_BP_PROXY_DB_ENTRY record_to_update)
{
	if(!record_to_update)
	{
		this->AddErrorToStack("Attempted to update a null proxy db entry.");
		return ERR_FAILURE;
	}
	if(!this->mysqlSession)
		return ERR_FAILURE;
	BP_BLOCK_MARIADB_ENTER_CRITICAL_SECTION;
	BP_StringUtils * query_builder = new BP_StringUtils("");
	char *base_query =    "UPDATE `proxies` SET `id` = `id` ";
	query_builder->BuildString(base_query);
	if(record_to_update->user_id)
	{
		query_builder->BuildString( (char *) ", `user_id` = ? ");
	}
	if(record_to_update->group_id)
	{
		query_builder->BuildString( (char *) ", `group_id` = ? ");
	}
	if(record_to_update->proxy_type)
	{
		query_builder->BuildString( (char *) ", `proxy_type` = ? ");
	}
	if(strnlen(record_to_update->host, 2047))
	{
		query_builder->BuildString( (char *) ", `host` = ? ");
	}
	if(record_to_update->port)
	{
		query_builder->BuildString( (char *) ", `port` = ? ");
	}
	if(strnlen(record_to_update->username, 2047))
	{
		query_builder->BuildString( (char *) ", `username` = ? ");
	}
	if(strnlen(record_to_update->password, 2047))
	{
		query_builder->BuildString( (char *) ", `password` = ? ");
	}
	if(strnlen(record_to_update->user_notes, 2047))
	{
		query_builder->BuildString( (char *) ", `user_notes` = ? ");
	}
	if(strnlen(record_to_update->created_ts, 255))
	{
		query_builder->BuildString( (char *) ", `created_ts` = ? ");
	}
	if(strnlen(record_to_update->last_validated_ts, 255))
	{
		query_builder->BuildString( (char *) ", `last_validated_ts` = NOW() ");
	}
	if(record_to_update->enabled)
	{
		query_builder->BuildString( (char *) ", `enabled` = ? ");
	}
	query_builder->BuildString( (char *) ", `validation_status` = ? ");
	query_builder->BuildString( (char *) " WHERE `id` = ? ");
	query_builder->BuildString( (char *) " LIMIT 1");
	if(this->mysqlPrepareQuery(query_builder->build_str) != ERR_SUCCESS)
	{
		delete query_builder;
		BP_BLOCK_MARIADB_LEAVE_CRITICAL_SECTION_AND_RETURN_FROM_FUNC(ERR_FAILURE);
	}
	if(record_to_update->user_id)
	{
		this->mysqlAddParameter(MYSQL_TYPE_LONG,     (char *) &record_to_update->user_id, sizeof(record_to_update->user_id));
	}
	if(record_to_update->group_id)
	{
		this->mysqlAddParameter(MYSQL_TYPE_LONG,     (char *) &record_to_update->group_id, sizeof(record_to_update->group_id));
	}
	if(record_to_update->proxy_type)
	{
		this->mysqlAddParameter(MYSQL_TYPE_LONG,     (char *) &record_to_update->proxy_type, sizeof(record_to_update->proxy_type));
	}
	if(strnlen(record_to_update->host, 2047))
	{
		this->mysqlAddParameter(MYSQL_TYPE_STRING,     (char *) &record_to_update->host, sizeof(record_to_update->host)-1);
	}
	if(record_to_update->port)
	{
		this->mysqlAddParameter(MYSQL_TYPE_LONG,     (char *) &record_to_update->port, sizeof(record_to_update->port));
	}
	if(strnlen(record_to_update->username, 2047))
	{
		this->mysqlAddParameter(MYSQL_TYPE_STRING,     (char *) &record_to_update->username, sizeof(record_to_update->username)-1);
	}
	if(strnlen(record_to_update->password, 2047))
	{
		this->mysqlAddParameter(MYSQL_TYPE_STRING,     (char *) &record_to_update->password, sizeof(record_to_update->password)-1);
	}
	if(strnlen(record_to_update->user_notes, 2047))
	{
		this->mysqlAddParameter(MYSQL_TYPE_STRING,     (char *) &record_to_update->user_notes, sizeof(record_to_update->user_notes)-1);
	}
	if(strnlen(record_to_update->created_ts, 255))
	{
		this->mysqlAddParameter(MYSQL_TYPE_STRING,     (char *) &record_to_update->created_ts, sizeof(record_to_update->created_ts)-1);
	}
	if(strnlen(record_to_update->last_validated_ts, 255))
	{
	}
	if(record_to_update->enabled)
	{
		this->mysqlAddParameter(MYSQL_TYPE_LONG,     (char *) &record_to_update->enabled, sizeof(record_to_update->enabled));
	}
	this->mysqlAddParameter(MYSQL_TYPE_LONG, (char *) &record_to_update->proxy_has_been_validated_at_runtime, sizeof(record_to_update->proxy_has_been_validated_at_runtime));
	this->mysqlAddParameter(MYSQL_TYPE_LONG,     (char *) &record_to_update->id, sizeof(record_to_update->id));
	this->mysqlBindParameters();
	if(this->mysqlExecuteStatement() != ERR_SUCCESS)
	{
		this->AddErrorToStack((char *) "Unable to execute proxy db entry update query.");
		delete query_builder;
		BP_BLOCK_MARIADB_LEAVE_CRITICAL_SECTION_AND_RETURN_FROM_FUNC(ERR_FAILURE);
	}
	this->mysqlDestroyStatement();
	delete query_builder;
	BP_BLOCK_MARIADB_LEAVE_CRITICAL_SECTION_AND_RETURN_FROM_FUNC(ERR_SUCCESS);
}
BP_ERROR_T Block :: updateProxyDBEntryInDB ( P_BP_PROXY_DB_ENTRY record_to_update ) { if ( ! record_to_update ) { this -> AddErrorToStack ( " " ) ; return ERR_FAILURE ; } if ( ! this -> mysqlSession ) return ERR_FAILURE ; BP_BLOCK_MARIADB_ENTER_CRITICAL_SECTION ; BP_StringUtils * query_builder = new BP_StringUtils ( " " ) ; char * base_query = " " ; query_builder -> BuildString ( base_query ) ; if ( record_to_update -> user_id ) { query_builder -> BuildString ( ( char * ) " " ) ; } if ( record_to_update -> group_id ) { query_builder -> BuildString ( ( char * ) " " ) ; } if ( record_to_update -> proxy_type ) { query_builder -> BuildString ( ( char * ) " " ) ; } if ( strnlen ( record_to_update -> host , 2047 ) ) { query_builder -> BuildString ( ( char * ) " " ) ; } if ( record_to_update -> port ) { query_builder -> BuildString ( ( char * ) " " ) ; } if ( strnlen ( record_to_update -> username , 2047 ) ) { query_builder -> BuildString ( ( char * ) " " ) ; } if ( strnlen ( record_to_update -> password , 2047 ) ) { query_builder -> BuildString ( ( char * ) " " ) ; } if ( strnlen ( record_to_update -> user_notes , 2047 ) ) { query_builder -> BuildString ( ( char * ) " " ) ; } if ( strnlen ( record_to_update -> created_ts , 255 ) ) { query_builder -> BuildString ( ( char * ) " " ) ; } if ( strnlen ( record_to_update -> last_validated_ts , 255 ) ) { query_builder -> BuildString ( ( char * ) " " ) ; } if ( record_to_update -> enabled ) { query_builder -> BuildString ( ( char * ) " " ) ; } query_builder -> BuildString ( ( char * ) " " ) ; query_builder -> BuildString ( ( char * ) " " ) ; query_builder -> BuildString ( ( char * ) " " ) ; if ( this -> mysqlPrepareQuery ( query_builder -> build_str ) != ERR_SUCCESS ) { delete query_builder ; BP_BLOCK_MARIADB_LEAVE_CRITICAL_SECTION_AND_RETURN_FROM_FUNC ( ERR_FAILURE ) ; } if ( record_to_update -> user_id ) { this -> mysqlAddParameter ( MYSQL_TYPE_LONG , ( char * ) & record_to_update -> user_id , sizeof ( record_to_update -> user_id ) ) ; } if ( record_to_update -> group_id ) { this -> mysqlAddParameter ( MYSQL_TYPE_LONG , ( char * ) & record_to_update -> group_id , sizeof ( record_to_update -> group_id ) ) ; } if ( record_to_update -> proxy_type ) { this -> mysqlAddParameter ( MYSQL_TYPE_LONG , ( char * ) & record_to_update -> proxy_type , sizeof ( record_to_update -> proxy_type ) ) ; } if ( strnlen ( record_to_update -> host , 2047 ) ) { this -> mysqlAddParameter ( MYSQL_TYPE_STRING , ( char * ) & record_to_update -> host , sizeof ( record_to_update -> host ) - 1 ) ; } if ( record_to_update -> port ) { this -> mysqlAddParameter ( MYSQL_TYPE_LONG , ( char * ) & record_to_update -> port , sizeof ( record_to_update -> port ) ) ; } if ( strnlen ( record_to_update -> username , 2047 ) ) { this -> mysqlAddParameter ( MYSQL_TYPE_STRING , ( char * ) & record_to_update -> username , sizeof ( record_to_update -> username ) - 1 ) ; } if ( strnlen ( record_to_update -> password , 2047 ) ) { this -> mysqlAddParameter ( MYSQL_TYPE_STRING , ( char * ) & record_to_update -> password , sizeof ( record_to_update -> password ) - 1 ) ; } if ( strnlen ( record_to_update -> user_notes , 2047 ) ) { this -> mysqlAddParameter ( MYSQL_TYPE_STRING , ( char * ) & record_to_update -> user_notes , sizeof ( record_to_update -> user_notes ) - 1 ) ; } if ( strnlen ( record_to_update -> created_ts , 255 ) ) { this -> mysqlAddParameter ( MYSQL_TYPE_STRING , ( char * ) & record_to_update -> created_ts , sizeof ( record_to_update -> created_ts ) - 1 ) ; } if ( strnlen ( record_to_update -> last_validated_ts , 255 ) ) { } if ( record_to_update -> enabled ) { this -> mysqlAddParameter ( MYSQL_TYPE_LONG , ( char * ) & record_to_update -> enabled , sizeof ( record_to_update -> enabled ) ) ; } this -> mysqlAddParameter ( MYSQL_TYPE_LONG , ( char * ) & record_to_update -> proxy_has_been_validated_at_runtime , sizeof ( record_to_update -> proxy_has_been_validated_at_runtime ) ) ; this -> mysqlAddParameter ( MYSQL_TYPE_LONG , ( char * ) & record_to_update -> id , sizeof ( record_to_update -> id ) ) ; this -> mysqlBindParameters ( ) ; if ( this -> mysqlExecuteStatement ( ) != ERR_SUCCESS ) { this -> AddErrorToStack ( ( char * ) " " ) ; delete query_builder ; BP_BLOCK_MARIADB_LEAVE_CRITICAL_SECTION_AND_RETURN_FROM_FUNC ( ERR_FAILURE ) ; } this -> mysqlDestroyStatement ( ) ; delete query_builder ; BP_BLOCK_MARIADB_LEAVE_CRITICAL_SECTION_AND_RETURN_FROM_FUNC ( ERR_SUCCESS ) ; }
Update a proxy db entry in the database.
Update a proxy db entry in the database .
// ensure we have a record to update // exit if the mysqli object is unset // enter critical section // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% // %%%%%% Build Query %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% // create new string builder // select query to run // add the base query // add user id as a query constraint if its set // add group id as query constraint if its set // add proxy type as query constraint if set // add host as query constraint if set // add port as a query constraint if its set // add username as a query constraint if its set // add password as a query constraint if its set // add user notes as a query constraint if its set // add created timestamp as a query constraint if set // set the last validated ts as constraint // set the enabled/disabled status as a constraint // always add validation status (should be 0 or 1) // always add the id limiter // always add limit string (only one update at a time) // prepare the query // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% // %%%%%%%%%%% Add Parameters %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% // add user id as a query constraint if its set // add group id as query constraint if its set // add proxy type as query constraint if set // add host as query constraint if set // add port as a query constraint if its set // add username as a query constraint if its set // add password as a query constraint if its set // add user notes as a query constraint if its set // add created timestamp as a query constraint if set // set the last validated ts as constraint // this is set via NOW() // this->mysqlAddParameter(MYSQL_TYPE_STRING,     (char *) &record_to_update->last_validated_ts, sizeof(record_to_update->last_validated_ts)-1); // set the enabled/disabled status as a constraint // always add validation data // add specific id limitation // bind the query parameters before executing statement // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% // %%%%%% Add Results %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% // -- no results will be generated for this routine ---- // %%%%%%% Execute the SELECT query %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% // execute the statement // destroy statement (free memory) // destroy the query builder // return indicating success