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:
parent
3424b62aa0
commit
d1114793a1
3 changed files with 27 additions and 1 deletions
|
|
@ -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);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -127,6 +127,9 @@ namespace Pgsql {
|
|||
// iterator begin();
|
||||
private:
|
||||
PGresult *result = nullptr;
|
||||
|
||||
void colRangeCheck(int col) const;
|
||||
void rowRangeCheck(int row) const;
|
||||
};
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue