aboutsummaryrefslogtreecommitdiff
path: root/src/server/database/Database/MySQLConnection.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/server/database/Database/MySQLConnection.h')
-rw-r--r--src/server/database/Database/MySQLConnection.h66
1 files changed, 25 insertions, 41 deletions
diff --git a/src/server/database/Database/MySQLConnection.h b/src/server/database/Database/MySQLConnection.h
index 81b57261899..e8f42d49b34 100644
--- a/src/server/database/Database/MySQLConnection.h
+++ b/src/server/database/Database/MySQLConnection.h
@@ -15,18 +15,23 @@
* with this program. If not, see <http://www.gnu.org/licenses/>.
*/
-#include "DatabaseWorkerPool.h"
-#include "Transaction.h"
-#include "Util.h"
-#include "ProducerConsumerQueue.h"
-
#ifndef _MYSQLCONNECTION_H
#define _MYSQLCONNECTION_H
+#include "Define.h"
+#include "DatabaseEnvFwd.h"
+#include <map>
+#include <memory>
+#include <mutex>
+#include <string>
+#include <vector>
+
+template <typename T>
+class ProducerConsumerQueue;
+
class DatabaseWorker;
-class PreparedStatement;
class MySQLPreparedStatement;
-class PingOperation;
+class SQLOperation;
enum ConnectionFlags
{
@@ -37,21 +42,7 @@ enum ConnectionFlags
struct TC_DATABASE_API MySQLConnectionInfo
{
- explicit MySQLConnectionInfo(std::string const& infoString)
- {
- Tokenizer tokens(infoString, ';');
-
- if (tokens.size() != 5)
- return;
-
- uint8 i = 0;
-
- host.assign(tokens[i++]);
- port_or_socket.assign(tokens[i++]);
- user.assign(tokens[i++]);
- password.assign(tokens[i++]);
- database.assign(tokens[i++]);
- }
+ explicit MySQLConnectionInfo(std::string const& infoString);
std::string user;
std::string password;
@@ -76,36 +67,29 @@ class TC_DATABASE_API MySQLConnection
bool PrepareStatements();
public:
- bool Execute(const char* sql);
+ bool Execute(char const* sql);
bool Execute(PreparedStatement* stmt);
- ResultSet* Query(const char* sql);
+ ResultSet* Query(char const* sql);
PreparedResultSet* Query(PreparedStatement* stmt);
- bool _Query(const char *sql, MYSQL_RES **pResult, MYSQL_FIELD **pFields, uint64* pRowCount, uint32* pFieldCount);
- bool _Query(PreparedStatement* stmt, MYSQL_RES **pResult, uint64* pRowCount, uint32* pFieldCount);
+ bool _Query(char const* sql, MYSQL_RES** pResult, MYSQL_FIELD** pFields, uint64* pRowCount, uint32* pFieldCount);
+ bool _Query(PreparedStatement* stmt, MYSQL_RES** pResult, uint64* pRowCount, uint32* pFieldCount);
void BeginTransaction();
void RollbackTransaction();
void CommitTransaction();
int ExecuteTransaction(SQLTransaction& transaction);
- operator bool () const { return m_Mysql != NULL; }
- void Ping() { mysql_ping(m_Mysql); }
+ void Ping();
- uint32 GetLastError() { return mysql_errno(m_Mysql); }
+ uint32 GetLastError();
protected:
- bool LockIfReady()
- {
- /// Tries to acquire lock. If lock is acquired by another thread
- /// the calling parent will just try another connection
- return m_Mutex.try_lock();
- }
-
- void Unlock()
- {
- /// Called by parent databasepool. Will let other threads access this connection
- m_Mutex.unlock();
- }
+ /// Tries to acquire lock. If lock is acquired by another thread
+ /// the calling parent will just try another connection
+ bool LockIfReady();
+
+ /// Called by parent databasepool. Will let other threads access this connection
+ void Unlock();
MYSQL* GetHandle() { return m_Mysql; }
MySQLPreparedStatement* GetPreparedStatement(uint32 index);