diff options
author | randomdan <randomdan@localhost> | 2013-01-27 00:02:16 +0000 |
---|---|---|
committer | randomdan <randomdan@localhost> | 2013-01-27 00:02:16 +0000 |
commit | 67cd4ca02d2581e8498c44bb640ea923a4ddc553 (patch) | |
tree | 0ee2e936d58e2064ff9b795ec96612212d0676cf | |
parent | Default to string binding instead of throwing an error (diff) | |
download | libdbpp-postgresql-67cd4ca02d2581e8498c44bb640ea923a4ddc553.tar.bz2 libdbpp-postgresql-67cd4ca02d2581e8498c44bb640ea923a4ddc553.tar.xz libdbpp-postgresql-67cd4ca02d2581e8498c44bb640ea923a4ddc553.zip |
Fix issues with PQ connection errors not being handled correctly
-rw-r--r-- | libpqpp/connection.cpp | 9 | ||||
-rw-r--r-- | libpqpp/selectcommand.cpp | 4 |
2 files changed, 11 insertions, 2 deletions
diff --git a/libpqpp/connection.cpp b/libpqpp/connection.cpp index d07b9d2..7c26ecb 100644 --- a/libpqpp/connection.cpp +++ b/libpqpp/connection.cpp @@ -89,6 +89,15 @@ PQ::Connection::bulkUpdateStyle() const void PQ::Connection::ping() const { + if (PQstatus(conn) != CONNECTION_OK) { + if (inTx()) { + throw ConnectionError(); + } + PQreset(conn); + if (PQstatus(conn) != CONNECTION_OK) { + throw ConnectionError(); + } + } } diff --git a/libpqpp/selectcommand.cpp b/libpqpp/selectcommand.cpp index da12331..cc92540 100644 --- a/libpqpp/selectcommand.cpp +++ b/libpqpp/selectcommand.cpp @@ -12,13 +12,12 @@ PQ::SelectCommand::SelectCommand(const Connection * conn, const std::string & sq tuple(0), execRes(NULL) { - c->beginTx(); } PQ::SelectCommand::~SelectCommand() { - c->commitTx(); if (executed) { + c->commitTx(); PQclear(PQexec(c->conn, ("CLOSE " + stmntName).c_str())); if (execRes) { PQclear(execRes); @@ -54,6 +53,7 @@ PQ::SelectCommand::execute() psql += *i; } } + c->beginTx(); c->checkResultFree( PQexecParams(c->conn, psql.c_str(), values.size(), NULL, &values.front(), &lengths.front(), &formats.front(), 0), PGRES_COMMAND_OK); |