TrinityCore
Loading...
Searching...
No Matches
MySQLConnection Class Referenceabstract

#include <MySQLConnection.h>

+ Inheritance diagram for MySQLConnection:

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 (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 ()
 

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 const &sql, ConnectionFlags flags)
 
virtual void DoPrepareStatements ()=0
 

Protected Attributes

PreparedStatementContainer m_stmts
 
bool m_reconnecting
 PreparedStatements storage.
 
bool m_prepareError
 Are we reconnecting?
 

Private Member Functions

bool _HandleMySQLErrno (uint32 errNo, uint8 attempts=5)
 Was there any error while preparing statements?
 
 MySQLConnection (MySQLConnection const &right)=delete
 
MySQLConnection & operator= (MySQLConnection const &right)=delete
 

Private Attributes

ProducerConsumerQueue< SQLOperation * > * m_queue
 
std::unique_ptr< DatabaseWorker > m_worker
 Queue shared with other asynchronous connections.
 
MySQLHandle * m_Mysql
 Core worker task.
 
MySQLConnectionInfo & m_connectionInfo
 MySQL Handle.
 
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
 

Detailed Description

Definition at line 55 of file MySQLConnection.h.

Member Typedef Documentation

◆ PreparedStatementContainer

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

Definition at line 100 of file MySQLConnection.h.

Constructor & Destructor Documentation

◆ MySQLConnection() [1/3]

MySQLConnection::MySQLConnection ( MySQLConnectionInfo &  connInfo)

Definition at line 50 of file MySQLConnection.cpp.

◆ MySQLConnection() [2/3]

MySQLConnection::MySQLConnection ( ProducerConsumerQueue< SQLOperation * > *  queue,
MySQLConnectionInfo &  connInfo 
)

Constructor for synchronous connections.

Definition at line 58 of file MySQLConnection.cpp.

References m_queue, and m_worker.

◆ ~MySQLConnection()

MySQLConnection::~MySQLConnection ( )
virtual

Constructor for asynchronous connections.

Definition at line 69 of file MySQLConnection.cpp.

References Close().

◆ MySQLConnection() [3/3]

MySQLConnection::MySQLConnection ( MySQLConnection const &  right)
privatedelete

Member Function Documentation

◆ _HandleMySQLErrno()

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

◆ _Query() [1/2]

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

◆ _Query() [2/2]

◆ BeginTransaction()

void MySQLConnection::BeginTransaction ( )

Definition at line 374 of file MySQLConnection.cpp.

References Execute().

Referenced by ExecuteTransaction().

◆ Close()

void MySQLConnection::Close ( )

Definition at line 74 of file MySQLConnection.cpp.

References m_Mysql, m_stmts, and m_worker.

Referenced by ~MySQLConnection().

◆ CommitTransaction()

void MySQLConnection::CommitTransaction ( )

Definition at line 384 of file MySQLConnection.cpp.

References Execute().

Referenced by ExecuteTransaction().

◆ DoPrepareStatements()

virtual void MySQLConnection::DoPrepareStatements ( )
protectedpure virtual

◆ EscapeString()

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

Definition at line 440 of file MySQLConnection.cpp.

References m_Mysql.

◆ Execute() [1/2]

◆ Execute() [2/2]

◆ ExecuteTransaction()

◆ GetLastError()

uint32 MySQLConnection::GetLastError ( )

Definition at line 450 of file MySQLConnection.cpp.

References m_Mysql.

Referenced by ExecuteTransaction().

◆ GetPreparedStatement()

MySQLPreparedStatement * MySQLConnection::GetPreparedStatement ( uint32  index)
protected

◆ GetServerVersion()

uint32 MySQLConnection::GetServerVersion ( ) const
protected

Definition at line 465 of file MySQLConnection.cpp.

References m_Mysql.

◆ 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 455 of file MySQLConnection.cpp.

References m_Mutex.

◆ Open()

◆ operator=()

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

◆ Ping()

void MySQLConnection::Ping ( )

Definition at line 445 of file MySQLConnection.cpp.

References m_Mysql.

Referenced by PingOperation::Execute().

◆ PrepareStatement()

void MySQLConnection::PrepareStatement ( uint32  index,
std::string const &  sql,
ConnectionFlags  flags 
)
protected

◆ PrepareStatements()

bool MySQLConnection::PrepareStatements ( )

Definition at line 183 of file MySQLConnection.cpp.

References DoPrepareStatements(), and m_prepareError.

Referenced by _HandleMySQLErrno().

◆ Query() [1/2]

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

◆ Query() [2/2]

PreparedResultSet * MySQLConnection::Query ( PreparedStatementBase *  stmt)

Definition at line 514 of file MySQLConnection.cpp.

References _Query(), MySQLPreparedStatement::GetSTMT(), and m_Mysql.

◆ RollbackTransaction()

void MySQLConnection::RollbackTransaction ( )

Definition at line 379 of file MySQLConnection.cpp.

References Execute().

Referenced by ExecuteTransaction().

◆ Unlock()

void MySQLConnection::Unlock ( )
protected

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

Definition at line 460 of file MySQLConnection.cpp.

References m_Mutex.

Friends And Related Symbol Documentation

◆ DatabaseWorkerPool

template<class T >
friend class DatabaseWorkerPool
friend

Definition at line 57 of file MySQLConnection.h.

◆ PingOperation

friend class PingOperation
friend

Definition at line 58 of file MySQLConnection.h.

Member Data Documentation

◆ m_connectionFlags

ConnectionFlags MySQLConnection::m_connectionFlags
private

Connection info (used for logging)

Definition at line 113 of file MySQLConnection.h.

Referenced by _HandleMySQLErrno(), GetPreparedStatement(), and PrepareStatement().

◆ m_connectionInfo

MySQLConnectionInfo& MySQLConnection::m_connectionInfo
private

MySQL Handle.

Definition at line 112 of file MySQLConnection.h.

Referenced by _HandleMySQLErrno(), GetPreparedStatement(), and Open().

◆ m_Mutex

std::mutex MySQLConnection::m_Mutex
private

Connection flags (for preparing relevant statements)

Definition at line 114 of file MySQLConnection.h.

Referenced by LockIfReady(), and Unlock().

◆ m_Mysql

MySQLHandle* MySQLConnection::m_Mysql
private

◆ m_prepareError

bool MySQLConnection::m_prepareError
protected

Are we reconnecting?

Definition at line 104 of file MySQLConnection.h.

Referenced by PrepareStatement(), and PrepareStatements().

◆ m_queue

ProducerConsumerQueue<SQLOperation*>* MySQLConnection::m_queue
private

Definition at line 109 of file MySQLConnection.h.

Referenced by MySQLConnection().

◆ m_reconnecting

bool MySQLConnection::m_reconnecting
protected

◆ m_stmts

◆ m_worker

std::unique_ptr<DatabaseWorker> MySQLConnection::m_worker
private

Queue shared with other asynchronous connections.

Definition at line 110 of file MySQLConnection.h.

Referenced by Close(), and MySQLConnection().


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