From 5886b037ecf017819406a11588b627d16e01e38f Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Sun, 24 Apr 2016 15:43:07 +0100 Subject: Introduce select base for different kinds of select --- libpqpp/pq-column.cpp | 4 ++-- libpqpp/pq-column.h | 6 +++--- libpqpp/pq-cursorselectcommand.cpp | 3 --- libpqpp/pq-cursorselectcommand.h | 8 +++----- libpqpp/pq-selectbase.cpp | 9 +++++++++ libpqpp/pq-selectbase.h | 20 ++++++++++++++++++++ 6 files changed, 37 insertions(+), 13 deletions(-) create mode 100644 libpqpp/pq-selectbase.cpp create mode 100644 libpqpp/pq-selectbase.h diff --git a/libpqpp/pq-column.cpp b/libpqpp/pq-column.cpp index 31a3d9b..a073f26 100644 --- a/libpqpp/pq-column.cpp +++ b/libpqpp/pq-column.cpp @@ -1,10 +1,10 @@ #include "pq-column.h" -#include "pq-cursorselectcommand.h" +#include "pq-selectbase.h" #include "pq-error.h" #include #include -PQ::Column::Column(const CursorSelectCommand * s, unsigned int i) : +PQ::Column::Column(const SelectBase * s, unsigned int i) : DB::Column(PQfname(s->execRes, i), i), sc(s), oid(PQftype(sc->execRes, colNo)) diff --git a/libpqpp/pq-column.h b/libpqpp/pq-column.h index 99a37fb..f01ee9a 100644 --- a/libpqpp/pq-column.h +++ b/libpqpp/pq-column.h @@ -5,16 +5,16 @@ #include namespace PQ { - class CursorSelectCommand; + class SelectBase; class Column : public DB::Column { public: - Column(const CursorSelectCommand *, unsigned int field); + Column(const SelectBase *, unsigned int field); bool isNull() const override; void apply(DB::HandleField &) const override; protected: - const CursorSelectCommand * sc; + const SelectBase * sc; const Oid oid; }; } diff --git a/libpqpp/pq-cursorselectcommand.cpp b/libpqpp/pq-cursorselectcommand.cpp index fe097a5..ab21f66 100644 --- a/libpqpp/pq-cursorselectcommand.cpp +++ b/libpqpp/pq-cursorselectcommand.cpp @@ -9,10 +9,7 @@ PQ::CursorSelectCommand::CursorSelectCommand(Connection * conn, const std::strin 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()) diff --git a/libpqpp/pq-cursorselectcommand.h b/libpqpp/pq-cursorselectcommand.h index aafe4e1..6182d3f 100644 --- a/libpqpp/pq-cursorselectcommand.h +++ b/libpqpp/pq-cursorselectcommand.h @@ -2,6 +2,7 @@ #define PQ_CURSORSELECTCOMMAND_H #include +#include "pq-selectbase.h" #include "pq-command.h" #include #include @@ -9,7 +10,7 @@ namespace PQ { class Connection; class Column; - class CursorSelectCommand : public DB::SelectCommand, public Command { + class CursorSelectCommand : public DB::SelectCommand, public SelectBase, public Command { public: CursorSelectCommand(Connection *, const std::string & sql, unsigned int no); virtual ~CursorSelectCommand(); @@ -25,13 +26,10 @@ namespace PQ { mutable bool executed; mutable bool txOpened; - int nTuples, tuple, fTuples; - PGresult * execRes; + int fTuples; std::string s_declare; std::string s_fetch; std::string s_close; - - friend class Column; }; } diff --git a/libpqpp/pq-selectbase.cpp b/libpqpp/pq-selectbase.cpp new file mode 100644 index 0000000..1ede6b8 --- /dev/null +++ b/libpqpp/pq-selectbase.cpp @@ -0,0 +1,9 @@ +#include "pq-selectbase.h" + +PQ::SelectBase::SelectBase() : + nTuples(0), + tuple(0), + execRes(NULL) +{ +} + diff --git a/libpqpp/pq-selectbase.h b/libpqpp/pq-selectbase.h new file mode 100644 index 0000000..217a9e7 --- /dev/null +++ b/libpqpp/pq-selectbase.h @@ -0,0 +1,20 @@ +#ifndef PQ_SELECTBASE_H +#define PQ_SELECTBASE_H + +#include + +namespace PQ { + class SelectBase { + friend class Column; + + protected: + SelectBase(); + ~SelectBase() = default; + + int nTuples, tuple; + PGresult * execRes; + }; +} + +#endif + -- cgit v1.2.3