xbmc
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 field_value& fv);
80  ~field_value();
81 
82  fType get_fType() const { return field_type; }
83  bool get_isNull() const { return is_null; }
84  std::string get_asString() const;
85  bool get_asBool() const;
86  char get_asChar() const;
87  short get_asShort() const;
88  unsigned short get_asUShort() const;
89  int get_asInt() const;
90  unsigned int get_asUInt() const;
91  float get_asFloat() const;
92  double get_asDouble() const;
93  int64_t get_asInt64() const;
94 
95  field_value& operator=(const char* s)
96  {
97  set_asString(s);
98  return *this;
99  }
100  field_value& operator=(const std::string& s)
101  {
102  set_asString(s);
103  return *this;
104  }
105  field_value& operator=(const bool b)
106  {
107  set_asBool(b);
108  return *this;
109  }
110  field_value& operator=(const short s)
111  {
112  set_asShort(s);
113  return *this;
114  }
115  field_value& operator=(const unsigned short us)
116  {
117  set_asUShort(us);
118  return *this;
119  }
120  field_value& operator=(const int l)
121  {
122  set_asInt(l);
123  return *this;
124  }
125  field_value& operator=(const unsigned int l)
126  {
127  set_asUInt(l);
128  return *this;
129  }
130  field_value& operator=(const float f)
131  {
132  set_asFloat(f);
133  return *this;
134  }
135  field_value& operator=(const double d)
136  {
137  set_asDouble(d);
138  return *this;
139  }
140  field_value& operator=(const int64_t i)
141  {
142  set_asInt64(i);
143  return *this;
144  }
145  field_value& operator=(const field_value& fv);
146 
147  //class ostream;
148  friend std::ostream& operator<<(std::ostream& os, const field_value& fv)
149  {
150  switch (fv.get_fType())
151  {
152  case ft_String:
153  {
154  return os << fv.get_asString();
155  break;
156  }
157  case ft_Boolean:
158  {
159  return os << fv.get_asBool();
160  break;
161  }
162  case ft_Char:
163  {
164  return os << fv.get_asChar();
165  break;
166  }
167  case ft_Short:
168  {
169  return os << fv.get_asShort();
170  break;
171  }
172  case ft_UShort:
173  {
174  return os << fv.get_asUShort();
175  break;
176  }
177  case ft_Int:
178  {
179  return os << fv.get_asInt();
180  break;
181  }
182  case ft_UInt:
183  {
184  return os << fv.get_asUInt();
185  break;
186  }
187  case ft_Float:
188  {
189  return os << fv.get_asFloat();
190  break;
191  }
192  case ft_Double:
193  {
194  return os << fv.get_asDouble();
195  break;
196  }
197  case ft_Int64:
198  {
199  return os << fv.get_asInt64();
200  break;
201  }
202  default:
203  {
204  return os;
205  break;
206  }
207  }
208  }
209 
210  void set_isNull() { is_null = true; }
211  void set_asString(const char* s);
212  void set_asString(const std::string& s);
213  void set_asBool(const bool b);
214  void set_asChar(const char c);
215  void set_asShort(const short s);
216  void set_asUShort(const unsigned short us);
217  void set_asInt(const int l);
218  void set_asUInt(const unsigned int l);
219  void set_asFloat(const float f);
220  void set_asDouble(const double d);
221  void set_asInt64(const int64_t i);
222 
223  fType get_field_type();
224  std::string gft();
225 };
226 
228 {
229  std::string name;
230 };
231 
232 struct field
233 {
234  field_prop props;
235  field_value val;
236 };
237 
238 typedef std::vector<field> Fields;
239 typedef std::vector<field_value> sql_record;
240 typedef std::vector<field_prop> record_prop;
241 typedef std::vector<sql_record*> query_data;
242 typedef field_value variant;
243 
245 {
246 public:
247  result_set() = default;
248  ~result_set() { clear(); };
249  void clear()
250  {
251  for (unsigned int i = 0; i < records.size(); i++)
252  if (records[i])
253  delete records[i];
254  records.clear();
255  record_header.clear();
256  };
257 
258  record_prop record_header;
259  query_data records;
260 };
261 
262 #ifdef TARGET_WINDOWS_STORE
263 #pragma pack(pop)
264 #endif
265 } // namespace dbiplus
Definition: qry_dat.h:232
Definition: Database.h:11
Definition: qry_dat.h:46
Definition: qry_dat.h:244
Definition: qry_dat.h:227