SQL result representation. More...
#include <resultSet.hpp>
Public Member Functions | |
| ResultSet () noexcept | |
| virtual | ~ResultSet () noexcept |
| template<typename T> | |
| bool | get (std::size_t idx, T &out) |
| template<anch::sql::SystemTimePoint 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<anch::sql::SystemTimePoint T> | |
| std::optional< T > | get (std::size_t idx) |
| template<typename T> | |
| const std::optional< T > | get (const std::string field) |
| std::vector< std::string > | columns () const |
| std::optional< std::size_t > | columnIndex (const std::string &name) const |
| bool | next () |
| template<> | |
| bool | get (std::size_t idx, int64_t &out) |
| template<> | |
| bool | get (std::size_t idx, int32_t &out) |
| template<> | |
| bool | get (std::size_t idx, int16_t &out) |
| template<> | |
| bool | get (std::size_t idx, uint64_t &out) |
| template<> | |
| bool | get (std::size_t idx, uint32_t &out) |
| template<> | |
| bool | get (std::size_t idx, uint16_t &out) |
| template<> | |
| bool | get (std::size_t idx, double &out) |
| template<> | |
| bool | get (std::size_t idx, float &out) |
| template<> | |
| bool | get (std::size_t idx, bool &out) |
| template<> | |
| std::optional< int64_t > | get (std::size_t idx) |
| template<> | |
| std::optional< int32_t > | get (std::size_t idx) |
| template<> | |
| std::optional< int16_t > | get (std::size_t idx) |
| template<> | |
| std::optional< uint64_t > | get (std::size_t idx) |
| template<> | |
| std::optional< uint32_t > | get (std::size_t idx) |
| template<> | |
| std::optional< uint16_t > | get (std::size_t idx) |
| template<> | |
| std::optional< double > | get (std::size_t idx) |
| template<> | |
| std::optional< float > | get (std::size_t idx) |
| template<> | |
| std::optional< bool > | get (std::size_t idx) |
Protected Member Functions | |
| virtual bool | fetchNext ()=0 |
| void | invalidateStatement () noexcept |
| 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::DateFormatter & | getTimestampFormatter ()=0 |
| const anch::date::DateFormatter & | getDefaultTimestampFormatter () |
Protected Attributes | |
| std::map< std::string, std::size_t > | _fields |
Friends | |
| class | Connection |
| class | PreparedStatement |
SQL result representation.
The ResultSet has to be used with while(res.next()) { [...] }.
Errors raised by next are reported to the connection which has executed the query (a fatal error invalidates it).
Field getter is templated. Specializations are included in library. If you need other conversions, you can implement them in your own program.
|
noexcept |
ResultSet default constructor
|
virtualnoexcept |
| std::optional< std::size_t > anch::sql::ResultSet::columnIndex | ( | const std::string & | name | ) | const |
Column index
| name | the column name (exact) |
std::nullopt when there is no column of this name| std::vector< std::string > anch::sql::ResultSet::columns | ( | ) | const |
Columns names, in order of their indices (aliases when they are given ; PostgreSQL gives unquoted names in lowercase). A name given to several columns is the name of the last one only. SQLite and PostgreSQL know the columns once the first row has been fetched ( next ).
|
protectedpure virtual |
Retrieve next row (driver implementation)
true if next row exists, false otherwise| SqlException | any error (with connection status) |
Implemented in anch::sql::MySQLPreparedStatementResultSet, anch::sql::MySQLResultSet, anch::sql::PostgreSQLResultSet, and anch::sql::SQLite3ResultSet.
|
inline |
Get field value by field name.
| T | expected type |
| field | the field name |
| SqlException | any error |
|
inline |
Get field value by field name.
The output parameter will be set only if SQL result is not NULL.
| T | expected type |
| field | the field name |
| out | the result |
true if result is NULL, false otherwise | std::optional< int64_t > anch::sql::ResultSet::get | ( | std::size_t | idx | ) |
Get field value by index as 64 bits signed integer.
| idx | the index |
std::nullopt if result is NULL | SqlException | index out of range or not an integer of this type (non fatal), database error |
| std::optional< int32_t > anch::sql::ResultSet::get | ( | std::size_t | idx | ) |
Get field value by index as 32 bits signed integer.
| idx | the index |
std::nullopt if result is NULL | SqlException | index out of range or not an integer of this type (non fatal), database error |
| std::optional< int16_t > anch::sql::ResultSet::get | ( | std::size_t | idx | ) |
Get field value by index as 16 bits signed integer.
| idx | the index |
std::nullopt if result is NULL | SqlException | index out of range or not an integer of this type (non fatal), database error |
| std::optional< uint64_t > anch::sql::ResultSet::get | ( | std::size_t | idx | ) |
Get field value by index as 64 bits unsigned integer.
| idx | the index |
std::nullopt if result is NULL | SqlException | index out of range or not an integer of this type (non fatal), database error |
| std::optional< uint32_t > anch::sql::ResultSet::get | ( | std::size_t | idx | ) |
Get field value by index as 32 bits unsigned integer.
| idx | the index |
std::nullopt if result is NULL | SqlException | index out of range or not an integer of this type (non fatal), database error |
| std::optional< uint16_t > anch::sql::ResultSet::get | ( | std::size_t | idx | ) |
Get field value by index as 16 bits unsigned integer.
| idx | the index |
std::nullopt if result is NULL | SqlException | index out of range or not an integer of this type (non fatal), database error |
| std::optional< double > anch::sql::ResultSet::get | ( | std::size_t | idx | ) |
Get field value by index as double precision floating point number (PostgreSQL NaN , Infinity included).
| idx | the index |
std::nullopt if result is NULL | SqlException | index out of range or not a number (non fatal), database error |
| std::optional< float > anch::sql::ResultSet::get | ( | std::size_t | idx | ) |
Get field value by index as single precision floating point number.
| idx | the index |
std::nullopt if result is NULL | SqlException | index out of range or not a number (non fatal), database error |
| std::optional< bool > anch::sql::ResultSet::get | ( | std::size_t | idx | ) |
Get field value by index as boolean ( 1 / 0 , t / f , true / false ).
| idx | the index |
std::nullopt if result is NULL | SqlException | index out of range or not a boolean (non fatal), database error |
| std::optional< T > anch::sql::ResultSet::get | ( | std::size_t | idx | ) |
Get field value by index as std::chrono::system_clock point in time: read as anch::date::DateTime , rounded down to T precision.
| T | expected type ( std::chrono::sys_seconds , std::chrono::sys_time<std::chrono::milliseconds> , ...) |
| idx | the index |
std::nullopt if result is NULL | SqlException | index out of range or invalid timestamp (non fatal), database error |
| std::optional< T > anch::sql::ResultSet::get | ( | std::size_t | idx | ) |
Get field value by index.
| T | expected type: std::string , integers, anch::date::Date , anch::date::Time , anch::date::DateTime , anch::UUID (with ANCH_UUID ), std::chrono::sys_time , double , float , bool |
| idx | the index |
| SqlException | any error |
| bool anch::sql::ResultSet::get | ( | std::size_t | idx, |
| bool & | out ) |
Get field value by index as boolean ( 1 / 0 , t / f , true / false ).
The output parameter is set only if SQL result is not NULL.
| idx | the index |
| out | the result |
true if result is NULL , false otherwise| SqlException | index out of range or not a boolean (non fatal), database error |
| bool anch::sql::ResultSet::get | ( | std::size_t | idx, |
| double & | out ) |
Get field value by index as double precision floating point number (PostgreSQL NaN , Infinity included).
The output parameter is set only if SQL result is not NULL.
| idx | the index |
| out | the result |
true if result is NULL , false otherwise| SqlException | index out of range or not a number (non fatal), database error |
| bool anch::sql::ResultSet::get | ( | std::size_t | idx, |
| float & | out ) |
Get field value by index as single precision floating point number.
The output parameter is set only if SQL result is not NULL.
| idx | the index |
| out | the result |
true if result is NULL , false otherwise| SqlException | index out of range or not a number (non fatal), database error |
| bool anch::sql::ResultSet::get | ( | std::size_t | idx, |
| int16_t & | out ) |
Get field value by index as 16 bits signed integer.
The output parameter is set only if SQL result is not NULL.
| idx | the index |
| out | the result |
true if result is NULL , false otherwise| SqlException | index out of range or not an integer of this type (non fatal), database error |
| bool anch::sql::ResultSet::get | ( | std::size_t | idx, |
| int32_t & | out ) |
Get field value by index as 32 bits signed integer.
The output parameter is set only if SQL result is not NULL.
| idx | the index |
| out | the result |
true if result is NULL , false otherwise| SqlException | index out of range or not an integer of this type (non fatal), database error |
| bool anch::sql::ResultSet::get | ( | std::size_t | idx, |
| int64_t & | out ) |
Get field value by index as 64 bits signed integer.
The output parameter is set only if SQL result is not NULL.
| idx | the index |
| out | the result |
true if result is NULL , false otherwise| SqlException | index out of range or not an integer of this type (non fatal), database error |
| bool anch::sql::ResultSet::get | ( | std::size_t | idx, |
| T & | out ) |
Get field value by index as std::chrono::system_clock point in time: read as anch::date::DateTime , rounded down to T precision.
The output parameter will be set only if SQL result is not NULL.
| T | expected type ( std::chrono::sys_seconds , std::chrono::sys_time<std::chrono::milliseconds> , ...) |
| idx | the index |
| out | the result |
true if result is NULL , false otherwise| SqlException | index out of range or invalid timestamp (non fatal), database error |
| 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.
| T | expected type: std::string , integers, anch::date::Date , anch::date::Time , anch::date::DateTime , anch::UUID (with ANCH_UUID ), std::chrono::sys_time , double , float , bool |
| idx | the index |
| out | the result |
true if result is NULL, false otherwise| SqlException | any error |
| bool anch::sql::ResultSet::get | ( | std::size_t | idx, |
| uint16_t & | out ) |
Get field value by index as 16 bits unsigned integer.
The output parameter is set only if SQL result is not NULL.
| idx | the index |
| out | the result |
true if result is NULL , false otherwise| SqlException | index out of range or not an integer of this type (non fatal), database error |
| bool anch::sql::ResultSet::get | ( | std::size_t | idx, |
| uint32_t & | out ) |
Get field value by index as 32 bits unsigned integer.
The output parameter is set only if SQL result is not NULL.
| idx | the index |
| out | the result |
true if result is NULL , false otherwise| SqlException | index out of range or not an integer of this type (non fatal), database error |
| bool anch::sql::ResultSet::get | ( | std::size_t | idx, |
| uint64_t & | out ) |
Get field value by index as 64 bits unsigned integer.
The output parameter is set only if SQL result is not NULL.
| idx | the index |
| out | the result |
true if result is NULL , false otherwise| SqlException | index out of range or not an integer of this type (non fatal), database error |
|
protected |
Retrieve SQL timestamp formatter
|
protectedpure virtual |
Retrieve SQL timestamp formatter
Implemented in anch::sql::MySQLPreparedStatementResultSet, anch::sql::MySQLResultSet, anch::sql::PostgreSQLResultSet, and anch::sql::SQLite3ResultSet.
|
protectedpure virtual |
Retrieve string value from result set according to SQL database engine.
| idx | the field index |
| SqlException | any error |
Implemented in anch::sql::MySQLPreparedStatementResultSet, anch::sql::MySQLResultSet, anch::sql::PostgreSQLResultSet, and anch::sql::SQLite3ResultSet.
|
protectedpure virtual |
Retrieve string value from result set according to SQL database engine.
| idx | the field index |
| out | the result |
| SqlException | any error |
Implemented in anch::sql::MySQLPreparedStatementResultSet, anch::sql::MySQLResultSet, anch::sql::PostgreSQLResultSet, and anch::sql::SQLite3ResultSet.
|
protectednoexcept |
Invalidate the prepared statement which has executed the query, if any (see PreparedStatement::invalidate )
| bool anch::sql::ResultSet::next | ( | ) |
|
protected |
Result set fields