EXASockets  0.9
Interface to the EXASOL DB via JSON over Websockets protocol
exaResultSet.h
1 /*
2 exaResultSet.h and exaResultSet.cpp
3 http://www.github.com/marcelboldt/EXASockets
4 
5  The MIT License (MIT)
6 
7 Copyright (C) 2016 Marcel Boldt / EXASOL
8 
9 Permission is hereby granted, free of charge, to any person obtaining a copy
10 of this software and associated documentation files (the "Software"), to deal
11 in the Software without restriction, including without limitation the rights
12 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13 copies of the Software, and to permit persons to whom the Software is
14 furnished to do so, subject to the following conditions:
15 
16 The above copyright notice and this permission notice shall be included in all
17 copies or substantial portions of the Software.
18 
19 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
25 SOFTWARE.
26 
27 Marcel Boldt <marcel.boldt@exasol.com>
28 
29 */
30 
31 
32 #ifndef EXASOCKETS_EXARESULTSET_H
33 #define EXASOCKETS_EXARESULTSET_H
34 
35 #define COL_DEFAULT_ROWS 1000
36 
37 #define EXA_BOOLEAN 301
38 #define EXA_CHAR 302
39 #define EXA_DATE 303
40 #define EXA_DECIMAL 304
41 #define EXA_DOUBLE 305
42 #define EXA_GEOMETRY 306
43 #define EXA_INTERVAL_DS 307
44 #define EXA_INTERVAL_YM 308
45 #define EXA_TIMESTAMP 309
46 #define EXA_TIMESTAMP_TZ 310
47 #define EXA_VARCHAR 311
48 
49 #include <cstdint>
50 #include <vector>
51 #include <memory>
52 #include <cstddef>
53 #include <cstring>
54 #include <string>
55 #include <iostream>
56 #include <ctime>
57 
58 
59 class exaTblColumn {
60 public:
61  static exaTblColumn *create(std::string name, int datatype, size_t num_rows = COL_DEFAULT_ROWS,
62  int precision = 0, int scale = 0, int size = 0, std::string charset = "",
63  bool w_local_tz = false,
64  int fraction = 0, int srid = 0);
65 
66  exaTblColumn(std::string name, int datatype, size_t num_rows = COL_DEFAULT_ROWS, int precision = 0, int scale = 0,
67  int size = 0, std::string charset = "",
68  bool w_local_tz = false, int fraction = 0, int srid = 0) {};
69 
70  virtual ~exaTblColumn() {};
71 
73 
78  virtual std::shared_ptr<void> operator[](size_t row) = 0;
79 
81 
85  virtual void *as_std_vector() = 0;
86 
88 
93 // virtual int32_t intVal(size_t row) = 0;
94 
96 
102  virtual void appendData(const void *value, bool null = false) = 0;
103 
105  virtual bool is_null(size_t rowno);
106 
108  virtual size_t count() const = 0;
109 
110  int type() {
111  return datatype;
112  }
113 
114  std::string getName() const {
115  return name;
116  }
117 
118  void setName(std::string name) {
119  exaTblColumn::name = name;
120  }
121 
122  int getPrecision() const;
123 
124  void setPrecision(int precision);
125 
126  int getScale() const;
127 
128  void setScale(int scale);
129 
130  int getSize() const;
131 
132  void setSize(int size);
133 
134  std::string getCharacterSet() const;
135 
136  void setCharacterSet(std::string characterSet);
137 
138  bool isWithLocalTimeTone() const;
139 
140  void setWithLocalTimeTone(bool withLocalTimeTone);
141 
142  int getFraction() const;
143 
144  void setFraction(int fraction);
145 
146  int getSrid() const;
147 
148  void setSrid(int srid);
149 
150  std::vector<bool> nulls;
151 protected:
152  std::string name;
153  int datatype;
154  int precision = 0;
155  int scale = 0;
156  int size = 0;
157  std::string characterSet = "";
158  bool withLocalTimeTone = 0;
159  int fraction = 0;
160  int srid = 0;
161 };
162 
163 template<typename T>
164 class exaColumn : public exaTblColumn {
165 public:
166  exaColumn(std::string name, int datatype, size_t num_rows = COL_DEFAULT_ROWS, int precision = 0, int scale = 0,
167  int size = 0, std::string charset = "",
168  bool w_local_tz = false,
169  int fraction = 0, int srid = 0) : exaTblColumn(name, datatype, num_rows, precision,
170  scale, size, charset, w_local_tz, fraction, srid) {
171  this->name = name;
172  this->datatype = datatype;
173  this->precision = precision;
174  this->scale = scale;
175  this->size = size;
176  this->characterSet = charset;
177  this->withLocalTimeTone = w_local_tz;
178  this->fraction = fraction;
179  this->srid = srid;
180 
181  this->data.reserve(num_rows);
182  };
183  // exaColumn(std::vector<T> *data);
184  // exaColumn(char *data);
185  // ~exaColumn();
186 
187  std::shared_ptr<void> operator[](size_t row);
188 
189  // int32_t intVal(size_t row);
190 
191  void appendData(const void *value, const bool null = false);
192 
193  size_t count() const;
194 
195  void *as_std_vector() {
196  // returns a pointer to the vector
197  return &this->data;
198  }
199 
200 protected:
201  std::vector<T> data;
202 };
203 
204 
206 public:
207  // exaResultSetHandler();
208  // ~exaResultSetHandler();
209 
211  void addColumn(exaTblColumn *c);
212 
214  void addColumn(std::shared_ptr<exaTblColumn> c);
215 
216  // int removeColumn();
217 
219  size_t cols();
220 
222  size_t rows();
223 
224  exaTblColumn &operator[](size_t col);
225 
226  // int getRows(int start_row_no, int stop_row_no = -1);
227  // int fetchRows(size_t limit, size_t offset);
228 
229  std::vector<std::shared_ptr<exaTblColumn>> &getColumns() {
230  return this->columns;
231  }
232 
233  int getHandle() const;
234 
235  void setHandle(int handle);
236 
237 
238 protected:
239  std::vector<std::shared_ptr<exaTblColumn>> columns;
240  int handle;
241 
242 };
243 
244 
245 #endif //EXASOCKETS_EXARESULTSET_H
virtual void appendData(const void *value, bool null=false)=0
Returns the value as a 32 Bit integer.
virtual size_t count() const =0
Returns the number of rows contained in the column.
virtual void * as_std_vector()=0
Returns a void pointer to the embedded std::vector.
Definition: exaResultSet.h:59
Definition: exaResultSet.h:205
virtual std::shared_ptr< void > operator[](size_t row)=0
Returns a void pointer to the value, or a nullptr if the value is NULL.
virtual bool is_null(size_t rowno)
Returns a boolean on whether the row specified contains a NULL value.
Definition: exaResultSet.cpp:79
void * as_std_vector()
Returns a void pointer to the embedded std::vector.
Definition: exaResultSet.h:195
Definition: exaResultSet.h:164