AnCH Framework 0.1
Another C++ Hack Framework
 
Loading...
Searching...
No Matches
anch::sql::ResultSet Class Referenceabstract

SQL result representation. More...

#include <resultSet.hpp>

+ Inheritance diagram for anch::sql::ResultSet:
+ Collaboration diagram for anch::sql::ResultSet:

Public Member Functions

 ResultSet () noexcept
 
virtual ~ResultSet () noexcept
 
template<typename T>
bool get (std::size_t idx, T &out)
 
template<typename T>
bool get (const std::string field, T &out)
 
template<typename T>
std::optional< T > get (std::size_t idx)
 
template<typename T>
const std::optional< T > get (const std::string field)
 
virtual bool next ()=0
 

Protected Member Functions

virtual bool getValue (std::size_t idx, std::string &out)=0
 
virtual std::optional< std::string > getValue (std::size_t idx)=0
 
virtual const anch::date::DateFormattergetDateFormatter ()=0
 
virtual const anch::date::DateFormattergetTimeFormatter ()=0
 
virtual const anch::date::DateFormattergetTimestampFormatter ()=0
 
const anch::date::DateFormattergetDefaultDateFormatter ()
 
const anch::date::DateFormattergetDefaultTimeFormatter ()
 
const anch::date::DateFormattergetDefaultTimestampFormatter ()
 

Protected Attributes

std::map< std::string, std::size_t > _fields
 

Detailed Description

SQL result representation.

The ResultSet has to be used with while(res.hasNext()) {res.next(); [...]}.
Field getter is templated. Specializations are included in library. If you need other conversions, you can implement them in your own program.

Author
Vincent Lachenal
Since
0.1

Constructor & Destructor Documentation

◆ ResultSet()

anch::sql::ResultSet::ResultSet ( )
noexcept

ResultSet default constructor

◆ ~ResultSet()

virtual anch::sql::ResultSet::~ResultSet ( )
virtualnoexcept

ResultSet destrcutor

+ Here is the call graph for this function:

Member Function Documentation

◆ get() [1/4]

template<typename T>
const std::optional< T > anch::sql::ResultSet::get ( const std::string field)
inline

Get field value by field name.

Template Parameters
Texpected type
Parameters
fieldthe field name
Returns
the result
Exceptions
SqlExceptionany error
+ Here is the call graph for this function:

◆ get() [2/4]

template<typename T>
bool anch::sql::ResultSet::get ( const std::string field,
T & out )
inline

Get field value by field name.
The output parameter will be set only if SQL result is not NULL.

Template Parameters
Texpected type
Parameters
fieldthe field name
outthe result
Returns
true if result is NULL, false otherwise
+ Here is the call graph for this function:

◆ get() [3/4]

template<typename T>
std::optional< T > anch::sql::ResultSet::get ( std::size_t idx)

Get field value by index.

Template Parameters
Texpected type
Parameters
idxthe index
Returns
the result
Exceptions
SqlExceptionany error

◆ get() [4/4]

template<typename T>
bool anch::sql::ResultSet::get ( std::size_t idx,
T & out )

Get field value by index.
The output parameter will be set only if SQL result is not NULL.

Template Parameters
Texpected type
Parameters
idxthe index
outthe result
Returns
true if result is NULL, false otherwise
Exceptions
SqlExceptionany error
+ Here is the call graph for this function:

◆ getDateFormatter()

virtual const anch::date::DateFormatter & anch::sql::ResultSet::getDateFormatter ( )
protectedpure virtual

Retrieve SQL date formatter

Returns
the SQL date formatter

Implemented in anch::sql::MySQLPreparedStatementResultSet, anch::sql::MySQLResultSet, anch::sql::PostgreSQLResultSet, and anch::sql::SQLite3ResultSet.

◆ getDefaultDateFormatter()

const anch::date::DateFormatter & anch::sql::ResultSet::getDefaultDateFormatter ( )
protected

Retrieve SQL date formatter

Returns
the SQL date formatter

◆ getDefaultTimeFormatter()

const anch::date::DateFormatter & anch::sql::ResultSet::getDefaultTimeFormatter ( )
protected

Retrieve SQL time formatter

Returns
the SQL time formatter

◆ getDefaultTimestampFormatter()

const anch::date::DateFormatter & anch::sql::ResultSet::getDefaultTimestampFormatter ( )
protected

Retrieve SQL timestamp formatter

Returns
the SQL timestamp formatter

◆ getTimeFormatter()

virtual const anch::date::DateFormatter & anch::sql::ResultSet::getTimeFormatter ( )
protectedpure virtual

Retrieve SQL time formatter

Returns
the SQL time formatter

Implemented in anch::sql::MySQLPreparedStatementResultSet, anch::sql::MySQLResultSet, anch::sql::PostgreSQLResultSet, and anch::sql::SQLite3ResultSet.

◆ getTimestampFormatter()

virtual const anch::date::DateFormatter & anch::sql::ResultSet::getTimestampFormatter ( )
protectedpure virtual

Retrieve SQL timestamp formatter

Returns
the SQL timestamp formatter

Implemented in anch::sql::MySQLPreparedStatementResultSet, anch::sql::MySQLResultSet, anch::sql::PostgreSQLResultSet, and anch::sql::SQLite3ResultSet.

◆ getValue() [1/2]

virtual std::optional< std::string > anch::sql::ResultSet::getValue ( std::size_t idx)
protectedpure virtual

Retrieve string value from result set according to SQL database engine.

Parameters
idxthe field index
Returns
the result as optional character string
Exceptions
SqlExceptionany error

Implemented in anch::sql::MySQLPreparedStatementResultSet, anch::sql::MySQLResultSet, anch::sql::PostgreSQLResultSet, and anch::sql::SQLite3ResultSet.

◆ getValue() [2/2]

virtual bool anch::sql::ResultSet::getValue ( std::size_t idx,
std::string & out )
protectedpure virtual

Retrieve string value from result set according to SQL database engine.

Parameters
idxthe field index
outthe result
Exceptions
SqlExceptionany error

Implemented in anch::sql::MySQLPreparedStatementResultSet, anch::sql::MySQLResultSet, anch::sql::PostgreSQLResultSet, and anch::sql::SQLite3ResultSet.

◆ next()

virtual bool anch::sql::ResultSet::next ( )
pure virtual

Retrieve next row

Returns
true if next row exists, false otherwise
Exceptions
SqlExceptionany error

Implemented in anch::sql::MySQLPreparedStatementResultSet, anch::sql::MySQLResultSet, anch::sql::PostgreSQLResultSet, and anch::sql::SQLite3ResultSet.

Member Data Documentation

◆ _fields

std::map<std::string, std::size_t> anch::sql::ResultSet::_fields
protected

Result set fields


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