GnuCash de0bfde+
Loading...
Searching...
No Matches
GncDbiSqlResult::IteratorImpl Class Reference
Inheritance diagram for GncDbiSqlResult::IteratorImpl:
GncSqlResult::IteratorImpl

Public Member Functions

 IteratorImpl (GncDbiSqlResult *inst)
virtual GncSqlRow & operator++ ()
virtual GncSqlRow & operator++ (int)
virtual GncSqlResult * operator* ()
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< time64 > get_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 131 of file gnc-dbisqlresult.cpp.

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

◆ get_float_at_col()

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

Implements GncSqlResult::IteratorImpl.

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

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

◆ 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 106 of file gnc-dbisqlresult.cpp.

107{
108 auto type = dbi_result_get_field_type (m_inst->m_dbi_result, col);
109 if(type != DBI_TYPE_INTEGER)
110 return std::nullopt;
111 return std::optional<int64_t>{dbi_result_get_longlong (m_inst->m_dbi_result, col)};
112}

◆ 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 145 of file gnc-dbisqlresult.cpp.

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

◆ get_time64_at_col()

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

Implements GncSqlResult::IteratorImpl.

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

157{
158 auto result = (dbi_result_t*) (m_inst->m_dbi_result);
159 auto type = dbi_result_get_field_type (result, col);
160 dbi_result_get_field_attribs (result, col);
161 if (type != DBI_TYPE_DATETIME)
162 return std::nullopt;
163#if HAVE_LIBDBI_TO_LONGLONG
164 /* A less evil hack than the one required by libdbi-0.8, but
165 * still necessary to work around the same bug.
166 */
167 auto timeval = dbi_result_get_as_longlong(result, col);
168#else
169 /* A seriously evil hack to work around libdbi bug #15
170 * https://sourceforge.net/p/libdbi/bugs/15/. When libdbi
171 * v0.9 is widely available this can be replaced with
172 * dbi_result_get_as_longlong.
173 * Note: 0.9 is available in Debian Jessie and Fedora 21.
174 */
175 auto row = dbi_result_get_currow (result);
176 auto idx = dbi_result_get_field_idx (result, col) - 1;
177 time64 timeval = result->rows[row]->field_values[idx].d_datetime;
178#endif //HAVE_LIBDBI_TO_LONGLONG
179 if (timeval < MINTIME || timeval > MAXTIME)
180 timeval = 0;
181 return std::optional<time64>(timeval);
182}
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 92 of file gnc-dbisqlresult.cpp.

93{
94 int status = dbi_result_next_row (m_inst->m_dbi_result);
95 if (status)
96 return m_inst->m_row;
97 int error = m_inst->dberror();
98 if (error == DBI_ERROR_BADIDX || error == 0) //ran off the end of the results
99 return m_inst->m_sentinel;
100 PERR("Error %d incrementing results iterator.", error);
101 qof_backend_set_error (m_inst->m_conn->qbe(), ERR_BACKEND_SERVER_ERR);
102 return m_inst->m_sentinel;
103}
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: