diff options
author | Azazel <azazel.kon@gmail.com> | 2011-04-07 15:30:38 +0600 |
---|---|---|
committer | Azazel <azazel.kon@gmail.com> | 2011-04-07 15:30:38 +0600 |
commit | 4db04b63dd0d60c54c775e68ae560f33d159bbb9 (patch) | |
tree | 4c3e44acd86760f917b32b99e1b7358bfa5822a0 /src/server/shared/Database/MySQLConnection.cpp | |
parent | 770c8a950e8d46139ba28157dfad8ffff1798b20 (diff) |
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.
Diffstat (limited to 'src/server/shared/Database/MySQLConnection.cpp')
-rwxr-xr-x | src/server/shared/Database/MySQLConnection.cpp | 36 |
1 files changed, 25 insertions, 11 deletions
diff --git a/src/server/shared/Database/MySQLConnection.cpp b/src/server/shared/Database/MySQLConnection.cpp index fad73844743..b9a45e8fe77 100755 --- a/src/server/shared/Database/MySQLConnection.cpp +++ b/src/server/shared/Database/MySQLConnection.cpp @@ -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) |