1
#include "CSQLResultPostgre.h"
7
#include "IDatabaseManager.h"
11
CSQLResultPostgre::CSQLResultPostgre(PGresult *res_, IDatabaseManager *databaseMgr_, const std::string query_)
12
: ISQLResult(databaseMgr_, query_), res(res_)
16
CSQLResultPostgre::~CSQLResultPostgre()
22
s32 CSQLResultPostgre::getRowCount() const
24
if(!res || !this->isValidTuple())
27
return PQntuples(res);
30
s32 CSQLResultPostgre::getColumnCount() const
32
if(!res || !this->isValidTuple())
35
return PQnfields(res);
38
s32 CSQLResultPostgre::getColumnFromName(const std::string name) const
42
if(res && this->isValidTuple())
43
val = PQfnumber(res, name.c_str());
46
databaseMgr->logWarning(std::string("Couldn't get column-number: ") + name);
51
ESQLResultType CSQLResultPostgre::getType() const
53
ExecStatusType type = PQresultStatus(res);
55
if(type == PGRES_EMPTY_QUERY)
56
return ESQLR_EmptyQuery;
57
else if(type == PGRES_COMMAND_OK)
58
return ESQLR_CommandOk;
59
else if(type == PGRES_TUPLES_OK)
60
return ESQLR_TuplesOk;
61
else if(type == PGRES_BAD_RESPONSE || type == PGRES_NONFATAL_ERROR)
63
else if(type == PGRES_FATAL_ERROR)
64
return ESQLR_ErrorFatal;
69
s32 CSQLResultPostgre::getFieldLength(const s32 row, const s32 column) const
71
if(!this->isValidTuple())
74
if(!this->isInRange(row, column))
77
return PQgetlength(res, row, column);
80
std::string CSQLResultPostgre::getString(const s32 row, const s32 column) const
82
if(!this->isValidTuple())
85
if(!this->isInRange(row, column))
88
return std::string(PQgetvalue(res, row, column));
91
std::string CSQLResultPostgre::getError()
96
return PQresultErrorMessage(res);
99
bool CSQLResultPostgre::isInRange(const s32 row, const s32 column) const
101
if((row >= this->getRowCount()) || (column >= this->getColumnCount()))
103
std::stringstream msg;
104
msg << "Database Request out of range (Query: \"" << this->getQuery() << " \")";
106
databaseMgr->logWarning(msg.str());