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
|
|
@ -7,7 +7,7 @@ std::string PgClassContainer::getLoadQuery() const
|
||||||
return "SELECT oid, relname, relnamespace, reltype, reloftype, "
|
return "SELECT oid, relname, relnamespace, reltype, reloftype, "
|
||||||
" relowner, relam, relfilenode, reltablespace, relpages, "
|
" relowner, relam, relfilenode, reltablespace, relpages, "
|
||||||
" reltuples, reltoastrelid, relisshared, relpersistence, "
|
" reltuples, reltoastrelid, relisshared, relpersistence, "
|
||||||
" relkind, relhasoids, relispopulated, relfrozenxid, relminmxid "
|
" relkind, relhasoids, relispopulated, relfrozenxid, relminmxid, "
|
||||||
" relacl, reloptions \n"
|
" relacl, reloptions \n"
|
||||||
"FROM pg_catalog.pg_class";
|
"FROM pg_catalog.pg_class";
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -158,13 +158,31 @@ const char * Result::getColName(int idx) const
|
||||||
return PQfname(result, idx);
|
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
|
const char * Result::val(int col, int row) const
|
||||||
{
|
{
|
||||||
|
colRangeCheck(col);
|
||||||
|
rowRangeCheck(row);
|
||||||
return PQgetvalue(result, row, col);
|
return PQgetvalue(result, row, col);
|
||||||
}
|
}
|
||||||
|
|
||||||
Value Result::get(int col, int row) const
|
Value Result::get(int col, int row) const
|
||||||
{
|
{
|
||||||
|
colRangeCheck(col);
|
||||||
|
rowRangeCheck(row);
|
||||||
|
|
||||||
return Value(
|
return Value(
|
||||||
PQgetvalue(result, row, col),
|
PQgetvalue(result, row, col),
|
||||||
PQftype(result, col)
|
PQftype(result, col)
|
||||||
|
|
@ -173,10 +191,15 @@ Value Result::get(int col, int row) const
|
||||||
|
|
||||||
Oid Result::type(int col) const
|
Oid Result::type(int col) const
|
||||||
{
|
{
|
||||||
|
colRangeCheck(col);
|
||||||
|
|
||||||
return PQftype(result, col);
|
return PQftype(result, col);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Result::null(int col, int row) const
|
bool Result::null(int col, int row) const
|
||||||
{
|
{
|
||||||
|
colRangeCheck(col);
|
||||||
|
rowRangeCheck(row);
|
||||||
|
|
||||||
return PQgetisnull(result, row, col);
|
return PQgetisnull(result, row, col);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -127,6 +127,9 @@ namespace Pgsql {
|
||||||
// iterator begin();
|
// iterator begin();
|
||||||
private:
|
private:
|
||||||
PGresult *result = nullptr;
|
PGresult *result = nullptr;
|
||||||
|
|
||||||
|
void colRangeCheck(int col) const;
|
||||||
|
void rowRangeCheck(int row) const;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue