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.

This commit is contained in:
Machiavelli
2011-01-08 19:07:13 +01:00
parent 04d7476087
commit c4cac049b4
8 changed files with 322 additions and 288 deletions

View File

@@ -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;