transactd 1.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (218) hide show
  1. checksums.yaml +7 -0
  2. data/BUILD_UNIX-JA +174 -0
  3. data/BUILD_WIN-JA +256 -0
  4. data/CMakeLists.txt +96 -0
  5. data/COPYING +339 -0
  6. data/README +406 -0
  7. data/README-JA +424 -0
  8. data/bin/common/tdclc_32_1_0.dll +0 -0
  9. data/bin/common/tdclc_64_1_0.dll +0 -0
  10. data/build/common/check_for_link_iconv.cmake +73 -0
  11. data/build/common/copyifgreater.cmd +30 -0
  12. data/build/common/copyifgreater.js +290 -0
  13. data/build/common/get_boost_libs.cmake +106 -0
  14. data/build/common/get_ruby_path.cmake +115 -0
  15. data/build/common/options.cmake +127 -0
  16. data/build/common/smart_install.cmake +263 -0
  17. data/build/common/system.cmake +122 -0
  18. data/build/common/transactd.rc.in +52 -0
  19. data/build/common/transactd_cl_common.cmake +101 -0
  20. data/build/common/transactd_cl_output.cmake +93 -0
  21. data/build/common/transactd_common.cmake +237 -0
  22. data/build/common/transactd_required.cmake +28 -0
  23. data/build/swig/ruby/generate.cmake.in +35 -0
  24. data/build/swig/ruby/generate.cmd.in +19 -0
  25. data/build/swig/ruby/ruby.swg +101 -0
  26. data/build/swig/tdcl.i +188 -0
  27. data/build/tdclc/BUILDNUMBER.txt +1 -0
  28. data/build/tdclc/CMakeLists.txt +170 -0
  29. data/build/tdclc/tdclc_32.cbproj +181 -0
  30. data/build/tdclc/tdclc_64.cbproj +205 -0
  31. data/build/tdclcpp/BUILDNUMBER.txt +1 -0
  32. data/build/tdclcpp/CMakeLists.txt +142 -0
  33. data/build/tdclcpp/tdclcpp_bcb_32.cbproj +239 -0
  34. data/build/tdclcpp/tdclcpp_bcb_64.cbproj +304 -0
  35. data/build/tdclrb/BUILDNUMBER.txt +1 -0
  36. data/build/tdclrb/CMakeLists.txt +258 -0
  37. data/build/tdclrb/GEM_VERSION +3 -0
  38. data/build/tdclrb/bldgem/extconf.rb +123 -0
  39. data/build/tdclrb/gem/INSTALLLOG.win32 +9 -0
  40. data/build/tdclrb/gem/Makefile.win32-VS +65 -0
  41. data/build/tdclrb/gem/Makefile.win32-prebuilt +48 -0
  42. data/build/tdclrb/gem/detect.rb +31 -0
  43. data/build/tdclrb/gem/helper.rb +113 -0
  44. data/build/tdclrb/gem/transactd.rb +22 -0
  45. data/build/tdclrb/gem_output.cmake +44 -0
  46. data/source/bzs/db/IBlobBuffer.h +51 -0
  47. data/source/bzs/db/blobBuffer.h +177 -0
  48. data/source/bzs/db/blobStructs.h +85 -0
  49. data/source/bzs/db/engine/mysql/IReadRecords.h +52 -0
  50. data/source/bzs/db/engine/mysql/bookmark.h +195 -0
  51. data/source/bzs/db/engine/mysql/database.cpp +1882 -0
  52. data/source/bzs/db/engine/mysql/database.h +465 -0
  53. data/source/bzs/db/engine/mysql/dbManager.cpp +303 -0
  54. data/source/bzs/db/engine/mysql/dbManager.h +143 -0
  55. data/source/bzs/db/engine/mysql/errorMessage.cpp +75 -0
  56. data/source/bzs/db/engine/mysql/errorMessage.h +43 -0
  57. data/source/bzs/db/engine/mysql/fieldAccess.h +158 -0
  58. data/source/bzs/db/engine/mysql/mydebuglog.cpp +349 -0
  59. data/source/bzs/db/engine/mysql/mydebuglog.h +89 -0
  60. data/source/bzs/db/engine/mysql/mysqlInternal.h +171 -0
  61. data/source/bzs/db/engine/mysql/mysqlThd.cpp +169 -0
  62. data/source/bzs/db/engine/mysql/mysqlThd.h +35 -0
  63. data/source/bzs/db/engine/mysql/percentageKey.h +260 -0
  64. data/source/bzs/db/protocol/ICommandExecuter.h +49 -0
  65. data/source/bzs/db/protocol/hs/hsCommandExecuter.cpp +689 -0
  66. data/source/bzs/db/protocol/hs/hsCommandExecuter.h +228 -0
  67. data/source/bzs/db/protocol/tdap/btrDate.cpp +437 -0
  68. data/source/bzs/db/protocol/tdap/btrDate.h +227 -0
  69. data/source/bzs/db/protocol/tdap/client/bulkInsert.h +127 -0
  70. data/source/bzs/db/protocol/tdap/client/client.cpp +106 -0
  71. data/source/bzs/db/protocol/tdap/client/client.h +292 -0
  72. data/source/bzs/db/protocol/tdap/client/connMgr.cpp +144 -0
  73. data/source/bzs/db/protocol/tdap/client/connMgr.h +82 -0
  74. data/source/bzs/db/protocol/tdap/client/database.cpp +863 -0
  75. data/source/bzs/db/protocol/tdap/client/database.h +118 -0
  76. data/source/bzs/db/protocol/tdap/client/databaseFactory.cpp +100 -0
  77. data/source/bzs/db/protocol/tdap/client/dbDef.cpp +1640 -0
  78. data/source/bzs/db/protocol/tdap/client/dbDef.h +135 -0
  79. data/source/bzs/db/protocol/tdap/client/dllmain.cpp +434 -0
  80. data/source/bzs/db/protocol/tdap/client/errorMessage.cpp +92 -0
  81. data/source/bzs/db/protocol/tdap/client/errorMessage_ja.cpp +98 -0
  82. data/source/bzs/db/protocol/tdap/client/fieldDDF.cpp +174 -0
  83. data/source/bzs/db/protocol/tdap/client/fieldDDF.h +91 -0
  84. data/source/bzs/db/protocol/tdap/client/fileDDF.cpp +140 -0
  85. data/source/bzs/db/protocol/tdap/client/fileDDF.h +86 -0
  86. data/source/bzs/db/protocol/tdap/client/filter.cpp +527 -0
  87. data/source/bzs/db/protocol/tdap/client/filter.h +154 -0
  88. data/source/bzs/db/protocol/tdap/client/indexDDF.cpp +137 -0
  89. data/source/bzs/db/protocol/tdap/client/indexDDF.h +84 -0
  90. data/source/bzs/db/protocol/tdap/client/nsDatabase.cpp +724 -0
  91. data/source/bzs/db/protocol/tdap/client/nsDatabase.h +123 -0
  92. data/source/bzs/db/protocol/tdap/client/nsTable.cpp +899 -0
  93. data/source/bzs/db/protocol/tdap/client/nsTable.h +199 -0
  94. data/source/bzs/db/protocol/tdap/client/request.h +198 -0
  95. data/source/bzs/db/protocol/tdap/client/sharedData.cpp +58 -0
  96. data/source/bzs/db/protocol/tdap/client/sharedData.h +56 -0
  97. data/source/bzs/db/protocol/tdap/client/sqlBuilder.cpp +574 -0
  98. data/source/bzs/db/protocol/tdap/client/sqlBuilder.h +53 -0
  99. data/source/bzs/db/protocol/tdap/client/stringConverter.h +627 -0
  100. data/source/bzs/db/protocol/tdap/client/table.cpp +2613 -0
  101. data/source/bzs/db/protocol/tdap/client/table.h +221 -0
  102. data/source/bzs/db/protocol/tdap/client/trdboostapi.h +1096 -0
  103. data/source/bzs/db/protocol/tdap/client/trdboostapiInternal.h +179 -0
  104. data/source/bzs/db/protocol/tdap/client/trdclcppautolink.h +40 -0
  105. data/source/bzs/db/protocol/tdap/client/trnsctcl.def +11 -0
  106. data/source/bzs/db/protocol/tdap/myDateTime.cpp +500 -0
  107. data/source/bzs/db/protocol/tdap/mysql/characterset.cpp +184 -0
  108. data/source/bzs/db/protocol/tdap/mysql/characterset.h +60 -0
  109. data/source/bzs/db/protocol/tdap/mysql/databaseSchema.cpp +284 -0
  110. data/source/bzs/db/protocol/tdap/mysql/databaseSchema.h +53 -0
  111. data/source/bzs/db/protocol/tdap/mysql/debuglog.cpp +383 -0
  112. data/source/bzs/db/protocol/tdap/mysql/debuglog.h +106 -0
  113. data/source/bzs/db/protocol/tdap/mysql/recordsetReader.h +680 -0
  114. data/source/bzs/db/protocol/tdap/mysql/request.h +202 -0
  115. data/source/bzs/db/protocol/tdap/mysql/tdapCommandExecuter.cpp +1020 -0
  116. data/source/bzs/db/protocol/tdap/mysql/tdapCommandExecuter.h +141 -0
  117. data/source/bzs/db/protocol/tdap/tdapRequest.h +190 -0
  118. data/source/bzs/db/protocol/tdap/tdapSchema.cpp +295 -0
  119. data/source/bzs/db/protocol/tdap/tdapSchema.h +558 -0
  120. data/source/bzs/db/protocol/tdap/tdapcapi.h +423 -0
  121. data/source/bzs/db/transactd/appBuilderImple.h +55 -0
  122. data/source/bzs/db/transactd/appModule.cpp +183 -0
  123. data/source/bzs/db/transactd/appModule.h +80 -0
  124. data/source/bzs/db/transactd/connManager.cpp +201 -0
  125. data/source/bzs/db/transactd/connManager.h +60 -0
  126. data/source/bzs/db/transactd/connectionRecord.h +69 -0
  127. data/source/bzs/db/transactd/transactd.cpp +325 -0
  128. data/source/bzs/env/compiler.h +135 -0
  129. data/source/bzs/env/crosscompile.cpp +130 -0
  130. data/source/bzs/env/crosscompile.h +150 -0
  131. data/source/bzs/env/fileopen.h +36 -0
  132. data/source/bzs/env/mbcswchrLinux.cpp +40 -0
  133. data/source/bzs/env/mbcswchrLinux.h +88 -0
  134. data/source/bzs/env/tstring.h +183 -0
  135. data/source/bzs/example/changeSchema.cpp +117 -0
  136. data/source/bzs/example/changeSchema_c.cpp +78 -0
  137. data/source/bzs/example/connection_pool_c.cpp +171 -0
  138. data/source/bzs/example/createDatabase.cpp +305 -0
  139. data/source/bzs/example/createDatabase_c.cpp +202 -0
  140. data/source/bzs/example/deleteRecords.cpp +87 -0
  141. data/source/bzs/example/deleteRecords_c.cpp +57 -0
  142. data/source/bzs/example/dropDatabase.cpp +59 -0
  143. data/source/bzs/example/dropDatabase_c.cpp +34 -0
  144. data/source/bzs/example/insertRecords.cpp +212 -0
  145. data/source/bzs/example/insertRecords_c.cpp +153 -0
  146. data/source/bzs/example/readRecords.cpp +141 -0
  147. data/source/bzs/example/readRecords_c.cpp +107 -0
  148. data/source/bzs/example/updateRecords.cpp +99 -0
  149. data/source/bzs/example/updateRecords_c.cpp +71 -0
  150. data/source/bzs/example/update_with_transaction.cpp +104 -0
  151. data/source/bzs/example/update_with_transaction_c.cpp +80 -0
  152. data/source/bzs/netsvc/client/tcpClient.cpp +226 -0
  153. data/source/bzs/netsvc/client/tcpClient.h +489 -0
  154. data/source/bzs/netsvc/server/IAppModule.h +94 -0
  155. data/source/bzs/netsvc/server/iserver.h +65 -0
  156. data/source/bzs/netsvc/server/serverCpt.cpp +522 -0
  157. data/source/bzs/netsvc/server/serverCpt.h +88 -0
  158. data/source/bzs/netsvc/server/serverPipe.cpp +705 -0
  159. data/source/bzs/netsvc/server/serverPipe.h +96 -0
  160. data/source/bzs/netsvc/server/serverTpool.cpp +416 -0
  161. data/source/bzs/netsvc/server/serverTpool.h +84 -0
  162. data/source/bzs/rtl/benchmark.cpp +96 -0
  163. data/source/bzs/rtl/benchmark.h +65 -0
  164. data/source/bzs/rtl/datetime.cpp +375 -0
  165. data/source/bzs/rtl/datetime.h +53 -0
  166. data/source/bzs/rtl/debuglog.cpp +106 -0
  167. data/source/bzs/rtl/debuglog.h +97 -0
  168. data/source/bzs/rtl/exception.h +116 -0
  169. data/source/bzs/rtl/stl_uty.cpp +35 -0
  170. data/source/bzs/rtl/stl_uty.h +29 -0
  171. data/source/bzs/rtl/stringBuffers.cpp +101 -0
  172. data/source/bzs/rtl/stringBuffers.h +58 -0
  173. data/source/bzs/rtl/strtrim.cpp +135 -0
  174. data/source/bzs/rtl/strtrim.h +46 -0
  175. data/source/bzs/test/tdclatl/bench_tdclatl.js +445 -0
  176. data/source/bzs/test/tdclrb/bench_tdclcpp.rb +375 -0
  177. data/source/bzs/test/tdclrb/prepare.rb +226 -0
  178. data/source/bzs/test/tdclrb/transactd_datetime_spec.rb +172 -0
  179. data/source/bzs/test/tdclrb/transactd_kanjischema_spec.rb +208 -0
  180. data/source/bzs/test/tdclrb/transactd_spec.rb +1536 -0
  181. data/source/bzs/test/transactdBench/transactdBench.cpp +430 -0
  182. data/source/bzs/test/transactdBench/transactdBench2.cpp +342 -0
  183. data/source/bzs/test/trdclengn/test_trdclengn.cpp +2030 -0
  184. data/source/global/tdclatl/Database.cpp +503 -0
  185. data/source/global/tdclatl/Database.h +139 -0
  186. data/source/global/tdclatl/DbDef.cpp +242 -0
  187. data/source/global/tdclatl/DbDef.h +79 -0
  188. data/source/global/tdclatl/Field.cpp +92 -0
  189. data/source/global/tdclatl/Field.h +59 -0
  190. data/source/global/tdclatl/FieldDef.cpp +238 -0
  191. data/source/global/tdclatl/FieldDef.h +87 -0
  192. data/source/global/tdclatl/Flags.cpp +111 -0
  193. data/source/global/tdclatl/Flags.h +55 -0
  194. data/source/global/tdclatl/KeyDef.cpp +51 -0
  195. data/source/global/tdclatl/KeyDef.h +55 -0
  196. data/source/global/tdclatl/KeySegment.cpp +55 -0
  197. data/source/global/tdclatl/Table.cpp +600 -0
  198. data/source/global/tdclatl/Table.h +144 -0
  199. data/source/global/tdclatl/TableDef.cpp +291 -0
  200. data/source/global/tdclatl/TableDef.h +86 -0
  201. data/source/global/tdclatl/TdVersion.cpp +74 -0
  202. data/source/global/tdclatl/TdVersion.h +54 -0
  203. data/source/global/tdclatl/_IDatabaseEvents_CP.h +113 -0
  204. data/source/global/tdclatl/dllmain.cpp +30 -0
  205. data/source/global/tdclatl/dllmain.h +27 -0
  206. data/source/global/tdclatl/keySegment.h +57 -0
  207. data/source/global/tdclatl/resource.h +0 -0
  208. data/source/global/tdclatl/stdafx.cpp +2 -0
  209. data/source/global/tdclatl/stdafx.h +25 -0
  210. data/source/global/tdclatl/targetver.h +4 -0
  211. data/source/global/tdclatl/tdclatl.cpp +68 -0
  212. data/source/global/tdclatl/tdclatl.def +10 -0
  213. data/source/global/tdclatl/tdclatl.idl +1035 -0
  214. data/source/linux/charsetConvert.h +112 -0
  215. data/source/linux/linuxTypes.h +33 -0
  216. data/source/linux/tchar.h +428 -0
  217. data/transactd.gemspec +97 -0
  218. metadata +267 -0
@@ -0,0 +1,527 @@
1
+ /* =================================================================
2
+ Copyright (C) 2000-2013 BizStation Corp All rights reserved.
3
+
4
+ This program is free software; you can redistribute it and/or
5
+ modify it under the terms of the GNU General Public License
6
+ as published by the Free Software Foundation; either version 2
7
+ of the License, or (at your option) any later version.
8
+
9
+ This program is distributed in the hope that it will be useful,
10
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
11
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
+ GNU General Public License for more details.
13
+
14
+ You should have received a copy of the GNU General Public License
15
+ along with this program; if not, write to the Free Software
16
+ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
17
+ 02111-1307, USA.
18
+ ================================================================= */
19
+ #include <bzs/env/tstring.h>
20
+ #pragma hdrstop
21
+
22
+ #include "filter.h"
23
+ #pragma option -w-ucp
24
+
25
+ #pragma package(smart_init)
26
+
27
+ namespace bzs
28
+ {
29
+ namespace db
30
+ {
31
+ namespace protocol
32
+ {
33
+ namespace tdap
34
+ {
35
+ namespace client
36
+ {
37
+
38
+ inline ushort_td varlenForFilter(const fielddef& fd)
39
+ {
40
+ if (((fd.type >= ft_myvarchar) && (fd.type <= ft_mywvarbinary)) || fd.type == ft_lstring)
41
+ return fd.len < 256 ? 1 : 2;
42
+ else if ((fd.type == ft_myblob) || (fd.type == ft_mytext))
43
+ return fd.len - 8;
44
+ return 0;
45
+ }
46
+
47
+ /** Length of compare
48
+ * if part of string or zstring then return strlen.
49
+ */
50
+ inline uint_td compDataLen(const fielddef& fd, const uchar_td* ptr, bool part)
51
+ {
52
+ uint_td length = fd.keyDataLen(ptr);
53
+ if (part)
54
+ {
55
+ if ((fd.type == ft_string) || (fd.type == ft_zstring) || (fd.type == ft_note))
56
+ length = (uint_td)strlen((const char*)ptr);
57
+ else if ((fd.type == ft_wstring) || (fd.type == ft_wzstring))
58
+ length = (uint_td)wcslen((const wchar_t*)ptr);
59
+ }
60
+ return length;
61
+ }
62
+
63
+ /** copy data for select comp
64
+ */
65
+ inline ushort_td copyForCompare(const fielddef& fd, uchar_td* to, const uchar_td* from, bool part)
66
+ {
67
+ ushort_td varlen = varlenForFilter(fd);
68
+ int copylen = compDataLen(fd, from, part);
69
+ if (varlen)
70
+ memcpy(to, from, varlen);
71
+ memcpy(to + varlen, fd.keyData(from), copylen);
72
+ return copylen + varlen;
73
+ }
74
+
75
+ filter::filter(table* pBao)
76
+ {
77
+ m_pFilter = NULL;
78
+ m_pEntendBuf = NULL;
79
+ m_pEntendBuflen = 0;
80
+
81
+ init(pBao);
82
+
83
+ }
84
+
85
+ void filter::init(table* pBao)
86
+ {
87
+ m_tb = pBao;
88
+ strcpy(&m_PosType[0], "UC");
89
+ m_RejectCount = 65000;
90
+ m_iRecordCount = 1;
91
+ m_iFieldCount = 1;
92
+ memset(m_iFieldLen, 0, 255 * sizeof(ushort_td));
93
+ memset(m_iFieldOffset, 0, 255 * sizeof(ushort_td));
94
+ m_iFieldLen[0] = (ushort_td) m_tb->tableDef()->maxRecordLen;
95
+ m_iFieldOffset[0] = 0;
96
+ }
97
+
98
+ filter::~filter()
99
+ {
100
+ if (m_pFilter != NULL)
101
+ delete[]m_pFilter; ;
102
+ if (m_pEntendBuf != NULL)
103
+ free(m_pEntendBuf);
104
+
105
+ }
106
+
107
+ ushort_td filter::GetFieldLen(int index) {return m_iFieldLen[index];
108
+
109
+ }
110
+
111
+ ushort_td filter::GetFieldOffset(int index) {return m_iFieldOffset[index];}
112
+
113
+ _TCHAR* filter::filterStr() {return m_pFilter;}
114
+
115
+ bool filter::GetPosType()
116
+ {
117
+
118
+ if (strcmp(m_PosType, "UC") == 0)
119
+ return false;
120
+ else
121
+ return true;
122
+ }
123
+
124
+ void filter::SetPosType(bool getnext)
125
+ {
126
+
127
+ if (getnext)
128
+ strcpy(&m_PosType[0], "EG");
129
+ else
130
+ strcpy(&m_PosType[0], "UC");
131
+ if (m_pEntendBuf)
132
+ memcpy((void*)((char*)m_pEntendBuf + 2), &m_PosType[0], 2);
133
+
134
+ }
135
+
136
+ void filter::WriteBuffer() {memcpy(m_tb->dataBak(), m_pEntendBuf, m_pEntendBuflen);}
137
+
138
+ bool filter::setFilter(const _TCHAR* str, ushort_td RejectCount, ushort_td CashCount)
139
+ {
140
+
141
+ _TCHAR* NewPointer;
142
+
143
+ BFilter* itm;
144
+ BFilter* Olditm = NULL;
145
+
146
+ bool joint = false;
147
+ bool cmpfield;
148
+ ushort_td Oldlen;
149
+ short OldfieldNum = -1;
150
+ BFilterHeader* FilterHead;
151
+ ushort_td LogicalCount = 0;
152
+ BFilterDisc* disc;
153
+
154
+ m_RejectCount = RejectCount;
155
+ m_iRecordCount = CashCount;
156
+
157
+ if (m_pFilter)
158
+ delete[]m_pFilter;
159
+ size_t size = _tcslen(str) + 2;
160
+ m_pFilter = new _TCHAR[size];
161
+ if (m_pFilter == NULL)
162
+ return false;
163
+ memset(m_pFilter, 0, size * sizeof(_TCHAR));
164
+ _tcscpy(m_pFilter, str);
165
+
166
+ int sDataBufSize = 8192;
167
+ if (m_pEntendBuf == NULL)
168
+ m_pEntendBuf = malloc(sDataBufSize);
169
+ else
170
+ memset(m_pEntendBuf, 0, sDataBufSize);
171
+
172
+ if (m_pEntendBuf == NULL)
173
+ return false;
174
+
175
+ itm = (BFilter*)((char*)m_pEntendBuf + 8);
176
+
177
+ NewPointer = m_pFilter;
178
+
179
+ m_FieldSelected = false;
180
+ if (m_pFilter[0] == '*')
181
+ LogicalCount = 0;
182
+ else
183
+ {
184
+
185
+ // -------------------------------------------------------------
186
+ // SELECT
187
+ if (_tcsstr(m_pFilter, _T("SELECT ")) == NewPointer)
188
+ {
189
+ if (!MakeFieldSelect(&NewPointer))
190
+ return false;
191
+ }
192
+
193
+ while (1)
194
+ {
195
+ cmpfield = false;
196
+
197
+ // -------------------------------------------------------------
198
+ // Get filed number
199
+ // -------------------------------------------------------------
200
+ short fieldNum = GetField(&NewPointer);
201
+ if (fieldNum == -1)
202
+ break;
203
+
204
+ LogicalCount++;
205
+ fielddef* fd = &m_tb->tableDef()->fieldDefs[fieldNum];
206
+ itm->Type = fd->type;
207
+ itm->Len = fd->len;
208
+ itm->Pos = fd->pos;
209
+
210
+ // -------------------------------------------------------------
211
+ // Get logical type
212
+ // -------------------------------------------------------------
213
+ itm->CompType = GetCompType(&NewPointer);
214
+ if (itm->CompType == 255)
215
+ return false;
216
+
217
+ // -------------------------------------------------------------
218
+ // Get compare value
219
+ // if [fieldName] then comapre as field value
220
+ // -------------------------------------------------------------
221
+ _TCHAR* start = NewPointer;
222
+ if (!GetCompStr(&NewPointer))
223
+ return false;
224
+ if (NewPointer == NULL)
225
+ return false;
226
+
227
+ int offset = 0;
228
+ if (start[0] == '[')
229
+ {
230
+ start++;
231
+ int num = m_tb->fieldNumByName(start);
232
+ if (num != -1)
233
+ {
234
+ itm->Data = m_tb->tableDef()->fieldDefs[num].pos;
235
+ itm->CompType |= CMPLOGICAL_FIELD;
236
+ cmpfield = true;
237
+ }
238
+ }
239
+ else
240
+ {
241
+
242
+ bool isPart = false;
243
+ if (start[0] == '\'')
244
+ {// string
245
+ start++; // erase front '
246
+ int len = (ushort_td) _tcslen(start);
247
+ start[--len] = 0x00; // erase after '
248
+ isPart = (start[len - 1] == '*');
249
+ if (isPart)
250
+ start[--len] = 0x00;
251
+
252
+ }
253
+ m_tb->setFV(fieldNum, start);
254
+ itm->Len =
255
+ copyForCompare(*fd, (uchar_td*)(&itm->Data),
256
+ (const uchar_td*)m_tb->fieldPtr(fieldNum), isPart);
257
+ if (!isPart && (fd->varLenBytes() || fd->blobLenBytes()))
258
+ itm->CompType |= CMPLOGICAL_VAR_COMP_ALL; //match complate
259
+ offset = itm->Len - 2;
260
+ }
261
+
262
+ // LogicalType
263
+ itm->LogicalType = GetLogical(&NewPointer);
264
+ // ------------------------------------------------------------
265
+ // chain befor field
266
+ // ------------------------------------------------------------
267
+ Oldlen = fd->len;
268
+
269
+ if ((joint == true) && (OldfieldNum + 1 == fieldNum) && (itm->CompType == 1) &&
270
+ (cmpfield == false) && (itm->Len == fd->len) && (itm->Type != 11) &&
271
+ (varlenForFilter(*fd) == 0))
272
+ {
273
+ Olditm->LogicalType = itm->LogicalType;
274
+ Oldlen = itm->Len;
275
+ memcpy((void*)((char*)(&Olditm->Data) + Olditm->Len), &itm->Data, itm->Len);
276
+ Olditm->Len += Oldlen;
277
+ Oldlen = Olditm->Len;
278
+ itm = Olditm;
279
+ itm->Type = 0; // comapre as string
280
+
281
+ offset = itm->Len - 2;
282
+ LogicalCount--;
283
+ }
284
+ if (itm->LogicalType != 0) // If zero then logical is end.
285
+ {
286
+ // ------------------------------------------------------------
287
+ // Can it connect? not * and not zstring
288
+ // ------------------------------------------------------------
289
+ if ((itm->CompType == 1) && (itm->LogicalType == 1) && (cmpfield == false) &&
290
+ (itm->Len == Oldlen) && (itm->Type != 11) && (varlenForFilter(*fd) == 0))
291
+ joint = true;
292
+ else
293
+ joint = false;
294
+ Olditm = itm;
295
+ OldfieldNum = fieldNum;
296
+ }
297
+ // ------------------------------------------------------------
298
+ // move pointer
299
+ itm = (BFilter*)((char*)itm +sizeof(BFilter) + offset);
300
+ }
301
+ }
302
+ _tcscpy(m_pFilter, str);
303
+ // header
304
+ FilterHead = (BFilterHeader*) m_pEntendBuf;
305
+ FilterHead->BufLen = (ushort_td)((char*)itm - (char*)m_pEntendBuf + 4 + (m_iFieldCount * 4));
306
+ memcpy(FilterHead->PosType, m_PosType, 2);
307
+ FilterHead->RejectCount = m_RejectCount;
308
+ FilterHead->LogicalCount = LogicalCount;
309
+
310
+ // descipter
311
+ disc = (BFilterDisc*)itm;
312
+ disc->iRecordCount = m_iRecordCount;
313
+ disc->iFieldCount = m_iFieldCount;
314
+ int RecordSize = 0;
315
+ for (int i = 0; i < m_iFieldCount; i++)
316
+ {
317
+ disc->iSelectFields[i].iFieldLen = m_iFieldLen[i];
318
+ disc->iSelectFields[i].iFieldOffset = m_iFieldOffset[i];
319
+ RecordSize += m_iFieldLen[i];
320
+ }
321
+ m_iRecordCountDirect = &disc->iRecordCount;
322
+ m_pEntendBuflen = FilterHead->BufLen;
323
+ if (disc->iRecordCount == 0)
324
+ {
325
+ disc->iRecordCount = (ushort_td)(57000 / (RecordSize + 6));
326
+ }
327
+ m_ExDataBufLen = (ushort_td)((disc->iRecordCount * (RecordSize + 6)) + 2);
328
+
329
+ if ((ushort_td)m_ExDataBufLen < m_pEntendBuflen)
330
+ m_ExDataBufLen = m_pEntendBuflen;
331
+
332
+ uint_td len;
333
+ if ((m_FieldSelected == false) && !m_tb->valiableFormatType())
334
+ len = m_ExDataBufLen;
335
+ else
336
+ len = (uint_td)(m_ExDataBufLen + m_tb->buflen());
337
+
338
+ if (m_tb->buflen() < len)
339
+ {
340
+ m_tb->setDataBak((void*) realloc(m_tb->dataBak(), len));
341
+ m_tb->setData(m_tb->dataBak());
342
+
343
+ if (m_tb->data() == NULL)
344
+ return false;
345
+
346
+ }
347
+ return true;
348
+ }
349
+
350
+ bool filter::MakeFieldSelect(_TCHAR** str)
351
+ {
352
+ _TCHAR* p;
353
+ _TCHAR* ret;
354
+ _TCHAR* point[255];
355
+ ushort_td index = 0;
356
+ _TCHAR FiledName[20] = {0x00};
357
+
358
+ m_iFieldCount = 0;
359
+
360
+
361
+ *str += 7; // "select" length = 7
362
+ point[index] = *str;
363
+
364
+ ret = (_TCHAR*)_tcsmstr((_TUCHAR*)*str, (_TUCHAR*)_T(" "));
365
+ if (ret == NULL)
366
+ return false;
367
+ ret[0] = 0x00; // set null
368
+ *str = ret + 1;
369
+
370
+ index++;
371
+ p = (_TCHAR*)_tcsmstr((_TUCHAR*)point[index - 1], (_TUCHAR*)_T(",")) + 1;
372
+ point[index] = p;
373
+ p--;
374
+ while (p)
375
+ {
376
+ index++;
377
+ p = (_TCHAR*)_tcsmstr((_TUCHAR*)point[index - 1], (_TUCHAR*)_T(","));
378
+ if (p)
379
+ point[index] = p + 1;
380
+ else
381
+ break;
382
+
383
+ }
384
+ point[index] = ret + 1;
385
+ size_t n;
386
+ short FieldNum;
387
+ for (int i = 0; i < index; i++)
388
+ {
389
+ n = point[i + 1] - point[i] - 1;
390
+ _tcsncpy(FiledName, point[i], n);
391
+ FiledName[n] = 0x00;
392
+ FieldNum = m_tb->fieldNumByName(FiledName);
393
+ if (FieldNum < 0)
394
+ return false;
395
+ m_iFieldLen[i] = m_tb->tableDef()->fieldDefs[FieldNum].len;
396
+ m_iFieldOffset[i] = m_tb->tableDef()->fieldDefs[FieldNum].pos;
397
+ }
398
+ m_iFieldCount = index;
399
+ m_FieldSelected = true;
400
+
401
+ return true;
402
+ }
403
+
404
+ short filter::GetField(_TCHAR** str)
405
+ {
406
+ _TCHAR* ret;
407
+ _TCHAR FiledName[20] = {0x00};
408
+ int offset = 0;
409
+ // Get string that until next space.
410
+ if (*str[0] == '[')
411
+ {
412
+ offset = 1;
413
+ ret = (_TCHAR*)_tcsmstr((_TUCHAR*)*str, (_TUCHAR*) _T("]"));
414
+ }
415
+ else
416
+ ret = (_TCHAR*)_tcsmstr((_TUCHAR*)*str, (_TUCHAR*)_T(" "));
417
+
418
+ if (ret)
419
+ {
420
+ _tcsncpy(FiledName, *str + offset, ret - *str - offset);
421
+ *str = ret + 1 + offset;
422
+ return m_tb->fieldNumByName(FiledName);
423
+ }
424
+ else
425
+ return -1;
426
+ }
427
+
428
+ bool filter::GetCompStr(_TCHAR** str)
429
+ {
430
+ _TCHAR* ret;
431
+ int offset = 0;
432
+
433
+ // Get string that until next space.
434
+ if (*str[0] == _T('['))
435
+ {
436
+ offset = 1;
437
+ ret = _tcsstr(*str, _T("]"));
438
+ if (!ret)
439
+ return false;
440
+ }
441
+ else if (*str[0] == _T('\''))
442
+ { // find next '
443
+ ret = (_TCHAR*)_tcsmstr((_TUCHAR*)*str + 1, (_TUCHAR*)_T("\'"));
444
+
445
+ if (ret)
446
+ ret += 1;
447
+ else
448
+ return false;
449
+ }
450
+ else
451
+ ret = (_TCHAR*)_tcsmstr((_TUCHAR*)*str, (_TUCHAR*)_T(" "));
452
+
453
+ if (ret)
454
+ {
455
+ *ret = 0x00;
456
+ *str = ret + 1 + offset;
457
+
458
+ }
459
+ return true;
460
+ }
461
+
462
+ uchar_td filter::GetLogical(_TCHAR** str)
463
+ {
464
+ _TCHAR* ret;
465
+ _TCHAR LogicalStr[10] = {0x00};
466
+
467
+ // Get string that until next space.
468
+ ret = (_TCHAR*)_tcsmstr((_TUCHAR*)*str, (_TUCHAR*)_T(" "));
469
+ if (ret)
470
+ {
471
+ _tcsncpy(LogicalStr, *str, ret - *str);
472
+ _tcsmupr((_TUCHAR*)LogicalStr);
473
+ *str = ret + 1;
474
+ if (_tcscmp(LogicalStr, _T("AND")) == 0)
475
+ return (uchar_td)1;
476
+ else if (_tcscmp(LogicalStr, _T("OR")) == 0)
477
+ return (uchar_td)2;
478
+ else
479
+ return 0;
480
+ }
481
+ else
482
+ return 0;
483
+ }
484
+
485
+ uchar_td filter::GetCompType(_TCHAR** str)
486
+ {
487
+ _TCHAR* ret;
488
+ _TCHAR cmpstr[10] = {0x00};
489
+
490
+ // Get string that until next space.
491
+ ret = (_TCHAR*)_tcsmstr((_TUCHAR*)*str, (_TUCHAR*)_T(" "));
492
+ if (ret)
493
+ {
494
+ _tcsncpy(cmpstr, *str, ret - *str);
495
+ *str = ret + 1;
496
+ if (_tcscmp(cmpstr, _T("=")) == 0)
497
+ return (uchar_td)1;
498
+
499
+ if (_tcscmp(cmpstr, _T(">")) == 0)
500
+ return (uchar_td)2;
501
+
502
+ if (_tcscmp(cmpstr, _T("<")) == 0)
503
+ return (uchar_td)3;
504
+
505
+ if (_tcscmp(cmpstr, _T("<>")) == 0)
506
+ return (uchar_td)4;
507
+
508
+ if (_tcscmp(cmpstr, _T("=>")) == 0)
509
+ return (uchar_td)5;
510
+ if (_tcscmp(cmpstr, _T(">=")) == 0)
511
+ return (uchar_td)5;
512
+
513
+ if (_tcscmp(cmpstr, _T("=<")) == 0)
514
+ return (uchar_td)6;
515
+ if (_tcscmp(cmpstr, _T("<=")) == 0)
516
+ return (uchar_td)6;
517
+ return 255;
518
+ }
519
+ else
520
+ return 255;
521
+ }
522
+
523
+ }// namespace client
524
+ }// namespace tdap
525
+ }// namespace protocol
526
+ }// namespace db
527
+ }// namespace bzs
@@ -0,0 +1,154 @@
1
+ #ifndef BZS_DB_PROTOCOL_TDAP_CLIENT_FILTER_H
2
+ #define BZS_DB_PROTOCOL_TDAP_CLIENT_FILTER_H
3
+ /* =================================================================
4
+ Copyright (C) 2000-2013 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 "table.h"
22
+
23
+ namespace bzs
24
+ {
25
+ namespace db
26
+ {
27
+ namespace protocol
28
+ {
29
+ namespace tdap
30
+ {
31
+ namespace client
32
+ {
33
+
34
+
35
+ #pragma option -a-
36
+ pragma_pack1
37
+
38
+ struct BFilter
39
+ {
40
+ uchar_td Type;
41
+ ushort_td Len;
42
+ ushort_td Pos;
43
+ uchar_td CompType;
44
+ uchar_td LogicalType;
45
+ ushort_td Data;
46
+ };
47
+
48
+ struct BFilterHeader
49
+ {
50
+ ushort_td BufLen;
51
+ char PosType[2]; // "EG" or "UC"
52
+ ushort_td RejectCount;
53
+ ushort_td LogicalCount;
54
+ };
55
+
56
+ struct BSelectField
57
+ {
58
+ ushort_td iFieldLen;
59
+ ushort_td iFieldOffset;
60
+ };
61
+
62
+ struct BFilterDisc
63
+ {
64
+ ushort_td iRecordCount;
65
+ ushort_td iFieldCount;
66
+ BSelectField iSelectFields[255];
67
+ };
68
+
69
+ #pragma option -a
70
+ pragma_pop
71
+
72
+ class filter
73
+ {
74
+
75
+ table* m_tb;
76
+
77
+ //buffer
78
+ _TCHAR* m_pFilter;
79
+ void* m_pEntendBuf;
80
+ ushort_td m_pEntendBuflen;
81
+ uint_td m_ExDataBufLen;
82
+
83
+ //hedaer
84
+ ushort_td m_RejectCount;
85
+ char m_PosType[3]; // "EG" or "UC"
86
+
87
+ //tail
88
+ ushort_td m_iRecordCount;
89
+ ushort_td m_iFieldCount;
90
+
91
+ ushort_td* m_iRecordCountDirect;
92
+ //result
93
+ ushort_td m_iFieldLen[255];
94
+ ushort_td m_iFieldOffset[255];
95
+
96
+ bool GetCompStr(_TCHAR** str);
97
+ uchar_td GetLogical(_TCHAR** str);
98
+ uchar_td GetCompType(_TCHAR** str);
99
+ short GetField(_TCHAR** str);
100
+ ushort_td GetFieldLen(int index);
101
+ ushort_td GetFieldOffset(int index);
102
+ bool MakeFieldSelect(_TCHAR** str);
103
+
104
+ bool m_FieldSelected;
105
+
106
+ public:
107
+ filter(table* pBao);
108
+ ~filter();
109
+
110
+ bool posTypeNext() {return GetPosType();}
111
+
112
+ void setPosTypeNext(bool v) {SetPosType(v);}
113
+
114
+ uint_td exDataBufLen() const {return m_ExDataBufLen;}
115
+
116
+ ushort_td recordCount() const {return m_iRecordCount;}
117
+
118
+ void setRecordCount(ushort_td v) {m_iRecordCount = v;}
119
+
120
+ ushort_td fieldCount() const {return m_iFieldCount;}
121
+
122
+ void setFieldCount(ushort_td v) {m_iFieldCount = v;}
123
+
124
+ void* entendBuf() const {return m_pEntendBuf;}
125
+
126
+ void setEntendBuf(void* v) {m_pEntendBuf = v;};
127
+
128
+ ushort_td* recordCountDirect() const {return m_iRecordCountDirect;}
129
+
130
+ void setRecordCountDirect(ushort_td* v) {m_iRecordCountDirect = v;}
131
+
132
+ ushort_td rejectCount() const {return m_RejectCount;}
133
+
134
+ ushort_td fieldLen(int index) {return GetFieldLen(index);}
135
+
136
+ ushort_td fieldOffset(int index) {return GetFieldOffset(index);}
137
+
138
+ bool fieldSelected() const {return m_FieldSelected;}
139
+
140
+ void init(table* pBao);
141
+ bool GetPosType();
142
+ void SetPosType(bool);
143
+ void WriteBuffer();
144
+ bool setFilter(const _TCHAR* str, ushort_td RejectCount, ushort_td CashCount);
145
+ _TCHAR* filterStr();
146
+
147
+ };
148
+
149
+ }// namespace client
150
+ }// namespace tdap
151
+ }// namespace protocol
152
+ }// namespace db
153
+ }// namespace bzs
154
+ #endif//BZS_DB_PROTOCOL_TDAP_CLIENT_FILTER_H