summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorrandomdan <randomdan@localhost>2012-11-21 01:34:51 +0000
committerrandomdan <randomdan@localhost>2012-11-21 01:34:51 +0000
commit4d9f046664aa6ae2fff675c9d5872c7082d2f0e5 (patch)
treeae5346f135a34038257715ac51cb7cb8f02604cb
parentAdd a basic MySQL connector, not fully functional, but will suffice for p2tv (diff)
downloadlibdbpp-mysql-4d9f046664aa6ae2fff675c9d5872c7082d2f0e5.tar.bz2
libdbpp-mysql-4d9f046664aa6ae2fff675c9d5872c7082d2f0e5.tar.xz
libdbpp-mysql-4d9f046664aa6ae2fff675c9d5872c7082d2f0e5.zip
Fix error checking on mysql_ping causing db connection reuse failure; always reconnected
-rw-r--r--libmysqlpp/connection.cpp24
-rw-r--r--libmysqlpp/connection.h1
2 files changed, 12 insertions, 13 deletions
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));
+ }
}
@@ -128,14 +136,6 @@ MySQL::Connection::newModifyCommand(const std::string & sql) const
}
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
{
(void)table;
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;
};