diff --git a/plugins/input/postgis/resultset.hpp b/plugins/input/postgis/resultset.hpp index 4e43763a3..beab2d729 100644 --- a/plugins/input/postgis/resultset.hpp +++ b/plugins/input/postgis/resultset.hpp @@ -47,57 +47,61 @@ public: class ResultSet : public IResultSet { -private: - PGresult* res_; - int pos_; - int numTuples_; - int *refCount_; - public: ResultSet(PGresult *res) - : res_(res), - pos_(-1), - refCount_(new int(1)) + : res_(res), + pos_(-1), + refCount_(new int(1)) { - numTuples_=PQntuples(res_); + numTuples_ = PQntuples(res_); } ResultSet(const ResultSet& rhs) - : res_(rhs.res_), - pos_(rhs.pos_), - numTuples_(rhs.numTuples_), - refCount_(rhs.refCount_) + : res_(rhs.res_), + pos_(rhs.pos_), + numTuples_(rhs.numTuples_), + refCount_(rhs.refCount_) { (*refCount_)++; } ResultSet& operator=(const ResultSet& rhs) { - if (this==&rhs) return *this; - if (--(refCount_)==0) + if (this == &rhs) + { + return *this; + } + + if (--(refCount_) == 0) { close(); - delete refCount_,refCount_=0; + + delete refCount_; + refCount_ = 0; } - res_=rhs.res_; - pos_=rhs.pos_; - numTuples_=rhs.numTuples_; - refCount_=rhs.refCount_; + + res_ = rhs.res_; + pos_ = rhs.pos_; + numTuples_ = rhs.numTuples_; + refCount_ = rhs.refCount_; (*refCount_)++; return *this; } virtual void close() { - PQclear(res_),res_=0; + PQclear(res_); + res_ = 0; } virtual ~ResultSet() { - if (--(*refCount_)==0) + if (--(*refCount_) == 0) { PQclear(res_); - delete refCount_,refCount_=0; + + delete refCount_; + refCount_ = 0; } } @@ -118,60 +122,69 @@ public: virtual bool next() { - return (++pos_=0) - return PQgetlength(res_,pos_,col); + int col = PQfnumber(res_, name); + if (col >= 0) + { + return PQgetlength(res_, pos_, col); + } return 0; } virtual int getTypeOID(int index) const { - return PQftype(res_,index); + return PQftype(res_, index); } virtual int getTypeOID(const char* name) const { - int col=PQfnumber(res_,name); - if (col>=0) - return PQftype(res_,col); + int col = PQfnumber(res_, name); + if (col >= 0) + { + return PQftype(res_, col); + } return 0; } virtual bool isNull(int index) const { - return static_cast(PQgetisnull(res_,pos_,index)); + return static_cast(PQgetisnull(res_, pos_, index)); } virtual const char* getValue(int index) const { - return PQgetvalue(res_,pos_,index); + return PQgetvalue(res_, pos_, index); } virtual const char* getValue(const char* name) const { - int col=PQfnumber(res_,name); - if (col>=0) + int col = PQfnumber(res_, name); + if (col >= 0) + { return getValue(col); + } return 0; } + +private: + PGresult* res_; + int pos_; + int numTuples_; + int *refCount_; }; #endif //RESULTSET_HPP - - -