GnuCash c935c2f+
Loading...
Searching...
No Matches
Public Member Functions | Friends
GncSqlRow Class Reference

Row of SQL Query results. More...

#include <gnc-sql-result.hpp>

Public Member Functions

 GncSqlRow (GncSqlResult::IteratorImpl *iter)
 
GncSqlRowoperator++ ()
 
GncSqlRowoperator* ()
 
std::optional< int64_t > get_int_at_col (const char *col) const
 
std::optional< double > get_float_at_col (const char *col) const
 
std::optional< double > get_double_at_col (const char *col) const
 
std::optional< std::string > get_string_at_col (const char *col) const
 
std::optional< time64get_time64_at_col (const char *col) const
 
bool is_col_null (const char *col) const noexcept
 

Friends

bool operator!= (const GncSqlRow &, const GncSqlRow &)
 

Detailed Description

Row of SQL Query results.

This is a "pointer" class of a pimpl pattern, the implementation being GncSqlResult::IteratorImpl. It's designed to present a std::forward_iterator like interface for use with range-for while allowing for wrapping a C API.

Important Implementation Note: Operator++() as written requires that the sentinel GncSqlRow returned by GncSqlResult::end() has m_impl = nullptr in order to terminate the loop condition. This is a bit of a hack and might be a problem with a different SQL interface library from libdbi.

Note that GncSqlResult::begin and GncSqlRow::operator++() return GncSqlRow&. This is necessary for operator++() to be called: Using operator ++() on a pointer performs pointer arithmetic rather than calling the pointed-to-class's operator++() and C++'s range-for uses operator++() directly on whatever begin() gives it.

Definition at line 80 of file gnc-sql-result.hpp.

Constructor & Destructor Documentation

◆ GncSqlRow()

GncSqlRow::GncSqlRow ( GncSqlResult::IteratorImpl iter)
inline

Definition at line 83 of file gnc-sql-result.hpp.

83: m_iter{iter} {}

◆ ~GncSqlRow()

GncSqlRow::~GncSqlRow ( )
inline

Definition at line 84 of file gnc-sql-result.hpp.

84{ }

Member Function Documentation

◆ get_double_at_col()

std::optional< double > GncSqlRow::get_double_at_col ( const char *  col) const
inline

Definition at line 92 of file gnc-sql-result.hpp.

92 {
93 return m_iter->get_double_at_col (col); }

◆ get_float_at_col()

std::optional< double > GncSqlRow::get_float_at_col ( const char *  col) const
inline

Definition at line 90 of file gnc-sql-result.hpp.

90 {
91 return m_iter->get_float_at_col (col); }

◆ get_int_at_col()

std::optional< int64_t > GncSqlRow::get_int_at_col ( const char *  col) const
inline

Definition at line 88 of file gnc-sql-result.hpp.

88 {
89 return m_iter->get_int_at_col (col); }

◆ get_string_at_col()

std::optional< std::string > GncSqlRow::get_string_at_col ( const char *  col) const
inline

Definition at line 94 of file gnc-sql-result.hpp.

94 {
95 return m_iter->get_string_at_col (col); }

◆ get_time64_at_col()

std::optional< time64 > GncSqlRow::get_time64_at_col ( const char *  col) const
inline

Definition at line 96 of file gnc-sql-result.hpp.

96 {
97 return m_iter->get_time64_at_col (col); }

◆ is_col_null()

bool GncSqlRow::is_col_null ( const char *  col) const
inlinenoexcept

Definition at line 98 of file gnc-sql-result.hpp.

98 {
99 return m_iter->is_col_null (col); }

◆ operator*()

GncSqlRow & GncSqlRow::operator* ( )
inline

Definition at line 86 of file gnc-sql-result.hpp.

86{ return *this; }

◆ operator++()

GncSqlRow & GncSqlRow::operator++ ( )

Definition at line 31 of file gnc-sql-result.cpp.

32{
33 auto& new_row = m_iter->operator++();
34 if (new_row != *this)
35 m_iter = nullptr;
36 return new_row;
37}

Friends And Related Symbol Documentation

◆ operator!=

bool operator!= ( const GncSqlRow lr,
const GncSqlRow rr 
)
friend

Definition at line 104 of file gnc-sql-result.hpp.

104 {
105 return lr.m_iter != rr.m_iter;
106}

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