全て クラス 名前空間 関数 変数 型定義 列挙型 列挙値 フレンド ページ
groupQuery.h
1 #ifndef BZS_DB_PROTOCOL_TDAP_CLIENT_GROUPQUERY_H
2 #define BZS_DB_PROTOCOL_TDAP_CLIENT_GROUPQUERY_H
3 /*=================================================================
4  Copyright (C) 2014 BizStation Corp All rights reserved.
5 
6  This program is free software; you can redistribute it and/or
7  modify it under the terms of the GNU General Public License
8  as published by the Free Software Foundation; either version 2
9  of the License, or (at your option) any later version.
10 
11  This program is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  GNU General Public License for more details.
15 
16  You should have received a copy of the GNU General Public License
17  along with this program; if not, write to the Free Software
18  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
19  02111-1307, USA.
20 =================================================================*/
21 #include <bzs/db/protocol/tdap/client/trdboostapi.h>
22 
23 namespace bzs
24 {
25 namespace db
26 {
27 namespace protocol
28 {
29 namespace tdap
30 {
31 namespace client
32 {
33 
34 class DLLLIB fieldNames
35 {
36 
37 protected:
38  /** @cond INTERNAL */
39  struct fieldNamesImple* m_impl;
40  /** @endcond */
41 
42 public:
43  fieldNames();
44  fieldNames(const fieldNames& r);
45  fieldNames& operator=(const fieldNames& r);
46 
47  virtual ~fieldNames();
48  virtual fieldNames& reset();
49  fieldNames& keyField(const _TCHAR* name, const _TCHAR* name1 = NULL,
50  const _TCHAR* name2 = NULL, const _TCHAR* name3 = NULL,
51  const _TCHAR* name4 = NULL, const _TCHAR* name5 = NULL,
52  const _TCHAR* name6 = NULL, const _TCHAR* name7 = NULL,
53  const _TCHAR* name8 = NULL, const _TCHAR* name9 = NULL,
54  const _TCHAR* name10 = NULL);
55 
56  int count() const;
57  const _TCHAR* operator[](int index) const;
58  const _TCHAR* getValue(int index) const;
59  void addValue(const _TCHAR* v);
60  void addValues(const _TCHAR* values,
61  const _TCHAR* delmi); // delmi = boost::is_any_of
62  static fieldNames* create();
63  void release();
64 };
65 
66 struct sortField
67 {
68  std::_tstring name;
69  bool asc;
70 };
71 
73 {
74  std::vector<sortField> m_params;
75  /** @cond INTERNAL */
76  template <class Archive>
77  friend void serialize(Archive& ar, sortFields& q, const unsigned int);
78  /** @endcond */
79 
80 public:
81  inline sortFields& add(const _TCHAR* name, bool asc)
82  {
83  sortField op = { name, asc };
84  m_params.push_back(op);
85  return *this;
86  }
87  inline size_t size() const { return m_params.size(); }
88  inline const sortField& operator[](int index) const
89  {
90  return m_params[index];
91  }
92  inline void clear() { m_params.clear(); }
93 };
94 
95 class DLLLIB recordsetQuery : protected query
96 {
97  friend class groupFuncBase;
98  friend class recordsetImple;
99 
100  struct recordsetQueryImple* m_imple;
101  void init(const fielddefs* fdinfo);
102  bool isMatch(int ret, unsigned char compType) const;
103  bool match(const row_ptr row) const;
104 
105 public:
106  recordsetQuery();
107  recordsetQuery(const recordsetQuery& r);
108  ~recordsetQuery();
109 
110  recordsetQuery& operator=(const recordsetQuery& r);
111 
112  template <class T>
113  inline recordsetQuery& when(const _TCHAR* name, const _TCHAR* qlogic,
114  T value)
115  {
116  query::where(name, qlogic, value);
117  return *this;
118  }
119 
120  template <class T>
121  inline recordsetQuery& and_(const _TCHAR* name, const _TCHAR* qlogic,
122  T value)
123  {
124  query::and_(name, qlogic, value);
125  return *this;
126  }
127 
128  template <class T>
129  inline recordsetQuery& or_(const _TCHAR* name, const _TCHAR* qlogic,
130  T value)
131  {
132  query::or_(name, qlogic, value);
133  return *this;
134  }
135 
137  {
138  query::reset();
139  return *this;
140  }
141 
142  inline const _TCHAR* toString() const { return queryBase::toString(); }
143 
144  inline query* internalQuery() { return this; }
145  static recordsetQuery* create();
146  void release();
147 };
148 
149 class DLLLIB groupFuncBase : public recordsetQuery
150 {
151 protected:
152  friend class groupQueryImple;
153  friend class groupFuncBaseImple;
154 
155  typedef double numeric_type;
156 
157  class groupFuncBaseImple* m_imple;
158 
159  void init(const fielddefs* fdinfo);
160  unsigned char* stringResult(int groupIndex) const;
161  uchar_td resultType() const;
162  ushort_td resultLen() const;
163  void operator()(const row_ptr& row, int index, bool insert);
164 
165  virtual void initResultVariable(int index);
166  virtual void doCalc(const row_ptr& row, int groupIndex);
167  virtual void doReset();
168  virtual void doInit(const fielddefs* fdinfo);
169  virtual numeric_type numericResult(int groupIndex) const;
170 
171 
172 public:
173  groupFuncBase();
174  groupFuncBase(const groupFuncBase& v);
175  groupFuncBase(const fieldNames& targetNames,
176  const _TCHAR* resultName = NULL);
177  virtual ~groupFuncBase();
178  groupFuncBase& operator=(const groupFuncBase& v);
179  groupFuncBase& operator=(const recordsetQuery& v);
180  fieldNames& targetNames() const;
181  const _TCHAR* resultName() const;
182  void setResultName(const _TCHAR* v);
183  int resultKey() const;
184  void reset();
185  virtual groupFuncBase* clone() = 0;
186 };
187 
188 class recordsetImple;
189 
190 class DLLLIB groupQuery
191 {
192  friend class recordsetImple;
193  class groupQueryImple* m_imple;
194  void grouping(recordsetImple& rs);
195 
196 public:
197  groupQuery();
198  groupQuery(const groupQuery& r);
199  groupQuery& operator=(const groupQuery& r);
200 
201  ~groupQuery();
202  groupQuery& reset();
203  groupQuery& addFunction(groupFuncBase* func);
204  groupQuery& keyField(const _TCHAR* name, const _TCHAR* name1 = NULL,
205  const _TCHAR* name2 = NULL, const _TCHAR* name3 = NULL,
206  const _TCHAR* name4 = NULL, const _TCHAR* name5 = NULL,
207  const _TCHAR* name6 = NULL, const _TCHAR* name7 = NULL,
208  const _TCHAR* name8 = NULL, const _TCHAR* name9 = NULL,
209  const _TCHAR* name10 = NULL);
210  const fieldNames& getKeyFields() const;
211  const groupFuncBase* getFunction(int index) const;
212  int functionCount() const;
213  static groupQuery* create();
214  void release();
215 };
216 
217 class DLLLIB sum : public groupFuncBase
218 {
219 protected:
220  void doCalc(const row_ptr& row, int index);
221  groupFuncBase* clone();
222 public:
223  sum() {}
224  sum(const fieldNames& targetNames, const _TCHAR* resultName = NULL);
225  static sum* create(const fieldNames& targetNames,
226  const _TCHAR* resultName = NULL);
227 };
228 
229 class DLLLIB count : public groupFuncBase
230 {
231 protected:
232  groupFuncBase* clone();
233  void doCalc(const row_ptr& row, int index);
234 
235 public:
236  count() {}
237  count(const _TCHAR* resultName);
238  static count* create(const _TCHAR* resultName);
239 };
240 
241 class DLLLIB avg : public sum
242 {
243  void initResultVariable(int index);
244  void doCalc(const row_ptr& row, int index);
245  numeric_type numericResult(int index) const;
246  groupFuncBase* clone();
247 
248 public:
249  avg() {}
250  avg(const fieldNames& targetNames, const _TCHAR* resultName = NULL);
251  static avg* create(const fieldNames& targetNames,
252  const _TCHAR* resultName = NULL);
253 };
254 
255 #undef min
256 class DLLLIB min : public sum
257 {
258 protected:
259  bool m_flag;
260  void doCalc(const row_ptr& row, int index);
261  groupFuncBase* clone();
262  min& operator=(const min& r);
263 
264 public:
265  min() {}
266  min(const fieldNames& targetNames, const _TCHAR* resultName = NULL);
267  static min* create(const fieldNames& targetNames,
268  const _TCHAR* resultName = NULL);
269 };
270 
271 #undef max
272 class DLLLIB max : public sum
273 {
274  bool m_flag;
275  void doCalc(const row_ptr& row, int index);
276  groupFuncBase* clone();
277  max& operator=(const max& r);
278 
279 public:
280  max() {}
281  max(const fieldNames& targetNames, const _TCHAR* resultName = NULL);
282  static max* create(const fieldNames& targetNames,
283  const _TCHAR* resultName = NULL);
284 };
285 
286 
287 class DLLLIB last : public groupFuncBase
288 {
289 protected:
290  void doCalc(const row_ptr& row, int index);
291  void doInit(const fielddefs* fdinfo);
292  groupFuncBase* clone();
293 public:
294  last() {}
295  last(const fieldNames& targetNames, const _TCHAR* resultName = NULL);
296  static last* create(const fieldNames& targetNames,
297  const _TCHAR* resultName = NULL);
298 };
299 
300 
301 class DLLLIB first : public last
302 {
303  bool m_readed;
304 protected:
305  void doCalc(const row_ptr& row, int index);
306  void doReset();
307  groupFuncBase* clone();
308  first& operator=(const first& r);
309 public:
310  first() {}
311  first(const fieldNames& targetNames, const _TCHAR* resultName = NULL);
312  static first* create(const fieldNames& targetNames,
313  const _TCHAR* resultName = NULL);
314 };
315 
316 
317 
318 } // namespace client
319 } // namespace tdap
320 } // namespace protocol
321 } // namespace db
322 } // namespace bzs
323 
324 #endif // BZS_DB_PROTOCOL_TDAP_CLIENT_GROUPQUERY_H
const _TCHAR * protocol(const _TCHAR *uri)
Definition: uri.h:42
last()
Definition: groupQuery.h:294
グルーピング Firstクラス
Definition: groupQuery.h:301
const _TCHAR * toString() const
Definition: groupQuery.h:142
グルーピング 最小値計算クラス
Definition: groupQuery.h:256
min()
Definition: groupQuery.h:265
sortFields & add(const _TCHAR *name, bool asc)
Definition: groupQuery.h:81
query & where(const _TCHAR *name, const _TCHAR *qlogic, T value)
Definition: table.h:499
グルーピング 合計計算クラス
Definition: groupQuery.h:217
max()
Definition: groupQuery.h:280
グルーピング 最大値計算クラス
Definition: groupQuery.h:272
グルーピング条件を指定するクラス
Definition: groupQuery.h:190
query & reset()
Definition: table.h:456
recordsetQuery & and_(const _TCHAR *name, const _TCHAR *qlogic, T value)
Definition: groupQuery.h:121
query * internalQuery()
Definition: groupQuery.h:144
グルーピング 平均値計算クラス
Definition: groupQuery.h:241
recordsetQuery & when(const _TCHAR *name, const _TCHAR *qlogic, T value)
Definition: groupQuery.h:113
sum()
Definition: groupQuery.h:223
fielddef のコレクションクラス
Definition: field.h:73
recordset のソートパラメータコレクションクラス
Definition: groupQuery.h:72
グルーピング レコード数カウンター
Definition: groupQuery.h:229
recordset フィルタリングクエリー
Definition: groupQuery.h:95
double numeric_type
Definition: groupQuery.h:155
フィールドコレクションのベースクラス
Definition: fields.h:123
query & and_(const _TCHAR *name, const _TCHAR *qlogic, T value)
Definition: table.h:506
bool m_flag
Definition: groupQuery.h:259
読み取り用クエリー
Definition: table.h:448
count()
Definition: groupQuery.h:236
bool asc
Definition: groupQuery.h:69
std::_tstring name
Definition: groupQuery.h:68
void clear()
Definition: groupQuery.h:92
first()
Definition: groupQuery.h:310
size_t size() const
Definition: groupQuery.h:87
class groupFuncBaseImple * m_imple
Definition: groupQuery.h:157
グルーピング Lastクラス
Definition: groupQuery.h:287
フィールド名を保持するクラス
Definition: groupQuery.h:34
query & or_(const _TCHAR *name, const _TCHAR *qlogic, T value)
Definition: table.h:517
const sortField & operator[](int index) const
Definition: groupQuery.h:88
グルーピング計算関数のベースクラス
Definition: groupQuery.h:149
recordset のソートパラメータ構造体
Definition: groupQuery.h:66
avg()
Definition: groupQuery.h:249
recordsetQuery & or_(const _TCHAR *name, const _TCHAR *qlogic, T value)
Definition: groupQuery.h:129
recordsetQuery & reset()
Definition: groupQuery.h:136

Transactd SDK 2015年09月08日(火) 19時13分35秒 doxygen