From cb08ec0d74c4c935457e4df2cc480a7b55387b18 Mon Sep 17 00:00:00 2001 From: Machiavelli Date: Fri, 17 Dec 2010 15:55:16 +0100 Subject: Core/DBLayer: Don“t prepare asynchronous statements on synchronous connections and vice versa. Prevents allocating RAM that will never be used. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --HG-- branch : trunk --- src/server/shared/Database/MySQLConnection.cpp | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) (limited to 'src/server/shared/Database/MySQLConnection.cpp') diff --git a/src/server/shared/Database/MySQLConnection.cpp b/src/server/shared/Database/MySQLConnection.cpp index 84d1948622e..e2acdb5d29e 100755 --- a/src/server/shared/Database/MySQLConnection.cpp +++ b/src/server/shared/Database/MySQLConnection.cpp @@ -36,14 +36,16 @@ MySQLConnection::MySQLConnection(MySQLConnectionInfo& connInfo) : m_queue(NULL), m_worker(NULL), m_Mysql(NULL), -m_connectionInfo(connInfo) +m_connectionInfo(connInfo), +m_connectionFlags(CONNECTION_SYNCH) { } MySQLConnection::MySQLConnection(ACE_Activation_Queue* queue, MySQLConnectionInfo& connInfo) : m_queue(queue), m_Mysql(NULL), -m_connectionInfo(connInfo) +m_connectionInfo(connInfo), +m_connectionFlags(CONNECTION_ASYNC) { m_worker = new DatabaseWorker(m_queue, this); } @@ -345,11 +347,25 @@ void MySQLConnection::CommitTransaction() MySQLPreparedStatement* MySQLConnection::GetPreparedStatement(uint32 index) { ASSERT(index < m_stmts.size()); - return m_stmts[index]; + MySQLPreparedStatement* ret = m_stmts[index]; + if (!ret) + sLog.outSQLDriver("ERROR: Could not fetch prepared statement %u on database `%s`, connection type: %s.", + index, m_connectionInfo.database.c_str(), (m_connectionFlags & CONNECTION_ASYNC) ? "asynchronous" : "synchronous"); + + return ret; } -void MySQLConnection::PrepareStatement(uint32 index, const char* sql) +void MySQLConnection::PrepareStatement(uint32 index, const char* sql, bool async) { + // Check if specified query should be prepared on this connection + // ie. don't prepare async statements on synchronous connections + // to save memory that will not be used. + if (async && !(m_connectionFlags & CONNECTION_ASYNC)) + { + m_stmts[index] = NULL; + return; + } + MYSQL_STMT * stmt = mysql_stmt_init(m_Mysql); if (!stmt) { -- cgit v1.2.3