summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorrandomdan <randomdan@localhost>2013-01-27 18:18:31 +0000
committerrandomdan <randomdan@localhost>2013-01-27 18:18:31 +0000
commitaf7b76b6bc14c57a753d6a58365bd4a6cc4e914d (patch)
tree9f796b3ce7356a995508959676da6cd521060a7a
parentFix issues with PQ connection errors not being handled correctly (diff)
downloadlibdbpp-postgresql-af7b76b6bc14c57a753d6a58365bd4a6cc4e914d.tar.bz2
libdbpp-postgresql-af7b76b6bc14c57a753d6a58365bd4a6cc4e914d.tar.xz
libdbpp-postgresql-af7b76b6bc14c57a753d6a58365bd4a6cc4e914d.zip
Record tx open separately from executed for the cases when the execute fails
-rw-r--r--libpqpp/selectcommand.cpp6
-rw-r--r--libpqpp/selectcommand.h1
2 files changed, 6 insertions, 1 deletions
diff --git a/libpqpp/selectcommand.cpp b/libpqpp/selectcommand.cpp
index cc92540..3798406 100644
--- a/libpqpp/selectcommand.cpp
+++ b/libpqpp/selectcommand.cpp
@@ -8,6 +8,7 @@ PQ::SelectCommand::SelectCommand(const Connection * conn, const std::string & sq
DB::SelectCommand(sql),
PQ::Command(conn, sql, no),
executed(false),
+ txOpened(false),
nTuples(0),
tuple(0),
execRes(NULL)
@@ -16,8 +17,10 @@ PQ::SelectCommand::SelectCommand(const Connection * conn, const std::string & sq
PQ::SelectCommand::~SelectCommand()
{
- if (executed) {
+ if (txOpened) {
c->commitTx();
+ }
+ if (executed) {
PQclear(PQexec(c->conn, ("CLOSE " + stmntName).c_str()));
if (execRes) {
PQclear(execRes);
@@ -54,6 +57,7 @@ PQ::SelectCommand::execute()
}
}
c->beginTx();
+ txOpened = true;
c->checkResultFree(
PQexecParams(c->conn, psql.c_str(), values.size(), NULL, &values.front(), &lengths.front(), &formats.front(), 0),
PGRES_COMMAND_OK);
diff --git a/libpqpp/selectcommand.h b/libpqpp/selectcommand.h
index 932717d..507bf43 100644
--- a/libpqpp/selectcommand.h
+++ b/libpqpp/selectcommand.h
@@ -22,6 +22,7 @@ namespace PQ {
unsigned int getOrdinal(const Glib::ustring&) const;
private:
mutable bool executed;
+ mutable bool txOpened;
std::vector<Column *> fields;
std::map<Glib::ustring, Column *> fieldsName;
int nTuples, tuple;