library/src/blockclass/BP-BlockClass.cc
// retrieves proxy group sets via criteria (zero / empty values for unset/wildcard search terms)
retrieves proxy group sets via criteria (zero / empty values for unset/wildcard search terms)
retrieves proxy group sets via criteria ( zero / empty values for unset / wildcard search terms )
BP_ERROR_T Block::getProxyDBGroupSetByCriteria
(
		size_t id,
		size_t user_id,
		char *group_name,
		size_t bottom_limit,
		size_t top_limit
)
{
	if(!this->mysqlSession)
		return ERR_FAILURE;
	BP_BLOCK_MARIADB_ENTER_CRITICAL_SECTION;
	if(!this->mysqlSession->conn)
		BP_BLOCK_MARIADB_LEAVE_CRITICAL_SECTION_AND_RETURN_FROM_FUNC(ERR_FAILURE);
	BP_StringUtils * query_builder = new BP_StringUtils((char *) "");
	char *base_query = (char *) "SELECT "\
						" `id`, `user_id`, `group_name`, `enabled`, `created_ts`, `group_description` "\
						"FROM `proxy_groups` WHERE 1=1 ";
	query_builder->BuildString(base_query);
	if(id)
		query_builder->BuildString( (char *) " AND `id` = ?");
	if(user_id)
		query_builder->BuildString( (char *) " AND `user_id` = ?");
	if(group_name)
		query_builder->BuildString( (char *) " AND `group_name` = ?");
	char limit_str[256] = {0};
	sprintf((char *) &limit_str, (char *) " LIMIT %u, %u ", bottom_limit, top_limit);
	query_builder->BuildString(limit_str);
	if(this->mysqlPrepareQuery(query_builder->build_str) != ERR_SUCCESS)
	{
		BP_BLOCK_MARIADB_LEAVE_CRITICAL_SECTION_AND_RETURN_FROM_FUNC(ERR_FAILURE);
	}
	if(id)
		this->mysqlAddParameter(MYSQL_TYPE_LONG,   (char *) &id,  sizeof(id));
	if(user_id)
		this->mysqlAddParameter(MYSQL_TYPE_LONG,   (char *) &user_id,  sizeof(user_id));
	if(group_name)
		this->mysqlAddParameter(MYSQL_TYPE_STRING, (char *) group_name, strnlen(group_name, 1024)-1);
	this->mysqlBindParameters();
	BP_PROXY_DB_GROUP proxy_result = {0};
	memset((void *)&proxy_result, 0x00, sizeof(proxy_result));
	this->mysqlAddResult(MYSQL_TYPE_LONG, (char *) &proxy_result.id, sizeof(proxy_result.id));
	this->mysqlAddResult(MYSQL_TYPE_LONG, (char *) &proxy_result.user_id, sizeof(proxy_result.user_id));
	this->mysqlAddResult(MYSQL_TYPE_STRING, (char *) &proxy_result.name, sizeof(proxy_result.name)-1);
	this->mysqlAddResult(MYSQL_TYPE_LONG, (char *) &proxy_result.enabled, sizeof(proxy_result.enabled));
	this->mysqlAddResult(MYSQL_TYPE_STRING, (char *) &proxy_result.created_ts, sizeof(proxy_result.created_ts)-1);
	this->mysqlAddResult(MYSQL_TYPE_STRING, (char *) &proxy_result.user_notes, sizeof(proxy_result.user_notes)-1);
	this->mysqlBindResults();
	if(this->mysqlExecuteStatement() != ERR_SUCCESS)
	{
		printf("\n First execute select statement failed.  Exiting getProxyDBGroupSetByCriteria.");
		BP_BLOCK_MARIADB_LEAVE_CRITICAL_SECTION_AND_RETURN_FROM_FUNC(ERR_FAILURE);
	}
	this->mysqlStoreResults();
	if(this->db_populated_proxy_groups)
		tq_free(this->tq, this->db_populated_proxy_groups);
	this->db_populated_proxy_groups   = NULL;
	this->db_populated_proxy_group_n  = 0;
	while(this->mysqlFetchResult() == ERR_SUCCESS)
	{
		this->db_populated_proxy_group_n++;
		this->db_populated_proxy_groups = (P_BP_PROXY_DB_GROUP) tq_realloc(this->tq, (void *) this->db_populated_proxy_groups, sizeof(BP_PROXY_DB_GROUP) * this->db_populated_proxy_group_n, BPLN);
		memcpy((void *) &this->db_populated_proxy_groups[this->db_populated_proxy_group_n-1], (void *) &proxy_result, sizeof(proxy_result));
		memset((void *)&proxy_result, 0x00, sizeof(proxy_result));
	}
	this->mysqlDestroyStatement();
	delete query_builder;
	BP_BLOCK_MARIADB_LEAVE_CRITICAL_SECTION_AND_RETURN_FROM_FUNC(ERR_SUCCESS);
}
BP_ERROR_T Block :: getProxyDBGroupSetByCriteria ( size_t id , size_t user_id , char * group_name , size_t bottom_limit , size_t top_limit ) { if ( ! this -> mysqlSession ) return ERR_FAILURE ; BP_BLOCK_MARIADB_ENTER_CRITICAL_SECTION ; if ( ! this -> mysqlSession -> conn ) BP_BLOCK_MARIADB_LEAVE_CRITICAL_SECTION_AND_RETURN_FROM_FUNC ( ERR_FAILURE ) ; BP_StringUtils * query_builder = new BP_StringUtils ( ( char * ) " " ) ; char * base_query = ( char * ) " " " " " " ; query_builder -> BuildString ( base_query ) ; if ( id ) query_builder -> BuildString ( ( char * ) " " ) ; if ( user_id ) query_builder -> BuildString ( ( char * ) " " ) ; if ( group_name ) query_builder -> BuildString ( ( char * ) " " ) ; char limit_str [ 256 ] = { 0 } ; sprintf ( ( char * ) & limit_str , ( char * ) " " , bottom_limit , top_limit ) ; query_builder -> BuildString ( limit_str ) ; if ( this -> mysqlPrepareQuery ( query_builder -> build_str ) != ERR_SUCCESS ) { BP_BLOCK_MARIADB_LEAVE_CRITICAL_SECTION_AND_RETURN_FROM_FUNC ( ERR_FAILURE ) ; } if ( id ) this -> mysqlAddParameter ( MYSQL_TYPE_LONG , ( char * ) & id , sizeof ( id ) ) ; if ( user_id ) this -> mysqlAddParameter ( MYSQL_TYPE_LONG , ( char * ) & user_id , sizeof ( user_id ) ) ; if ( group_name ) this -> mysqlAddParameter ( MYSQL_TYPE_STRING , ( char * ) group_name , strnlen ( group_name , 1024 ) - 1 ) ; this -> mysqlBindParameters ( ) ; BP_PROXY_DB_GROUP proxy_result = { 0 } ; memset ( ( void * ) & proxy_result , 0x00 , sizeof ( proxy_result ) ) ; this -> mysqlAddResult ( MYSQL_TYPE_LONG , ( char * ) & proxy_result . id , sizeof ( proxy_result . id ) ) ; this -> mysqlAddResult ( MYSQL_TYPE_LONG , ( char * ) & proxy_result . user_id , sizeof ( proxy_result . user_id ) ) ; this -> mysqlAddResult ( MYSQL_TYPE_STRING , ( char * ) & proxy_result . name , sizeof ( proxy_result . name ) - 1 ) ; this -> mysqlAddResult ( MYSQL_TYPE_LONG , ( char * ) & proxy_result . enabled , sizeof ( proxy_result . enabled ) ) ; this -> mysqlAddResult ( MYSQL_TYPE_STRING , ( char * ) & proxy_result . created_ts , sizeof ( proxy_result . created_ts ) - 1 ) ; this -> mysqlAddResult ( MYSQL_TYPE_STRING , ( char * ) & proxy_result . user_notes , sizeof ( proxy_result . user_notes ) - 1 ) ; this -> mysqlBindResults ( ) ; if ( this -> mysqlExecuteStatement ( ) != ERR_SUCCESS ) { printf ( " \n " ) ; BP_BLOCK_MARIADB_LEAVE_CRITICAL_SECTION_AND_RETURN_FROM_FUNC ( ERR_FAILURE ) ; } this -> mysqlStoreResults ( ) ; if ( this -> db_populated_proxy_groups ) tq_free ( this -> tq , this -> db_populated_proxy_groups ) ; this -> db_populated_proxy_groups = NULL ; this -> db_populated_proxy_group_n = 0 ; while ( this -> mysqlFetchResult ( ) == ERR_SUCCESS ) { this -> db_populated_proxy_group_n ++ ; this -> db_populated_proxy_groups = ( P_BP_PROXY_DB_GROUP ) tq_realloc ( this -> tq , ( void * ) this -> db_populated_proxy_groups , sizeof ( BP_PROXY_DB_GROUP ) * this -> db_populated_proxy_group_n , BPLN ) ; memcpy ( ( void * ) & this -> db_populated_proxy_groups [ this -> db_populated_proxy_group_n - 1 ] , ( void * ) & proxy_result , sizeof ( proxy_result ) ) ; memset ( ( void * ) & proxy_result , 0x00 , sizeof ( proxy_result ) ) ; } this -> mysqlDestroyStatement ( ) ; delete query_builder ; BP_BLOCK_MARIADB_LEAVE_CRITICAL_SECTION_AND_RETURN_FROM_FUNC ( ERR_SUCCESS ) ; }
retrieves proxy group sets via criteria (zero / empty values for unset/wildcard search terms)
retrieves proxy group sets via criteria ( zero / empty values for unset / wildcard search terms )
// this method requires a valid mysql session // enter critical section // exit if the mysqli object is unset // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% // %%%%%% Build Query %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% // create new string builder // select query to run // add the base query // dynamically add initial query constraints // create simple limit string // populate the limit string (transfer lengths precalculated) // append the limit string // prepare the query // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% // %%%%%%%%%%% Add Parameters %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% // dynamically add initial query constraints // bind the query parameters before executing statement // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% // %%%%%% Add Results %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% // allocate new proxy result value // `id` // `user_id` // `name` // `enabled` // `created_ts` // `user_notes` // now bind results // %%%%%%% Execute the SELECT query %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% // execute the statement // store the results of the query // destroy structure if necessary before proceeding // reset class proxy sets before continuing // fetch an individual record // display the fetched record // this->displayProxyDBEntryRecord((P_BP_PROXY_DB_ENTRY) &proxy_result); // increment the populated proxy array count // allocate space for the new set // copy the retrieved data into class array // zero out the result structure before loop (new record) // destroy statement (free memory) // destroy the query builder // return indicating success