diff options
author | Shauren <shauren.trinity@gmail.com> | 2017-05-12 18:49:51 +0200 |
---|---|---|
committer | Shauren <shauren.trinity@gmail.com> | 2017-05-12 18:50:27 +0200 |
commit | 7e538980a2b4fc6c74bde7bd456633d954272708 (patch) | |
tree | 73454d83035b0ddd099e4bc934222df60b66f597 /src/server/database/Database/MySQLConnection.h | |
parent | 8fdf0778ca340d0bbf0e70dbf091d20c838981d3 (diff) |
Core/Database: Include cleanup
Diffstat (limited to 'src/server/database/Database/MySQLConnection.h')
-rw-r--r-- | src/server/database/Database/MySQLConnection.h | 59 |
1 files changed, 21 insertions, 38 deletions
diff --git a/src/server/database/Database/MySQLConnection.h b/src/server/database/Database/MySQLConnection.h index 42fb976c729..3bc9aa603c7 100644 --- a/src/server/database/Database/MySQLConnection.h +++ b/src/server/database/Database/MySQLConnection.h @@ -15,19 +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" -#include <map> - #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 { @@ -38,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; @@ -91,24 +81,17 @@ class TC_DATABASE_API MySQLConnection 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); |