diff options
Diffstat (limited to 'libpqpp')
-rw-r--r-- | libpqpp/pq-selectcommand.cpp | 2 | ||||
-rw-r--r-- | libpqpp/unittests/testpq.cpp | 19 |
2 files changed, 20 insertions, 1 deletions
diff --git a/libpqpp/pq-selectcommand.cpp b/libpqpp/pq-selectcommand.cpp index e5a6cf2..6c02fc4 100644 --- a/libpqpp/pq-selectcommand.cpp +++ b/libpqpp/pq-selectcommand.cpp @@ -64,7 +64,7 @@ void PQ::SelectCommand::execute() { if (!executed) { - if (!txOpened) { + if (!c->inTx()) { c->beginTx(); txOpened = true; } diff --git a/libpqpp/unittests/testpq.cpp b/libpqpp/unittests/testpq.cpp index ed6c4bc..c49fa34 100644 --- a/libpqpp/unittests/testpq.cpp +++ b/libpqpp/unittests/testpq.cpp @@ -80,6 +80,25 @@ BOOST_AUTO_TEST_CASE( bindAndSelect ) delete ro; } +BOOST_AUTO_TEST_CASE( selectInTx ) +{ + auto db = DB::MockDatabase::openConnectionTo("pqmock"); + + auto select = db->newSelectCommand("SELECT * FROM test"); + while (select->fetch()) { } + delete select; + db->finish(); + + db->beginTx(); + select = db->newSelectCommand("SELECT * FROM test"); + while (select->fetch()) { } + delete select; + db->commitTx(); + db->finish(); + + delete db; +} + BOOST_AUTO_TEST_CASE( bindAndSelectOther ) { auto ro = DB::MockDatabase::openConnectionTo("pqmock"); |