kodi
qry_dat.h
1 /*
2  * Copyright (C) 2004, Leo Seib, Hannover
3  *
4  * Project:Dataset C++ Dynamic Library
5  * Module: FieldValue class and result sets classes header file
6  * Author: Leo Seib E-Mail: leoseib@web.de
7  * Begin: 5/04/2002
8  *
9  * SPDX-License-Identifier: MIT
10  * See LICENSES/README.md for more information.
11  */
12 
13 #pragma once
14 
15 #include <iostream>
16 #include <stdint.h>
17 #include <string>
18 #include <vector>
19 
20 namespace dbiplus
21 {
22 
23 enum fType
24 {
25  ft_String,
26  ft_Boolean,
27  ft_Char,
28  ft_WChar,
29  ft_WideString,
30  ft_Short,
31  ft_UShort,
32  ft_Int,
33  ft_UInt,
34  ft_Float,
35  ft_Double,
36  ft_LongDouble,
37  ft_Int64,
38  ft_Object
39 };
40 
41 #ifdef TARGET_WINDOWS_STORE
42 #pragma pack(push)
43 #pragma pack(8)
44 #endif
45 
47 {
48 private:
49  fType field_type;
50  std::string str_value;
51  union
52  {
53  bool bool_value;
54  char char_value;
55  short short_value;
56  unsigned short ushort_value;
57  int int_value;
58  unsigned int uint_value;
59  float float_value;
60  double double_value;
61  int64_t int64_value;
62  void* object_value;
63  };
64 
65  bool is_null;
66 
67 public:
68  field_value();
69  explicit field_value(const char* s);
70  explicit field_value(const bool b);
71  explicit field_value(const char c);
72  explicit field_value(const short s);
73  explicit field_value(const unsigned short us);
74  explicit field_value(const int l);
75  explicit field_value(const unsigned int ul);
76  explicit field_value(const float f);
77  explicit field_value(const double d);
78  explicit field_value(const int64_t i);
79  field_value(const char* s, std::size_t len);
80  field_value(const field_value& fv);
81  field_value(field_value&& fv) noexcept;
82  ~field_value();
83 
84  fType get_fType() const { return field_type; }
85  bool get_isNull() const { return is_null; }
86  std::string get_asString() const&;
87  std::string get_asString() &&;
88  bool get_asBool() const;
89  char get_asChar() const;
90  short get_asShort() const;
91  unsigned short get_asUShort() const;
92  int get_asInt() const;
93  unsigned int get_asUInt() const;
94  float get_asFloat() const;
95  double get_asDouble() const;
96  int64_t get_asInt64() const;
97 
98  field_value& operator=(const char* s)
99  {
100  set_asString(s);
101  return *this;
102  }
103  field_value& operator=(const std::string& s)
104  {
105  set_asString(s);
106  return *this;
107  }
108  field_value& operator=(std::string&& s)
109  {
110  set_asString(std::move(s));
111  return *this;
112  }
113  field_value& operator=(const bool b)
114  {
115  set_asBool(b);
116  return *this;
117  }
118  field_value& operator=(const short s)
119  {
120  set_asShort(s);
121  return *this;
122  }
123  field_value& operator=(const unsigned short us)
124  {
125  set_asUShort(us);
126  return *this;
127  }
128  field_value& operator=(const int l)
129  {
130  set_asInt(l);
131  return *this;
132  }
133  field_value& operator=(const unsigned int l)
134  {
135  set_asUInt(l);
136  return *this;
137  }
138  field_value& operator=(const float f)
139  {
140  set_asFloat(f);
141  return *this;
142  }
143  field_value& operator=(const double d)
144  {
145  set_asDouble(d);
146  return *this;
147  }
148  field_value& operator=(const int64_t i)
149  {
150  set_asInt64(i);
151  return *this;
152  }
153  field_value& operator=(const field_value& fv);
154  field_value& operator=(field_value&& fv) noexcept;
155 
156  //class ostream;
157  friend std::ostream& operator<<(std::ostream& os, const field_value& fv)
158  {
159  switch (fv.get_fType())
160  {
161  case ft_String:
162  {
163  return os << fv.get_asString();
164  break;
165  }
166  case ft_Boolean:
167  {
168  return os << fv.get_asBool();
169  break;
170  }
171  case ft_Char:
172  {
173  return os << fv.get_asChar();
174  break;
175  }
176  case ft_Short:
177  {
178  return os << fv.get_asShort();
179  break;
180  }
181  case ft_UShort:
182  {
183  return os << fv.get_asUShort();
184  break;
185  }
186  case ft_Int:
187  {
188  return os << fv.get_asInt();
189  break;
190  }
191  case ft_UInt:
192  {
193  return os << fv.get_asUInt();
194  break;
195  }
196  case ft_Float:
197  {
198  return os << fv.get_asFloat();
199  break;
200  }
201  case ft_Double:
202  {
203  return os << fv.get_asDouble();
204  break;
205  }
206  case ft_Int64:
207  {
208  return os << fv.get_asInt64();
209  break;
210  }
211  default:
212  {
213  return os;
214  break;
215  }
216  }
217  }
218 
219  void set_isNull() { is_null = true; }
220  void set_asString(const char* s);
221  void set_asString(const char* s, std::size_t len);
222  void set_asString(const std::string& s);
223  void set_asString(std::string&& s);
224  void set_asBool(const bool b);
225  void set_asChar(const char c);
226  void set_asShort(const short s);
227  void set_asUShort(const unsigned short us);
228  void set_asInt(const int l);
229  void set_asUInt(const unsigned int l);
230  void set_asFloat(const float f);
231  void set_asDouble(const double d);
232  void set_asInt64(const int64_t i);
233 
234  fType get_field_type();
235  std::string gft();
236 };
237 
239 {
240  std::string name;
241 };
242 
243 struct field
244 {
245  field_prop props;
246  field_value val;
247 };
248 
249 typedef std::vector<field> Fields;
250 typedef std::vector<field_value> sql_record;
251 typedef std::vector<field_prop> record_prop;
252 typedef std::vector<sql_record*> query_data;
253 typedef field_value variant;
254 
256 {
257 public:
258  result_set() = default;
259  ~result_set() { clear(); };
260  void clear()
261  {
262  for (unsigned int i = 0; i < records.size(); i++)
263  if (records[i])
264  delete records[i];
265  records.clear();
266  record_header.clear();
267  };
268 
269  record_prop record_header;
270  query_data records;
271 };
272 
273 #ifdef TARGET_WINDOWS_STORE
274 #pragma pack(pop)
275 #endif
276 } // namespace dbiplus
Definition: qry_dat.h:243
Definition: Database.h:11
Definition: qry_dat.h:46
Definition: qry_dat.h:255
Definition: qry_dat.h:238