- postgis resultset cosmetics

This commit is contained in:
kunitoki 2012-03-31 22:24:32 +02:00
parent 14bc344898
commit 4a7966498c

View file

@ -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_<numTuples_);
return (++pos_ < numTuples_);
}
virtual const char* getFieldName(int index) const
{
return PQfname(res_,index);
return PQfname(res_, index);
}
virtual int getFieldLength(int index) const
{
return PQgetlength(res_,pos_,index);
return PQgetlength(res_, pos_, index);
}
virtual int getFieldLength(const char* name) const
{
int col=PQfnumber(res_,name);
if (col>=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<bool>(PQgetisnull(res_,pos_,index));
return static_cast<bool>(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