2015-12-17 21:04:38 +00:00
|
|
|
#ifndef ENGINE_SERVER_SQL_SERVER_H
|
|
|
|
#define ENGINE_SERVER_SQL_SERVER_H
|
2015-11-21 23:52:12 +00:00
|
|
|
|
|
|
|
#include <mysql_connection.h>
|
|
|
|
|
|
|
|
#include <cppconn/driver.h>
|
|
|
|
#include <cppconn/exception.h>
|
|
|
|
#include <cppconn/statement.h>
|
|
|
|
|
|
|
|
class CSqlServer
|
|
|
|
{
|
|
|
|
public:
|
2017-03-21 10:24:44 +00:00
|
|
|
CSqlServer(const char *pDatabase, const char *pPrefix, const char *pUser, const char *pPass, const char *pIp, int Port, bool ReadOnly = true, bool SetUpDb = false);
|
2015-11-21 23:52:12 +00:00
|
|
|
~CSqlServer();
|
|
|
|
|
2015-12-20 15:07:32 +00:00
|
|
|
bool Connect();
|
2015-11-21 23:52:12 +00:00
|
|
|
void Disconnect();
|
|
|
|
void CreateTables();
|
|
|
|
|
2017-03-21 10:24:44 +00:00
|
|
|
void executeSql(const char *pCommand);
|
|
|
|
void executeSqlQuery(const char *pQuery);
|
2015-11-21 23:52:12 +00:00
|
|
|
|
2015-11-23 18:19:44 +00:00
|
|
|
sql::ResultSet* GetResults() { return m_pResults; }
|
|
|
|
|
|
|
|
const char* GetDatabase() { return m_aDatabase; }
|
|
|
|
const char* GetPrefix() { return m_aPrefix; }
|
|
|
|
const char* GetUser() { return m_aUser; }
|
|
|
|
const char* GetPass() { return m_aPass; }
|
|
|
|
const char* GetIP() { return m_aIp; }
|
|
|
|
int GetPort() { return m_Port; }
|
|
|
|
|
2015-11-24 17:44:08 +00:00
|
|
|
void Lock() { lock_wait(m_SqlLock); }
|
|
|
|
void UnLock() { lock_unlock(m_SqlLock); }
|
|
|
|
|
2016-01-28 16:46:51 +00:00
|
|
|
static int ms_NumReadServer;
|
|
|
|
static int ms_NumWriteServer;
|
2015-11-21 23:52:12 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
sql::Driver *m_pDriver;
|
|
|
|
sql::Connection *m_pConnection;
|
|
|
|
sql::Statement *m_pStatement;
|
|
|
|
sql::ResultSet *m_pResults;
|
2015-11-23 21:49:18 +00:00
|
|
|
|
2015-11-21 23:52:12 +00:00
|
|
|
// copy of config vars
|
2015-11-23 18:19:44 +00:00
|
|
|
char m_aDatabase[64];
|
|
|
|
char m_aPrefix[64];
|
|
|
|
char m_aUser[64];
|
|
|
|
char m_aPass[64];
|
|
|
|
char m_aIp[64];
|
2015-11-21 23:52:12 +00:00
|
|
|
int m_Port;
|
2015-11-24 17:44:08 +00:00
|
|
|
|
2015-12-20 15:07:32 +00:00
|
|
|
bool m_SetUpDB;
|
|
|
|
|
2015-11-24 17:44:08 +00:00
|
|
|
LOCK m_SqlLock;
|
2015-11-21 23:52:12 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|