fastcgi++  3.1alpha
A C++ FastCGI/Web API
Fastcgipp::SQL::Results< Types > Class Template Reference

Holds SQL query result sets. More...

#include <fastcgi++/sql/results.hpp>

Inheritance diagram for Fastcgipp::SQL::Results< Types >:
[legend]
Collaboration diagram for Fastcgipp::SQL::Results< Types >:
[legend]

Public Types

typedef std::tuple< Types... > Row
 Type returned for row retrieval requests. More...
 

Public Member Functions

int verify () const
 Verify consistency between the tuple and the SQL data. More...
 
Row row (int index) const
 Retrieve row data in tuple form. More...
 
Status status () const
 Get status of SQL query result. More...
 
const char * errorMessage () const
 Get error message associated with SQL query result. More...
 
unsigned rows () const
 How many rows were returned with the SQL query. More...
 
unsigned affectedRows () const
 How many rows were affected from the SQL query. More...
 
bool null (int row, int column) const
 Check for nullness of a specific row/column. More...
 
template<typename Numeric >
void field (int row, int column, Numeric &value) const
 

Protected Member Functions

int columns () const
 How many columns are associated with the underlying results. More...
 
template<typename T >
bool verifyColumn (int column) const
 Verify type and size consistency for the specified column. More...
 
template<typename Numeric >
void field (int row, int column, std::vector< Numeric > &value) const
 Extract typed array from specific row and column. More...
 
template<typename T >
void field (int row, int column, T &value) const
 Extract typed value from specific row and column. More...
 
template<>
void field (int row, int column, bool &value) const
 
template<>
void field (int row, int column, std::vector< char > &value) const
 

Protected Attributes

void * m_res
 Pointer to underlying SQL results object. More...
 

Private Member Functions

template<int column, int... columns>
int verify_impl (std::integer_sequence< int, column, columns... >) const
 
template<int column>
int verify_impl (std::integer_sequence< int, column >) const
 
template<int column, int... columns>
void row_impl (Row &row, int index, std::integer_sequence< int, column, columns... >) const
 
template<int column>
void row_impl (Row &row, int index, std::integer_sequence< int, column >) const
 

Static Private Attributes

static const int size = sizeof...(Types)
 How many columns in the row? More...
 

Detailed Description

template<typename... Types>
class Fastcgipp::SQL::Results< Types >

Holds SQL query result sets.

This class provides a strongly typed method for getting result sets from an SQL query. Auxiliary data is available through accessor functions while row data is retrieved as tuples with types defined by the template parameters.

Once a query is complete:

  1. Call status() to ensure no errors.
  2. Call verify() to ensure the SQL data types and the tuple are consistent.
  3. If there is row data, call row() to retrieve a row.
Template Parameters
TypesPack of types to contain in the row tuple.
Date
October 10, 2018
Author
Eddie Carle <eddie.nosp@m.@isa.nosp@m.tec.c.nosp@m.a>

Definition at line 181 of file results.hpp.

Member Typedef Documentation

◆ Row

template<typename... Types>
typedef std::tuple<Types...> Fastcgipp::SQL::Results< Types >::Row

Type returned for row retrieval requests.

Definition at line 185 of file results.hpp.

Member Function Documentation

◆ affectedRows()

unsigned Fastcgipp::SQL::Results_base::affectedRows ( ) const
inherited

How many rows were affected from the SQL query.

Definition at line 463 of file results.cpp.

References Fastcgipp::Http::atoi().

Here is the call graph for this function:

◆ columns()

int Fastcgipp::SQL::Results_base::columns ( ) const
protectedinherited

How many columns are associated with the underlying results.

Definition at line 492 of file results.cpp.

Referenced by Fastcgipp::SQL::Results< Types >::verify().

Here is the caller graph for this function:

◆ errorMessage()

const char * Fastcgipp::SQL::Results_base::errorMessage ( ) const
inherited

Get error message associated with SQL query result.

Definition at line 474 of file results.cpp.

◆ field() [1/5]

template<>
void Fastcgipp::SQL::Results_base::field ( int  row,
int  column,
bool &  value 
) const
protectedinherited

Definition at line 120 of file results.cpp.

◆ field() [2/5]

template<typename Numeric >
void Fastcgipp::SQL::Results_base::field ( int  row,
int  column,
Numeric &  value 
) const
inherited

Definition at line 85 of file results.cpp.

References Fastcgipp::BigEndian< T >::read().

Here is the call graph for this function:

◆ field() [3/5]

template<>
void Fastcgipp::SQL::Results_base::field ( int  row,
int  column,
std::vector< char > &  value 
) const
protectedinherited

Definition at line 297 of file results.cpp.

◆ field() [4/5]

template<typename Numeric >
void Fastcgipp::SQL::Results_base::field ( int  row,
int  column,
std::vector< Numeric > &  value 
) const
protectedinherited

Extract typed array from specific row and column.

Definition at line 213 of file results.cpp.

References WARNING_LOG.

Referenced by Fastcgipp::SQL::Results< Types >::verify_impl().

Here is the caller graph for this function:

◆ field() [5/5]

template<typename T >
void Fastcgipp::SQL::Results_base::field ( int  row,
int  column,
T &  value 
) const
protectedinherited

Extract typed value from specific row and column.

This function has no default definition and must be specialized for each and every type that is to be used.

◆ null()

bool Fastcgipp::SQL::Results_base::null ( int  row,
int  column 
) const
inherited

Check for nullness of a specific row/column.

Definition at line 484 of file results.cpp.

◆ row()

template<typename... Types>
Row Fastcgipp::SQL::Results< Types >::row ( int  index) const
inline

Retrieve row data in tuple form.

Retrieve a row in tuple form from the underlying SQL result data. Do not call this function is the result set validity has not been verified first by calling verify().

Parameters
[in]indexZero indexed row number. If this value is greater than or equal to rows(), the result is undefined and will likely segfault.
Returns
Row data in tuple form

Definition at line 264 of file results.hpp.

Referenced by Fastcgipp::SQL::Results< Types >::verify_impl().

Here is the caller graph for this function:

◆ row_impl() [1/2]

template<typename... Types>
template<int column>
void Fastcgipp::SQL::Results< Types >::row_impl ( Row row,
int  index,
std::integer_sequence< int, column >   
) const
inlineprivate

Definition at line 222 of file results.hpp.

◆ row_impl() [2/2]

template<typename... Types>
template<int column, int... columns>
void Fastcgipp::SQL::Results< Types >::row_impl ( Row row,
int  index,
std::integer_sequence< int, column, columns... >   
) const
inlineprivate

Definition at line 213 of file results.hpp.

◆ rows()

unsigned Fastcgipp::SQL::Results_base::rows ( ) const
inherited

How many rows were returned with the SQL query.

Definition at line 479 of file results.cpp.

Referenced by Fastcgipp::SQL::Results< Types >::verify().

Here is the caller graph for this function:

◆ status()

Fastcgipp::SQL::Status Fastcgipp::SQL::Results_base::status ( ) const
inherited

Get status of SQL query result.

This function should be called first thing after an SQL query is complete to ensure the result of the query is what you expect it to be.

Definition at line 433 of file results.cpp.

References Fastcgipp::SQL::badResponse, Fastcgipp::SQL::commandOk, Fastcgipp::SQL::copyBoth, Fastcgipp::SQL::copyIn, Fastcgipp::SQL::copyOut, Fastcgipp::SQL::emptyQuery, Fastcgipp::SQL::fatalError, Fastcgipp::SQL::nonfatalError, Fastcgipp::SQL::noResult, Fastcgipp::SQL::rowsOk, and Fastcgipp::SQL::singleTuple.

◆ verify()

template<typename... Types>
int Fastcgipp::SQL::Results< Types >::verify ( ) const
inline

Verify consistency between the tuple and the SQL data.

This function should be called when an SQL query is complete after ensuring status() is what you're expecting it to be. It will first ensure that the tuple size matches the column count and subsequently ensure every column type in the underlying SQL data set matches that of the row tuple. If this function does not return 0 it is not safe to call row().

Returns
0 if everything is good. -1 if the column count doesn't match the tuple size. A positive non-zero integer indicates a type mismatch at that column.

Definition at line 244 of file results.hpp.

References Fastcgipp::SQL::Results_base::columns(), and Fastcgipp::SQL::Results_base::rows().

Here is the call graph for this function:

◆ verify_impl() [1/2]

template<typename... Types>
template<int column>
int Fastcgipp::SQL::Results< Types >::verify_impl ( std::integer_sequence< int, column >  ) const
inlineprivate

Definition at line 204 of file results.hpp.

◆ verify_impl() [2/2]

template<typename... Types>
template<int column, int... columns>
int Fastcgipp::SQL::Results< Types >::verify_impl ( std::integer_sequence< int, column, columns... >  ) const
inlineprivate

Definition at line 192 of file results.hpp.

References Fastcgipp::SQL::Results_base::field(), and Fastcgipp::SQL::Results< Types >::row().

Here is the call graph for this function:

◆ verifyColumn()

template<typename T >
template bool Fastcgipp::SQL::Results_base::verifyColumn< double > ( int  column) const
protectedinherited

Verify type and size consistency for the specified column.

This function has no default definition and must be specialized for each and every type that is to be used.

Definition at line 41 of file results.cpp.

References Fastcgipp::SQL::Results_base::m_res.

Member Data Documentation

◆ m_res

void* Fastcgipp::SQL::Results_base::m_res
protectedinherited

Pointer to underlying SQL results object.

Definition at line 130 of file results.hpp.

Referenced by Fastcgipp::SQL::Results_base::verifyColumn().

◆ size

template<typename... Types>
const int Fastcgipp::SQL::Results< Types >::size = sizeof...(Types)
staticprivate

How many columns in the row?

Definition at line 189 of file results.hpp.


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