transactd 1.0.1

Sign up to get free protection for your applications and to get access to all the features.
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,680 @@
1
+ /*=================================================================
2
+ Copyright (C) 2012 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
+ #ifndef BZS_DB_PROTOCOL_TDAP_MYSQL_RECORDSETREADER_H
20
+ #define BZS_DB_PROTOCOL_TDAP_MYSQL_RECORDSETREADER_H
21
+
22
+ #include "request.h"
23
+ #include <bzs/rtl/exception.h>
24
+ #include <bzs/db/engine/mysql/IReadRecords.h>
25
+ #include <bzs/db/engine/mysql/fieldAccess.h>
26
+ #include <boost/shared_ptr.hpp>
27
+
28
+ namespace bzs
29
+ {
30
+ namespace db
31
+ {
32
+ namespace protocol
33
+ {
34
+ namespace tdap
35
+ {
36
+ namespace mysql
37
+ {
38
+
39
+ #pragma option -a-
40
+ pragma_pack1
41
+
42
+ struct logicalField;
43
+ struct resultField;
44
+
45
+ /** calculate record position
46
+ */
47
+ class position
48
+ {
49
+ engine::mysql::table* m_tb;
50
+ const char* m_record;
51
+ public:
52
+ inline position();
53
+ inline void setTable(engine::mysql::table* tb);
54
+ inline char* fieldPtr(const resultField* rf) const;
55
+ inline bool isBlobField(const resultField* rf) const;
56
+ inline void addBlobBuffer(int fieldNum){m_tb->addBlobBuffer(fieldNum);};
57
+ inline void setBlobFieldCount(int v){m_tb->setBlobFieldCount(v);};
58
+ inline unsigned short packLen(const resultField* rf) const;
59
+ inline const char* record()const{return m_record;}
60
+ inline ulong recordLenCl()const{return m_tb->recordLenCl();}
61
+ inline int recordFormatType()const {return m_tb->recordFormatType();};
62
+ inline uint recordPackCopy(char* buf, uint maxlen)const{return m_tb->recordPackCopy(buf, maxlen);}
63
+ int getFieldNumByPos(unsigned short pos)const
64
+ {
65
+ for (int i=0;i<m_tb->fields();i++)
66
+ {
67
+ char* start = m_tb->fieldPos(0);
68
+ if (m_tb->fieldPos(i)-start == pos)
69
+ return i;
70
+ }
71
+ return -1;
72
+ }
73
+ inline uint fieldSizeByte(int fieldNum){return m_tb->fieldSizeByte(fieldNum);}
74
+ };
75
+
76
+ /** If get all field then len = record length.
77
+ *
78
+ */
79
+ struct resultField
80
+ {
81
+ unsigned short len;
82
+ union
83
+ {
84
+ unsigned short pos;
85
+ unsigned short fieldNum;
86
+ };
87
+ };
88
+
89
+ struct extResultDef
90
+ {
91
+ unsigned short maxRows;
92
+ unsigned short fieldCount;
93
+ resultField field[1]; //variable
94
+ };
95
+
96
+
97
+
98
+
99
+ inline position::position():m_tb(NULL),m_record(NULL){};
100
+ inline void position::setTable( engine::mysql::table* tb)
101
+ {
102
+ m_tb = tb;
103
+ m_record = (const char*)m_tb->record();
104
+ }
105
+
106
+ inline char* position::fieldPtr(const resultField* rf) const
107
+ {
108
+ return m_tb->fieldPos(rf->fieldNum);
109
+ }
110
+
111
+ inline bool position::isBlobField(const resultField* rf) const
112
+ {
113
+ return db::engine::mysql::isBlobType(m_tb->fieldType(rf->fieldNum));
114
+ }
115
+
116
+
117
+ /** return data length as real rength.
118
+ */
119
+ inline unsigned short position::packLen(const resultField* rf) const
120
+ {
121
+ return m_tb->fieldDataLen(rf->fieldNum);
122
+ }
123
+
124
+ inline int compareUint24(const char* l, const char* r)
125
+ {
126
+ unsigned int lv = *((unsigned int*)l) & 0xFFFFFF;
127
+ unsigned int rv = *((unsigned int*)r) & 0xFFFFFF;
128
+ if (lv < rv)
129
+ return -1;
130
+ if (lv > rv)
131
+ return 1;
132
+ return 0;
133
+ }
134
+
135
+ inline int compareInt24(const char* l, const char* r)
136
+ {
137
+ int lv = ((*((int*)l) & 0xFFFFFF) << 8) / 0x100;
138
+ int rv = ((*((int*)r) & 0xFFFFFF) << 8) / 0x100;
139
+
140
+ if (lv < rv)
141
+ return -1;
142
+ else if (lv > rv)
143
+ return 1;
144
+ return 0;
145
+ }
146
+
147
+ template <class T>
148
+ int compare(const char* l, const char* r)
149
+ {
150
+ if (*((T*)l) < *((T*)r))
151
+ return -1;
152
+ else if (*((T*)l) > *((T*)r))
153
+ return 1;
154
+ return 0;
155
+ }
156
+
157
+ template <class T>
158
+ int compare(T l, T r)
159
+ {
160
+ if (l < r)
161
+ return -1;
162
+ else if (l > r)
163
+ return 1;
164
+ return 0;
165
+ }
166
+
167
+ template <class T>
168
+ int compareVartype(const char* l, const char* r, bool bin, char logType)
169
+ {
170
+ int llen = (*(T*)l);
171
+ int rlen = (*(T*)r);
172
+ int tmp = std::min(llen, rlen);
173
+ if (logType & CMPLOGICAL_CASEINSENSITIVE)
174
+ tmp = _strnicmp(l + sizeof(T), r + sizeof(T), tmp);
175
+ else if (bin)
176
+ tmp = memcmp(l + sizeof(T), r + sizeof(T), tmp);
177
+ else
178
+ tmp = strncmp(l + sizeof(T), r + sizeof(T), tmp);
179
+
180
+ if (logType & CMPLOGICAL_VAR_COMP_ALL)
181
+ return (tmp==0)?compare<int>(llen, rlen):tmp; //match complete
182
+ return (tmp==0 && (llen < rlen))? -1:tmp; //match a part
183
+ }
184
+
185
+ template <class T>
186
+ int compareWvartype(const char* l, const char* r, bool bin, char logType)
187
+ {
188
+ int llen = (*(T*)l) / sizeof(char16_t);
189
+ int rlen = (*(T*)r) / sizeof(char16_t);
190
+ int tmp = std::min(llen, rlen);
191
+ if (logType & CMPLOGICAL_CASEINSENSITIVE)
192
+ tmp = wcsnicmp16((char16_t*)(l + sizeof(T)), (char16_t*)(r + sizeof(T)), tmp);
193
+ else if (bin)
194
+ tmp = memcmp((char16_t*)(l + sizeof(T)), (char16_t*)(r + sizeof(T)), tmp);
195
+ else
196
+ tmp = wcsncmp16((char16_t*)(l + sizeof(T)), (char16_t*)(r + sizeof(T)), tmp);
197
+ if (logType & CMPLOGICAL_VAR_COMP_ALL)
198
+ return (tmp==0)?compare<int>(llen, rlen):tmp; //match complete
199
+ return (tmp==0 && (llen < rlen))? -1:tmp; //match a part
200
+ }
201
+
202
+ inline int compareBlobType(const char* l, const char* r, bool bin, char logType, int sizeByte)
203
+ {
204
+ int llen = 0;
205
+ int rlen = 0;
206
+ memcpy(&llen, l, sizeByte);
207
+ memcpy(&rlen, r, sizeByte);
208
+ int tmp = std::min(llen, rlen);
209
+ const char* lptr = *((const char**)(l + sizeByte));
210
+ const char* rptr = r + sizeByte;
211
+ if (logType & CMPLOGICAL_CASEINSENSITIVE)
212
+ tmp = _strnicmp(lptr, rptr, tmp);
213
+ else if (bin)
214
+ tmp = memcmp(lptr, rptr, tmp);
215
+ else
216
+ tmp = strncmp(lptr, rptr, tmp);
217
+
218
+ if (logType & CMPLOGICAL_VAR_COMP_ALL)
219
+ return (tmp==0)?compare<int>(llen, rlen):tmp;
220
+ return (tmp==0 && (llen < rlen))? -1:tmp;
221
+ }
222
+
223
+ #define MAX_ISINDEX_CACHE 8
224
+ #define REC_MACTH 0
225
+ #define REC_NOMACTH 1
226
+ #define REC_NOMACTH_NOMORE 2
227
+
228
+
229
+
230
+
231
+ struct extRequest;
232
+ class fieldInfoCache
233
+ {
234
+ char m_sizeBytes[1000];
235
+ bool m_isIndex[MAX_ISINDEX_CACHE];
236
+ mutable int m_index;
237
+
238
+ public:
239
+ inline fieldInfoCache();
240
+ inline ~fieldInfoCache();
241
+ inline short cache(extRequest& req, position& position, const KEY* key);
242
+ inline int getPos()const;
243
+ inline bool isIndex()const;
244
+ inline void reset()const;
245
+
246
+ };
247
+
248
+
249
+ struct logicalField
250
+ {
251
+
252
+ public:
253
+ unsigned char type;
254
+ unsigned short len;
255
+ unsigned short pos;
256
+ char logType;
257
+ char opr;
258
+ union
259
+ {
260
+ unsigned short offset;
261
+ unsigned char ptr[2]; //variable
262
+ };
263
+
264
+ logicalField* next() const
265
+ {
266
+ return (logType & 64)?(logicalField*)(ptr + 2):(logicalField*)(ptr + len/*std::max((unsigned short)2,len)*/);
267
+ }
268
+
269
+ private:
270
+ int comp(const char* record, int sizeByte) const
271
+ {
272
+ const char* r = (const char*) ptr;
273
+ if (logType & CMPLOGICAL_FIELD)
274
+ r = record + offset;
275
+ const char* l = record + pos;
276
+ switch(type)
277
+ {
278
+ case ft_integer:
279
+ case ft_autoinc:
280
+ case ft_currency:
281
+ {
282
+ switch(len)
283
+ {
284
+ case 1:return compare<char>(l, r);
285
+ case 2:return compare<short>(l, r);
286
+ case 3:return compareInt24(l, r);
287
+ case 4:return compare<int>(l, r);
288
+ case 8:return compare<__int64>(l, r);
289
+ }
290
+ }
291
+ case ft_mychar:
292
+ case ft_string:
293
+ if (logType & CMPLOGICAL_CASEINSENSITIVE)
294
+ return _strnicmp(l, r, len);
295
+ return memcmp(l, r, len);
296
+ case ft_zstring:
297
+ case ft_note:
298
+ if (logType & CMPLOGICAL_CASEINSENSITIVE)
299
+ return _strnicmp(l, r, len);
300
+ return strncmp(l, r, len);
301
+ case ft_logical:
302
+ case ft_uinteger:
303
+ case ft_date:
304
+ case ft_time:
305
+ case ft_timestamp:
306
+ case ft_mydate:
307
+ {
308
+ switch(len)
309
+ {
310
+ case 1:return compare<unsigned char>(l, r);
311
+ case 2:return compare<unsigned short>(l, r);
312
+ case 3:return compareUint24(l, r);
313
+ case 4:return compare<unsigned int>(l, r);
314
+ case 8:return compare<unsigned __int64>(l, r);
315
+ }
316
+ }
317
+
318
+ case ft_mytime:
319
+ case ft_mydatetime:
320
+ case ft_mytimestamp:
321
+ return memcmp(l, r, len);
322
+ case ft_float:
323
+ switch(len)
324
+ {
325
+ case 4:return compare<float>(l, r);
326
+ case 8:return compare<double>(l, r);
327
+ }
328
+ case ft_mywchar:
329
+ case ft_wstring:
330
+ case ft_wzstring:
331
+ if (logType & CMPLOGICAL_CASEINSENSITIVE)
332
+ return wcsnicmp16((char16_t*)l, (char16_t*)r, len);
333
+ if ((type==ft_wstring)||(type==ft_mywchar))
334
+ return memcmp(l, r, len);
335
+ return wcsncmp16((char16_t*)l, (char16_t*)r, len);
336
+ case ft_lstring:
337
+ case ft_myvarchar:
338
+ case ft_myvarbinary:
339
+ if (sizeByte==1)
340
+ return compareVartype<unsigned char>(l, r, type==ft_myvarbinary, logType);
341
+ return compareVartype<unsigned short>(l, r, type==ft_myvarbinary, logType);
342
+ case ft_mywvarchar:
343
+ case ft_mywvarbinary:
344
+ if (sizeByte==1)
345
+ return compareWvartype<unsigned char>(l, r, type==ft_mywvarbinary, logType);
346
+ return compareWvartype<unsigned short>(l, r, type==ft_mywvarbinary, logType);
347
+ case ft_mytext:
348
+ case ft_myblob:
349
+ return compareBlobType(l, r, type==ft_myblob, logType, sizeByte);
350
+ }
351
+ return 0;
352
+ };
353
+ bool matchThis(const char* record, int sizeByte) const
354
+ {
355
+
356
+ int v = comp(record, sizeByte);
357
+ switch(logType & 0xF) //16 or more are disregarded.
358
+ {
359
+ case 1:return (v==0); //==
360
+ case 2:return (v>0); //>
361
+ case 3:return (v<0); //<
362
+ case 4:return (v!=0); //!=
363
+ case 5:return (v>=0); //>=
364
+ case 6:return (v<=0); //<=
365
+ }
366
+ return false;
367
+ }
368
+ public:
369
+ int checkNomore(bool matchResult, bool typeNext, const fieldInfoCache& sb)const
370
+ {
371
+ if (matchResult)
372
+ return REC_MACTH;
373
+ else if(sb.isIndex())
374
+ {
375
+ char log = logType & 0xF;
376
+ if (log == 1)//==
377
+ return REC_NOMACTH_NOMORE;
378
+ else if (typeNext && (log == 3 || log==6))
379
+ return REC_NOMACTH_NOMORE;
380
+ else if (!typeNext && (log == 2 || log==5))
381
+ return REC_NOMACTH_NOMORE;
382
+ }
383
+ return REC_NOMACTH;
384
+ }
385
+ int match(const char* record, bool typeNext, const fieldInfoCache& sb) const
386
+ {
387
+ bool ret = matchThis(record, sb.getPos());
388
+ if (opr == 0) //this is last
389
+ return checkNomore(ret, typeNext, sb);
390
+ if (!ret)
391
+ return (opr == 1)?checkNomore(ret, typeNext, sb):next()->match(record, typeNext, sb);
392
+ else
393
+ return (opr == 1)?next()->match(record, typeNext, sb):checkNomore(ret, typeNext, sb);
394
+ }
395
+ extResultDef* resultDef() const
396
+ {
397
+ if (opr == 0)
398
+ return (extResultDef*)next();
399
+ return next()->resultDef();
400
+ }
401
+ };
402
+
403
+ struct extRequest
404
+ {
405
+ unsigned short len;
406
+ char type[2];
407
+ unsigned short rejectCount;
408
+ unsigned short logicalCount;
409
+ logicalField field;
410
+ int match(const char* record, bool typeNext, const fieldInfoCache& sb)const
411
+ {
412
+ if (logicalCount)
413
+ return field.match(record, typeNext, sb);
414
+ return REC_MACTH;
415
+ }
416
+ extResultDef* resultDef()const
417
+ {
418
+ if (logicalCount)
419
+ return field.resultDef();
420
+ return (extResultDef*)&field;
421
+ }
422
+
423
+ };
424
+
425
+ #pragma option -a
426
+ pragma_pop
427
+
428
+ class resultWriter
429
+ {
430
+ char* m_buf;
431
+ extResultDef* m_def;
432
+ unsigned short m_rowsPos;
433
+ unsigned short m_maxLen;
434
+ unsigned short m_resultLen;
435
+ bool m_writeFirst;
436
+
437
+ short writeFirst( position* pos, unsigned int bookmark)
438
+ {
439
+ m_rowsPos = m_resultLen;
440
+
441
+ memset(m_buf + m_resultLen, 0x00, sizeof(unsigned short));
442
+ m_resultLen += sizeof(unsigned short);
443
+ return doWrite(pos, bookmark);
444
+ }
445
+
446
+ short doWrite(position* pos, unsigned int bookmark)
447
+ {
448
+ // write rowCount
449
+ unsigned short* rows = (unsigned short*) (m_buf + m_rowsPos);
450
+ ++(*rows);
451
+ //write recLength space;
452
+ unsigned short recLen = 0;
453
+ unsigned short recLenPos = m_resultLen;
454
+ memcpy(m_buf + m_resultLen, (const char*)&recLen, sizeof(unsigned short));
455
+ m_resultLen += sizeof(unsigned short);
456
+ //write bookmark
457
+ memcpy(m_buf + m_resultLen, (const char*)&bookmark, sizeof(unsigned int));
458
+ m_resultLen += sizeof(unsigned int);
459
+
460
+ if ((m_def->fieldCount == 1) && (m_def->field[0].len >= pos->recordLenCl()))
461
+ { //write whole row
462
+ int len = pos->recordLenCl();
463
+ if (m_maxLen + RETBUF_EXT_RESERVE_SIZE >= m_resultLen + len)
464
+ {
465
+ int maxlen = m_maxLen + RETBUF_EXT_RESERVE_SIZE - m_resultLen;
466
+ len = pos->recordPackCopy(m_buf + m_resultLen, maxlen);
467
+ if (len == 0)
468
+ return STATUS_BUFFERTOOSMALL;
469
+ m_resultLen += len;
470
+ recLen += len;
471
+ }else
472
+ return STATUS_BUFFERTOOSMALL;
473
+ }else
474
+ {
475
+ //write each fields by field num.
476
+ for (int i=0;i<m_def->fieldCount;i++)
477
+ {
478
+ resultField& fd = m_def->field[i];
479
+ if (m_maxLen+RETBUF_EXT_RESERVE_SIZE>= m_resultLen + fd.len)
480
+ {
481
+ //memcpy(m_buf + m_resultLen, pos->record() + fd.pos, fd.len);
482
+ memcpy(m_buf + m_resultLen, pos->fieldPtr(&fd), fd.len);
483
+ m_resultLen += fd.len;
484
+ recLen += fd.len;
485
+ if (pos->isBlobField(&fd))
486
+ pos->addBlobBuffer(fd.fieldNum);
487
+ }
488
+ else
489
+ return STATUS_BUFFERTOOSMALL;
490
+ }
491
+ }
492
+ //write recLength;
493
+ unsigned short* tmp = (unsigned short*) (m_buf + recLenPos);
494
+ *tmp = recLen;
495
+ return 0;
496
+ }
497
+ public:
498
+ resultWriter(char* buf ,size_t offset, extResultDef* def, unsigned short maxlen)
499
+ :m_buf(buf),m_def(def),m_rowsPos(0),m_maxLen(maxlen),m_writeFirst(true)
500
+ {
501
+ m_resultLen = (unsigned short)offset;
502
+ }
503
+
504
+ short write(position* pos, unsigned int bookmark)
505
+ {
506
+ if (m_writeFirst)
507
+ {
508
+ m_writeFirst = false;
509
+ return writeFirst(pos, bookmark);
510
+ }
511
+ return doWrite(pos, bookmark);
512
+ }
513
+
514
+ unsigned short resultLen(){return m_resultLen;};
515
+
516
+ const char* resultBuffer(){return m_buf;}
517
+ };
518
+
519
+ /* ---------------------------------------------------------------
520
+ * Implement fieldInfoCache
521
+ * ---------------------------------------------------------------*/
522
+ inline fieldInfoCache::fieldInfoCache()
523
+ {
524
+ memset(m_isIndex, 0, sizeof(bool) * MAX_ISINDEX_CACHE);
525
+ }
526
+
527
+ inline fieldInfoCache::~fieldInfoCache()
528
+ {
529
+
530
+ }
531
+
532
+ inline short fieldInfoCache::cache(extRequest& req, position& position, const KEY* key)
533
+ {
534
+
535
+ m_index = 0;
536
+ logicalField* fd = &req.field;
537
+ char* pos = m_sizeBytes;
538
+ bool isCheckKeyseg = (key != NULL);
539
+ unsigned short segmentIndex = 0;
540
+ for (int i=0;i<req.logicalCount;i++)
541
+ {
542
+
543
+ int num = position.getFieldNumByPos(fd->pos);
544
+ if (num == -1)
545
+ return STATUS_INVALID_FIELD_OFFSET;
546
+ *pos = (char)position.fieldSizeByte(num);
547
+
548
+ /* Is target field current keynum segnmnt
549
+ For optimize match() return NOMATCH_NOMORE
550
+ */
551
+ if (isCheckKeyseg && (i < MAX_ISINDEX_CACHE))
552
+ {
553
+ if (segmentIndex < key->user_defined_key_parts)
554
+ {
555
+ m_isIndex[i] = (key->key_part[segmentIndex].field->field_index == num);
556
+ if (!m_isIndex[i] && (++segmentIndex < key->user_defined_key_parts))
557
+ m_isIndex[i] = (key->key_part[segmentIndex].field->field_index == num);
558
+ }
559
+ isCheckKeyseg = m_isIndex[i];
560
+ if (fd->opr == 2) isCheckKeyseg = false;
561
+ }
562
+
563
+ ++pos;
564
+ fd = fd->next();
565
+ }
566
+ return 0;
567
+ }
568
+
569
+ /* get value and inc index.
570
+ */
571
+ inline int fieldInfoCache::getPos()const
572
+ {
573
+ return m_sizeBytes[m_index++];
574
+ }
575
+
576
+ /* It certainly calls after getPos() */
577
+ inline bool fieldInfoCache::isIndex()const
578
+ {
579
+ return m_isIndex[m_index-1];
580
+ }
581
+
582
+ /* reset for next record */
583
+ inline void fieldInfoCache::reset()const
584
+ {
585
+ m_index = 0;
586
+
587
+ }
588
+
589
+ /* ---------------------------------------------------------------*/
590
+
591
+ class ReadRecordsHandler : public engine::mysql::IReadRecordsHandler
592
+ {
593
+ boost::shared_ptr<resultWriter> m_writer;
594
+ extRequest* m_req;
595
+ extResultDef* m_resultDef;
596
+ position m_position;
597
+ fieldInfoCache m_fieldInfoCache;
598
+ public:
599
+
600
+ short begin(engine::mysql::table* tb, extRequest* req, char* buf,size_t offset, unsigned short maxlen)
601
+ {
602
+ short ret = 0;
603
+ m_position.setTable(tb);
604
+ m_req = req;
605
+ const KEY* key = NULL;
606
+ if (tb->keyNum() >= 0)
607
+ key = &tb->keyDef(tb->keyNum());
608
+ m_fieldInfoCache.cache(*m_req, m_position, key);
609
+
610
+ m_resultDef = m_req->resultDef();
611
+ if (m_resultDef->fieldCount > 1)
612
+ ret = convResultPosToFieldNum();
613
+
614
+ m_writer.reset(new resultWriter(buf, offset, m_resultDef, maxlen));
615
+ //DEBUG_RECORDS_BEGIN(m_resultDef, m_req)
616
+ return ret;
617
+ }
618
+
619
+ //TODO This convert is move to client. but legacy app is need this
620
+ short convResultPosToFieldNum()
621
+ {
622
+ int blobs = 0;
623
+ for (int i=0;i<m_resultDef->fieldCount;i++)
624
+ {
625
+ resultField& fd = m_resultDef->field[i];
626
+ int num = m_position.getFieldNumByPos(fd.pos);
627
+ if (num == -1)
628
+ return STATUS_INVALID_FIELD_OFFSET;
629
+ fd.fieldNum = num;
630
+ if (m_position.isBlobField(&fd))
631
+ ++blobs;
632
+
633
+ }
634
+
635
+ m_position.setBlobFieldCount(blobs);
636
+ return 0;
637
+ }
638
+
639
+ unsigned int end()
640
+ {
641
+ unsigned int len = m_writer->resultLen();
642
+ //DEBUG_RECORDS_END(m_writer.get())
643
+
644
+ m_writer.reset();
645
+ return len;
646
+ }
647
+
648
+ int match(bool typeNext)const
649
+ {
650
+ m_fieldInfoCache.reset();
651
+ return m_req->match(m_position.record(), typeNext, m_fieldInfoCache);
652
+ }
653
+
654
+ short write(const unsigned char* bmPtr, unsigned int bmlen)
655
+ {
656
+ unsigned int bookmark = 0;
657
+ switch(bmlen)
658
+ {
659
+ case 4:
660
+ bookmark = *((unsigned int*)bmPtr);break;
661
+ case 2:
662
+ bookmark = *((unsigned short*)bmPtr);break;
663
+ case 3:
664
+ bookmark = *((unsigned int*)bmPtr) & 0x0FFFFFF;break;
665
+ case 1:
666
+ bookmark = *((unsigned short*)bmPtr) & 0x0FF;break;
667
+ }
668
+ return m_writer->write(&m_position, bookmark);
669
+ }
670
+ unsigned short rejectCount(){return m_req->rejectCount;};
671
+ unsigned short maxRows(){return m_resultDef->maxRows;};
672
+ };
673
+
674
+ }//namespace mysql
675
+ }//namespace protocol
676
+ }//namespace db
677
+ }//namespace tdap
678
+ }//namespace bzs
679
+
680
+ #endif //BZS_DB_PROTOCOL_TDAP_MYSQL_RECORDSETREADER_H