GnuCash c935c2f+
Loading...
Searching...
No Matches
Public Member Functions
GncDbiSqlResult::IteratorImpl Class Reference
Inheritance diagram for GncDbiSqlResult::IteratorImpl:
GncSqlResult::IteratorImpl

Public Member Functions

 IteratorImpl (GncDbiSqlResult *inst)
 
virtual GncSqlRowoperator++ ()
 
virtual GncSqlRowoperator++ (int)
 
virtual GncSqlResultoperator* ()
 
virtual std::optional< int64_t > get_int_at_col (const char *col) const
 
virtual std::optional< double > get_float_at_col (const char *col) const
 
virtual std::optional< double > get_double_at_col (const char *col) const
 
virtual std::optional< std::string > get_string_at_col (const char *col) const
 
virtual std::optional< time64get_time64_at_col (const char *col) const
 
virtual bool is_col_null (const char *col) const noexcept
 

Detailed Description

Definition at line 51 of file gnc-dbisqlresult.hpp.

Constructor & Destructor Documentation

◆ ~IteratorImpl()

GncDbiSqlResult::IteratorImpl::~IteratorImpl ( )
virtualdefault

Reimplemented from GncSqlResult::IteratorImpl.

◆ IteratorImpl()

GncDbiSqlResult::IteratorImpl::IteratorImpl ( GncDbiSqlResult inst)
inline

Definition at line 55 of file gnc-dbisqlresult.hpp.

55: m_inst{inst} {}

Member Function Documentation

◆ get_double_at_col()

std::optional< double > GncDbiSqlResult::IteratorImpl::get_double_at_col ( const char *  col) const
virtual

Implements GncSqlResult::IteratorImpl.

Definition at line 127 of file gnc-dbisqlresult.cpp.

128{
129 auto type = dbi_result_get_field_type (m_inst->m_dbi_result, col);
130 auto attrs = dbi_result_get_field_attribs (m_inst->m_dbi_result, col);
131 if(type != DBI_TYPE_DECIMAL ||
132 (attrs & DBI_DECIMAL_SIZEMASK) != DBI_DECIMAL_SIZE8)
133 return std::nullopt;
134 auto locale = gnc_push_locale (LC_NUMERIC, "C");
135 auto retval = dbi_result_get_double(m_inst->m_dbi_result, col);
136 gnc_pop_locale (LC_NUMERIC, locale);
137 return std::optional<double>{retval};
138}

◆ get_float_at_col()

std::optional< double > GncDbiSqlResult::IteratorImpl::get_float_at_col ( const char *  col) const
virtual

Implements GncSqlResult::IteratorImpl.

Definition at line 111 of file gnc-dbisqlresult.cpp.

112{
113 constexpr double float_precision = 1000000.0;
114 auto type = dbi_result_get_field_type (m_inst->m_dbi_result, col);
115 auto attrs = dbi_result_get_field_attribs (m_inst->m_dbi_result, col);
116 if(type != DBI_TYPE_DECIMAL ||
117 (attrs & DBI_DECIMAL_SIZEMASK) != DBI_DECIMAL_SIZE4)
118 return std::nullopt;
119 auto locale = gnc_push_locale (LC_NUMERIC, "C");
120 auto interim = dbi_result_get_float(m_inst->m_dbi_result, col);
121 gnc_pop_locale (LC_NUMERIC, locale);
122 double retval = static_cast<double>(round(interim * float_precision)) / float_precision;
123 return std::optional<double>{retval};
124}

◆ get_int_at_col()

std::optional< int64_t > GncDbiSqlResult::IteratorImpl::get_int_at_col ( const char *  col) const
virtual

Implements GncSqlResult::IteratorImpl.

Definition at line 102 of file gnc-dbisqlresult.cpp.

103{
104 auto type = dbi_result_get_field_type (m_inst->m_dbi_result, col);
105 if(type != DBI_TYPE_INTEGER)
106 return std::nullopt;
107 return std::optional<int64_t>{dbi_result_get_longlong (m_inst->m_dbi_result, col)};
108}

◆ get_string_at_col()

std::optional< std::string > GncDbiSqlResult::IteratorImpl::get_string_at_col ( const char *  col) const
virtual

Implements GncSqlResult::IteratorImpl.

Definition at line 141 of file gnc-dbisqlresult.cpp.

142{
143 auto type = dbi_result_get_field_type (m_inst->m_dbi_result, col);
144 dbi_result_get_field_attribs (m_inst->m_dbi_result, col);
145 if(type != DBI_TYPE_STRING)
146 return std::nullopt;
147 auto strval = dbi_result_get_string(m_inst->m_dbi_result, col);
148 return std::optional<std::string>{strval ? strval : ""};
149}

◆ get_time64_at_col()

std::optional< time64 > GncDbiSqlResult::IteratorImpl::get_time64_at_col ( const char *  col) const
virtual

Implements GncSqlResult::IteratorImpl.

Definition at line 152 of file gnc-dbisqlresult.cpp.

153{
154 auto result = (dbi_result_t*) (m_inst->m_dbi_result);
155 auto type = dbi_result_get_field_type (result, col);
156 dbi_result_get_field_attribs (result, col);
157 if (type != DBI_TYPE_DATETIME)
158 return std::nullopt;
159#if HAVE_LIBDBI_TO_LONGLONG
160 /* A less evil hack than the one required by libdbi-0.8, but
161 * still necessary to work around the same bug.
162 */
163 auto timeval = dbi_result_get_as_longlong(result, col);
164#else
165 /* A seriously evil hack to work around libdbi bug #15
166 * https://sourceforge.net/p/libdbi/bugs/15/. When libdbi
167 * v0.9 is widely available this can be replaced with
168 * dbi_result_get_as_longlong.
169 * Note: 0.9 is available in Debian Jessie and Fedora 21.
170 */
171 auto row = dbi_result_get_currow (result);
172 auto idx = dbi_result_get_field_idx (result, col) - 1;
173 time64 timeval = result->rows[row]->field_values[idx].d_datetime;
174#endif //HAVE_LIBDBI_TO_LONGLONG
175 if (timeval < MINTIME || timeval > MAXTIME)
176 timeval = 0;
177 return std::optional<time64>(timeval);
178}
gint64 time64
Most systems that are currently maintained, including Microsoft Windows, BSD-derived Unixes and Linux...
Definition gnc-date.h:87

◆ is_col_null()

virtual bool GncDbiSqlResult::IteratorImpl::is_col_null ( const char *  col) const
inlinevirtualnoexcept

Implements GncSqlResult::IteratorImpl.

Definition at line 64 of file gnc-dbisqlresult.hpp.

65 {
66 return dbi_result_field_is_null(m_inst->m_dbi_result, col);
67 }

◆ operator*()

virtual GncSqlResult * GncDbiSqlResult::IteratorImpl::operator* ( )
inlinevirtual

Implements GncSqlResult::IteratorImpl.

Definition at line 58 of file gnc-dbisqlresult.hpp.

58{ return m_inst; }

◆ operator++() [1/2]

GncSqlRow & GncDbiSqlResult::IteratorImpl::operator++ ( )
virtual

Implements GncSqlResult::IteratorImpl.

Definition at line 88 of file gnc-dbisqlresult.cpp.

89{
90 int status = dbi_result_next_row (m_inst->m_dbi_result);
91 if (status)
92 return m_inst->m_row;
93 int error = m_inst->dberror();
94 if (error == DBI_ERROR_BADIDX || error == 0) //ran off the end of the results
95 return m_inst->m_sentinel;
96 PERR("Error %d incrementing results iterator.", error);
97 qof_backend_set_error (m_inst->m_conn->qbe(), ERR_BACKEND_SERVER_ERR);
98 return m_inst->m_sentinel;
99}
void qof_backend_set_error(QofBackend *qof_be, QofBackendError err)
Set the error on the specified QofBackend.
@ ERR_BACKEND_SERVER_ERR
error in response from server
Definition qofbackend.h:71
#define PERR(format, args...)
Log a serious error.
Definition qoflog.h:244

◆ operator++() [2/2]

virtual GncSqlRow & GncDbiSqlResult::IteratorImpl::operator++ ( int  )
inlinevirtual

Definition at line 57 of file gnc-dbisqlresult.hpp.

57{ return ++(*this); };

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