library/src/blockclass/BP-BlockClass.cc
// Connect to a mysql database.
Connect to a mysql database.
Connect to a mysql database .
BP_ERROR_T Block::MysqlConnect(char *mysqlHost, char *mysqlUser, char *mysqlPass, char *mysqlDB, size_t port)
{
	BP_BLOCK_MARIADB_ENTER_CRITICAL_SECTION;
	if(this->mysqlSession)
	{
		this->mysqlDestroyStatement();
		BP_MySQLClose(this->mysqlSession);
		this->mysqlSession = NULL;
	}
	this->mysqlSession = BP_MySQLConnect(mysqlHost, mysqlUser, mysqlPass, mysqlDB, port);
	if(!this->mysqlSession)
	{
		BP_MySQLAddErr(this->mysqlSession, BP_MYSQL_ERROR_CONNECT, 0, "Block class could not connect to database.", BPLN);
		BP_BLOCK_MARIADB_LEAVE_CRITICAL_SECTION_AND_RETURN_FROM_FUNC(ERR_FAILURE);
	}
	BP_BLOCK_MARIADB_LEAVE_CRITICAL_SECTION;
	return ERR_SUCCESS;
}
BP_ERROR_T Block :: MysqlConnect ( char * mysqlHost , char * mysqlUser , char * mysqlPass , char * mysqlDB , size_t port ) { BP_BLOCK_MARIADB_ENTER_CRITICAL_SECTION ; if ( this -> mysqlSession ) { this -> mysqlDestroyStatement ( ) ; BP_MySQLClose ( this -> mysqlSession ) ; this -> mysqlSession = NULL ; } this -> mysqlSession = BP_MySQLConnect ( mysqlHost , mysqlUser , mysqlPass , mysqlDB , port ) ; if ( ! this -> mysqlSession ) { BP_MySQLAddErr ( this -> mysqlSession , BP_MYSQL_ERROR_CONNECT , 0 , " " , BPLN ) ; BP_BLOCK_MARIADB_LEAVE_CRITICAL_SECTION_AND_RETURN_FROM_FUNC ( ERR_FAILURE ) ; } BP_BLOCK_MARIADB_LEAVE_CRITICAL_SECTION ; return ERR_SUCCESS ; }
Connect to a mysql database.
Connect to a mysql database .
// enter critical section // destroy existing session if one exists // destroy a statement if it exists // close the session // set the class handle to null // try to connect here // ensure we have created a session, if not, exit // leave the critical section // return indicating success