![]() |
AzerothCore 3.3.5a
OpenSource WoW Emulator
|
#include "MySQLConnection.h"
Public Member Functions | |
| MySQLConnection (MySQLConnectionInfo &connInfo) | |
| MySQLConnection (ProducerConsumerQueue< SQLOperation * > *queue, MySQLConnectionInfo &connInfo) | |
| Constructor for synchronous connections. | |
| virtual | ~MySQLConnection () |
| Constructor for asynchronous connections. | |
| virtual uint32 | Open () |
| void | Close () |
| bool | PrepareStatements () |
| bool | Execute (std::string_view sql) |
| bool | Execute (PreparedStatementBase *stmt) |
| ResultSet * | Query (std::string_view sql) |
| PreparedResultSet * | Query (PreparedStatementBase *stmt) |
| bool | _Query (std::string_view 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) |
| std::size_t | EscapeString (char *to, const char *from, std::size_t length) |
| void | Ping () |
| uint32 | GetLastError () |
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 |
| std::string | GetServerInfo () const |
| MySQLPreparedStatement * | GetPreparedStatement (uint32 index) |
| void | PrepareStatement (uint32 index, std::string_view sql, ConnectionFlags flags) |
| virtual void | DoPrepareStatements ()=0 |
| virtual bool | _HandleMySQLErrno (uint32 errNo, char const *err="", uint8 attempts=5) |
Protected Attributes | |
| PreparedStatementContainer | m_stmts |
| bool | m_reconnecting |
| PreparedStatements storage. | |
| bool | m_prepareError |
| Are we reconnecting? | |
| MySQLHandle * | m_Mysql |
| Was there any error while preparing statements? | |
Private Member Functions | |
| MySQLConnection (MySQLConnection const &right)=delete | |
| MySQLConnection & | operator= (MySQLConnection const &right)=delete |
Private Attributes | |
| ProducerConsumerQueue< SQLOperation * > * | m_queue |
| MySQL Handle. | |
| std::unique_ptr< DatabaseWorker > | m_worker |
| Queue shared with other asynchronous connections. | |
| MySQLConnectionInfo & | m_connectionInfo |
| Core worker task. | |
| ConnectionFlags | m_connectionFlags |
| Connection info (used for logging) | |
| std::mutex | m_Mutex |
| Connection flags (for preparing relevant statements) | |
Friends | |
| template<class T > | |
| class | DatabaseWorkerPool |
| class | PingOperation |
|
protected |
| MySQLConnection::MySQLConnection | ( | MySQLConnectionInfo & | connInfo | ) |
| MySQLConnection::MySQLConnection | ( | ProducerConsumerQueue< SQLOperation * > * | queue, |
| MySQLConnectionInfo & | connInfo | ||
| ) |
Constructor for synchronous connections.
|
virtual |
Constructor for asynchronous connections.
References Close().
|
privatedelete |
|
protectedvirtual |
References _HandleMySQLErrno(), ABORT, CONNECTION_ASYNC, MySQLConnectionInfo::database, MySQLConnectionInfo::host, LOG_ERROR, LOG_FATAL, LOG_INFO, m_connectionFlags, m_connectionInfo, m_Mysql, m_reconnecting, Open(), MySQLConnectionInfo::port_or_socket, and PrepareStatements().
Referenced by _HandleMySQLErrno(), _Query(), _Query(), Execute(), and Execute().
| bool MySQLConnection::_Query | ( | PreparedStatementBase * | stmt, |
| MySQLPreparedStatement ** | mysqlStmt, | ||
| MySQLResult ** | pResult, | ||
| uint64 * | pRowCount, | ||
| uint32 * | pFieldCount | ||
| ) |
References _HandleMySQLErrno(), _Query(), ASSERT, MySQLPreparedStatement::BindParameters(), MySQLPreparedStatement::ClearParameters(), MySQLPreparedStatement::GetBind(), PreparedStatementBase::GetIndex(), getMSTime(), getMSTimeDiff(), MySQLPreparedStatement::GetParameterCount(), GetPreparedStatement(), MySQLPreparedStatement::getQueryString(), MySQLPreparedStatement::GetSTMT(), LOG_DEBUG, LOG_ERROR, and m_Mysql.
| bool MySQLConnection::_Query | ( | std::string_view | sql, |
| MySQLResult ** | pResult, | ||
| MySQLField ** | pFields, | ||
| uint64 * | pRowCount, | ||
| uint32 * | pFieldCount | ||
| ) |
References _HandleMySQLErrno(), _Query(), getMSTime(), getMSTimeDiff(), LOG_DEBUG, LOG_ERROR, LOG_INFO, and m_Mysql.
| void MySQLConnection::BeginTransaction | ( | ) |
| void MySQLConnection::Close | ( | ) |
| void MySQLConnection::CommitTransaction | ( | ) |
|
protectedpure virtual |
Implemented in CharacterDatabaseConnection, LoginDatabaseConnection, and WorldDatabaseConnection.
Referenced by PrepareStatements().
| std::size_t MySQLConnection::EscapeString | ( | char * | to, |
| const char * | from, | ||
| std::size_t | length | ||
| ) |
| bool MySQLConnection::Execute | ( | PreparedStatementBase * | stmt | ) |
References _HandleMySQLErrno(), ASSERT, MySQLPreparedStatement::BindParameters(), MySQLPreparedStatement::ClearParameters(), Execute(), MySQLPreparedStatement::GetBind(), PreparedStatementBase::GetIndex(), getMSTime(), getMSTimeDiff(), MySQLPreparedStatement::GetParameterCount(), GetPreparedStatement(), MySQLPreparedStatement::getQueryString(), MySQLPreparedStatement::GetSTMT(), LOG_DEBUG, LOG_ERROR, and m_Mysql.
| bool MySQLConnection::Execute | ( | std::string_view | sql | ) |
References _HandleMySQLErrno(), Execute(), getMSTime(), getMSTimeDiff(), LOG_DEBUG, LOG_ERROR, LOG_INFO, and m_Mysql.
Referenced by BeginTransaction(), CommitTransaction(), BasicStatementTask::Execute(), PreparedStatementTask::Execute(), Execute(), Execute(), ExecuteTransaction(), and RollbackTransaction().
| int MySQLConnection::ExecuteTransaction | ( | std::shared_ptr< TransactionBase > | transaction | ) |
References ABORT, ASSERT, BeginTransaction(), CommitTransaction(), Execute(), GetLastError(), LOG_FATAL, LOG_WARN, RollbackTransaction(), SQL_ELEMENT_PREPARED, and SQL_ELEMENT_RAW.
Referenced by TransactionTask::TryExecute().
| uint32 MySQLConnection::GetLastError | ( | ) |
|
protected |
References ASSERT, CONNECTION_ASYNC, MySQLConnectionInfo::database, LOG_ERROR, m_connectionFlags, m_connectionInfo, and m_stmts.
|
protected |
|
protected |
|
protected |
Tries to acquire lock. If lock is acquired by another thread the calling parent will just try another connection
References m_Mutex.
|
virtual |
References MySQLConnectionInfo::database, MySQLConnectionInfo::host, LOG_ERROR, LOG_INFO, m_connectionInfo, m_Mysql, m_reconnecting, MySQLConnectionInfo::password, MySQLConnectionInfo::port_or_socket, MySQLConnectionInfo::ssl, and MySQLConnectionInfo::user.
Referenced by _HandleMySQLErrno().
|
privatedelete |
| void MySQLConnection::Ping | ( | ) |
|
protected |
References LOG_ERROR, m_connectionFlags, m_Mysql, m_prepareError, and m_stmts.
Referenced by CharacterDatabaseConnection::DoPrepareStatements(), LoginDatabaseConnection::DoPrepareStatements(), and WorldDatabaseConnection::DoPrepareStatements().
| bool MySQLConnection::PrepareStatements | ( | ) |
References DoPrepareStatements(), and m_prepareError.
Referenced by _HandleMySQLErrno().
| PreparedResultSet * MySQLConnection::Query | ( | PreparedStatementBase * | stmt | ) |
| ResultSet * MySQLConnection::Query | ( | std::string_view | sql | ) |
References _Query().
Referenced by BasicStatementTask::Execute(), PreparedStatementTask::Execute(), and SQLQueryHolderTask::Execute().
| void MySQLConnection::RollbackTransaction | ( | ) |
|
protected |
|
friend |
|
friend |
|
private |
Connection info (used for logging)
Referenced by _HandleMySQLErrno(), GetPreparedStatement(), and PrepareStatement().
|
private |
Core worker task.
Referenced by _HandleMySQLErrno(), GetPreparedStatement(), and Open().
|
private |
Connection flags (for preparing relevant statements)
Referenced by LockIfReady(), and Unlock().
|
protected |
Was there any error while preparing statements?
Referenced by _HandleMySQLErrno(), _Query(), _Query(), Close(), EscapeString(), Execute(), Execute(), GetLastError(), GetServerInfo(), GetServerVersion(), Open(), Ping(), PrepareStatement(), and Query().
|
protected |
Are we reconnecting?
Referenced by PrepareStatement(), and PrepareStatements().
|
private |
MySQL Handle.
Referenced by MySQLConnection().
|
protected |
PreparedStatements storage.
Referenced by _HandleMySQLErrno(), CharacterDatabaseConnection::DoPrepareStatements(), LoginDatabaseConnection::DoPrepareStatements(), WorldDatabaseConnection::DoPrepareStatements(), and Open().
|
protected |
|
private |
Queue shared with other asynchronous connections.
Referenced by Close(), and MySQLConnection().