libUTL++
DBresult.h
1 #pragma once
2 
4 
5 #include <libutl/BitArray.h>
6 #include <libutl/DBfield.h>
7 #include <libutl/Decimal.h>
8 
10 
11 UTL_NS_BEGIN;
12 
14 
20 {
25 };
26 
28 
38 
40 class DBresult : public Object
41 {
43 
44 public:
46  void initialize(uint_t numRows, uint_t numFields, DBfield** fields);
47 
49  void clear();
50 
52  uint_t
53  status() const
54  {
55  return _status;
56  }
57 
59  uint_t&
61  {
62  return _status;
63  }
64 
66  uint_t
67  numRows() const
68  {
69  return _numRows;
70  }
71 
73  uint_t
74  numFields() const
75  {
76  return _numFields;
77  }
78 
80  const DBfield&
81  field(uint_t idx) const
82  {
83  return (const DBfield&)*_fields[idx];
84  }
85 
87  uint_t
88  rowIndex(uint_t rowIdx) const
89  {
90  ASSERTD(rowIdx < _numRows);
91  return (rowIdx * _numFields);
92  }
93 
95  const uint64_t*
96  values() const
97  {
98  return _values;
99  }
100 
102  uint64_t*
104  {
105  return _values;
106  }
107 
109  char* getString(uint_t rowIdx, uint_t fieldIdx) const;
110 
112  bool getBool(uint_t rowIdx, uint_t fieldIdx) const;
113 
115  int getInt32(uint_t rowIdx, uint_t fieldIdx) const;
116 
118  int64_t getInt64(uint_t rowIdx, uint_t fieldIdx) const;
119 
121  double getDouble(uint_t rowIdx, uint_t fieldIdx) const;
122 
124  char* getDecimal(uint_t rowIdx, uint_t fieldIdx) const;
125 
127  time_t getDateTime(uint_t rowIdx, uint_t fieldIdx) const;
128 
130  bool
131  isNull(uint_t rowIdx, uint_t fieldIdx) const
132  {
133  ASSERTD(rowIdx < _numRows);
134  ASSERTD(fieldIdx < _numFields);
135  uint_t valueIdx = (rowIdx * _numFields) + fieldIdx;
136  return _nullArray.get(valueIdx);
137  }
138 
140  void
141  setNull(uint_t rowIdx, uint_t fieldIdx)
142  {
143  ASSERTD(rowIdx < _numRows);
144  ASSERTD(fieldIdx < _numFields);
145  uint_t valueIdx = (rowIdx * _numFields) + fieldIdx;
146  _nullArray.set(valueIdx, 1);
147  }
148 
150  const BitArray&
151  nullArray() const
152  {
153  return _nullArray;
154  }
155 
157  const String&
158  errorMsg() const
159  {
160  return _errorMsg;
161  }
162 
164  String&
166  {
167  return _errorMsg;
168  }
169 
170 private:
171  void init();
172  void deInit();
173 
174 private:
175  uint_t _status;
176  uint_t _numRows;
177  uint_t _numFields;
178  String _errorMsg;
179 
180  DBfield** _fields;
181  uint64_t* _values;
182  size_t _valuesSize;
183  BitArray _nullArray;
184 };
185 
187 
188 UTL_NS_END;
const String & errorMsg() const
Get error message.
Definition: DBresult.h:158
Undefined status.
Definition: DBresult.h:24
void deInit()
De-initialize UTL++.
String & errorMsg()
Get error message.
Definition: DBresult.h:165
uint_t status() const
Get the status.
Definition: DBresult.h:53
uint_t & status()
Get the status.
Definition: DBresult.h:60
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
Command executed successfully.
Definition: DBresult.h:21
db_result_status_t
Database command status.
Definition: DBresult.h:19
const DBfield & field(uint_t idx) const
Get the field at the given index.
Definition: DBresult.h:81
unsigned long uint64_t
Unsigned 64-bit integer.
Definition: types.h:154
const BitArray & nullArray() const
Get the nullptr map.
Definition: DBresult.h:151
uint_t numFields() const
Get the number of fields.
Definition: DBresult.h:74
unsigned int uint_t
Unsigned integer.
Definition: types.h:59
uint_t rowIndex(uint_t rowIdx) const
Get a row index.
Definition: DBresult.h:88
void setNull(uint_t rowIdx, uint_t fieldIdx)
Mark the given value as nullptr.
Definition: DBresult.h:141
Non-fatal error during command execution.
Definition: DBresult.h:22
uint64_t * values()
Get values pointer.
Definition: DBresult.h:103
bool isNull(uint_t rowIdx, uint_t fieldIdx) const
Is the given value nullptr?
Definition: DBresult.h:131
Field in a DBresult tuple.
Definition: DBfield.h:40
const uint64_t * values() const
Get values pointer.
Definition: DBresult.h:96
Fatal error during command execution.
Definition: DBresult.h:23
Root of UTL++ class hierarchy.
Definition: Object.h:52
uint_t numRows() const
Get the number of rows.
Definition: DBresult.h:67
void init()
Initialize UTL++.
#define ASSERTD
Do an assertion in DEBUG mode only.
Array of n-bit values.
Definition: BitArray.h:36