summaryrefslogtreecommitdiff
path: root/libpqpp/pq-cursorselectcommand.cpp
diff options
context:
space:
mode:
authorDan Goodliffe <dan@randomdan.homeip.net>2017-01-04 02:00:04 +0000
committerDan Goodliffe <dan@randomdan.homeip.net>2017-01-04 02:00:04 +0000
commit74fcbf827294bac907fffe57382e34359893f20f (patch)
treea20e7f29872515ca3cbba3f66c656aa119aeb1c9 /libpqpp/pq-cursorselectcommand.cpp
parentTidy clearing of PGresults (diff)
downloadlibdbpp-postgresql-74fcbf827294bac907fffe57382e34359893f20f.tar.bz2
libdbpp-postgresql-74fcbf827294bac907fffe57382e34359893f20f.tar.xz
libdbpp-postgresql-74fcbf827294bac907fffe57382e34359893f20f.zip
C++ify the SQL preparer and skip it if no variables are being bound
Diffstat (limited to 'libpqpp/pq-cursorselectcommand.cpp')
-rw-r--r--libpqpp/pq-cursorselectcommand.cpp11
1 files changed, 7 insertions, 4 deletions
diff --git a/libpqpp/pq-cursorselectcommand.cpp b/libpqpp/pq-cursorselectcommand.cpp
index 4ee6e80..ac4b825 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 %? CURSOR FOR ");
AdHocFormatter(PQCursorSelectFetch, "FETCH %? IN %?");
AdHocFormatter(PQCursorSelectClose, "CLOSE %?");
@@ -14,7 +14,6 @@ PQ::CursorSelectCommand::CursorSelectCommand(Connection * conn, const std::strin
executed(false),
txOpened(false),
fTuples(35),
- s_declare(mkdeclare()),
s_fetch(PQCursorSelectFetch::get(fTuples, stmntName)),
s_close(PQCursorSelectClose::get(stmntName))
{
@@ -33,9 +32,10 @@ PQ::CursorSelectCommand::~CursorSelectCommand()
std::string
PQ::CursorSelectCommand::mkdeclare() const
{
- std::string psql;
+ std::stringstream psql;
+ PQCursorSelectDeclare::write(psql, stmntName);
prepareSql(psql, sql);
- return PQCursorSelectDeclare::get(stmntName, psql);
+ return psql.str();
}
void
@@ -46,6 +46,9 @@ PQ::CursorSelectCommand::execute()
c->beginTx();
txOpened = true;
}
+ if (s_declare.empty()) {
+ s_declare = mkdeclare();
+ }
c->checkResultFree(
PQexecParams(c->conn, s_declare.c_str(), values.size(), NULL, &values.front(), &lengths.front(), NULL, 0),
PGRES_COMMAND_OK);