summaryrefslogtreecommitdiff
path: root/libpqpp/pq-selectcommand.cpp
diff options
context:
space:
mode:
authorDan Goodliffe <dan@randomdan.homeip.net>2016-04-24 14:34:16 +0100
committerDan Goodliffe <dan@randomdan.homeip.net>2016-04-24 14:40:20 +0100
commiteab3a1beba707e9f531a250a5c74a6ba462aa4fc (patch)
tree0bac5aa1211d282f996d2b9bf3b72d81717df5e9 /libpqpp/pq-selectcommand.cpp
parentDon't attempt to close cursors when in failed transaction (it's failed and re... (diff)
downloadlibdbpp-postgresql-eab3a1beba707e9f531a250a5c74a6ba462aa4fc.tar.bz2
libdbpp-postgresql-eab3a1beba707e9f531a250a5c74a6ba462aa4fc.tar.xz
libdbpp-postgresql-eab3a1beba707e9f531a250a5c74a6ba462aa4fc.zip
Rename SelectCommand to CursorSelectCommand
Diffstat (limited to 'libpqpp/pq-selectcommand.cpp')
-rw-r--r--libpqpp/pq-selectcommand.cpp113
1 files changed, 0 insertions, 113 deletions
diff --git a/libpqpp/pq-selectcommand.cpp b/libpqpp/pq-selectcommand.cpp
deleted file mode 100644
index b049eea..0000000
--- a/libpqpp/pq-selectcommand.cpp
+++ /dev/null
@@ -1,113 +0,0 @@
-#include "pq-selectcommand.h"
-#include "pq-connection.h"
-#include "pq-column.h"
-#include "pq-error.h"
-
-PQ::SelectCommand::SelectCommand(Connection * conn, const std::string & sql, unsigned int no) :
- DB::Command(sql),
- DB::SelectCommand(sql),
- PQ::Command(conn, sql, no),
- executed(false),
- txOpened(false),
- nTuples(0),
- tuple(0),
- fTuples(35),
- execRes(NULL),
- s_declare(mkdeclare()),
- s_fetch(mkfetch()),
- s_close(mkclose())
-{
-}
-
-PQ::SelectCommand::~SelectCommand()
-{
- if (execRes) {
- PQclear(execRes);
- }
- 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
-PQ::SelectCommand::mkdeclare() const
-{
- std::string psql;
- psql.reserve(sql.length() + 40);
- psql += "DECLARE ";
- psql += stmntName;
- psql += " CURSOR FOR ";
- prepareSql(psql, sql);
- return psql;
-}
-
-std::string
-PQ::SelectCommand::mkfetch() const
-{
- char buf[BUFSIZ];
- snprintf(buf, sizeof(buf), "FETCH %d IN %s", fTuples, stmntName.c_str());
- return buf;
-}
-
-std::string
-PQ::SelectCommand::mkclose() const
-{
- char buf[BUFSIZ];
- snprintf(buf, sizeof(buf), "CLOSE %s", stmntName.c_str());
- return buf;
-}
-
-void
-PQ::SelectCommand::execute()
-{
- if (!executed) {
- if (!c->inTx()) {
- c->beginTx();
- txOpened = true;
- }
- execRes = c->checkResult(
- PQexecParams(c->conn, s_declare.c_str(), values.size(), NULL, &values.front(), &lengths.front(), NULL, 0),
- PGRES_COMMAND_OK);
- fetchTuples();
- unsigned int nFields = PQnfields(execRes);
- for (unsigned int f = 0; f < nFields; f += 1) {
- insertColumn(DB::ColumnPtr(new Column(this, f)));
- }
- executed = true;
- }
-}
-
-void
-PQ::SelectCommand::fetchTuples()
-{
- if (execRes) {
- PQclear(execRes);
- }
- execRes = NULL;
- execRes = c->checkResult(PQexec(c->conn, s_fetch.c_str()), PGRES_TUPLES_OK);
- nTuples = PQntuples(execRes);
- tuple = -1;
-}
-
-bool
-PQ::SelectCommand::fetch()
-{
- execute();
- if ((tuple >= (nTuples - 1)) && (nTuples == fTuples)) {
- fetchTuples();
- }
- if (tuple++ < (nTuples - 1)) {
- return true;
- }
- else {
- PQclear(PQexec(c->conn, s_close.c_str()));
- PQclear(execRes);
- execRes = NULL;
- executed = false;
- return false;
- }
-}
-