FOSSology  4.4.0
Open Source License Compliance by Open Source Software
fo::QueryResult Class Reference

Wrapper for DB result. More...

#include <libfossdbQueryResult.hpp>

Collaboration diagram for fo::QueryResult:
Collaboration graph

Public Member Functions

 QueryResult (QueryResult &&o)
 
bool isFailed () const
 Check if the query failed. More...
 
 operator bool () const
 
int getRowCount () const
 
std::vector< std::string > getRow (int i) const
 
template<typename T >
std::vector< T > getSimpleResults (int columnN, T(functionP)(const char *)) const
 Get vector of a single column from query result. More...
 

Private Member Functions

 QueryResult (PGresult *ptr)
 

Private Attributes

unptr::unique_ptr< PGresult, PGresultDeleterptr
 Unique pointer to the actual PGresult.
 

Friends

class DbManager
 
class AgentDatabaseHandler
 

Detailed Description

Wrapper for DB result.

Definition at line 42 of file libfossdbQueryResult.hpp.

Constructor & Destructor Documentation

◆ QueryResult()

QueryResult::QueryResult ( PGresult *  pgResult)
private

Constructor for QueryResult

Parameters
pgResultPostgres query result object

Definition at line 23 of file libfossdbQueryResult.cc.

Member Function Documentation

◆ getRow()

std::vector< std::string > QueryResult::getRow ( int  i) const

Get all columns from required row as a string vector

Parameters
iThe row to be fetched
Returns
String vector with each column as new element

Definition at line 53 of file libfossdbQueryResult.cc.

◆ getRowCount()

int QueryResult::getRowCount ( ) const

Check the row count in the query result

Returns
Row count if result exists, -1 otherwise

Definition at line 40 of file libfossdbQueryResult.cc.

◆ getSimpleResults()

template<typename T >
std::vector< T > fo::QueryResult::getSimpleResults ( int  columnN,
T(functionP)(const char *)   
) const

Get vector of a single column from query result.

Get a single column's values as a vector of type T (defined by functionP param). The values will be translated using the functionP.

Parameters
columnNPosition of the required column
functionPFunction to translate the string result in desired format
Returns
Vector with translated values of a single column

Definition at line 85 of file libfossdbQueryResult.hpp.

◆ isFailed()

bool QueryResult::isFailed ( ) const

Check if the query failed.

Check if the query is failed by checking the Postgres object for NULL

Returns
True if failed, false on success.

Definition at line 32 of file libfossdbQueryResult.cc.

◆ operator bool()

fo::QueryResult::operator bool ( ) const
inline

Check if the query result failed

Returns
True if failed, false on success.
See also
fo::QueryResult::isFailed()

Definition at line 60 of file libfossdbQueryResult.hpp.


The documentation for this class was generated from the following files: