1 #ifndef BZS_DB_PROTOCOL_TDAP_CLIENT_TABLE_H
2 #define BZS_DB_PROTOCOL_TDAP_CLIENT_TABLE_H
24 #include <boost/shared_ptr.hpp>
47 #if (defined(__BORLANDC__) && !defined(__clang__))
48 typedef void __stdcall(* recordCountFn)(table* tb,
int count,
bool& complate);
52 typedef void(__STDCALL* recordCountFn)(table* tb,
int count,
bool& complate);
55 #define null_str _T("")
57 #pragma warning(disable : 4251)
59 static const int mra_nojoin = 0;
60 static const int mra_first = 0;
61 static const int mra_nextrows = 1;
62 static const int mra_innerjoin = 2;
63 static const int mra_outerjoin = 4;
64 static const int mra_current_block = -1;
66 class multiRecordAlocator
70 virtual ~multiRecordAlocator() {}
71 virtual void init(
size_t recordCount,
size_t recordLen,
int addType,
72 const class table* tb) = 0;
73 virtual unsigned char* allocBlobBlock(
size_t size) = 0;
74 virtual unsigned char* ptr(
size_t row,
int stat) = 0;
75 virtual void setJoinType(
int v) = 0;
76 virtual void setInvalidRecord(
size_t row,
bool v) = 0;
77 virtual void setJoinRowMap(
78 const std::vector<std::vector<int> >* v ) = 0;
79 virtual const std::vector<std::vector<int> >* joinRowMap()
const = 0;
80 virtual void duplicateRow(
int row,
int count) = 0;
81 virtual void removeLastMemBlock(
int row) = 0;
85 typedef boost::shared_ptr<filter> pq_handle;
93 friend class recordCache;
99 struct tbimpl* m_impl;
103 uchar_td charset()
const;
104 bool checkIndex(
short index)
const;
105 void getKeySpec(
keySpec* ks,
bool SpecifyKeyNum =
false);
106 const bzs::db::blobHeader* getBlobHeader();
107 unsigned char* setBlobFieldPointer(
char* ptr, const ::bzs::db::blobHeader* p,
108 unsigned char* to=NULL);
109 void addSendBlob(
const bzs::db::blob* blob);
110 void addBlobEndRow();
111 void resetSendBlob();
112 void btrvGetExtend(ushort_td op);
113 void getRecords(ushort_td op);
114 uint_td doGetWriteImageLen();
115 void doUpdate(
bool ncc =
false);
116 ushort_td doCommitBulkInsert(
bool autoCommit =
false);
117 void doAbortBulkInsert();
118 void doCreateIndex(
bool SpecifyKeyNum =
false);
119 uint_td doRecordCount(
bool estimate,
bool fromCurrent);
120 short_td doBtrvErr(HWND hWnd, _TCHAR* retbuf = NULL);
121 void doFind(ushort_td op,
bool notIncCurrent);
122 bool setSeekValueField(
int row);
123 void btrvSeekMulti();
124 bool doSeekMultiAfter(
int row);
125 void* doDdba(uint_td size);
126 bool isReadContinue(ushort_td& op);
131 void* dataBak()
const;
132 void* reallocDataBuffer(uint_td v);
133 int dataBufferLen()
const;
134 uint_td unPack(
char* ptr,
size_t size);
135 uint_td pack(
char* ptr,
size_t size);
137 keylen_td writeKeyData();
138 keylen_td writeKeyDataTo(uchar_td* to,
int keySize);
143 bool onUpdateCheck(eUpdateType type);
147 void onUpdateAfter(
int beforeResult);
148 bool onDeleteCheck(
bool inkey);
152 void onInsertAfter(
int beforeResult);
153 bool isUniqeKey(char_td keynum);
154 void init(
tabledef** def,
short filenum,
bool regularDir);
155 void* attachBuffer(
void* newPtr,
bool unpack =
false,
size_t size = 0);
156 void dettachBuffer();
159 virtual void doInit(
tabledef** def,
short filenum,
bool regularDir);
161 virtual void onRecordCounting(
size_t count,
bool& cancel);
171 return const_cast<const tabledef**
>(m_tableDef);
176 return (*m_tableDef)->optionFlags.bitA;
179 inline bool blobFieldUsed()
const {
return (*m_tableDef)->optionFlags.bitB; }
181 bool logicalToString()
const;
182 void setLogicalToString(
bool v);
183 void* optionalData()
const;
184 void setOptionalData(
void* v);
185 bool myDateTimeValueByBtrv()
const;
186 void insertBookmarks(
unsigned int start,
void* data, ushort_td
count);
187 int bookmarksCount()
const;
188 void moveBookmarks(
unsigned int index);
189 bookmark_td bookmarks(
unsigned int index)
const;
191 unsigned int getRecordHash();
194 void setMra(multiRecordAlocator* p);
195 multiRecordAlocator* mra()
const;
197 void find(eFindType type = findForword);
200 void findNext(
bool notIncCurrent =
true);
201 void findPrev(
bool notIncCurrent =
true);
202 short statReasonOfFind()
const ;
203 eFindType lastFindDirection()
const;
204 bookmark_td bookmarkFindCurrent()
const;
208 return setQuery(query, serverPrepare);
210 void setPrepare(
const pq_handle stmt);
212 void setFilter(
const _TCHAR* str, ushort_td rejectCount,
213 ushort_td cacheCount,
bool autoEscape =
true);
214 short fieldNumByName(
const _TCHAR* name);
215 unsigned char getFVbyt(
short index);
216 short getFVsht(
short index);
217 int getFVint(
short index);
218 int getFVlng(
short index);
219 __int64 getFV64(
short index);
220 float getFVflt(
short index);
221 double getFVdbl(
short index);
222 const char* getFVAstr(
short index);
223 void* getFVbin(
short index, uint_td& size);
224 unsigned char getFVbyt(
const _TCHAR* fieldName);
225 short getFVsht(
const _TCHAR* fieldName);
226 int getFVint(
const _TCHAR* fieldName);
227 int getFVlng(
const _TCHAR* fieldName);
228 __int64 getFV64(
const _TCHAR* fieldName);
229 float getFVflt(
const _TCHAR* fieldName);
230 double getFVdbl(
const _TCHAR* fieldName);
231 const char* getFVAstr(
const _TCHAR* fieldName);
232 void* getFVbin(
const _TCHAR* fieldName, uint_td& size);
233 void setFV(
short index,
double data);
234 void setFV(
short index,
float data);
235 void setFV(
short index,
unsigned char data);
236 void setFV(
short index,
short data);
237 void setFVA(
short index,
const char* data);
238 void setFV(
short index,
int data);
239 void setFV(
short index,
const void* data, uint_td size);
240 void setFV(
const _TCHAR* fieldName,
int data);
241 void setFVA(
const _TCHAR* fieldName,
const char* data);
244 const wchar_t* getFVWstr(
const _TCHAR* fieldName);
245 const wchar_t* getFVWstr(
short index);
246 void setFVW(
short index,
const wchar_t* data);
247 void setFVW(
const _TCHAR* fieldName,
const wchar_t* data);
251 inline const wchar_t* getFVstr(
short index) {
return getFVWstr(index); };
252 inline const wchar_t* getFVstr(
const wchar_t* fieldName)
254 return getFVWstr(fieldName);
257 inline const char*
getFVstr(
short index) {
return getFVAstr(index); };
260 return getFVAstr(fieldName);
264 inline void setFV(
short index,
const char* data) { setFVA(index, data); };
265 inline void setFV(
const _TCHAR* fieldName,
const char* data)
267 setFVA(fieldName, data);
270 inline void setFV(
short index,
const wchar_t* data)
274 inline void setFV(
const _TCHAR* fieldName,
const wchar_t* data)
276 setFVW(fieldName, data);
280 void setFV(
const _TCHAR* fieldName,
double data);
281 void setFV(
const _TCHAR* fieldName,
float data);
282 void setFV(
const _TCHAR* fieldName,
unsigned char data);
283 void setFV(
const _TCHAR* fieldName,
short data);
284 void setFV(
const _TCHAR* fieldName,
const void* data, uint_td size);
285 void setFV(
short index, __int64 data);
286 void setFV(
const _TCHAR* fieldName, __int64 data);
287 void* fieldPtr(
short index)
const;
288 void keyValueDescription(_TCHAR* buf,
int bufsize);
289 short getCurProcFieldCount()
const;
290 short getCurProcFieldIndex(
short index)
const;
291 void setOnRecordCount(
const recordCountFn v);
292 recordCountFn onRecordCount()
const;
293 client::fields& fields();
296 #define KEYVALUE_PTR 0
297 #define KEYVALUE_STR 1
298 #define KEYVALUE_NEED_COPY 2
299 #define KEYVALUE_STR_NEED_COPY 3
303 struct DLLLIB keyValuePtr
309 keyValuePtr(
const void* p, ushort_td l,
short typeStr);
320 const std::vector<std::_tstring>& getSelects()
const;
321 const std::vector<std::_tstring>& getWheres()
const;
322 const std::vector<std::_tstring>& getSeekKeyValues()
const;
323 const std::vector<keyValuePtr>& getSeekValuesPtr()
const;
329 joinHasOneOrHasMany = 1,
339 void clearSeekKeyValues();
340 void clearSelectFields();
341 void addField(
const _TCHAR* name);
342 void addLogic(
const _TCHAR* name,
const _TCHAR* logic,
const _TCHAR* value);
343 void addLogic(
const _TCHAR* combine,
const _TCHAR* name,
344 const _TCHAR* logic,
const _TCHAR* value);
345 void addSeekKeyValue(
const _TCHAR* value,
bool reset =
false);
346 void addSeekBookmark(bookmark_td& bm, ushort_td len,
bool reset =
false);
347 void addSeekKeyValuePtr(
const void* value, ushort_td len,
short typeStr,
349 void reserveSeekKeyValueSize(
size_t v);
350 void reserveSeekKeyValuePtrSize(
size_t v);
351 queryBase& queryString(
const _TCHAR* str,
bool autoEscape =
false);
360 const _TCHAR* toString()
const;
362 int getReject()
const;
363 int getLimit()
const;
365 int getJoinKeySize()
const;
366 eOptimize getOptimize()
const;
367 bool isStopAtLimit()
const;
368 bool isBookmarkAlso()
const;
369 bool isSeekByBookmarks()
const;
370 short selectCount()
const;
371 const _TCHAR* getSelect(
short index)
const;
372 short whereTokens()
const;
373 const _TCHAR* getWhereToken(
short index)
const;
374 void setWhereToken(
short index,
const _TCHAR* v);
375 void reverseAliasName(
const _TCHAR* alias,
const _TCHAR* src);
382 inline std::_tstring lexical_cast(__int64 v)
385 _i64tot_s(v, tmp, 256, 10);
386 return std::_tstring(tmp);
389 inline std::_tstring lexical_cast(
int v)
392 _ltot_s(v, tmp, 256, 10);
393 return std::_tstring(tmp);
396 inline std::_tstring lexical_cast(
short v)
399 _ltot_s((
int)v, tmp, 256, 10);
400 return std::_tstring(tmp);
403 inline std::_tstring lexical_cast(
char v)
406 _ltot_s((
int)v, tmp, 256, 10);
407 return std::_tstring(tmp);
410 inline std::_tstring lexical_cast(
double v)
413 _stprintf_s(tmp, 256, _T(
"%.*f"), 15, v);
414 return std::_tstring(tmp);
417 inline std::_tstring lexical_cast(
float v)
420 _stprintf_s(tmp, 256, _T(
"%.*f"), 15, v);
421 return std::_tstring(tmp);
424 inline std::_tstring lexical_cast(
const _TCHAR* v)
427 return std::_tstring(v);
428 return std::_tstring(_T(
""));
433 std::_tstring m_name;
434 std::_tstring m_value;
435 std::_tstring m_type;
440 qlogic(
const _TCHAR* name,
const _TCHAR* type, T value,
combineType next)
441 : m_name(name), m_type(type), m_next(next)
443 m_value = lexical_cast(value);
463 const _TCHAR* name2 = NULL,
const _TCHAR* name3 = NULL,
464 const _TCHAR* name4 = NULL,
const _TCHAR* name5 = NULL,
465 const _TCHAR* name6 = NULL,
const _TCHAR* name7 = NULL,
466 const _TCHAR* name8 = NULL,
const _TCHAR* name9 = NULL,
467 const _TCHAR* name10 = NULL)
469 if (_tcscmp(name, _T(
"*")) == 0)
499 query&
where(
const _TCHAR* name,
const _TCHAR* qlogic, T value)
501 addLogic(name, qlogic, lexical_cast(value).
c_str());
506 query&
and_(
const _TCHAR* name,
const _TCHAR* qlogic, T value)
508 if (whereTokens() == 0)
509 THROW_BZS_ERROR_WITH_CODEMSG(STATUS_FILTERSTRING_ERROR,
510 _T(
"Invalid function call."));
512 addLogic(_T(
"and"), name, qlogic, lexical_cast(value).
c_str());
517 query&
or_(
const _TCHAR* name,
const _TCHAR* qlogic, T value)
519 if (whereTokens() == 0)
520 THROW_BZS_ERROR_WITH_CODEMSG(STATUS_FILTERSTRING_ERROR,
521 _T(
"Invalid function call."));
523 addLogic(_T(
"or"), name, qlogic, lexical_cast(value).
c_str());
527 template <
class T0,
class T1,
class T2,
class T3,
class T4,
class T5,
529 query&
in(
const T0 kv0,
const T1 kv1,
const T2 kv2,
const T3 kv3,
530 const T4 kv4,
const T5 kv5,
const T6 kv6,
const T7 kv7)
532 addSeekKeyValue(lexical_cast(kv0).
c_str());
533 addSeekKeyValue(lexical_cast(kv1).
c_str());
534 addSeekKeyValue(lexical_cast(kv2).
c_str());
535 addSeekKeyValue(lexical_cast(kv3).
c_str());
536 addSeekKeyValue(lexical_cast(kv4).
c_str());
537 addSeekKeyValue(lexical_cast(kv5).
c_str());
538 addSeekKeyValue(lexical_cast(kv6).
c_str());
539 addSeekKeyValue(lexical_cast(kv7).
c_str());
542 template <
class T0,
class T1,
class T2,
class T3,
class T4,
class T5,
544 query&
in(
const T0 kv0,
const T1 kv1,
const T2 kv2,
const T3 kv3,
545 const T4 kv4,
const T5 kv5,
const T6 kv6)
547 addSeekKeyValue(lexical_cast(kv0).
c_str());
548 addSeekKeyValue(lexical_cast(kv1).
c_str());
549 addSeekKeyValue(lexical_cast(kv2).
c_str());
550 addSeekKeyValue(lexical_cast(kv3).
c_str());
551 addSeekKeyValue(lexical_cast(kv4).
c_str());
552 addSeekKeyValue(lexical_cast(kv5).
c_str());
553 addSeekKeyValue(lexical_cast(kv6).
c_str());
557 template <
class T0,
class T1,
class T2,
class T3,
class T4,
class T5>
558 query&
in(
const T0 kv0,
const T1 kv1,
const T2 kv2,
const T3 kv3,
559 const T4 kv4,
const T5 kv5)
561 addSeekKeyValue(lexical_cast(kv0).
c_str());
562 addSeekKeyValue(lexical_cast(kv1).
c_str());
563 addSeekKeyValue(lexical_cast(kv2).
c_str());
564 addSeekKeyValue(lexical_cast(kv3).
c_str());
565 addSeekKeyValue(lexical_cast(kv4).
c_str());
566 addSeekKeyValue(lexical_cast(kv5).
c_str());
570 template <
class T0,
class T1,
class T2,
class T3,
class T4>
571 query&
in(
const T0 kv0,
const T1 kv1,
const T2 kv2,
const T3 kv3,
574 addSeekKeyValue(lexical_cast(kv0).
c_str());
575 addSeekKeyValue(lexical_cast(kv1).
c_str());
576 addSeekKeyValue(lexical_cast(kv2).
c_str());
577 addSeekKeyValue(lexical_cast(kv3).
c_str());
578 addSeekKeyValue(lexical_cast(kv4).
c_str());
582 template <
class T0,
class T1,
class T2,
class T3>
583 query&
in(
const T0 kv0,
const T1 kv1,
const T2 kv2,
const T3 kv3)
585 addSeekKeyValue(lexical_cast(kv0).
c_str());
586 addSeekKeyValue(lexical_cast(kv1).
c_str());
587 addSeekKeyValue(lexical_cast(kv2).
c_str());
588 addSeekKeyValue(lexical_cast(kv3).
c_str());
592 template <
class T0,
class T1,
class T2>
593 query&
in(
const T0 kv0,
const T1 kv1,
const T2 kv2)
595 addSeekKeyValue(lexical_cast(kv0).
c_str());
596 addSeekKeyValue(lexical_cast(kv1).
c_str());
597 addSeekKeyValue(lexical_cast(kv2).
c_str());
601 template <
class T0,
class T1>
query&
in(
const T0 kv0,
const T1 kv1)
603 addSeekKeyValue(lexical_cast(kv0).
c_str());
604 addSeekKeyValue(lexical_cast(kv1).
c_str());
610 addSeekKeyValue(lexical_cast(kv0).
c_str());
614 static query* create();
618 int DLLLIB makeSupplyValues(
const _TCHAR* values[],
int size,
619 const _TCHAR* value,
const _TCHAR* value1 = NULL,
620 const _TCHAR* value2 = NULL,
const _TCHAR* value3 = NULL,
621 const _TCHAR* value4 = NULL,
const _TCHAR* value5 = NULL,
622 const _TCHAR* value6 = NULL,
const _TCHAR* value7 = NULL,
623 const _TCHAR* value8 = NULL,
const _TCHAR* value9 = NULL,
624 const _TCHAR* value10 = NULL);
627 bool DLLLIB
supplyValues(pq_handle& filter,
const _TCHAR* values[],
int size);
628 bool DLLLIB
supplyValue(pq_handle& filter,
int index,
const _TCHAR* v);
629 bool DLLLIB
supplyValue(pq_handle& filter,
int index,
short v);
630 bool DLLLIB
supplyValue(pq_handle& filter,
int index,
int v);
631 bool DLLLIB
supplyValue(pq_handle& filter,
int index, __int64 v);
632 bool DLLLIB
supplyValue(pq_handle& filter,
int index,
float v);
633 bool DLLLIB
supplyValue(pq_handle& filter,
int index,
double v);
641 #pragma warning(default : 4251)
649 #endif // BZS_DB_PROTOCOL_TDAP_CLIENT_TABLE_H
query & in(const T0 kv0, const T1 kv1, const T2 kv2, const T3 kv3, const T4 kv4)
Definition: table.h:571
const _TCHAR * protocol(const _TCHAR *uri)
Definition: uri.h:42
combineType
Definition: tdapSchema.h:815
query()
Definition: table.h:451
query(const query &r)
Definition: table.h:452
int onInsertBefore()
Definition: table.h:150
const tabledef * tableDef() const
Definition: table.h:168
pq_handle setQuery(table_ptr &tb, const queryBase &q, bool serverPrepare=false)
Definition: trdboostapi.h:544
void writeRecordData()
Definition: table.h:140
クエリー(フィルター)作成の補助をするためのベースクラス
Definition: table.h:314
query & in(const T0 kv0, const T1 kv1)
Definition: table.h:601
eFindType
Definition: nsTable.h:56
const char * getFVstr(const char *fieldName)
Definition: table.h:258
データベースアクセス基本クラス (nocopyable)
Definition: nsDatabase.h:55
query & where(const _TCHAR *name, const _TCHAR *qlogic, T value)
Definition: table.h:499
フィールドコレクションクラス
Definition: fields.h:224
eOptimize
クエリーの実行時に行われる最適化条件をセットします。
Definition: table.h:326
findIterator find(table_ptr tb, const char_td keynum, const Q &q, const T0 kv0, const T1 kv1, const T2 kv2, const T3 kv3, const T4 kv4, const T5 kv5, const T6 kv6, const T7 kv7)
Definition: trdboostapi.h:569
query & reset()
Definition: table.h:456
query & in(const T0 kv0, const T1 kv1, const T2 kv2, const T3 kv3, const T4 kv4, const T5 kv5, const T6 kv6)
Definition: table.h:544
bool DLLLIB supplyValues(pq_handle &filter, const _TCHAR *values[], int size)
eFindType
findオペレーションで検索の方向を示すタイプ
Definition: nsTable.h:56
テーブルアクセスクラス (nocopyable)
Definition: table.h:89
query & in(const T0 kv0, const T1 kv1, const T2 kv2, const T3 kv3, const T4 kv4, const T5 kv5, const T6 kv6, const T7 kv7)
Definition: table.h:529
int onUpdateBefore()
Definition: table.h:145
テーブルアクセスの基本クラス (abstruct nocopyable)
Definition: nsTable.h:44
void setFV(const _TCHAR *fieldName, const char *data)
Definition: table.h:265
query & select(const _TCHAR *name, const _TCHAR *name1=NULL, const _TCHAR *name2=NULL, const _TCHAR *name3=NULL, const _TCHAR *name4=NULL, const _TCHAR *name5=NULL, const _TCHAR *name6=NULL, const _TCHAR *name7=NULL, const _TCHAR *name8=NULL, const _TCHAR *name9=NULL, const _TCHAR *name10=NULL)
Definition: table.h:462
query & in(const T0 kv0, const T1 kv1, const T2 kv2)
Definition: table.h:593
fielddef のコレクションクラス
Definition: field.h:73
query & in(const T0 kv0, const T1 kv1, const T2 kv2, const T3 kv3)
Definition: table.h:583
query & in(const T0 kv0)
Definition: table.h:608
グルーピング レコード数カウンター
Definition: groupQuery.h:229
create tableで使用するキーセグメント定義構造体
Definition: tdapSchema.h:108
フィールドコレクションのベースクラス
Definition: fields.h:123
fieldsBase row
Definition: fields.h:220
bool DLLLIB supplyValue(pq_handle &filter, int index, const _TCHAR *v)
query & and_(const _TCHAR *name, const _TCHAR *qlogic, T value)
Definition: table.h:506
読み取り用クエリー
Definition: table.h:448
const char * getFVstr(short index)
Definition: table.h:257
データベースアクセスクラス
Definition: database.h:59
query & in(const T0 kv0, const T1 kv1, const T2 kv2, const T3 kv3, const T4 kv4, const T5 kv5)
Definition: table.h:558
void setFV(short index, const char *data)
Definition: table.h:264
virtual void setNoUpdateTimeStamp(bool v)
Definition: table.h:163
query & or_(const _TCHAR *name, const _TCHAR *qlogic, T value)
Definition: table.h:517
pq_handle prepare(const queryBase *query, bool serverPrepare=false)
Definition: table.h:206
const _TCHAR * c_str(const btrDate &d)
Definition: btrDate.h:207
bool valiableFormatType() const
Definition: table.h:174
bool blobFieldUsed() const
Definition: table.h:179
const tabledef ** tableDefPtr() const
Definition: table.h:169
テーブル定義構造体
Definition: tdapSchema.h:660
virtual ~query()
Definition: table.h:454