library/src/blockclass/BP-BlockClass.cc
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)
{


	// exit if the mysqli object is unset
	if(!this->mysqlSession)
		return ERR_FAILURE;

	// enter critical section
	BP_BLOCK_MARIADB_ENTER_CRITICAL_SECTION;

	// %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
	// %%%%%% Build Query %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
	// %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

	// create new string builder
	BP_StringUtils * query_builder = new BP_StringUtils("");

	// select query to run
	char *base_query =    "SELECT "\
						" `id`, `user_id`, `group_name`, `group_description`, `created_ts` "\
						"FROM `validation_test_groups` WHERE 1=1 ";


	// add the base query
	query_builder->BuildString(base_query);

	// dynamically add initial query constraints
	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` = ?");
	// create simple limit string
	char limit_str[256] = {0};

	// populate the limit string
	sprintf((char *) &limit_str, " LIMIT %u, %u ", bottom_limit, top_limit);

	// append the limit string
	query_builder->BuildString(limit_str);

	// prepare the query
	if(this->mysqlPrepareQuery(query_builder->build_str) != ERR_SUCCESS)
	{
		BP_BLOCK_MARIADB_LEAVE_CRITICAL_SECTION_AND_RETURN_FROM_FUNC(ERR_FAILURE);
	}

	// %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
	// %%%%%%%%%%% Add Parameters %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
	// %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

	// dynamically add initial query constraints
	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);

	// bind the query parameters before executing statement
	this->mysqlBindParameters();

	// %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
	// %%%%%% Add Results %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
	// %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

	// allocate new proxy result value
	BP_PROXY_DB_VALIDATION_TEST_GROUP proxy_result = {0};
	memset((void *)&proxy_result, 0x00, sizeof(proxy_result));

	// `id`
	this->mysqlAddResult(MYSQL_TYPE_LONG, (char *) &proxy_result.id, sizeof(proxy_result.id));

	// `user_id`
	this->mysqlAddResult(MYSQL_TYPE_LONG, (char *) &proxy_result.user_id, sizeof(proxy_result.user_id));

	// `group_name`
	this->mysqlAddResult(MYSQL_TYPE_STRING, (char *) &proxy_result.group_name, sizeof(proxy_result.group_name));

	// `group_description`
	this->mysqlAddResult(MYSQL_TYPE_STRING, (char *) &proxy_result.group_description, sizeof(proxy_result.group_description));

	// `created_ts`
	this->mysqlAddResult(MYSQL_TYPE_STRING, (char *) &proxy_result.created_ts, sizeof(proxy_result.created_ts));

	// now bind results
	this->mysqlBindResults();


	// %%%%%%% Execute the SELECT query %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

	// execute the statement
	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);
	}

	// store the results of the query
	this->mysqlStoreResults();

	// destroy structure if necessary before proceeding
	if(this->db_populated_proxy_validation_groups)
		tq_free(this->tq, this->db_populated_proxy_validation_groups);

	// reset class proxy sets before continuing
	this->db_populated_proxy_validation_groups     = NULL;
	this->db_populated_proxy_validation_group_n    = 0;


	// fetch an individual record
	while(this->mysqlFetchResult() == ERR_SUCCESS)
	{

		// increment the populated proxy array count
		this->db_populated_proxy_validation_group_n++;

		// allocate space for the new set
		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);


		// column iterator
		size_t col_iter = 0;

		// `id`,
		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++;

		// `user_id`,
		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++;

		// `group_name`,
		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++;

		// `group_description`,
		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++;

		// `created_ts`
		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++;

		// zero out the result structure before loop (new record)
		memset((void *)&proxy_result, 0x00, sizeof(proxy_result));

	}

	// destroy statement (free memory)
	this->mysqlDestroyStatement();

	// destroy the query builder
	delete query_builder;

	// return indicating success
	BP_BLOCK_MARIADB_LEAVE_CRITICAL_SECTION_AND_RETURN_FROM_FUNC(ERR_SUCCESS);

}
// 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