aboutsummaryrefslogtreecommitdiff
path: root/src/server/shared/Database/MySQLConnection.cpp
diff options
context:
space:
mode:
authorclick <none@none>2010-11-19 13:13:07 +0100
committerclick <none@none>2010-11-19 13:13:07 +0100
commit67fade84d313285ae6b219fddddb4868a7de203a (patch)
tree8b3d53b165468334c392bc80687cbdad1cbf03df /src/server/shared/Database/MySQLConnection.cpp
parent67cd8d18e1bb5e1c41670270def44c8b10f91945 (diff)
Core/Commands: Enable SQL query logging by config and command )patch by leak)
Closes issue 4853. --HG-- branch : trunk
Diffstat (limited to 'src/server/shared/Database/MySQLConnection.cpp')
-rwxr-xr-xsrc/server/shared/Database/MySQLConnection.cpp55
1 files changed, 28 insertions, 27 deletions
diff --git a/src/server/shared/Database/MySQLConnection.cpp b/src/server/shared/Database/MySQLConnection.cpp
index 35253cb9e8f..94244407c26 100755
--- a/src/server/shared/Database/MySQLConnection.cpp
+++ b/src/server/shared/Database/MySQLConnection.cpp
@@ -30,6 +30,7 @@
#include "PreparedStatement.h"
#include "DatabaseWorker.h"
#include "Timer.h"
+#include "Log.h"
MySQLConnection::MySQLConnection(MySQLConnectionInfo& connInfo) :
m_queue(NULL),
@@ -154,20 +155,19 @@ bool MySQLConnection::Execute(const char* sql)
return false;
{
- #ifdef SQLQUERY_LOG
- uint32 _s = getMSTime();
- #endif
+ uint32 _s;
+ if (sLog.GetSQLDriverQueryLogging())
+ _s = getMSTime();
+
if (mysql_query(m_Mysql, sql))
{
sLog.outSQLDriver("SQL: %s", sql);
sLog.outSQLDriver("SQL ERROR: %s", mysql_error(m_Mysql));
return false;
}
- else
+ else if (sLog.GetSQLDriverQueryLogging())
{
- #ifdef SQLQUERY_LOG
sLog.outSQLDriver("[%u ms] SQL: %s", getMSTimeDiff(_s, getMSTime()), sql);
- #endif
}
}
@@ -191,9 +191,10 @@ bool MySQLConnection::Execute(PreparedStatement* stmt)
MYSQL_STMT* msql_STMT = m_mStmt->GetSTMT();
MYSQL_BIND* msql_BIND = m_mStmt->GetBind();
- #ifdef SQLQUERY_LOG
- uint32 _s = getMSTime();
- #endif
+ uint32 _s;
+ if (sLog.GetSQLDriverQueryLogging())
+ _s = getMSTime();
+
if (mysql_stmt_bind_param(msql_STMT, msql_BIND))
{
sLog.outSQLDriver("[ERROR]: PreparedStatement (id: %u, database: `%s`) error binding params: %s",
@@ -209,11 +210,11 @@ bool MySQLConnection::Execute(PreparedStatement* stmt)
m_mStmt->ClearParameters();
return false;
}
-
- #ifdef SQLQUERY_LOG
- sLog.outSQLDriver("[%u ms] Prepared SQL: %u on database `%s`",
- getMSTimeDiff(_s, getMSTime()), index, m_connectionInfo.database.c_str());
- #endif
+
+ if (sLog.GetSQLDriverQueryLogging())
+ sLog.outSQLDriver("[%u ms] Prepared SQL: %u on database `%s`",
+ getMSTimeDiff(_s, getMSTime()), index, m_connectionInfo.database.c_str());
+
m_mStmt->ClearParameters();
return true;
}
@@ -236,9 +237,10 @@ bool MySQLConnection::_Query(PreparedStatement* stmt, MYSQL_RES **pResult, uint6
MYSQL_STMT* msql_STMT = m_mStmt->GetSTMT();
MYSQL_BIND* msql_BIND = m_mStmt->GetBind();
- #ifdef SQLQUERY_LOG
- uint32 _s = getMSTime();
- #endif
+ uint32 _s;
+ if (sLog.GetSQLDriverQueryLogging())
+ _s = getMSTime();
+
if (mysql_stmt_bind_param(msql_STMT, msql_BIND))
{
sLog.outSQLDriver("[ERROR]: PreparedStatement (id: %u, database: `%s`) error binding params: %s",
@@ -255,10 +257,10 @@ bool MySQLConnection::_Query(PreparedStatement* stmt, MYSQL_RES **pResult, uint6
return false;
}
- #ifdef SQLQUERY_LOG
- sLog.outSQLDriver("[%u ms] Prepared SQL: %u on database `%s`",
- getMSTimeDiff(_s, getMSTime()), index, m_connectionInfo.database.c_str());
- #endif
+ if (sLog.GetSQLDriverQueryLogging())
+ sLog.outSQLDriver("[%u ms] Prepared SQL: %u on database `%s`",
+ getMSTimeDiff(_s, getMSTime()), index, m_connectionInfo.database.c_str());
+
m_mStmt->ClearParameters();
*pResult = mysql_stmt_result_metadata(msql_STMT);
@@ -292,20 +294,19 @@ bool MySQLConnection::_Query(const char *sql, MYSQL_RES **pResult, MYSQL_FIELD *
return false;
{
- #ifdef SQLQUERY_LOG
- uint32 _s = getMSTime();
- #endif
+ uint32 _s;
+ if (sLog.GetSQLDriverQueryLogging())
+ _s = getMSTime();
+
if (mysql_query(m_Mysql, sql))
{
sLog.outSQLDriver("SQL: %s", sql);
sLog.outSQLDriver("query ERROR: %s", mysql_error(m_Mysql));
return false;
}
- else
+ else if (sLog.GetSQLDriverQueryLogging())
{
- #ifdef SQLQUERY_LOG
sLog.outSQLDriver("[%u ms] SQL: %s", getMSTimeDiff(_s,getMSTime()), sql);
- #endif
}
*pResult = mysql_store_result(m_Mysql);