aboutsummaryrefslogtreecommitdiff
path: root/src/server/shared/Database/MySQLConnection.cpp
diff options
context:
space:
mode:
authorMachiavelli <machiavelli.trinity@gmail.com>2011-01-08 19:07:13 +0100
committerMachiavelli <machiavelli.trinity@gmail.com>2011-01-08 19:07:13 +0100
commitc4cac049b4eff3b933d2121ccabf80012f5e90fd (patch)
tree1640d21b84951081b2b64c0a2b6dcfbb1cef598a /src/server/shared/Database/MySQLConnection.cpp
parent04d74760872d9e6e887bd6e5dcea9021add6454c (diff)
Core/DBLayer: Define prepared statements in an array per database instead of explicit calls to MySQL::PrepareStatement. Now the core will show the raw query (without bound arguments) in related log entries instead of PreparedStatement id: X on database Y.
Diffstat (limited to 'src/server/shared/Database/MySQLConnection.cpp')
-rwxr-xr-xsrc/server/shared/Database/MySQLConnection.cpp46
1 files changed, 24 insertions, 22 deletions
diff --git a/src/server/shared/Database/MySQLConnection.cpp b/src/server/shared/Database/MySQLConnection.cpp
index 468136cc423..e8f91195600 100755
--- a/src/server/shared/Database/MySQLConnection.cpp
+++ b/src/server/shared/Database/MySQLConnection.cpp
@@ -38,7 +38,8 @@ m_queue(NULL),
m_worker(NULL),
m_Mysql(NULL),
m_connectionInfo(connInfo),
-m_connectionFlags(CONNECTION_SYNCH)
+m_connectionFlags(CONNECTION_SYNCH),
+m_statementTable(NULL)
{
}
@@ -47,7 +48,8 @@ m_reconnecting(false),
m_queue(queue),
m_Mysql(NULL),
m_connectionInfo(connInfo),
-m_connectionFlags(CONNECTION_ASYNC)
+m_connectionFlags(CONNECTION_ASYNC),
+m_statementTable(NULL)
{
m_worker = new DatabaseWorker(m_queue, this);
}
@@ -197,9 +199,9 @@ bool MySQLConnection::Execute(PreparedStatement* stmt)
if (mysql_stmt_bind_param(msql_STMT, msql_BIND))
{
uint32 lErrno = mysql_errno(m_Mysql);
- sLog->outSQLDriver("[ERROR]: PreparedStatement (id: %u, database: `%s`) error binding params: [%u] %s",
- index, m_connectionInfo.database.c_str(), lErrno, mysql_stmt_error(msql_STMT));
-
+ sLog->outSQLDriver("SQL(p): %s\n [ERROR]: [%u] %s",
+ m_statementTable[index].query, lErrno, mysql_stmt_error(msql_STMT));
+
if (_HandleMySQLErrno(lErrno)) // If it returns true, an error was handled succesfuly (ie reconnection)
return Execute(stmt); // Try again
@@ -210,9 +212,9 @@ bool MySQLConnection::Execute(PreparedStatement* stmt)
if (mysql_stmt_execute(msql_STMT))
{
uint32 lErrno = mysql_errno(m_Mysql);
- sLog->outSQLDriver("[ERROR]: PreparedStatement (id: %u, database: `%s`) error executing: [%u] %s",
- index, m_connectionInfo.database.c_str(), lErrno, mysql_stmt_error(msql_STMT));
-
+ sLog->outSQLDriver("SQL(p): %s\n [ERROR]: [%u] %s",
+ m_statementTable[index].query, lErrno, mysql_stmt_error(msql_STMT));
+
if (_HandleMySQLErrno(lErrno)) // If it returns true, an error was handled succesfuly (ie reconnection)
return Execute(stmt); // Try again
@@ -221,8 +223,8 @@ bool MySQLConnection::Execute(PreparedStatement* stmt)
}
if (sLog->GetSQLDriverQueryLogging())
- sLog->outSQLDriver("[%u ms] Prepared SQL: %u on database `%s`",
- getMSTimeDiff(_s, getMSTime()), index, m_connectionInfo.database.c_str());
+ sLog->outSQLDriver("[%u ms] SQL(p): %s",
+ getMSTimeDiff(_s, getMSTime()), m_statementTable[index].query);
m_mStmt->ClearParameters();
return true;
@@ -253,11 +255,11 @@ bool MySQLConnection::_Query(PreparedStatement* stmt, MYSQL_RES **pResult, uint6
if (mysql_stmt_bind_param(msql_STMT, msql_BIND))
{
uint32 lErrno = mysql_errno(m_Mysql);
- sLog->outSQLDriver("[ERROR]: PreparedStatement (id: %u, database: `%s`) error binding params: [%u] %s",
- index, m_connectionInfo.database.c_str(), lErrno, mysql_stmt_error(msql_STMT));
-
+ sLog->outSQLDriver("SQL(p): %s\n [ERROR]: [%u] %s",
+ m_statementTable[index].query, lErrno, mysql_stmt_error(msql_STMT));
+
if (_HandleMySQLErrno(lErrno)) // If it returns true, an error was handled succesfuly (ie reconnection)
- return _Query(stmt, pResult, pRowCount, pFieldCount); // Try again
+ return Execute(stmt); // Try again
m_mStmt->ClearParameters();
return false;
@@ -266,19 +268,19 @@ bool MySQLConnection::_Query(PreparedStatement* stmt, MYSQL_RES **pResult, uint6
if (mysql_stmt_execute(msql_STMT))
{
uint32 lErrno = mysql_errno(m_Mysql);
- sLog->outSQLDriver("[ERROR]: PreparedStatement (id: %u, database: `%s`) error executing: [%u] %s",
- index, m_connectionInfo.database.c_str(), lErrno, mysql_stmt_error(msql_STMT));
-
+ sLog->outSQLDriver("SQL(p): %s\n [ERROR]: [%u] %s",
+ m_statementTable[index].query, lErrno, mysql_stmt_error(msql_STMT));
+
if (_HandleMySQLErrno(lErrno)) // If it returns true, an error was handled succesfuly (ie reconnection)
- return _Query(stmt, pResult, pRowCount, pFieldCount); // Try again
+ return Execute(stmt); // Try again
m_mStmt->ClearParameters();
return false;
}
if (sLog->GetSQLDriverQueryLogging())
- sLog->outSQLDriver("[%u ms] Prepared SQL: %u on database `%s`",
- getMSTimeDiff(_s, getMSTime()), index, m_connectionInfo.database.c_str());
+ sLog->outSQLDriver("[%u ms] SQL(p): %s",
+ getMSTimeDiff(_s, getMSTime()), m_statementTable[index].query);
m_mStmt->ClearParameters();
@@ -378,7 +380,7 @@ MySQLPreparedStatement* MySQLConnection::GetPreparedStatement(uint32 index)
return ret;
}
-void MySQLConnection::PrepareStatement(uint32 index, const char* sql, bool async)
+void MySQLConnection::PrepareStatement(uint32 index, const char* sql, ConnectionFlags flags)
{
// For reconnection case
if (m_reconnecting)
@@ -387,7 +389,7 @@ 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))
+ if (!(m_connectionFlags & flags))
{
m_stmts[index] = NULL;
return;