libUTL++
DBresultIterator.h
1 #pragma once
2 
4 #include <libutl/DBconnection.h>
5 #include <libutl/DBresult.h>
6 
8 
9 UTL_NS_BEGIN;
10 
12 
24 
26 class DBresultIterator : public Object
27 {
29 
30 public:
37  DBresultIterator(DBconnection* connection, const String& query, uint_t limit = uint_t_max)
38  {
39  init();
40  initialize(connection, query, limit);
41  }
42 
49  void initialize(DBconnection* connection, const String& query, uint_t limit = uint_t_max);
50 
52  bool
53  ok() const
54  {
55  return ((_result != nullptr) && (_result->status() == dbr_ok));
56  }
57 
59  uint_t
60  status() const
61  {
62  ASSERTD(_result != nullptr);
63  return _result->status();
64  }
65 
67  const String&
68  errorMsg() const
69  {
70  ASSERTD(_result != nullptr);
71  return _result->errorMsg();
72  }
73 
75  uint_t
76  numFields() const
77  {
78  ASSERTD(_result != nullptr);
79  return _result->numFields();
80  }
81 
83  bool
84  end() const
85  {
86  ASSERTD(_result != nullptr);
87  return (_row == _result->numRows());
88  }
89 
91  bool isNull(uint_t field) const;
92 
94  const uint64_t* values() const;
95 
97  uint64_t field(uint_t field) const;
98 
100  char* getString(uint_t fieldIdx) const;
101 
103  bool getBool(uint_t fieldIdx) const;
104 
106  int getInt32(uint_t fieldIdx) const;
107 
109  int64_t getInt64(uint_t fieldIdx) const;
110 
112  double getDouble(uint_t fieldIdx) const;
113 
115  time_t getDateTime(uint_t fieldIdx) const;
116 
118  uint_t row() const;
119 
121  void seek(uint_t row);
122 
124  void next();
125 
128  {
129  next();
130  return *this;
131  }
132 
133 private:
134  void init();
135  void
136  deInit()
137  {
138  }
139  void execute(uint_t page);
140 
141 private:
142  DBconnection* _connection;
143  const DBresult* _result;
144  String _query;
145  uint_t _limit;
146  uint_t _page;
147  uint_t _row;
148 };
149 
151 
152 UTL_NS_END;
void deInit()
De-initialize UTL++.
Database command result.
Definition: DBresult.h:40
#define UTL_CLASS_DECL(DC, BC)
Declaration of standard UTL++ functionality for a non-template class.
Definition: macros.h:688
Character string.
Definition: String.h:31
long int64_t
Signed 64-bit integer.
Definition: types.h:164
DBresultIterator(DBconnection *connection, const String &query, uint_t limit=uint_t_max)
Initialize.
Command executed successfully.
Definition: DBresult.h:21
uint_t status() const
Get the status.
bool end() const
No more result rows?
unsigned long uint64_t
Unsigned 64-bit integer.
Definition: types.h:154
Query result iterator.
unsigned int uint_t
Unsigned integer.
Definition: types.h:59
Database connection.
Definition: DBconnection.h:26
const uint_t uint_t_max
Maximum uint_t value.
const String & errorMsg() const
Get error message.
bool ok() const
Is everything OK?
DBresultIterator & operator++()
Move forward one row.
uint_t numFields() const
Get number of fields.
Root of UTL++ class hierarchy.
Definition: Object.h:52
void init()
Initialize UTL++.
#define ASSERTD
Do an assertion in DEBUG mode only.