Core/DBLayer: make use of return result of Connection::Open method and allow core to output all the errors in prepared statements instead of aborting on first error.

This commit is contained in:
Azazel
2011-04-07 15:30:38 +06:00
parent 770c8a950e
commit 4db04b63dd
9 changed files with 39 additions and 57 deletions

View File

@@ -34,6 +34,7 @@
MySQLConnection::MySQLConnection(MySQLConnectionInfo& connInfo) :
m_reconnecting(false),
m_prepareError(false),
m_queue(NULL),
m_worker(NULL),
m_Mysql(NULL),
@@ -44,6 +45,7 @@ m_connectionFlags(CONNECTION_SYNCH)
MySQLConnection::MySQLConnection(ACE_Activation_Queue* queue, MySQLConnectionInfo& connInfo) :
m_reconnecting(false),
m_prepareError(false),
m_queue(queue),
m_Mysql(NULL),
m_connectionInfo(connInfo),
@@ -137,7 +139,7 @@ bool MySQLConnection::Open()
// set connection properties to UTF8 to properly handle locales for different
// server configs - core sends data in UTF8, so MySQL must expect UTF8 too
mysql_set_character_set(m_Mysql, "utf8");
return true;
return PrepareStatements();
}
else
{
@@ -147,6 +149,14 @@ bool MySQLConnection::Open()
}
}
bool MySQLConnection::PrepareStatements()
{
DoPrepareStatements();
for (PreparedStatementMap::const_iterator itr = m_queries.begin(); itr != m_queries.end(); ++itr)
PrepareStatement(itr->first, itr->second.first, itr->second.second);
return !m_prepareError;
}
bool MySQLConnection::Execute(const char* sql)
{
if (!m_Mysql)
@@ -444,19 +454,23 @@ void MySQLConnection::PrepareStatement(uint32 index, const char* sql, Connection
{
sLog->outSQLDriver("[ERROR]: In mysql_stmt_init() id: %u, sql: \"%s\"", index, sql);
sLog->outSQLDriver("[ERROR]: %s", mysql_error(m_Mysql));
exit(1);
m_prepareError = true;
}
if (mysql_stmt_prepare(stmt, sql, static_cast<unsigned long>(strlen(sql))))
else
{
sLog->outSQLDriver("[ERROR]: In mysql_stmt_prepare() id: %u, sql: \"%s\"", index, sql);
sLog->outSQLDriver("[ERROR]: %s", mysql_stmt_error(stmt));
mysql_stmt_close(stmt);
exit(1);
if (mysql_stmt_prepare(stmt, sql, static_cast<unsigned long>(strlen(sql))))
{
sLog->outSQLDriver("[ERROR]: In mysql_stmt_prepare() id: %u, sql: \"%s\"", index, sql);
sLog->outSQLDriver("[ERROR]: %s", mysql_stmt_error(stmt));
mysql_stmt_close(stmt);
m_prepareError = true;
}
else
{
MySQLPreparedStatement* mStmt = new MySQLPreparedStatement(stmt);
m_stmts[index] = mStmt;
}
}
MySQLPreparedStatement* mStmt = new MySQLPreparedStatement(stmt);
m_stmts[index] = mStmt;
}
PreparedResultSet* MySQLConnection::Query(PreparedStatement* stmt)