CppCrate 0.1
Public Member Functions | List of all members
CppCrate::Result Class Reference

Public Member Functions

 Result (const RawResult &raw)
 
const std::vector< std::string > & cols () const
 
const std::vector< CrateDataType > & colTypes () const
 
double duration () const
 
const std::string & errorString () const
 
bool hasError () const
 
 operator bool () const
 
const RawResultrawResult () const
 
Record record (int pos) const
 
int recordSize () const
 
int rowCount () const
 
const std::vector< std::string > & rows () const
 

Detailed Description

The class Result encapsulates the reply of a Crate HTTP endpoint request. In contrast to RawResult it parses the reply and provides convenience function to access the result's information directly.

The following code for example shows how to iterate over all returned rows of a query:

Result result = client.exec("SELECT name FROM players");
if (result) {
for (int i = 0, total = result.recordSize(); i < total; ++i) {
Record r = result.record(i);
std::cout << r.value("name").asString() << "\n";
}
} else {
std::cout << result.errorString() << "\n";
}

Constructor & Destructor Documentation

◆ Result()

CppCrate::Result::Result ( const RawResult raw)
explicit

Constructs a result based on the raw result raw.

Member Function Documentation

◆ cols()

const std::vector< std::string > & CppCrate::Result::cols ( ) const

Returns the query's column names.

◆ colTypes()

const std::vector< CrateDataType > & CppCrate::Result::colTypes ( ) const

Returns the query's column types.

◆ duration()

double CppCrate::Result::duration ( ) const

Returns the query's duration.

◆ errorString()

const std::string & CppCrate::Result::errorString ( ) const

Returns the error string.

◆ hasError()

bool CppCrate::Result::hasError ( ) const

Returns whether the result has an error.

◆ operator bool()

CppCrate::Result::operator bool ( ) const
explicit

Returns whether the result is valid.

◆ rawResult()

const RawResult & CppCrate::Result::rawResult ( ) const

Returns the raw result on which this result is based on. Use

result.rawResult().reply();

to get the HTTP endpoint's original reply.

◆ record()

Record CppCrate::Result::record ( int  pos) const

Returns the record on the position pos. If pos is outside the record's boundaries an empty record is returned.

◆ recordSize()

int CppCrate::Result::recordSize ( ) const

Returns the amount of records that can be fetched using record().

◆ rowCount()

int CppCrate::Result::rowCount ( ) const

Returns the query's row count.

Note
To iterate over the records use recordSize().

◆ rows()

const std::vector< std::string > & CppCrate::Result::rows ( ) const

Returns the query's rows.