Fixed missing comman in pg_class query.

Added checks on row and column indexes in Pgsql::Result to detect these kind of problems earlier in the future.
This commit is contained in:
eelke 2017-12-17 20:22:55 +01:00
parent 3424b62aa0
commit d1114793a1
3 changed files with 27 additions and 1 deletions

View file

@ -7,7 +7,7 @@ std::string PgClassContainer::getLoadQuery() const
return "SELECT oid, relname, relnamespace, reltype, reloftype, "
" relowner, relam, relfilenode, reltablespace, relpages, "
" reltuples, reltoastrelid, relisshared, relpersistence, "
" relkind, relhasoids, relispopulated, relfrozenxid, relminmxid "
" relkind, relhasoids, relispopulated, relfrozenxid, relminmxid, "
" relacl, reloptions \n"
"FROM pg_catalog.pg_class";
}

View file

@ -158,13 +158,31 @@ const char * Result::getColName(int idx) const
return PQfname(result, idx);
}
inline void Result::colRangeCheck(int col) const
{
if (col < 0 || col >= cols())
throw std::range_error("column index out of range");
}
inline void Result::rowRangeCheck(int row) const
{
if (row < 0 || row >= rows())
throw std::range_error("row index out of range");
}
const char * Result::val(int col, int row) const
{
colRangeCheck(col);
rowRangeCheck(row);
return PQgetvalue(result, row, col);
}
Value Result::get(int col, int row) const
{
colRangeCheck(col);
rowRangeCheck(row);
return Value(
PQgetvalue(result, row, col),
PQftype(result, col)
@ -173,10 +191,15 @@ Value Result::get(int col, int row) const
Oid Result::type(int col) const
{
colRangeCheck(col);
return PQftype(result, col);
}
bool Result::null(int col, int row) const
{
colRangeCheck(col);
rowRangeCheck(row);
return PQgetisnull(result, row, col);
}

View file

@ -127,6 +127,9 @@ namespace Pgsql {
// iterator begin();
private:
PGresult *result = nullptr;
void colRangeCheck(int col) const;
void rowRangeCheck(int row) const;
};