diff options
author | Dan Goodliffe <dan@randomdan.homeip.net> | 2017-01-04 02:00:04 +0000 |
---|---|---|
committer | Dan Goodliffe <dan@randomdan.homeip.net> | 2017-01-04 02:00:04 +0000 |
commit | f9fc8240229cd1f059bfc56eb027aec11fec6b4c (patch) | |
tree | c276986ac80870167d594d5d8229824317d38582 /libpqpp/pq-cursorselectcommand.cpp | |
parent | Tidy clearing of PGresults (diff) | |
download | libdbpp-postgresql-f9fc8240229cd1f059bfc56eb027aec11fec6b4c.tar.bz2 libdbpp-postgresql-f9fc8240229cd1f059bfc56eb027aec11fec6b4c.tar.xz libdbpp-postgresql-f9fc8240229cd1f059bfc56eb027aec11fec6b4c.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.cpp | 11 |
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); |