![]() |
TrinityCore
|
#include <MySQLConnection.h>
Inheritance diagram for MySQLConnection:Classes | |
| struct | WorkerThread |
Public Member Functions | |
| MySQLConnection (MySQLConnectionInfo &connInfo, ConnectionFlags connectionFlags) | |
| virtual | ~MySQLConnection () |
| uint32 | Open () |
| void | Close () |
| bool | PrepareStatements () |
| bool | Execute (char const *sql) |
| bool | Execute (PreparedStatementBase *stmt) |
| ResultSet * | Query (char const *sql) |
| PreparedResultSet * | Query (PreparedStatementBase *stmt) |
| bool | _Query (char const *sql, MySQLResult **pResult, MySQLField **pFields, uint64 *pRowCount, uint32 *pFieldCount) |
| bool | _Query (PreparedStatementBase *stmt, MySQLPreparedStatement **mysqlStmt, MySQLResult **pResult, uint64 *pRowCount, uint32 *pFieldCount) |
| void | BeginTransaction () |
| void | RollbackTransaction () |
| void | CommitTransaction () |
| int | ExecuteTransaction (std::shared_ptr< TransactionBase > transaction) |
| size_t | EscapeString (char *to, const char *from, size_t length) |
| void | Ping () |
| uint32 | GetLastError () |
| void | StartWorkerThread (Trinity::Asio::IoContext *context) |
| std::thread::id | GetWorkerThreadId () const |
Protected Types | |
| typedef std::vector< std::unique_ptr< MySQLPreparedStatement > > | PreparedStatementContainer |
Protected Member Functions | |
| bool | LockIfReady () |
| void | Unlock () |
| Called by parent databasepool. Will let other threads access this connection. | |
| uint32 | GetServerVersion () const |
| MySQLPreparedStatement * | GetPreparedStatement (uint32 index) |
| void | PrepareStatement (uint32 index, std::string_view sql, ConnectionFlags flags) |
| virtual void | DoPrepareStatements ()=0 |
Protected Attributes | |
| PreparedStatementContainer | m_stmts |
| PreparedStatements storage. | |
| bool | m_reconnecting |
| Are we reconnecting? | |
| bool | m_prepareError |
| Was there any error while preparing statements? | |
Private Member Functions | |
| bool | _HandleMySQLErrno (uint32 errNo, uint8 attempts=5) |
| MySQLConnection (MySQLConnection const &right)=delete | |
| MySQLConnection & | operator= (MySQLConnection const &right)=delete |
Private Attributes | |
| std::unique_ptr< WorkerThread > | m_workerThread |
| Core worker thread. | |
| MySQLHandle * | m_Mysql |
| MySQL Handle. | |
| MySQLConnectionInfo & | m_connectionInfo |
| Connection info (used for logging) | |
| ConnectionFlags | m_connectionFlags |
| Connection flags (for preparing relevant statements) | |
| std::mutex | m_Mutex |
Friends | |
| template<class T > | |
| class | DatabaseWorkerPool |
| class | PingOperation |
Definition at line 51 of file MySQLConnection.h.
|
protected |
Definition at line 98 of file MySQLConnection.h.
| MySQLConnection::MySQLConnection | ( | MySQLConnectionInfo & | connInfo, |
| ConnectionFlags | connectionFlags | ||
| ) |
Definition at line 57 of file MySQLConnection.cpp.
|
virtual |
Definition at line 66 of file MySQLConnection.cpp.
References Close().
|
privatedelete |
Definition at line 526 of file MySQLConnection.cpp.
References _HandleMySQLErrno(), ABORT, CONNECTION_ASYNC, MySQLConnectionInfo::database, MySQLConnectionInfo::host, m_connectionFlags, m_connectionInfo, m_Mysql, m_reconnecting, Open(), MySQLConnectionInfo::port_or_socket, PrepareStatements(), TC_LOG_ERROR, TC_LOG_FATAL, and TC_LOG_INFO.
Referenced by _HandleMySQLErrno(), _Query(), _Query(), Execute(), and Execute().
| bool MySQLConnection::_Query | ( | char const * | sql, |
| MySQLResult ** | pResult, | ||
| MySQLField ** | pFields, | ||
| uint64 * | pRowCount, | ||
| uint32 * | pFieldCount | ||
| ) |
Definition at line 333 of file MySQLConnection.cpp.
References _HandleMySQLErrno(), _Query(), getMSTime(), getMSTimeDiff(), m_Mysql, TC_LOG_DEBUG, TC_LOG_ERROR, and TC_LOG_INFO.
| bool MySQLConnection::_Query | ( | PreparedStatementBase * | stmt, |
| MySQLPreparedStatement ** | mysqlStmt, | ||
| MySQLResult ** | pResult, | ||
| uint64 * | pRowCount, | ||
| uint32 * | pFieldCount | ||
| ) |
Definition at line 263 of file MySQLConnection.cpp.
References _HandleMySQLErrno(), _Query(), ASSERT, MySQLPreparedStatement::BindParameters(), MySQLPreparedStatement::ClearParameters(), MySQLPreparedStatement::GetBind(), PreparedStatementBase::GetIndex(), getMSTime(), getMSTimeDiff(), GetPreparedStatement(), MySQLPreparedStatement::getQueryString(), MySQLPreparedStatement::GetSTMT(), m_Mysql, TC_LOG_DEBUG, and TC_LOG_ERROR.
| void MySQLConnection::BeginTransaction | ( | ) |
Definition at line 374 of file MySQLConnection.cpp.
References Execute().
Referenced by ExecuteTransaction().
| void MySQLConnection::Close | ( | ) |
Definition at line 71 of file MySQLConnection.cpp.
References m_Mysql, m_stmts, and m_workerThread.
Referenced by ~MySQLConnection().
| void MySQLConnection::CommitTransaction | ( | ) |
Definition at line 384 of file MySQLConnection.cpp.
References Execute().
Referenced by ExecuteTransaction().
|
protectedpure virtual |
Implemented in CharacterDatabaseConnection, HotfixDatabaseConnection, LoginDatabaseConnection, and WorldDatabaseConnection.
Referenced by PrepareStatements().
| size_t MySQLConnection::EscapeString | ( | char * | to, |
| const char * | from, | ||
| size_t | length | ||
| ) |
Definition at line 417 of file MySQLConnection.cpp.
References m_Mysql.
| bool MySQLConnection::Execute | ( | char const * | sql | ) |
Definition at line 189 of file MySQLConnection.cpp.
References _HandleMySQLErrno(), Execute(), getMSTime(), getMSTimeDiff(), m_Mysql, TC_LOG_DEBUG, TC_LOG_ERROR, and TC_LOG_INFO.
Referenced by BeginTransaction(), CommitTransaction(), Execute(), BasicStatementTask::Execute(), PreparedStatementTask::Execute(), Execute(), ExecuteTransaction(), and RollbackTransaction().
| bool MySQLConnection::Execute | ( | PreparedStatementBase * | stmt | ) |
Definition at line 216 of file MySQLConnection.cpp.
References _HandleMySQLErrno(), ASSERT, MySQLPreparedStatement::BindParameters(), MySQLPreparedStatement::ClearParameters(), Execute(), MySQLPreparedStatement::GetBind(), PreparedStatementBase::GetIndex(), getMSTime(), getMSTimeDiff(), GetPreparedStatement(), MySQLPreparedStatement::getQueryString(), MySQLPreparedStatement::GetSTMT(), m_Mysql, TC_LOG_DEBUG, and TC_LOG_ERROR.
| int MySQLConnection::ExecuteTransaction | ( | std::shared_ptr< TransactionBase > | transaction | ) |
Definition at line 389 of file MySQLConnection.cpp.
References BeginTransaction(), CommitTransaction(), Execute(), GetLastError(), RollbackTransaction(), TC_LOG_WARN, and TransactionData::ToExecutable().
Referenced by TransactionTask::TryExecute().
| uint32 MySQLConnection::GetLastError | ( | ) |
Definition at line 427 of file MySQLConnection.cpp.
References m_Mysql.
Referenced by ExecuteTransaction().
|
protected |
Definition at line 465 of file MySQLConnection.cpp.
References ASSERT, CONNECTION_ASYNC, MySQLConnectionInfo::database, m_connectionFlags, m_connectionInfo, m_stmts, SZFMTD, and TC_LOG_ERROR.
|
protected |
Definition at line 460 of file MySQLConnection.cpp.
References m_Mysql.
| std::thread::id MySQLConnection::GetWorkerThreadId | ( | ) | const |
Definition at line 442 of file MySQLConnection.cpp.
References m_workerThread.
|
protected |
Tries to acquire lock. If lock is acquired by another thread the calling parent will just try another connection
Definition at line 450 of file MySQLConnection.cpp.
References m_Mutex.
| uint32 MySQLConnection::Open | ( | ) |
Definition at line 90 of file MySQLConnection.cpp.
References MySQLConnectionInfo::database, MySQLConnectionInfo::host, m_connectionInfo, m_Mysql, m_reconnecting, MySQLConnectionInfo::password, MySQLConnectionInfo::port_or_socket, MySQLConnectionInfo::ssl, TC_LOG_ERROR, TC_LOG_INFO, and MySQLConnectionInfo::user.
Referenced by _HandleMySQLErrno().
|
privatedelete |
| void MySQLConnection::Ping | ( | ) |
Definition at line 422 of file MySQLConnection.cpp.
References m_Mysql.
|
protected |
Definition at line 477 of file MySQLConnection.cpp.
References flags, m_connectionFlags, m_Mysql, m_prepareError, m_stmts, and TC_LOG_ERROR.
Referenced by CharacterDatabaseConnection::DoPrepareStatements(), HotfixDatabaseConnection::DoPrepareStatements(), LoginDatabaseConnection::DoPrepareStatements(), and WorldDatabaseConnection::DoPrepareStatements().
| bool MySQLConnection::PrepareStatements | ( | ) |
Definition at line 183 of file MySQLConnection.cpp.
References DoPrepareStatements(), and m_prepareError.
Referenced by _HandleMySQLErrno().
| ResultSet * MySQLConnection::Query | ( | char const * | sql | ) |
Definition at line 317 of file MySQLConnection.cpp.
References _Query().
Referenced by SQLQueryHolderTask::Execute(), BasicStatementTask::Query(), and PreparedStatementTask::Query().
| PreparedResultSet * MySQLConnection::Query | ( | PreparedStatementBase * | stmt | ) |
Definition at line 509 of file MySQLConnection.cpp.
References _Query(), MySQLPreparedStatement::GetSTMT(), and m_Mysql.
| void MySQLConnection::RollbackTransaction | ( | ) |
Definition at line 379 of file MySQLConnection.cpp.
References Execute().
Referenced by ExecuteTransaction().
| void MySQLConnection::StartWorkerThread | ( | Trinity::Asio::IoContext * | context | ) |
Definition at line 432 of file MySQLConnection.cpp.
References Trinity::Asio::IoContext::get_executor(), m_workerThread, Trinity::Asio::IoContext::run(), and MySQLConnection::WorkerThread::ThreadHandle.
|
protected |
Called by parent databasepool. Will let other threads access this connection.
Definition at line 455 of file MySQLConnection.cpp.
References m_Mutex.
|
friend |
Definition at line 53 of file MySQLConnection.h.
|
friend |
Definition at line 54 of file MySQLConnection.h.
|
private |
Connection flags (for preparing relevant statements)
Definition at line 111 of file MySQLConnection.h.
Referenced by _HandleMySQLErrno(), GetPreparedStatement(), and PrepareStatement().
|
private |
Connection info (used for logging)
Definition at line 110 of file MySQLConnection.h.
Referenced by _HandleMySQLErrno(), GetPreparedStatement(), and Open().
|
private |
Definition at line 112 of file MySQLConnection.h.
Referenced by LockIfReady(), and Unlock().
|
private |
MySQL Handle.
Definition at line 109 of file MySQLConnection.h.
Referenced by _HandleMySQLErrno(), _Query(), _Query(), Close(), EscapeString(), Execute(), Execute(), GetLastError(), GetServerVersion(), Open(), Ping(), PrepareStatement(), and Query().
|
protected |
Was there any error while preparing statements?
Definition at line 102 of file MySQLConnection.h.
Referenced by PrepareStatement(), and PrepareStatements().
|
protected |
Are we reconnecting?
Definition at line 101 of file MySQLConnection.h.
Referenced by _HandleMySQLErrno(), CharacterDatabaseConnection::DoPrepareStatements(), HotfixDatabaseConnection::DoPrepareStatements(), LoginDatabaseConnection::DoPrepareStatements(), WorldDatabaseConnection::DoPrepareStatements(), and Open().
|
protected |
PreparedStatements storage.
Definition at line 100 of file MySQLConnection.h.
Referenced by Close(), CharacterDatabaseConnection::DoPrepareStatements(), HotfixDatabaseConnection::DoPrepareStatements(), LoginDatabaseConnection::DoPrepareStatements(), WorldDatabaseConnection::DoPrepareStatements(), GetPreparedStatement(), and PrepareStatement().
|
private |
Core worker thread.
Definition at line 108 of file MySQLConnection.h.
Referenced by Close(), GetWorkerThreadId(), and StartWorkerThread().