library/src/blockclass/BP-BlockClass.cc
// pulls proxy validation groups by provided criteria.  null criteria is an empty (blanket) search.
pulls proxy validation groups by provided criteria.  null criteria is an empty (blanket) search.
pulls proxy validation groups by provided criteria . null criteria is an empty ( blanket ) search .
BP_ERROR_T Block::getProxyDBValidationGroupSetByCriteria(size_t id, size_t user_id, char *group_name, char *group_description, char *created_ts, size_t bottom_limit, size_t top_limit)
{
	if(!this->mysqlSession)
		return ERR_FAILURE;
	BP_BLOCK_MARIADB_ENTER_CRITICAL_SECTION;
	BP_StringUtils * query_builder = new BP_StringUtils("");
	char *base_query =    "SELECT "\
						" `id`, `user_id`, `group_name`, `group_description`, `created_ts` "\
						"FROM `validation_test_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` = ?");
	if(group_description)
		query_builder->BuildString( (char *) " AND `group_description` = ?");
	if(created_ts)
		query_builder->BuildString( (char *) " AND `created_ts` = ?");
	char limit_str[256] = {0};
	sprintf((char *) &limit_str, " 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);
	if(group_description)
		this->mysqlAddParameter(MYSQL_TYPE_STRING,   (char *) group_description, strnlen(group_description, 1024)-1 );
	if(created_ts)
		this->mysqlAddParameter(MYSQL_TYPE_STRING,   (char *) created_ts, strnlen(created_ts, 1024)-1);
	this->mysqlBindParameters();
	BP_PROXY_DB_VALIDATION_TEST_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.group_name, sizeof(proxy_result.group_name));
	this->mysqlAddResult(MYSQL_TYPE_STRING, (char *) &proxy_result.group_description, sizeof(proxy_result.group_description));
	this->mysqlAddResult(MYSQL_TYPE_STRING, (char *) &proxy_result.created_ts, sizeof(proxy_result.created_ts));
	this->mysqlBindResults();
	if(this->mysqlExecuteStatement() != ERR_SUCCESS)
	{
		printf("\n First execute select statement failed.  Exiting unit test.");
		BP_BLOCK_MARIADB_LEAVE_CRITICAL_SECTION_AND_RETURN_FROM_FUNC(ERR_FAILURE);
	}
	this->mysqlStoreResults();
	if(this->db_populated_proxy_validation_groups)
		tq_free(this->tq, this->db_populated_proxy_validation_groups);
	this->db_populated_proxy_validation_groups     = NULL;
	this->db_populated_proxy_validation_group_n    = 0;
	while(this->mysqlFetchResult() == ERR_SUCCESS)
	{
		this->db_populated_proxy_validation_group_n++;
		this->db_populated_proxy_validation_groups = (P_BP_PROXY_DB_VALIDATION_TEST_GROUP) tq_realloc(this->tq, (void *) this->db_populated_proxy_validation_groups, sizeof(BP_PROXY_DB_VALIDATION_TEST_GROUP) * this->db_populated_proxy_validation_group_n, BPLN);
		size_t col_iter = 0;
		,
		memcpy(&this->db_populated_proxy_validation_groups[this->db_populated_proxy_validation_group_n-1].id, mysqlSession->bind_results_external_ptr[col_iter].buffer, mysqlSession->bind_results_external_ptr[col_iter].buffer_length);
		col_iter++;
		,
		memcpy(&this->db_populated_proxy_validation_groups[this->db_populated_proxy_validation_group_n-1].user_id, mysqlSession->bind_results_external_ptr[col_iter].buffer, mysqlSession->bind_results_external_ptr[col_iter].buffer_length);
		col_iter++;
		,
		memcpy(&this->db_populated_proxy_validation_groups[this->db_populated_proxy_validation_group_n-1].group_name, mysqlSession->bind_results_external_ptr[col_iter].buffer, mysqlSession->bind_results_external_ptr[col_iter].buffer_length);
		col_iter++;
		,
		memcpy(&this->db_populated_proxy_validation_groups[this->db_populated_proxy_validation_group_n-1].group_description, mysqlSession->bind_results_external_ptr[col_iter].buffer, mysqlSession->bind_results_external_ptr[col_iter].buffer_length);
		col_iter++;
		memcpy(&this->db_populated_proxy_validation_groups[this->db_populated_proxy_validation_group_n-1].created_ts, mysqlSession->bind_results_external_ptr[col_iter].buffer, mysqlSession->bind_results_external_ptr[col_iter].buffer_length);
		col_iter++;
		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 :: getProxyDBValidationGroupSetByCriteria ( size_t id , size_t user_id , char * group_name , char * group_description , char * created_ts , size_t bottom_limit , size_t top_limit ) { 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 ( id ) query_builder -> BuildString ( ( char * ) " " ) ; if ( user_id ) query_builder -> BuildString ( ( char * ) " " ) ; if ( group_name ) query_builder -> BuildString ( ( char * ) " " ) ; if ( group_description ) query_builder -> BuildString ( ( char * ) " " ) ; if ( created_ts ) query_builder -> BuildString ( ( char * ) " " ) ; char limit_str [ 256 ] = { 0 } ; sprintf ( ( char * ) & limit_str , " " , 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 ) ; if ( group_description ) this -> mysqlAddParameter ( MYSQL_TYPE_STRING , ( char * ) group_description , strnlen ( group_description , 1024 ) - 1 ) ; if ( created_ts ) this -> mysqlAddParameter ( MYSQL_TYPE_STRING , ( char * ) created_ts , strnlen ( created_ts , 1024 ) - 1 ) ; this -> mysqlBindParameters ( ) ; BP_PROXY_DB_VALIDATION_TEST_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 . group_name , sizeof ( proxy_result . group_name ) ) ; this -> mysqlAddResult ( MYSQL_TYPE_STRING , ( char * ) & proxy_result . group_description , sizeof ( proxy_result . group_description ) ) ; this -> mysqlAddResult ( MYSQL_TYPE_STRING , ( char * ) & proxy_result . created_ts , sizeof ( proxy_result . created_ts ) ) ; 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_validation_groups ) tq_free ( this -> tq , this -> db_populated_proxy_validation_groups ) ; this -> db_populated_proxy_validation_groups = NULL ; this -> db_populated_proxy_validation_group_n = 0 ; while ( this -> mysqlFetchResult ( ) == ERR_SUCCESS ) { this -> db_populated_proxy_validation_group_n ++ ; this -> db_populated_proxy_validation_groups = ( P_BP_PROXY_DB_VALIDATION_TEST_GROUP ) tq_realloc ( this -> tq , ( void * ) this -> db_populated_proxy_validation_groups , sizeof ( BP_PROXY_DB_VALIDATION_TEST_GROUP ) * this -> db_populated_proxy_validation_group_n , BPLN ) ; size_t col_iter = 0 ; memcpy ( & this -> db_populated_proxy_validation_groups [ this -> db_populated_proxy_validation_group_n - 1 ] . id , mysqlSession -> bind_results_external_ptr [ col_iter ] . buffer , mysqlSession -> bind_results_external_ptr [ col_iter ] . buffer_length ) ; col_iter ++ ; memcpy ( & this -> db_populated_proxy_validation_groups [ this -> db_populated_proxy_validation_group_n - 1 ] . user_id , mysqlSession -> bind_results_external_ptr [ col_iter ] . buffer , mysqlSession -> bind_results_external_ptr [ col_iter ] . buffer_length ) ; col_iter ++ ; memcpy ( & this -> db_populated_proxy_validation_groups [ this -> db_populated_proxy_validation_group_n - 1 ] . group_name , mysqlSession -> bind_results_external_ptr [ col_iter ] . buffer , mysqlSession -> bind_results_external_ptr [ col_iter ] . buffer_length ) ; col_iter ++ ; memcpy ( & this -> db_populated_proxy_validation_groups [ this -> db_populated_proxy_validation_group_n - 1 ] . group_description , mysqlSession -> bind_results_external_ptr [ col_iter ] . buffer , mysqlSession -> bind_results_external_ptr [ col_iter ] . buffer_length ) ; col_iter ++ ; memcpy ( & this -> db_populated_proxy_validation_groups [ this -> db_populated_proxy_validation_group_n - 1 ] . created_ts , mysqlSession -> bind_results_external_ptr [ col_iter ] . buffer , mysqlSession -> bind_results_external_ptr [ col_iter ] . buffer_length ) ; col_iter ++ ; 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 ) ; }
pulls proxy validation groups by provided criteria.
pulls proxy validation groups by provided criteria .
// exit if the mysqli object is unset // enter critical section // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% // %%%%%% 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 // 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` // `group_name` // `group_description` // `created_ts` // 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 // increment the populated proxy array count // allocate space for the new set // column iterator // `id`, // `user_id`, // `group_name`, // `group_description`, // `created_ts` // zero out the result structure before loop (new record) // destroy statement (free memory) // destroy the query builder // return indicating success