library/src/blockclass/BP-BlockClass.cc
// Inserts anchor data into the db.
Inserts anchor data into the db.
Inserts anchor data into the db .
size_t Block::insertAnchor(P_BP_HTML_ANCHOR_LIST anchor, size_t result_id)
{
	if(!this->mysqlSession)
		return ERR_FAILURE;
	BP_BLOCK_MARIADB_ENTER_CRITICAL_SECTION;
	if(!anchor)
		BP_BLOCK_MARIADB_LEAVE_CRITICAL_SECTION_AND_RETURN_FROM_FUNC(ERR_FAILURE);
	char * anchor_query = (char *) "INSERT INTO `anchor_data` (`id` ,`result_id`,`rel_href` ,`script_name`)VALUES (NULL, ?, ?, ?	);";
	this->mysqlPrepareQuery(anchor_query);
	this->mysqlAddParameter(MYSQL_TYPE_LONG,   (char *) &result_id,        sizeof(result_id));
	this->mysqlAddParameter(MYSQL_TYPE_STRING, (char *) anchor->href,      bpstrlen(anchor->href));
	this->mysqlAddParameter(MYSQL_TYPE_STRING, (char *) "empty",           bpstrlen("empty"));
	this->mysqlBindParameters();
	if(this->mysqlExecuteStatement() != ERR_SUCCESS)
	{
		printf("\n ERR: Could not run anchor insert statement");
	}
	size_t 					  last_anchor_id   = this->mysqlSession->conn->insert_id;
	P_BP_HTML_ANCHOR_VAR_LIST anchor_vars = anchor->vars;
	char * var_query    = (char *) "INSERT INTO `anchor_var_data` (`id` ,`result_id` ,`anchor_id` ,`name` ,`value`)VALUES ('', ?, ?, ?, ?);";
	if(anchor_vars)
	for
	(
		anchor_vars = anchor_vars->first;
		anchor_vars;
		anchor_vars = anchor_vars->next
	)
	{
		this->mysqlPrepareQuery(var_query);
		char * anchor_var_name_tmp = anchor_vars->name;
		if(!anchor_var_name_tmp)
			anchor_var_name_tmp = "NULL";
		size_t anchor_var_name_len_tmp = bpstrlen(anchor_var_name_tmp);
		char * anchor_var_content_tmp = anchor_vars->content;
		if(!anchor_var_content_tmp)
			anchor_var_content_tmp = "NULL";
		size_t anchor_var_content_len_tmp = bpstrlen(anchor_var_content_tmp);
		this->mysqlAddParameter(MYSQL_TYPE_LONG,   (char *) &result_id,               sizeof(result_id));
		this->mysqlAddParameter(MYSQL_TYPE_LONG,   (char *) &last_anchor_id,          sizeof(last_anchor_id));
		this->mysqlAddParameter(MYSQL_TYPE_STRING, (char *) anchor_var_name_tmp,      bpstrlen(anchor_var_name_tmp));
		this->mysqlAddParameter(MYSQL_TYPE_STRING, (char *) anchor_var_content_tmp,   bpstrlen(anchor_var_content_tmp));
		this->mysqlBindParameters();
		if(this->mysqlExecuteStatement() != ERR_SUCCESS)
		{
			printf("\n ERR: Could not run anchor insert statement");
		}
	}
	BP_BLOCK_MARIADB_LEAVE_CRITICAL_SECTION_AND_RETURN_FROM_FUNC(ERR_SUCCESS);
}
size_t Block :: insertAnchor ( P_BP_HTML_ANCHOR_LIST anchor , size_t result_id ) { if ( ! this -> mysqlSession ) return ERR_FAILURE ; BP_BLOCK_MARIADB_ENTER_CRITICAL_SECTION ; if ( ! anchor ) BP_BLOCK_MARIADB_LEAVE_CRITICAL_SECTION_AND_RETURN_FROM_FUNC ( ERR_FAILURE ) ; char * anchor_query = ( char * ) " " ; this -> mysqlPrepareQuery ( anchor_query ) ; this -> mysqlAddParameter ( MYSQL_TYPE_LONG , ( char * ) & result_id , sizeof ( result_id ) ) ; this -> mysqlAddParameter ( MYSQL_TYPE_STRING , ( char * ) anchor -> href , bpstrlen ( anchor -> href ) ) ; this -> mysqlAddParameter ( MYSQL_TYPE_STRING , ( char * ) " " , bpstrlen ( " " ) ) ; this -> mysqlBindParameters ( ) ; if ( this -> mysqlExecuteStatement ( ) != ERR_SUCCESS ) { printf ( " \n " ) ; } size_t last_anchor_id = this -> mysqlSession -> conn -> insert_id ; P_BP_HTML_ANCHOR_VAR_LIST anchor_vars = anchor -> vars ; char * var_query = ( char * ) " " ; if ( anchor_vars ) for ( anchor_vars = anchor_vars -> first ; anchor_vars ; anchor_vars = anchor_vars -> next ) { this -> mysqlPrepareQuery ( var_query ) ; char * anchor_var_name_tmp = anchor_vars -> name ; if ( ! anchor_var_name_tmp ) anchor_var_name_tmp = " " ; size_t anchor_var_name_len_tmp = bpstrlen ( anchor_var_name_tmp ) ; char * anchor_var_content_tmp = anchor_vars -> content ; if ( ! anchor_var_content_tmp ) anchor_var_content_tmp = " " ; size_t anchor_var_content_len_tmp = bpstrlen ( anchor_var_content_tmp ) ; this -> mysqlAddParameter ( MYSQL_TYPE_LONG , ( char * ) & result_id , sizeof ( result_id ) ) ; this -> mysqlAddParameter ( MYSQL_TYPE_LONG , ( char * ) & last_anchor_id , sizeof ( last_anchor_id ) ) ; this -> mysqlAddParameter ( MYSQL_TYPE_STRING , ( char * ) anchor_var_name_tmp , bpstrlen ( anchor_var_name_tmp ) ) ; this -> mysqlAddParameter ( MYSQL_TYPE_STRING , ( char * ) anchor_var_content_tmp , bpstrlen ( anchor_var_content_tmp ) ) ; this -> mysqlBindParameters ( ) ; if ( this -> mysqlExecuteStatement ( ) != ERR_SUCCESS ) { printf ( " \n " ) ; } } BP_BLOCK_MARIADB_LEAVE_CRITICAL_SECTION_AND_RETURN_FROM_FUNC ( ERR_SUCCESS ) ; }
Inserts anchor data into the db.
Inserts anchor data into the db .
// ensure we have a mysql handle // enter critical section // insert an anchor // query to insert anchor into db (vals are added below) // prepare the query // insert anchor base data first // bind the parameters // execute the query // set the last anchor id // anchor variable insert query // prepare the query // generate tmp name or empty string if necessary // calculate name length // generate tmp content or empty string if necessary // calculate name length // insert anchor base data first // bind the parameters // execute the query // return indicating success