summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--libpqpp/pq-cursorselectcommand.cpp10
-rw-r--r--libpqpp/pq-cursorselectcommand.h1
-rw-r--r--libpqpp/unittests/testpq.cpp13
3 files changed, 10 insertions, 14 deletions
diff --git a/libpqpp/pq-cursorselectcommand.cpp b/libpqpp/pq-cursorselectcommand.cpp
index 2b639c8..53d951a 100644
--- a/libpqpp/pq-cursorselectcommand.cpp
+++ b/libpqpp/pq-cursorselectcommand.cpp
@@ -3,7 +3,7 @@
#include "pq-error.h"
#include <compileTimeFormatter.h>
-AdHocFormatter(PQCursorSelectDeclare, "DECLARE %? CURSOR FOR ");
+AdHocFormatter(PQCursorSelectDeclare, "DECLARE %? NO SCROLL CURSOR WITH HOLD FOR ");
AdHocFormatter(PQCursorSelectFetch, "FETCH %? IN %?");
AdHocFormatter(PQCursorSelectClose, "CLOSE %?");
@@ -12,7 +12,6 @@ PQ::CursorSelectCommand::CursorSelectCommand(Connection * conn, const std::strin
PQ::SelectBase(sql, pqco),
PQ::Command(conn, sql, opts),
executed(false),
- txOpened(false),
fTuples(pqco ? pqco->fetchTuples : 35),
s_fetch(PQCursorSelectFetch::get(fTuples, stmntName)),
s_close(PQCursorSelectClose::get(stmntName))
@@ -24,9 +23,6 @@ PQ::CursorSelectCommand::~CursorSelectCommand()
if (executed && PQtransactionStatus(c->conn) != PQTRANS_INERROR) {
c->checkResultFree((PQexec(c->conn, s_close.c_str())), PGRES_COMMAND_OK);
}
- if (txOpened) {
- c->commitTx();
- }
}
std::string
@@ -42,10 +38,6 @@ void
PQ::CursorSelectCommand::execute()
{
if (!executed) {
- if (!c->inTx()) {
- c->beginTx();
- txOpened = true;
- }
if (s_declare.empty()) {
s_declare = mkdeclare();
}
diff --git a/libpqpp/pq-cursorselectcommand.h b/libpqpp/pq-cursorselectcommand.h
index 8182210..4d47229 100644
--- a/libpqpp/pq-cursorselectcommand.h
+++ b/libpqpp/pq-cursorselectcommand.h
@@ -22,7 +22,6 @@ namespace PQ {
std::string mkdeclare() const;
mutable bool executed;
- mutable bool txOpened;
int fTuples;
std::string s_declare;
std::string s_fetch;
diff --git a/libpqpp/unittests/testpq.cpp b/libpqpp/unittests/testpq.cpp
index 476c3a2..cfe7b11 100644
--- a/libpqpp/unittests/testpq.cpp
+++ b/libpqpp/unittests/testpq.cpp
@@ -112,13 +112,18 @@ BOOST_AUTO_TEST_CASE( selectInTx )
{
auto db = DB::MockDatabase::openConnectionTo("PQmock");
- auto select = db->newSelectCommand("SELECT * FROM test");
- while (select->fetch()) { }
- delete select;
+ // Loop to ensure we can create the same statement several times
+ for (int x = 0; x < 2; x++) {
+ auto select = db->select("SELECT * FROM test");
+ // Loop to ensure we can use the same command several times
+ for (int y = 0; y < 2; y++) {
+ while (select->fetch()) { }
+ }
+ }
db->finish();
db->beginTx();
- select = db->newSelectCommand("SELECT * FROM test");
+ auto select = db->newSelectCommand("SELECT * FROM test");
while (select->fetch()) { }
delete select;
db->commitTx();