diff options
author | Machiavelli <none@none> | 2010-12-17 15:55:16 +0100 |
---|---|---|
committer | Machiavelli <none@none> | 2010-12-17 15:55:16 +0100 |
commit | cb08ec0d74c4c935457e4df2cc480a7b55387b18 (patch) | |
tree | 711305f2e9c8e0831a7fff8e0c28a4206a5c9651 /src/server/shared/Database/MySQLConnection.cpp | |
parent | 57d72fa708373b5db88d62190dac939cdfaea824 (diff) |
Core/DBLayer: Don´t prepare asynchronous statements on synchronous connections and vice versa. Prevents allocating RAM that will never be used.
--HG--
branch : trunk
Diffstat (limited to 'src/server/shared/Database/MySQLConnection.cpp')
-rwxr-xr-x | src/server/shared/Database/MySQLConnection.cpp | 24 |
1 files changed, 20 insertions, 4 deletions
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) { |