From 4d9f046664aa6ae2fff675c9d5872c7082d2f0e5 Mon Sep 17 00:00:00 2001 From: randomdan Date: Wed, 21 Nov 2012 01:34:51 +0000 Subject: Fix error checking on mysql_ping causing db connection reuse failure; always reconnected --- libmysqlpp/connection.cpp | 24 ++++++++++++------------ libmysqlpp/connection.h | 1 - 2 files changed, 12 insertions(+), 13 deletions(-) (limited to 'libmysqlpp') diff --git a/libmysqlpp/connection.cpp b/libmysqlpp/connection.cpp index f2b747a..65e7303 100644 --- a/libmysqlpp/connection.cpp +++ b/libmysqlpp/connection.cpp @@ -60,7 +60,9 @@ int MySQL::Connection::beginTx() const { if (txDepth == 0) { - checkResult(mysql_autocommit(&conn, 0), true); + if (mysql_autocommit(&conn, 0)) { + throw Error(mysql_error(&conn)); + } rolledback = false; } return ++txDepth; @@ -73,7 +75,9 @@ MySQL::Connection::commitTx() const return rollbackTx(); } if (--txDepth == 0) { - checkResult(mysql_commit(&conn), true); + if (mysql_commit(&conn)) { + throw Error(mysql_error(&conn)); + } } return txDepth; } @@ -82,7 +86,9 @@ int MySQL::Connection::rollbackTx() const { if (--txDepth == 0) { - checkResult(mysql_rollback(&conn), true); + if (mysql_rollback(&conn)) { + throw Error(mysql_error(&conn)); + } } else { rolledback = true; @@ -111,7 +117,9 @@ MySQL::Connection::bulkUpdateStyle() const void MySQL::Connection::ping() const { - checkResult(mysql_ping(&conn), true); + if (mysql_ping(&conn)) { + throw Error(mysql_error(&conn)); + } } @@ -127,14 +135,6 @@ MySQL::Connection::newModifyCommand(const std::string & sql) const return new ModifyCommand(this, sql); } -void -MySQL::Connection::checkResult(my_bool actual, my_bool expected) const -{ - if (actual != expected) { - throw Error(mysql_error(&conn)); - } -} - void MySQL::Connection::beginBulkUpload(const char * table, const char * extra) const { diff --git a/libmysqlpp/connection.h b/libmysqlpp/connection.h index a88d758..0524009 100644 --- a/libmysqlpp/connection.h +++ b/libmysqlpp/connection.h @@ -32,7 +32,6 @@ namespace MySQL { private: my_bool my_true; - void checkResult(my_bool actual, my_bool expected) const; mutable unsigned int txDepth; mutable bool rolledback; }; -- cgit v1.2.3