library/src/blockclass/BP-BlockClass.cc
// retrieve jit expressions from database (if expressions already exist, they are destroyed
// first.  This is functionally retrieve + update on loop.  Set elements to zero values to
// omit them from search.  All zero values for ALL tests.
retrieve jit expressions from database (if expressions already exist, they are destroyed
first.  This is functionally retrieve + update on loop.  Set elements to zero values to
omit them from search.  All zero values for ALL tests.
retrieve jit expressions from database ( if expressions already exist they are destroyed first . This is functionally retrieve + update on loop . Set elements to zero values to omit them from search . All zero values for ALL tests .
BP_ERROR_T Block::retrieveWebJITExpressionsFromDB(size_t db_id, size_t group_id, size_t user_id, 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_id`, `expression`, `description`, `created_ts` "\
							"FROM `web_jit_expression_tests` WHERE 1=1 ";
	query_builder->BuildString(base_query);
	if(db_id)
		query_builder->BuildString( (char *) " AND `id` = ?");
	if(user_id)
		query_builder->BuildString( (char *) " AND `user_id` = ?");
	if(group_id)
		query_builder->BuildString( (char *) " AND `group_id` = ?");
	char limit_str[256] = {0};
	sprintf((char *) &limit_str, (char *) " LIMIT %u, %u ", bottom_limit, top_limit);
	if(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(db_id)
		this->mysqlAddParameter(MYSQL_TYPE_LONG,   (char *) &db_id,  sizeof(db_id));
	if(user_id)
		this->mysqlAddParameter(MYSQL_TYPE_LONG,   (char *) &user_id,  sizeof(user_id));
	if(group_id)
		this->mysqlAddParameter(MYSQL_TYPE_LONG,   (char *) &group_id,  sizeof(group_id));
	this->mysqlBindParameters();
	BP_PCRE_JIT_MATCH_ENTRY result = {0};
	memset((void *)&result, 0x00, sizeof(result));
	this->mysqlAddResult(MYSQL_TYPE_LONG, (char *) &result.id, sizeof(result.id));
	this->mysqlAddResult(MYSQL_TYPE_LONG, (char *) &result.user_id, sizeof(result.user_id));
	this->mysqlAddResult(MYSQL_TYPE_LONG, (char *) &result.group_id, sizeof(result.group_id));
	this->mysqlAddResult(MYSQL_TYPE_STRING, (char *) &result.regexp, sizeof(result.regexp)-1);
	this->mysqlAddResult(MYSQL_TYPE_STRING, (char *) &result.description, sizeof(result.description)-1);
	this->mysqlAddResult(MYSQL_TYPE_STRING, (char *) &result.created_ts, sizeof(result.created_ts)-1);
	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();
	this->destroyWebJITExpressionData();
	this->web_request_jit_match_set   = NULL;
	this->web_request_jit_match_n     = 0;
	while(this->mysqlFetchResult() == ERR_SUCCESS)
	{
		this->web_request_jit_match_n++;
		this->web_request_jit_match_set = (P_BP_PCRE_JIT_MATCH_ENTRY) tq_realloc(this->tq, (void *) this->web_request_jit_match_set, sizeof(BP_PCRE_JIT_MATCH_ENTRY) * (this->web_request_jit_match_n+1), BPLN);
		size_t col_iter = 0;
		memcpy(&this->web_request_jit_match_set[this->web_request_jit_match_n-1].id, mysqlSession->bind_results_external_ptr[col_iter].buffer, mysqlSession->bind_results_external_ptr[col_iter].buffer_length);
		col_iter++;
		memcpy(&this->web_request_jit_match_set[this->web_request_jit_match_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->web_request_jit_match_set[this->web_request_jit_match_n-1].group_id, mysqlSession->bind_results_external_ptr[col_iter].buffer, mysqlSession->bind_results_external_ptr[col_iter].buffer_length);
		col_iter++;
		memcpy(&this->web_request_jit_match_set[this->web_request_jit_match_n-1].regexp, mysqlSession->bind_results_external_ptr[col_iter].buffer, mysqlSession->bind_results_external_ptr[col_iter].buffer_length);
		col_iter++;
		memcpy(&this->web_request_jit_match_set[this->web_request_jit_match_n-1].description, mysqlSession->bind_results_external_ptr[col_iter].buffer, mysqlSession->bind_results_external_ptr[col_iter].buffer_length);
		col_iter++;
		memcpy(&this->web_request_jit_match_set[this->web_request_jit_match_n-1].created_ts, mysqlSession->bind_results_external_ptr[col_iter].buffer, mysqlSession->bind_results_external_ptr[col_iter].buffer_length);
		col_iter++;
	}
	this->mysqlDestroyStatement();
	delete query_builder;
	BP_BLOCK_MARIADB_LEAVE_CRITICAL_SECTION_AND_RETURN_FROM_FUNC(ERR_SUCCESS);
}
BP_ERROR_T Block :: retrieveWebJITExpressionsFromDB ( size_t db_id , size_t group_id , size_t user_id , 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 ( db_id ) query_builder -> BuildString ( ( char * ) " " ) ; if ( user_id ) query_builder -> BuildString ( ( char * ) " " ) ; if ( group_id ) query_builder -> BuildString ( ( char * ) " " ) ; char limit_str [ 256 ] = { 0 } ; sprintf ( ( char * ) & limit_str , ( char * ) " " , bottom_limit , top_limit ) ; if ( 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 ( db_id ) this -> mysqlAddParameter ( MYSQL_TYPE_LONG , ( char * ) & db_id , sizeof ( db_id ) ) ; if ( user_id ) this -> mysqlAddParameter ( MYSQL_TYPE_LONG , ( char * ) & user_id , sizeof ( user_id ) ) ; if ( group_id ) this -> mysqlAddParameter ( MYSQL_TYPE_LONG , ( char * ) & group_id , sizeof ( group_id ) ) ; this -> mysqlBindParameters ( ) ; BP_PCRE_JIT_MATCH_ENTRY result = { 0 } ; memset ( ( void * ) & result , 0x00 , sizeof ( result ) ) ; this -> mysqlAddResult ( MYSQL_TYPE_LONG , ( char * ) & result . id , sizeof ( result . id ) ) ; this -> mysqlAddResult ( MYSQL_TYPE_LONG , ( char * ) & result . user_id , sizeof ( result . user_id ) ) ; this -> mysqlAddResult ( MYSQL_TYPE_LONG , ( char * ) & result . group_id , sizeof ( result . group_id ) ) ; this -> mysqlAddResult ( MYSQL_TYPE_STRING , ( char * ) & result . regexp , sizeof ( result . regexp ) - 1 ) ; this -> mysqlAddResult ( MYSQL_TYPE_STRING , ( char * ) & result . description , sizeof ( result . description ) - 1 ) ; this -> mysqlAddResult ( MYSQL_TYPE_STRING , ( char * ) & result . created_ts , sizeof ( result . created_ts ) - 1 ) ; this -> mysqlBindResults ( ) ; if ( this -> mysqlExecuteStatement ( ) != ERR_SUCCESS ) { printf ( " \n " ) ; BP_BLOCK_MARIADB_LEAVE_CRITICAL_SECTION_AND_RETURN_FROM_FUNC ( ERR_FAILURE ) ; } this -> mysqlStoreResults ( ) ; this -> destroyWebJITExpressionData ( ) ; this -> web_request_jit_match_set = NULL ; this -> web_request_jit_match_n = 0 ; while ( this -> mysqlFetchResult ( ) == ERR_SUCCESS ) { this -> web_request_jit_match_n ++ ; this -> web_request_jit_match_set = ( P_BP_PCRE_JIT_MATCH_ENTRY ) tq_realloc ( this -> tq , ( void * ) this -> web_request_jit_match_set , sizeof ( BP_PCRE_JIT_MATCH_ENTRY ) * ( this -> web_request_jit_match_n + 1 ) , BPLN ) ; size_t col_iter = 0 ; memcpy ( & this -> web_request_jit_match_set [ this -> web_request_jit_match_n - 1 ] . id , mysqlSession -> bind_results_external_ptr [ col_iter ] . buffer , mysqlSession -> bind_results_external_ptr [ col_iter ] . buffer_length ) ; col_iter ++ ; memcpy ( & this -> web_request_jit_match_set [ this -> web_request_jit_match_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 -> web_request_jit_match_set [ this -> web_request_jit_match_n - 1 ] . group_id , mysqlSession -> bind_results_external_ptr [ col_iter ] . buffer , mysqlSession -> bind_results_external_ptr [ col_iter ] . buffer_length ) ; col_iter ++ ; memcpy ( & this -> web_request_jit_match_set [ this -> web_request_jit_match_n - 1 ] . regexp , mysqlSession -> bind_results_external_ptr [ col_iter ] . buffer , mysqlSession -> bind_results_external_ptr [ col_iter ] . buffer_length ) ; col_iter ++ ; memcpy ( & this -> web_request_jit_match_set [ this -> web_request_jit_match_n - 1 ] . description , mysqlSession -> bind_results_external_ptr [ col_iter ] . buffer , mysqlSession -> bind_results_external_ptr [ col_iter ] . buffer_length ) ; col_iter ++ ; memcpy ( & this -> web_request_jit_match_set [ this -> web_request_jit_match_n - 1 ] . created_ts , mysqlSession -> bind_results_external_ptr [ col_iter ] . buffer , mysqlSession -> bind_results_external_ptr [ col_iter ] . buffer_length ) ; col_iter ++ ; } this -> mysqlDestroyStatement ( ) ; delete query_builder ; BP_BLOCK_MARIADB_LEAVE_CRITICAL_SECTION_AND_RETURN_FROM_FUNC ( ERR_SUCCESS ) ; }
retrieve jit expressions from database (if expressions already exist, they are destroyed
first.
retrieve jit expressions from database ( if expressions already exist they are destroyed first .
// 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`, // `group_id`, // `expression`, // `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 // (this->web_request_jit_match_set, this->tq); // 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_id`, // `expression`, // `description`, // `created_ts` // destroy statement (free memory) // destroy the query builder // return indicating success