全て クラス 名前空間 関数 変数 型定義 列挙型 列挙値 ページ
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 #define JOIN_NO_MORERECORD 1
35 
36 class DLLLIB fieldNames
37 {
38 
39 protected:
40  /** @cond INTERNAL */
41  struct fieldNamesImple* m_impl;
42  /** @endcond */
43  void doAddValue(const _TCHAR* v, bool isNull);
44 public:
45  fieldNames();
46  fieldNames(const fieldNames& r);
47  fieldNames& operator=(const fieldNames& r);
48 
49  virtual ~fieldNames();
50  virtual fieldNames& reset();
51  fieldNames& keyField(const _TCHAR* name, const _TCHAR* name1 = NULL,
52  const _TCHAR* name2 = NULL, const _TCHAR* name3 = NULL,
53  const _TCHAR* name4 = NULL, const _TCHAR* name5 = NULL,
54  const _TCHAR* name6 = NULL, const _TCHAR* name7 = NULL,
55  const _TCHAR* name8 = NULL, const _TCHAR* name9 = NULL,
56  const _TCHAR* name10 = NULL);
57 
58  int count() const;
59  const _TCHAR* operator[](int index) const;
60  const _TCHAR* getValue(int index) const;
61  void addValue(const _TCHAR* v);
62  void addValues(const _TCHAR* values,
63  const _TCHAR* delmi); // delmi = boost::is_any_of
64  static fieldNames* create();
65  void release();
66 };
67 
68 class DLLLIB fieldValues : public fieldNames
69 {
70 public:
71  fieldValues();
72  fieldValues(const fieldValues& r);
73  fieldValues& operator=(const fieldValues& r);
74  void addValue(const _TCHAR* v, bool isNull);
75  bool isNull(int index) const;
76 };
77 
78 struct sortField
79 {
80  std::_tstring name;
81  bool asc;
82 };
83 
85 {
86  std::vector<sortField> m_params;
87  /** @cond INTERNAL */
88  template <class Archive>
89  friend void serialize(Archive& ar, sortFields& q, const unsigned int);
90  /** @endcond */
91 
92 public:
93  inline sortFields& add(const _TCHAR* name, bool asc)
94  {
95  sortField op = { name, asc };
96  m_params.push_back(op);
97  return *this;
98  }
99  inline size_t size() const { return m_params.size(); }
100  inline const sortField& operator[](int index) const
101  {
102  return m_params[index];
103  }
104  inline void clear() { m_params.clear(); }
105 };
106 
107 class DLLLIB recordsetQuery : protected query
108 {
109  friend class groupFuncBase;
110  friend class recordsetImple;
111 
112  struct recordsetQueryImple* m_imple;
113 
114  void createTempRecord();
115  void init(const fielddefs* fdinfo);
116  void init(const fielddefs* fdinfo, const fielddefs* rfdinfo);
117  bool match(const row_ptr row) const;
118  bool matchJoin(const row_ptr rrow) const;
119  void setJoinRow(const row_ptr row);
120  int matchStatus() const;
121 
122 public:
123  recordsetQuery();
124  recordsetQuery(const recordsetQuery& r);
125  ~recordsetQuery();
126 
127  recordsetQuery& operator=(const recordsetQuery& r);
128 
129  template <class T>
130  inline recordsetQuery& when(const _TCHAR* name, const _TCHAR* qlogic,
131  T value)
132  {
133  query::where(name, qlogic, value);
134  return *this;
135  }
136 
137  template <class T>
138  inline recordsetQuery& and_(const _TCHAR* name, const _TCHAR* qlogic,
139  T value)
140  {
141  query::and_(name, qlogic, value);
142  return *this;
143  }
144 
145  template <class T>
146  inline recordsetQuery& or_(const _TCHAR* name, const _TCHAR* qlogic,
147  T value)
148  {
149  query::or_(name, qlogic, value);
150  return *this;
151  }
152 
154  {
155  query::reset();
156  return *this;
157  }
158 
159  inline recordsetQuery& whenIsNull(const _TCHAR* name)
160  {
161  query::whereIsNull(name);
162  return *this;
163  }
164 
165  inline recordsetQuery& whenIsNotNull(const _TCHAR* name)
166  {
167  query::whereIsNotNull(name);
168  return *this;
169  }
170 
171  inline recordsetQuery& andIsNull(const _TCHAR* name)
172  {
173  query::andIsNull(name);
174  return *this;
175  }
176 
177  inline recordsetQuery& andIsNotNull(const _TCHAR* name)
178  {
179  query::andIsNotNull(name);
180  return *this;
181  }
182 
183  inline recordsetQuery& orIsNull(const _TCHAR* name)
184  {
185  query::orIsNull(name);
186  return *this;
187  }
188 
189  inline recordsetQuery& orIsNotNull(const _TCHAR* name)
190  {
191  query::orIsNotNull(name);
192  return *this;
193  }
194 
195  inline const _TCHAR* toString() const { return queryBase::toString(); }
196 
197  inline query* internalQuery() { return this; }
198  static recordsetQuery* create();
199  void release();
200 };
201 
202 class DLLLIB groupFuncBase : public recordsetQuery
203 {
204 protected:
205  friend class groupQueryImple;
206  friend class groupFuncBaseImple;
207 
208  typedef double numeric_type;
209 
210  class groupFuncBaseImple* m_imple;
211 
212  void init(const fielddefs* fdinfo);
213  unsigned char* stringResult(int index) const;
214  uchar_td resultType() const;
215  ushort_td resultLen() const;
216  void operator()(const row_ptr& row, int index, bool insert);
217 
218  virtual void initResultVariable(int index);
219  virtual void doCalcEachkey(const field& fd, int index);
220  virtual void doCalc(const row_ptr& row, int index);
221  virtual void doReset();
222  virtual void doInit(const fielddefs* fdinfo);
223  virtual numeric_type numericResult(int index) const;
224  bool insertFlag() const ;
225  void clearInsertFlag();
226 
227 public:
228  groupFuncBase();
229  groupFuncBase(const groupFuncBase& v);
230  groupFuncBase(const fieldNames& targetNames,
231  const _TCHAR* resultName = NULL);
232  virtual ~groupFuncBase();
233  groupFuncBase& operator=(const groupFuncBase& v);
234  groupFuncBase& operator=(const recordsetQuery& v);
235  fieldNames& targetNames() const;
236  const _TCHAR* resultName() const;
237  void setResultName(const _TCHAR* v);
238  int resultKey() const;
239  void reset();
240  bool isNull(int index) const;
241  uchar_td decimals() const;
242  virtual groupFuncBase* clone() = 0;
243 
244 };
245 
246 class recordsetImple;
247 
248 class DLLLIB groupQuery
249 {
250  friend class recordsetImple;
251  class groupQueryImple* m_imple;
252  void grouping(recordsetImple& rs);
253 
254 public:
255  groupQuery();
256  groupQuery(const groupQuery& r);
257  groupQuery& operator=(const groupQuery& r);
258 
259  ~groupQuery();
260  groupQuery& reset();
261  groupQuery& addFunction(groupFuncBase* func);
262  groupQuery& keyField(const _TCHAR* name, const _TCHAR* name1 = NULL,
263  const _TCHAR* name2 = NULL, const _TCHAR* name3 = NULL,
264  const _TCHAR* name4 = NULL, const _TCHAR* name5 = NULL,
265  const _TCHAR* name6 = NULL, const _TCHAR* name7 = NULL,
266  const _TCHAR* name8 = NULL, const _TCHAR* name9 = NULL,
267  const _TCHAR* name10 = NULL);
268  const fieldNames& getKeyFields() const;
269  const groupFuncBase* getFunction(int index) const;
270  int functionCount() const;
271  static groupQuery* create();
272  void release();
273 };
274 
275 class DLLLIB sum : public groupFuncBase
276 {
277 protected:
278  virtual void doCalcEachkey(const field& fd, int index);
279  groupFuncBase* clone();
280 public:
282  sum(const fieldNames& targetNames, const _TCHAR* resultName = NULL);
283  static sum* create(const fieldNames& targetNames,
284  const _TCHAR* resultName = NULL);
285 };
286 
287 class DLLLIB count : public groupFuncBase
288 {
289 protected:
290  groupFuncBase* clone();
291  void doCalcEachkey(const field& fd, int index);
292  void doCalc(const row_ptr& row, int index);
293  void initResultVariable(int index);
294 public:
296  count(const _TCHAR* resultName);
297  count(const fieldNames& targetNames, const _TCHAR* resultName = NULL);
298  static count* create(const _TCHAR* resultName);
299  static count* create(const fieldNames& targetNames,
300  const _TCHAR* resultName = NULL);
301 };
302 
303 class DLLLIB avg : public groupFuncBase
304 {
305  void initResultVariable(int index);
306  void doCalcEachkey(const field& fd, int index);
307  numeric_type numericResult(int index) const;
308  groupFuncBase* clone();
309 public:
310  avg();
311  avg(const fieldNames& targetNames, const _TCHAR* resultName = NULL);
312  static avg* create(const fieldNames& targetNames,
313  const _TCHAR* resultName = NULL);
314 
315 };
316 
317 #undef min
318 class DLLLIB min : public groupFuncBase
319 {
320 protected:
321  void doCalcEachkey(const field& fd, int index);
322  groupFuncBase* clone();
323  min& operator=(const min& r);
324 
325 public:
327  min(const fieldNames& targetNames, const _TCHAR* resultName = NULL);
328  static min* create(const fieldNames& targetNames,
329  const _TCHAR* resultName = NULL);
330 };
331 
332 #undef max
333 class DLLLIB max : public groupFuncBase
334 {
335  void doCalcEachkey(const field& fd, int index);
336  groupFuncBase* clone();
337  max& operator=(const max& r);
338 
339 public:
341  max(const fieldNames& targetNames, const _TCHAR* resultName = NULL);
342  static max* create(const fieldNames& targetNames,
343  const _TCHAR* resultName = NULL);
344 };
345 
346 
347 class DLLLIB last : public groupFuncBase
348 {
349 protected:
350  void doCalc(const row_ptr& row, int index);
351  void doInit(const fielddefs* fdinfo);
352  groupFuncBase* clone();
353  void storeValue(const row_ptr& row, int index);
354 public:
356  last(const fieldNames& targetNames, const _TCHAR* resultName = NULL);
357  static last* create(const fieldNames& targetNames,
358  const _TCHAR* resultName = NULL);
359 };
360 
361 
362 class DLLLIB first : public last
363 {
364 protected:
365  void doCalc(const row_ptr& row, int index);
366  void doReset();
367  groupFuncBase* clone();
368  first& operator=(const first& r);
369 public:
370  first() : last() {}
371  first(const fieldNames& targetNames, const _TCHAR* resultName = NULL);
372  static first* create(const fieldNames& targetNames,
373  const _TCHAR* resultName = NULL);
374 };
375 
376 
377 
378 } // namespace client
379 } // namespace tdap
380 } // namespace protocol
381 } // namespace db
382 } // namespace bzs
383 
384 #endif // BZS_DB_PROTOCOL_TDAP_CLIENT_GROUPQUERY_H
last()
Definition: groupQuery.h:355
recordsetQuery & whenIsNull(const _TCHAR *name)
Definition: groupQuery.h:159
recordsetQuery & orIsNotNull(const _TCHAR *name)
Definition: groupQuery.h:189
グルーピング Firstクラス
Definition: groupQuery.h:362
const _TCHAR * toString() const
Definition: groupQuery.h:195
query & orIsNull(const _TCHAR *name)
Definition: table.h:594
query & orIsNotNull(const _TCHAR *name)
Definition: table.h:600
グルーピング 最小値計算クラス
Definition: groupQuery.h:318
min()
Definition: groupQuery.h:326
recordsetQuery & andIsNotNull(const _TCHAR *name)
Definition: groupQuery.h:177
query & whereIsNull(const _TCHAR *name)
Definition: table.h:548
sortFields & add(const _TCHAR *name, bool asc)
Definition: groupQuery.h:93
recordsetQuery & andIsNull(const _TCHAR *name)
Definition: groupQuery.h:171
query & where(const _TCHAR *name, const _TCHAR *qlogic, T value)
Definition: table.h:542
グルーピング 合計計算クラス
Definition: groupQuery.h:275
max()
Definition: groupQuery.h:340
グルーピング 最大値計算クラス
Definition: groupQuery.h:333
グルーピング条件を指定するクラス
Definition: groupQuery.h:248
query & reset()
Definition: table.h:499
recordsetQuery & and_(const _TCHAR *name, const _TCHAR *qlogic, T value)
Definition: groupQuery.h:138
query * internalQuery()
Definition: groupQuery.h:197
グルーピング 平均値計算クラス
Definition: groupQuery.h:303
recordsetQuery & when(const _TCHAR *name, const _TCHAR *qlogic, T value)
Definition: groupQuery.h:130
sum()
Definition: groupQuery.h:281
fielddef のコレクションクラス
Definition: field.h:74
query & andIsNull(const _TCHAR *name)
Definition: table.h:571
recordsetQuery & orIsNull(const _TCHAR *name)
Definition: groupQuery.h:183
recordset のソートパラメータコレクションクラス
Definition: groupQuery.h:84
グルーピング レコード数カウンター
Definition: groupQuery.h:287
recordsetQuery & whenIsNotNull(const _TCHAR *name)
Definition: groupQuery.h:165
recordset フィルタリングクエリー
Definition: groupQuery.h:107
double numeric_type
Definition: groupQuery.h:208
フィールドコレクションのベースクラス
Definition: fields.h:123
query & whereIsNotNull(const _TCHAR *name)
Definition: table.h:554
query & and_(const _TCHAR *name, const _TCHAR *qlogic, T value)
Definition: table.h:561
読み取り用クエリー
Definition: table.h:491
count()
Definition: groupQuery.h:295
bool asc
Definition: groupQuery.h:81
std::_tstring name
Definition: groupQuery.h:80
void clear()
Definition: groupQuery.h:104
first()
Definition: groupQuery.h:370
query & andIsNotNull(const _TCHAR *name)
Definition: table.h:577
フィールドの値を文字列で保持するクラス
Definition: groupQuery.h:68
size_t size() const
Definition: groupQuery.h:99
class groupFuncBaseImple * m_imple
Definition: groupQuery.h:210
グルーピング Lastクラス
Definition: groupQuery.h:347
フィールド名を保持するクラス
Definition: groupQuery.h:36
query & or_(const _TCHAR *name, const _TCHAR *qlogic, T value)
Definition: table.h:584
const sortField & operator[](int index) const
Definition: groupQuery.h:100
グルーピング計算関数のベースクラス
Definition: groupQuery.h:202
recordset のソートパラメータ構造体
Definition: groupQuery.h:78
フィールドアクセスクラス
Definition: field.h:118
recordsetQuery & or_(const _TCHAR *name, const _TCHAR *qlogic, T value)
Definition: groupQuery.h:146
recordsetQuery & reset()
Definition: groupQuery.h:153

Transactd SDK 2018年07月31日(火) 19時40分21秒 doxygen