GnuCash  4.12-399-g11d395185c
gnc-sql-result.hpp
1 /***********************************************************************\
2  * gnc-sql-result.hpp: Encapsulate the results of a SQL query. *
3  * *
4  * Copyright 2016 John Ralls <jralls@ceridwen.us> *
5  * *
6  * This program is free software; you can redistribute it and/or *
7  * modify it under the terms of the GNU General Public License as *
8  * published by the Free Software Foundation; either version 2 of *
9  * the License, or (at your option) any later version. *
10  * *
11  * This program is distributed in the hope that it will be useful, *
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
14  * GNU General Public License for more details. *
15  * *
16  * You should have received a copy of the GNU General Public License *
17  * along with this program; if not, contact: *
18  * *
19  * Free Software Foundation Voice: +1-617-542-5942 *
20  * 51 Franklin Street, Fifth Floor Fax: +1-617-542-2652 *
21  * Boston, MA 02110-1301, USA gnu@gnu.org *
22 \***********************************************************************/
23 
24 #ifndef __GNC_SQL_RESULT_HPP__
25 #define __GNC_SQL_RESULT_HPP__
26 
27 extern "C"
28 {
29 #include <qof.h>
30 }
31 #include <cstdint>
32 #include <string>
33 #include <vector>
34 
35 class GncSqlRow;
41 {
42 public:
43  virtual ~GncSqlResult() = default;
44  virtual uint64_t size() const noexcept = 0;
45  virtual GncSqlRow& begin() = 0;
46  virtual GncSqlRow& end() = 0;
47  friend GncSqlRow;
48 protected:
49  class IteratorImpl {
50  public:
51  virtual ~IteratorImpl() = default;
52  virtual GncSqlRow& operator++() = 0;
53  virtual GncSqlResult* operator*() = 0;
54  virtual int64_t get_int_at_col (const char* col) const = 0;
55  virtual double get_float_at_col (const char* col) const = 0;
56  virtual double get_double_at_col (const char* col) const = 0;
57  virtual std::string get_string_at_col (const char* col) const = 0;
58  virtual time64 get_time64_at_col (const char* col) const = 0;
59  virtual bool is_col_null (const char* col) const noexcept = 0;
60  };
61 };
62 
81 class GncSqlRow
82 {
83 public:
84  GncSqlRow (GncSqlResult::IteratorImpl* iter) : m_iter{iter} {}
85  ~GncSqlRow() { }
86  GncSqlRow& operator++();
87  GncSqlRow& operator*() { return *this; }
88  friend bool operator!=(const GncSqlRow&, const GncSqlRow&);
89  int64_t get_int_at_col (const char* col) const {
90  return m_iter->get_int_at_col (col); }
91  double get_float_at_col (const char* col) const {
92  return m_iter->get_float_at_col (col); }
93  double get_double_at_col (const char* col) const {
94  return m_iter->get_double_at_col (col); }
95  std::string get_string_at_col (const char* col) const {
96  return m_iter->get_string_at_col (col); }
97  time64 get_time64_at_col (const char* col) const {
98  return m_iter->get_time64_at_col (col); }
99  bool is_col_null (const char* col) const noexcept {
100  return m_iter->is_col_null (col); }
101 private:
103 };
104 
105 inline bool operator!=(const GncSqlRow& lr, const GncSqlRow& rr) {
106  return lr.m_iter != rr.m_iter;
107 }
108 
109 inline bool operator==(const GncSqlRow& lr, const GncSqlRow& rr) {
110  return !(lr != rr);
111 }
112 
113 
114 #endif //__GNC_SQL_RESULT_HPP__
Row of SQL Query results.
Pure virtual class to iterate over a query result set.
gint64 time64
Many systems, including Microsoft Windows and BSD-derived Unixes like Darwin, are retaining the int-3...
Definition: gnc-date.h:93