summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--libpqpp/connection.cpp9
-rw-r--r--libpqpp/selectcommand.cpp4
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);