Merge pull request #5039 from CEikermann/patch-1
[vuplus_xbmc] / xbmc / dbwrappers / 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  * 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
17  * all 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
25  * THE SOFTWARE.
26  *
27  **********************************************************************/
28
29 #ifndef _QRYDAT_H
30 #define _QRYDAT_H
31
32 #include <map>
33 #include <vector>
34 #include <iostream>
35 #include <string>
36 #include <stdint.h>
37
38 namespace dbiplus {
39
40 enum fType { 
41         ft_String,
42         ft_Boolean,
43         ft_Char,
44         ft_WChar,
45         ft_WideString,
46         ft_Short,
47         ft_UShort,
48         ft_Int,
49         ft_UInt,
50         ft_Float,
51         ft_Double,
52         ft_LongDouble,
53   ft_Int64,
54         ft_Object
55     };
56
57
58
59 class field_value {
60 private:
61   fType field_type;
62   std::string str_value;
63   union {
64     bool   bool_value;
65     char   char_value;
66     short  short_value;
67     unsigned short ushort_value;
68     int   int_value;
69     unsigned int uint_value;
70     float  float_value;
71     double double_value;
72     int64_t int64_value;
73     void   *object_value;
74   } ;
75
76   bool is_null;
77
78 public:
79   field_value();
80   field_value(const char *s);
81   field_value(const bool b);
82   field_value(const char c);
83   field_value(const short s);
84   field_value(const unsigned short us);
85   field_value(const int l);
86   field_value(const unsigned int ul);
87   field_value(const float f);
88   field_value(const double d);
89   field_value(const int64_t i);
90   field_value(const field_value & fv);
91   ~field_value();
92
93   fType get_fType() const {return field_type;}
94   bool get_isNull() const {return is_null;}
95   std::string get_asString() const;
96   bool get_asBool() const;
97   char get_asChar() const;
98   short get_asShort() const;
99   unsigned short get_asUShort() const;
100   int get_asInt() const;
101   unsigned int get_asUInt() const;
102   float get_asFloat() const;
103   double get_asDouble() const;
104   int64_t get_asInt64() const;
105
106   field_value& operator= (const char *s)
107     {set_asString(s); return *this;}
108   field_value& operator= (const std::string &s)
109     {set_asString(s); return *this;}
110   field_value& operator= (const bool b)
111     {set_asBool(b); return *this;}
112   field_value& operator= (const short s)
113     {set_asShort(s); return *this;}
114   field_value& operator= (const unsigned short us)
115     {set_asUShort(us); return *this;}
116   field_value& operator= (const int l)
117     {set_asInt(l); return *this;}
118   field_value& operator= (const unsigned int l)
119     {set_asUInt(l); return *this;}
120   field_value& operator= (const float f)
121     {set_asFloat(f); return *this;}
122   field_value& operator= (const double d)
123     {set_asDouble(d); return *this;}
124   field_value& operator= (const int64_t i)
125     {set_asInt64(i); return *this;}
126   field_value& operator= (const field_value & fv);
127   
128   //class ostream;
129   friend std::ostream& operator<< (std::ostream& os, const field_value &fv)
130   {switch (fv.get_fType()) {
131     case ft_String: {
132       return os << fv.get_asString();
133       break;
134     }
135     case ft_Boolean:{
136       return os << fv.get_asBool();
137       break;     
138     }
139     case ft_Char: {
140       return os << fv.get_asChar();
141       break;
142     }
143     case ft_Short: {
144       return os << fv.get_asShort();
145       break;
146     }
147     case ft_UShort: {
148       return os << fv.get_asUShort();
149       break;
150     }
151     case ft_Int: {
152       return os << fv.get_asInt();
153       break;
154     }
155     case ft_UInt: {
156       return os << fv.get_asUInt();
157       break;
158     }
159     case ft_Float: {
160       return os << fv.get_asFloat();
161       break;
162     }
163     case ft_Double: {
164       return os << fv.get_asDouble();
165       break;
166     }
167     case ft_Int64: {
168       return os << fv.get_asInt64();
169       break;
170     }
171     default: {
172       return os;
173       break;
174     }
175   }
176   }
177
178   void set_isNull(){is_null=true;}
179   void set_asString(const char *s);
180   void set_asString(const std::string & s);
181   void set_asBool(const bool b);
182   void set_asChar(const char c);
183   void set_asShort(const short s);
184   void set_asUShort(const unsigned short us);
185   void set_asInt(const int l);
186   void set_asUInt(const unsigned int l);
187   void set_asFloat(const float f);
188   void set_asDouble(const double d);
189   void set_asInt64(const int64_t i);
190
191   fType get_field_type();
192   std::string gft();
193 };
194
195 struct field_prop {
196   std::string name,display_name;
197   fType type;
198   std::string field_table; //?
199   bool read_only;
200   unsigned int field_len;
201   unsigned int field_flags;
202   int idx;
203 };
204
205 struct field {
206   field_prop props;
207   field_value val;
208 }; 
209
210
211 typedef std::vector<field> Fields;
212 typedef std::vector<field_value> sql_record;
213 typedef std::vector<field_prop> record_prop;
214 typedef std::vector<sql_record*> query_data;
215 typedef field_value variant;
216
217 //typedef Fields::iterator fld_itor;
218 typedef sql_record::iterator rec_itor;
219 typedef record_prop::iterator recprop_itor;
220 typedef query_data::iterator qry_itor;
221
222 class result_set
223 {
224 public:
225   result_set()
226   {
227   };
228   ~result_set()
229   {
230     clear();
231   };
232   void clear()
233   {
234     for (unsigned int i = 0; i < records.size(); i++)
235       if (records[i])
236         delete records[i];
237     records.clear();
238     record_header.clear();
239   };
240
241   record_prop record_header;
242   query_data records;
243 };
244
245 } // namespace
246
247 #endif