Added to functions to Pgsql::Result to help in doing smart things based on a result.
- ftable, return from which table the column in the result originates - ftableCol, returns the column number within that table (attnum) Ofcourse columns can also be expressions in which case these functions return InvalidOid and 0.
This commit is contained in:
parent
f629e48a85
commit
cfc218c43b
2 changed files with 21 additions and 3 deletions
|
|
@ -43,7 +43,6 @@ ErrorDetails ErrorDetails::createErrorDetailsFromPGresult(const PGresult *result
|
|||
return r;
|
||||
}
|
||||
|
||||
|
||||
Result::Result(PGresult *res)
|
||||
: result(res)
|
||||
{
|
||||
|
|
@ -96,7 +95,6 @@ std::string Result::diagSqlState()
|
|||
return s;
|
||||
}
|
||||
|
||||
|
||||
ErrorDetails Result::diagDetails()
|
||||
{
|
||||
// ErrorDetails r;
|
||||
|
|
@ -170,7 +168,6 @@ inline void Result::rowRangeCheck(int row) const
|
|||
throw std::range_error("row index out of range");
|
||||
}
|
||||
|
||||
|
||||
const char * Result::val(int col, int row) const
|
||||
{
|
||||
colRangeCheck(col);
|
||||
|
|
@ -205,3 +202,15 @@ bool Result::null(int col, int row) const
|
|||
|
||||
return PQgetisnull(result, row, col);
|
||||
}
|
||||
|
||||
Oid Result::ftable(int col) const
|
||||
{
|
||||
colRangeCheck(col);
|
||||
return PQftable(result, col);
|
||||
}
|
||||
|
||||
int Result::ftableCol(int col) const
|
||||
{
|
||||
colRangeCheck(col);
|
||||
return PQftablecol(result, col);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -123,6 +123,15 @@ namespace Pgsql {
|
|||
Oid type(int col) const;
|
||||
bool null(int col, int row) const;
|
||||
|
||||
/// Return the oid of the table this is a column of
|
||||
/// when the column isn't a table column InvalidOid is returned
|
||||
/// when col is out of range a std::range_error is thrown
|
||||
Oid ftable(int col) const;
|
||||
/// Returns the attnum of col in its table, attnum is negative for system cols like oid
|
||||
/// It is positive for user columns, 0 signals there is no direct table column mapping
|
||||
/// when col is out of range a std::range_error is thrown
|
||||
int ftableCol(int col) const;
|
||||
|
||||
|
||||
// iterator begin();
|
||||
private:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue