TrinityCore
MySQLConnection Class Referenceabstract

#include <MySQLConnection.h>

+ Inheritance diagram for MySQLConnection:

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)
 
ResultSetQuery (char const *sql)
 
PreparedResultSetQuery (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. More...
 
uint32 GetServerVersion () const
 
MySQLPreparedStatementGetPreparedStatement (uint32 index)
 
void PrepareStatement (uint32 index, std::string_view sql, ConnectionFlags flags)
 
virtual void DoPrepareStatements ()=0
 

Protected Attributes

PreparedStatementContainer m_stmts
 PreparedStatements storage. More...
 
bool m_reconnecting
 Are we reconnecting? More...
 
bool m_prepareError
 Was there any error while preparing statements? More...
 

Private Member Functions

bool _HandleMySQLErrno (uint32 errNo, uint8 attempts=5)
 
 MySQLConnection (MySQLConnection const &right)=delete
 
MySQLConnectionoperator= (MySQLConnection const &right)=delete
 

Private Attributes

std::unique_ptr< std::thread > m_workerThread
 Core worker thread. More...
 
MySQLHandlem_Mysql
 MySQL Handle. More...
 
MySQLConnectionInfom_connectionInfo
 Connection info (used for logging) More...
 
ConnectionFlags m_connectionFlags
 Connection flags (for preparing relevant statements) More...
 
std::mutex m_Mutex
 

Friends

template<class T >
class DatabaseWorkerPool
 
class PingOperation
 

Detailed Description

Definition at line 50 of file MySQLConnection.h.

Member Typedef Documentation

◆ PreparedStatementContainer

typedef std::vector<std::unique_ptr<MySQLPreparedStatement> > MySQLConnection::PreparedStatementContainer
protected

Definition at line 97 of file MySQLConnection.h.

Constructor & Destructor Documentation

◆ MySQLConnection() [1/2]

MySQLConnection::MySQLConnection ( MySQLConnectionInfo connInfo,
ConnectionFlags  connectionFlags 
)

Definition at line 50 of file MySQLConnection.cpp.

◆ ~MySQLConnection()

MySQLConnection::~MySQLConnection ( )
virtual

Definition at line 59 of file MySQLConnection.cpp.

+ Here is the call graph for this function:

◆ MySQLConnection() [2/2]

MySQLConnection::MySQLConnection ( MySQLConnection const &  right)
privatedelete

Member Function Documentation

◆ _HandleMySQLErrno()

bool MySQLConnection::_HandleMySQLErrno ( uint32  errNo,
uint8  attempts = 5 
)
private

Definition at line 539 of file MySQLConnection.cpp.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ _Query() [1/2]

bool MySQLConnection::_Query ( char const *  sql,
MySQLResult **  pResult,
MySQLField **  pFields,
uint64 pRowCount,
uint32 pFieldCount 
)

Definition at line 346 of file MySQLConnection.cpp.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ _Query() [2/2]

bool MySQLConnection::_Query ( PreparedStatementBase stmt,
MySQLPreparedStatement **  mysqlStmt,
MySQLResult **  pResult,
uint64 pRowCount,
uint32 pFieldCount 
)

Definition at line 276 of file MySQLConnection.cpp.

+ Here is the call graph for this function:

◆ BeginTransaction()

void MySQLConnection::BeginTransaction ( )

Definition at line 387 of file MySQLConnection.cpp.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ Close()

void MySQLConnection::Close ( )

Definition at line 64 of file MySQLConnection.cpp.

+ Here is the caller graph for this function:

◆ CommitTransaction()

void MySQLConnection::CommitTransaction ( )

Definition at line 397 of file MySQLConnection.cpp.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ DoPrepareStatements()

virtual void MySQLConnection::DoPrepareStatements ( )
protectedpure virtual

Implemented in CharacterDatabaseConnection, HotfixDatabaseConnection, LoginDatabaseConnection, and WorldDatabaseConnection.

+ Here is the caller graph for this function:

◆ EscapeString()

size_t MySQLConnection::EscapeString ( char *  to,
const char *  from,
size_t  length 
)

Definition at line 430 of file MySQLConnection.cpp.

◆ Execute() [1/2]

bool MySQLConnection::Execute ( char const *  sql)

Definition at line 183 of file MySQLConnection.cpp.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ Execute() [2/2]

bool MySQLConnection::Execute ( PreparedStatementBase stmt)

Definition at line 229 of file MySQLConnection.cpp.

+ Here is the call graph for this function:

◆ ExecuteTransaction()

int MySQLConnection::ExecuteTransaction ( std::shared_ptr< TransactionBase transaction)

Definition at line 402 of file MySQLConnection.cpp.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ GetLastError()

uint32 MySQLConnection::GetLastError ( )

Definition at line 440 of file MySQLConnection.cpp.

+ Here is the caller graph for this function:

◆ GetPreparedStatement()

MySQLPreparedStatement * MySQLConnection::GetPreparedStatement ( uint32  index)
protected

Definition at line 478 of file MySQLConnection.cpp.

+ Here is the caller graph for this function:

◆ GetServerVersion()

uint32 MySQLConnection::GetServerVersion ( ) const
protected

Definition at line 473 of file MySQLConnection.cpp.

◆ GetWorkerThreadId()

std::thread::id MySQLConnection::GetWorkerThreadId ( ) const

Definition at line 455 of file MySQLConnection.cpp.

◆ LockIfReady()

bool MySQLConnection::LockIfReady ( )
protected

Tries to acquire lock. If lock is acquired by another thread the calling parent will just try another connection

Definition at line 463 of file MySQLConnection.cpp.

◆ Open()

uint32 MySQLConnection::Open ( )

Definition at line 82 of file MySQLConnection.cpp.

+ Here is the caller graph for this function:

◆ operator=()

MySQLConnection & MySQLConnection::operator= ( MySQLConnection const &  right)
privatedelete

◆ Ping()

void MySQLConnection::Ping ( )

Definition at line 435 of file MySQLConnection.cpp.

◆ PrepareStatement()

void MySQLConnection::PrepareStatement ( uint32  index,
std::string_view  sql,
ConnectionFlags  flags 
)
protected

Definition at line 490 of file MySQLConnection.cpp.

+ Here is the caller graph for this function:

◆ PrepareStatements()

bool MySQLConnection::PrepareStatements ( )

Definition at line 177 of file MySQLConnection.cpp.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ Query() [1/2]

ResultSet * MySQLConnection::Query ( char const *  sql)

Definition at line 330 of file MySQLConnection.cpp.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ Query() [2/2]

PreparedResultSet * MySQLConnection::Query ( PreparedStatementBase stmt)

Definition at line 522 of file MySQLConnection.cpp.

+ Here is the call graph for this function:

◆ RollbackTransaction()

void MySQLConnection::RollbackTransaction ( )

Definition at line 392 of file MySQLConnection.cpp.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ StartWorkerThread()

void MySQLConnection::StartWorkerThread ( Trinity::Asio::IoContext context)

Definition at line 445 of file MySQLConnection.cpp.

+ Here is the call graph for this function:

◆ Unlock()

void MySQLConnection::Unlock ( )
protected

Called by parent databasepool. Will let other threads access this connection.

Definition at line 468 of file MySQLConnection.cpp.

Friends And Related Function Documentation

◆ DatabaseWorkerPool

template<class T >
friend class DatabaseWorkerPool
friend

Definition at line 52 of file MySQLConnection.h.

◆ PingOperation

friend class PingOperation
friend

Definition at line 53 of file MySQLConnection.h.

Member Data Documentation

◆ m_connectionFlags

ConnectionFlags MySQLConnection::m_connectionFlags
private

Connection flags (for preparing relevant statements)

Definition at line 109 of file MySQLConnection.h.

◆ m_connectionInfo

MySQLConnectionInfo& MySQLConnection::m_connectionInfo
private

Connection info (used for logging)

Definition at line 108 of file MySQLConnection.h.

◆ m_Mutex

std::mutex MySQLConnection::m_Mutex
private

Definition at line 110 of file MySQLConnection.h.

◆ m_Mysql

MySQLHandle* MySQLConnection::m_Mysql
private

MySQL Handle.

Definition at line 107 of file MySQLConnection.h.

◆ m_prepareError

bool MySQLConnection::m_prepareError
protected

Was there any error while preparing statements?

Definition at line 101 of file MySQLConnection.h.

◆ m_reconnecting

bool MySQLConnection::m_reconnecting
protected

Are we reconnecting?

Definition at line 100 of file MySQLConnection.h.

◆ m_stmts

PreparedStatementContainer MySQLConnection::m_stmts
protected

PreparedStatements storage.

Definition at line 99 of file MySQLConnection.h.

◆ m_workerThread

std::unique_ptr<std::thread> MySQLConnection::m_workerThread
private

Core worker thread.

Definition at line 106 of file MySQLConnection.h.


The documentation for this class was generated from the following files: