library/src/blockclass/BP-BlockClass.cc
// Inserts form data into the db.
Inserts form data into the db.
Inserts form data into the db .
size_t Block::insertForm(P_BP_HTML_FORM_LIST form, size_t result_id)
{
	if(!this->mysqlSession)
		return ERR_FAILURE;
	BP_BLOCK_MARIADB_ENTER_CRITICAL_SECTION;
	if(!form)
		BP_BLOCK_MARIADB_LEAVE_CRITICAL_SECTION_AND_RETURN_FROM_FUNC(ERR_FAILURE);
	char * form_data_query = (char *) "INSERT INTO `form_data` (	`id` ,`result_id` ,`form_method` ,`form_action`	)VALUES (NULL , ?, ?, ?);";
	char * form_property_data_query = (char *) "INSERT INTO `form_property_data` (`id`, `result_id`, `form_id`, `property_name`, `property_value`) VALUES (NULL, ?, ?, ?, ?);";
	char * form_input_data_query = (char *) "";
	char * form_input_property_data_query = (char *) "";
	P_BP_HTML_FORM_PROPERTY_LIST form_prop_list = form->properties;
	if(!form_prop_list)
		return ERR_FAILURE;
	char *action_string = (char *) "no action in form properties.";
	char *method_string = (char *) "no method set in form properties.";
	for
	(
			form_prop_list = form_prop_list->first;
			form_prop_list;
			form_prop_list = form_prop_list->next
	)
	{
		if(form_prop_list->nLen < 6)
			continue;
		if(BP_strncasecmp(form_prop_list->name, (char *) "action", 6) == 0)
		{
			action_string = form_prop_list->content;
		}
		if(BP_strncasecmp(form_prop_list->name, (char *) "method", 6) == 0)
		{
			method_string = form_prop_list->content;
		}
	}
	if(this->mysqlPrepareQuery(form_data_query) == ERR_FAILURE)
	{
		this->AddErrorToStack((char*) "Cannot prepare query.");
		BP_BLOCK_MARIADB_LEAVE_CRITICAL_SECTION_AND_RETURN_FROM_FUNC(ERR_FAILURE);
	}
	this->mysqlAddParameter(MYSQL_TYPE_LONG, (char *) &result_id, sizeof(result_id));
	this->mysqlAddParameter(MYSQL_TYPE_STRING, (char *) method_string, bpstrlen(method_string));
	this->mysqlAddParameter(MYSQL_TYPE_STRING, (char *) action_string, bpstrlen(action_string));
	this->mysqlBindParameters();
	if(this->mysqlExecuteStatement() == ERR_FAILURE)
	{
		BP_BLOCK_MARIADB_LEAVE_CRITICAL_SECTION_AND_RETURN_FROM_FUNC(ERR_FAILURE);
	}
	size_t form_insert_id = this->mysqlSession->conn->insert_id;
	%%%%%%%%%%%%%%%%%
	%%%%%%%%%%%%%%%%%
	P_BP_HTML_FORM_PROPERTY_LIST properties = form->properties;
	if(form->properties)
	{
		for
		(
			properties = properties->first;
			properties;
			properties = properties->next
		)
		{
			if(this->mysqlPrepareQuery(form_property_data_query) == ERR_FAILURE)
			{
				this->AddErrorToStack((char*) "Cannot prepare query form property data query.");
				BP_BLOCK_MARIADB_LEAVE_CRITICAL_SECTION_AND_RETURN_FROM_FUNC(ERR_FAILURE);
			}
			char *name_str = (char *) "empty";
			char *val_str  = (char *) "empty";
			if(properties->content)
				val_str = properties->content;
			if(properties->name)
				name_str = properties->name;
			this->mysqlAddParameter(MYSQL_TYPE_LONG, (char *) &result_id, sizeof(result_id));
			this->mysqlAddParameter(MYSQL_TYPE_LONG, (char *) &form_insert_id, sizeof(form_insert_id));
			this->mysqlAddParameter(MYSQL_TYPE_STRING, (char *) name_str, bpstrlen(name_str));
			this->mysqlAddParameter(MYSQL_TYPE_STRING, (char *) val_str,  bpstrlen(val_str));
			this->mysqlBindParameters();
			if(this->mysqlExecuteStatement() == ERR_FAILURE)
			{
				BP_BLOCK_MARIADB_LEAVE_CRITICAL_SECTION_AND_RETURN_FROM_FUNC(ERR_FAILURE);
			}
			size_t anchor_prop_insert_id = this->mysqlSession->conn->insert_id;
		}
	}
/*
	this->mysqlPrepareQuery(anchor_query);
	// insert anchor base data first
	this->mysqlAddParameter(MYSQL_TYPE_LONG, (char *) &result_id,            sizeof(result_id));
	this->mysqlAddParameter(MYSQL_TYPE_STRING, (char *) anchors->href,         bpstrlen(anchors->href));
	this->mysqlAddParameter(MYSQL_TYPE_STRING, (char *) "empty",         bpstrlen("empty"));
	// bind the parameters
	this->mysqlBindParameters();
	// execute the query
	if(this->mysqlExecuteStatement() != ERR_SUCCESS)
	{
		printf("\n ERR: Could not run anchor insert statement");
	}
	// set the last anchor id
	size_t last_anchor_id = this->mysqlSession->conn->insert_id;
	P_BP_HTML_ANCHOR_VAR_LIST anchor_vars = anchors->vars;
	if(anchor_vars)
	for
	(
		anchor_vars = anchor_vars->first;
		anchor_vars;
		anchor_vars = anchor_vars->next
	)
	{
		this->mysqlPrepareQuery(var_query);
		// insert anchor base data first
		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_vars->name,     strnlen(anchor_vars->name, 2048));
		this->mysqlAddParameter(MYSQL_TYPE_STRING, (char *) anchor_vars->content,  strnlen(anchor_vars->content, 2048));
		// bind the parameters
		this->mysqlBindParameters();
		// execute the query
		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 :: insertForm ( P_BP_HTML_FORM_LIST form , size_t result_id ) { if ( ! this -> mysqlSession ) return ERR_FAILURE ; BP_BLOCK_MARIADB_ENTER_CRITICAL_SECTION ; if ( ! form ) BP_BLOCK_MARIADB_LEAVE_CRITICAL_SECTION_AND_RETURN_FROM_FUNC ( ERR_FAILURE ) ; char * form_data_query = ( char * ) " " ; char * form_property_data_query = ( char * ) " " ; char * form_input_data_query = ( char * ) " " ; char * form_input_property_data_query = ( char * ) " " ; P_BP_HTML_FORM_PROPERTY_LIST form_prop_list = form -> properties ; if ( ! form_prop_list ) return ERR_FAILURE ; char * action_string = ( char * ) " " ; char * method_string = ( char * ) " " ; for ( form_prop_list = form_prop_list -> first ; form_prop_list ; form_prop_list = form_prop_list -> next ) { if ( form_prop_list -> nLen < 6 ) continue ; if ( BP_strncasecmp ( form_prop_list -> name , ( char * ) " " , 6 ) == 0 ) { action_string = form_prop_list -> content ; } if ( BP_strncasecmp ( form_prop_list -> name , ( char * ) " " , 6 ) == 0 ) { method_string = form_prop_list -> content ; } } if ( this -> mysqlPrepareQuery ( form_data_query ) == ERR_FAILURE ) { this -> AddErrorToStack ( ( char * ) " " ) ; BP_BLOCK_MARIADB_LEAVE_CRITICAL_SECTION_AND_RETURN_FROM_FUNC ( ERR_FAILURE ) ; } this -> mysqlAddParameter ( MYSQL_TYPE_LONG , ( char * ) & result_id , sizeof ( result_id ) ) ; this -> mysqlAddParameter ( MYSQL_TYPE_STRING , ( char * ) method_string , bpstrlen ( method_string ) ) ; this -> mysqlAddParameter ( MYSQL_TYPE_STRING , ( char * ) action_string , bpstrlen ( action_string ) ) ; this -> mysqlBindParameters ( ) ; if ( this -> mysqlExecuteStatement ( ) == ERR_FAILURE ) { BP_BLOCK_MARIADB_LEAVE_CRITICAL_SECTION_AND_RETURN_FROM_FUNC ( ERR_FAILURE ) ; } size_t form_insert_id = this -> mysqlSession -> conn -> insert_id ; P_BP_HTML_FORM_PROPERTY_LIST properties = form -> properties ; if ( form -> properties ) { for ( properties = properties -> first ; properties ; properties = properties -> next ) { if ( this -> mysqlPrepareQuery ( form_property_data_query ) == ERR_FAILURE ) { this -> AddErrorToStack ( ( char * ) " " ) ; BP_BLOCK_MARIADB_LEAVE_CRITICAL_SECTION_AND_RETURN_FROM_FUNC ( ERR_FAILURE ) ; } char * name_str = ( char * ) " " ; char * val_str = ( char * ) " " ; if ( properties -> content ) val_str = properties -> content ; if ( properties -> name ) name_str = properties -> name ; this -> mysqlAddParameter ( MYSQL_TYPE_LONG , ( char * ) & result_id , sizeof ( result_id ) ) ; this -> mysqlAddParameter ( MYSQL_TYPE_LONG , ( char * ) & form_insert_id , sizeof ( form_insert_id ) ) ; this -> mysqlAddParameter ( MYSQL_TYPE_STRING , ( char * ) name_str , bpstrlen ( name_str ) ) ; this -> mysqlAddParameter ( MYSQL_TYPE_STRING , ( char * ) val_str , bpstrlen ( val_str ) ) ; this -> mysqlBindParameters ( ) ; if ( this -> mysqlExecuteStatement ( ) == ERR_FAILURE ) { BP_BLOCK_MARIADB_LEAVE_CRITICAL_SECTION_AND_RETURN_FROM_FUNC ( ERR_FAILURE ) ; } size_t anchor_prop_insert_id = this -> mysqlSession -> conn -> insert_id ; } } BP_BLOCK_MARIADB_LEAVE_CRITICAL_SECTION_AND_RETURN_FROM_FUNC ( ERR_SUCCESS ) ; }
Inserts form data into the db.
Inserts form data into the db .
// ensure we have a mysql handle // enter critical section // insert an anchor // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% // %%% SQL Queries %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% // query to insert anchor into db (vals are added below) // query to insert form property data // query to insert input data // query to insert input property data // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% // %%% End SQL %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% // set form property list iter // exit if we have no property list // action/form string // walk the property list and find action/method // continue if the namelength is less than 6 (action and method are both six char strings) // prepare the query // add parameters // bind parameters // execute query // save the insert id for use further down // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% // %%% Insert Form Properties %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% // prepare the query // add parameters // bind parameters // execute query // save the insert id for use further down // %%%%%%%%%%%%%%%%%% Insert Form Inputs %%%%%%%%%%%%%%%%%%%%%%%%%%%% // %%%%%%%%%%%%%%%%%% Insert Form Input Properties %%%%%%%%%%%%%%%%%% /*
	// prepare the query
	this->mysqlPrepareQuery(anchor_query);

	// insert anchor base data first
	this->mysqlAddParameter(MYSQL_TYPE_LONG, (char *) &result_id,            sizeof(result_id));
	this->mysqlAddParameter(MYSQL_TYPE_STRING, (char *) anchors->href,         bpstrlen(anchors->href));
	this->mysqlAddParameter(MYSQL_TYPE_STRING, (char *) "empty",         bpstrlen("empty"));

	// bind the parameters
	this->mysqlBindParameters();

	// execute the query
	if(this->mysqlExecuteStatement() != ERR_SUCCESS)
	{
		printf("\n ERR: Could not run anchor insert statement");
	}

	// set the last anchor id
	size_t last_anchor_id = this->mysqlSession->conn->insert_id;
	P_BP_HTML_ANCHOR_VAR_LIST anchor_vars = anchors->vars;

	if(anchor_vars)
	for
	(
		anchor_vars = anchor_vars->first;
		anchor_vars;
		anchor_vars = anchor_vars->next
	)
	{

		// prepare the query
		this->mysqlPrepareQuery(var_query);

		// insert anchor base data first
		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_vars->name,     strnlen(anchor_vars->name, 2048));
		this->mysqlAddParameter(MYSQL_TYPE_STRING, (char *) anchor_vars->content,  strnlen(anchor_vars->content, 2048));

		// bind the parameters
		this->mysqlBindParameters();

		// execute the query
		if(this->mysqlExecuteStatement() != ERR_SUCCESS)
		{
			printf("\n ERR: Could not run anchor insert statement");
		}

	}
	*/ // return indicating success