You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

60 lines
1.6 KiB

#ifndef _database_class_h_
#define _database_class_h_
#include "../../components/base/basicLogCollection.h"
#include "../../components/base/basicMutex.h"
#include "../../components/base/basicTypes.h"
#include <mysql/mysql.h>
#ifdef DEBUG_EXTRA
#define DEBUG_MYSQL_QUERIES
#endif
// Reconnect attempts per query when the server went away (before: unlimited, holding the access mutex)
#define MYSQL_MAX_RECONNECT_ATTEMPTS 3
class MySQL_Connector
{
private:
basicLogCollection * m_pLog;
bool m_bIsConnected;
basicMutex m_mAccessMutex;
MYSQL * m_pDBLink;
MYSQL_RES * m_pResult;
MYSQL_ROW m_pRow;
CSTR m_pDBName;
CSTR m_pDBHost;
CSTR m_pDBUser;
CSTR m_pDBPassword;
uint16_t m_nPort;
public:
MySQL_Connector();
MySQL_Connector(CSTR DBHost, CSTR DBUser, CSTR DBPassword, U16 Port = 3306);
MySQL_Connector(CSTR DBName, CSTR DBHost, CSTR DBUser, CSTR DBPassword, U16 Port = 3306);
// MySQL_Connector( char *LocalUnixSocket, char *DBUser, char* DBPassword );
virtual ~MySQL_Connector();
bool Connect(CSTR DBHost, CSTR DBUser, CSTR DBPassword, uint16_t Port = 3306);
bool Connect(CSTR DBName, CSTR DBHost, CSTR DBUser, CSTR DBPassword, uint16_t Port = 3306);
bool ReConnect(void);
CSTR escapeString(CSTR str);
CSTR escapeBinary(uint8_t * Data, uint32_t Size);
bool isConnected(void)
{
return m_bIsConnected;
}
uint64_t QueryID(CSTR QS);
void SilentQuery(CSTR QS);
bool TrySilentQuery(CSTR QS); // never blocks, never logs (for the DB log service)
AAssoc * Query(CSTR QS, bool useCache = false);
};
void deleteResult(AAssoc *& ptr);
// extern MySQL_Connector DBC;
#endif