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,627 @@
1
+ #ifndef BZS_DB_PROTOCOL_TDAP_CLIENT_STRINGCONVERTER_H
2
+ #define BZS_DB_PROTOCOL_TDAP_CLIENT_STRINGCONVERTER_H
3
+ /* =================================================================
4
+ Copyright (C) 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 <bzs/db/protocol/tdap/tdapSchema.h>
22
+ #include <bzs/rtl/stringBuffers.h>
23
+ #include <bzs/env/crosscompile.h>
24
+ #ifdef LINUX
25
+ #include <bzs/env/mbcswchrLinux.h>
26
+ #endif
27
+ #include <limits.h>
28
+ #include <assert.h>
29
+
30
+ namespace bzs
31
+ {
32
+ namespace db
33
+ {
34
+ namespace protocol
35
+ {
36
+ namespace tdap
37
+ {
38
+ namespace client
39
+ {
40
+
41
+ typedef int(*isMbcleadFunc)(unsigned int c);
42
+
43
+ inline size_t charNumByteUtf8(const unsigned char *p, size_t isize, size_t num)
44
+ {
45
+ int n = 0;
46
+ const unsigned char* end = p + isize;
47
+ while (num && (p != end))
48
+ {
49
+ --num;
50
+
51
+ if ((*p & 0x80) == 0)
52
+ {
53
+ ++n;
54
+ ++p; // 1byte string
55
+ }
56
+ else
57
+ {
58
+ for (unsigned char tmp = *p & 0xfc; (tmp & 0x80); tmp = tmp << 1)
59
+ {
60
+ ++n;
61
+ if (++p == end)
62
+ break;
63
+ }
64
+ }
65
+ }
66
+ return n;
67
+ }
68
+
69
+ inline size_t charNumByte(isMbcleadFunc func, const unsigned char* p, size_t isize, size_t num)
70
+ {
71
+ size_t n = 0;
72
+ const unsigned char* end = p + isize;
73
+ while (num && (p != end))
74
+ {
75
+ if (func(*p))
76
+ {
77
+ ++n;
78
+ ++p;
79
+ }
80
+ ++p;
81
+ ++n;
82
+ --num;
83
+ }
84
+ return n;
85
+ }
86
+
87
+ /** Trim or fill fc charctor and return bytes that not include fill char bytes.
88
+ */
89
+ inline size_t validateTrim(isMbcleadFunc func, unsigned char* src, size_t maxBytes, int fc)
90
+ {
91
+ unsigned char* p = src + maxBytes - 1;
92
+ unsigned char* tmp = p;
93
+ if (fc == -1)
94
+ fc = 0x00;
95
+ while (func(*tmp) && (--tmp>=src));
96
+
97
+ //if (func(*p) && (maxBytes>1) && !func(*(p-1)))
98
+ if ((p-tmp) % 2)
99
+ {
100
+ *p = (unsigned char)fc;
101
+ return maxBytes - 1;
102
+ }
103
+ return maxBytes;
104
+
105
+ }
106
+
107
+ /** UTF8 Version: Trim or fill fc charctor and return bytes that not include fill char bytes.
108
+ */
109
+ inline size_t validateTrimUTF8(unsigned char* src, size_t maxBytes, int fc)
110
+ {
111
+ unsigned char* endpos = src + maxBytes;
112
+ unsigned char* p = endpos - 1;
113
+
114
+ if ((*p & 0x80) == 0)
115
+ return maxBytes;
116
+
117
+ //If multi byte string then first byte is 0xC0.
118
+ while ((*p & 0xC0) != 0xC0)
119
+ {
120
+ if (--p < src)
121
+ break;
122
+ }
123
+ size_t num = endpos - p;
124
+
125
+ unsigned char tmp = *p;
126
+ unsigned int num2 = 0;
127
+ while (tmp & 0x80)
128
+ {
129
+ tmp = tmp << 1;
130
+ ++num2;
131
+ }
132
+ if (num == num2)
133
+ return maxBytes;
134
+ memset(p, fc, endpos - p);
135
+ return p - src;
136
+ }
137
+
138
+ inline int isMbcCP932(unsigned int c) {return ((c >= 0x81) && (c <= 0x9F)) || ((c >= 0xE0) && (c <= 0xFC));
139
+ }
140
+
141
+ // Trim or fill fc charctor and return bytes.
142
+ inline size_t charNumTrim(int codePage, char* src, size_t inputsize, size_t maxCharnum, int fc)
143
+ {
144
+ size_t size = inputsize;
145
+ switch (codePage)
146
+ {
147
+ case CP_UTF8: size = charNumByteUtf8((unsigned char*)src, inputsize, maxCharnum);
148
+ break;
149
+ case 932: size = charNumByte(isMbcCP932, (unsigned char*)src, inputsize, maxCharnum);
150
+ break;
151
+
152
+ }
153
+ if (size && (fc != -1))
154
+ memset(src + size, fc, inputsize - size);
155
+ return size;
156
+ }
157
+
158
+ // Wide version: Trim or fill fc charctor and return wide char number..
159
+ inline size_t charNumTrim(int codePage, WCHAR* src, size_t inputsize, size_t maxCharnum, int fc)
160
+ {
161
+ WCHAR* end = src + inputsize;
162
+ WCHAR* p = src;
163
+ size_t n = 0;
164
+ while (p != end)
165
+ {
166
+ if (IS_HIGH_SURROGATE(*p))
167
+ ++p;
168
+ ++p;
169
+ ++n;
170
+ --maxCharnum;
171
+ if (maxCharnum == 0)
172
+ break;
173
+ }
174
+ return n;
175
+ }
176
+
177
+ // if invalid end charctor then fill fc char. And return charctor bytes.
178
+ inline size_t validateTrim(int codePage, char* src, size_t maxlen, int fc)
179
+ {
180
+ switch (codePage)
181
+ {
182
+ case CP_UTF8: return validateTrimUTF8((unsigned char*)src, maxlen, fc);
183
+ case 932: return validateTrim(isMbcCP932, (unsigned char*)src, maxlen, fc);
184
+ }
185
+ return maxlen;
186
+ }
187
+
188
+ // Wide Version if invalid end charctor then fill fc char. And return wide charctor number.
189
+ inline size_t validateTrim(int codePage, WCHAR* src, size_t maxlen, int fc)
190
+ {
191
+ if (IS_HIGH_SURROGATE(src[maxlen - 1]))
192
+ src[--maxlen] = 0x00;
193
+ return maxlen;
194
+ }
195
+
196
+ #define CP_UTF16 1200
197
+
198
+ class stringConverter
199
+ {
200
+ unsigned int m_codePage;
201
+ unsigned int m_exec_codePage;
202
+
203
+ public:
204
+ stringConverter(unsigned int src_codPage, unsigned int exec_codePage)
205
+ : m_codePage(src_codPage), m_exec_codePage(exec_codePage) {}
206
+
207
+ inline void setCodePage(unsigned int src_codPage) {m_codePage = src_codPage;}
208
+
209
+ inline void setExecCodePage(unsigned int codPage) {m_exec_codePage = codPage;}
210
+
211
+ inline unsigned int execCodePage() const {return m_exec_codePage;};
212
+
213
+ // wide to codepage. Result is no need Nullterminate.
214
+ inline size_t convert(char* to, size_t tsize, const WCHAR* from, size_t fsize)
215
+ {
216
+ to[tsize - 1] = 0x00;
217
+ size_t len = WideCharToMultiByte(m_codePage, (m_codePage == CP_UTF8) ? 0 :
218
+ WC_COMPOSITECHECK, from, (int)fsize, to, (int)tsize, NULL, NULL);
219
+ if (len == 0)
220
+ return tsize - (to[tsize - 1] ? 0 : 1);
221
+ return len;
222
+ }
223
+
224
+ inline size_t convert(WCHAR* to, size_t tsize, const char* from, size_t fsize)
225
+ {
226
+ to[tsize - 1] = 0x00;
227
+ size_t len = MultiByteToWideChar(m_exec_codePage, (m_exec_codePage == CP_UTF8) ? 0 :
228
+ MB_PRECOMPOSED, from, (int)fsize, to, (int)tsize);
229
+ if (len == 0)
230
+ return tsize - (to[tsize - 1] ? 0 : 1);
231
+ return len;
232
+
233
+ }
234
+
235
+ inline size_t convert(WCHAR* to, size_t tsize, const WCHAR* from, size_t fsize)
236
+ {
237
+ assert(0);
238
+ return fsize;
239
+ }
240
+
241
+ inline size_t convert(char* to, size_t tsize, const char* from, size_t fsize)
242
+ {
243
+ size_t size = 0;
244
+ #ifdef _WIN32
245
+ size = MultiByteToWideChar(m_exec_codePage, (m_exec_codePage == CP_UTF8) ? 0 :
246
+ MB_PRECOMPOSED, from, (int)fsize, NULL, (int)0);
247
+ WCHAR* ws = new WCHAR[++size];
248
+ size = MultiByteToWideChar(m_exec_codePage, (m_exec_codePage == CP_UTF8) ? 0 :
249
+ MB_PRECOMPOSED, from, (int)fsize, ws, (int)size);
250
+
251
+ to[tsize - 1] = 0x00;
252
+ size = WideCharToMultiByte(m_codePage, (m_codePage == CP_UTF8) ? 0 : WC_COMPOSITECHECK, ws,
253
+ (int)size, to, (int)tsize, NULL, NULL);
254
+ delete[]ws;
255
+ if (size == 0)
256
+ size = tsize - (to[tsize - 1] ? 0 : 1);
257
+ #else
258
+ if (m_exec_codePage == CP_UTF8)
259
+ size = bzs::env::u8tombc(from, fsize, to, tsize);
260
+ else
261
+ size = bzs::env::mbctou8(from, fsize, to, tsize);
262
+ #endif
263
+ return size;
264
+ }
265
+
266
+ // codepage to wide. Result is need Nullterminate.
267
+ inline size_t revert(WCHAR* to, size_t tsize, const char* from, size_t fsize) {
268
+ return MultiByteToWideChar(m_codePage, (m_codePage == CP_UTF8) ? 0 : MB_PRECOMPOSED, from,
269
+ (int)fsize, to, (int)tsize);}
270
+
271
+ inline size_t revert(char* to, size_t tsize, const WCHAR* from, size_t fsize) {
272
+ return WideCharToMultiByte(m_exec_codePage, (m_exec_codePage == CP_UTF8) ? 0 :
273
+ WC_COMPOSITECHECK, from, (int)fsize, to, (int)tsize, NULL, NULL);}
274
+
275
+ inline size_t revert(WCHAR* to, size_t tsize, const WCHAR* from, size_t fsize)
276
+ {
277
+ assert(0);
278
+ return fsize;
279
+ }
280
+
281
+ inline size_t revert(char* to, size_t tsize, const char* from, size_t fsize)
282
+ {
283
+ size_t size = 0;
284
+ #ifdef _WIN32
285
+ size = MultiByteToWideChar(m_codePage, (m_codePage == CP_UTF8) ? 0 : MB_PRECOMPOSED, from,
286
+ (int)fsize, NULL, (int)0);
287
+ WCHAR* ws = new WCHAR[++size];
288
+ size = MultiByteToWideChar(m_codePage, (m_codePage == CP_UTF8) ? 0 : MB_PRECOMPOSED, from,
289
+ (int)fsize, ws, (int)size);
290
+ size = WideCharToMultiByte(m_exec_codePage, (m_exec_codePage == CP_UTF8) ? 0 :
291
+ WC_COMPOSITECHECK, ws, (int)size, to, (int)tsize, NULL, NULL);
292
+ delete[]ws;
293
+ #else
294
+ if (m_exec_codePage == CP_UTF8)
295
+ size = bzs::env::mbctou8(from, fsize, to, tsize);
296
+ else
297
+ size = bzs::env::u8tombc(from, fsize, to, tsize);
298
+ #endif
299
+ return size;
300
+ }
301
+
302
+ inline bool isNeedConvert() const {return (m_codePage != m_exec_codePage);}
303
+
304
+ };
305
+
306
+ typedef stringConverter converter_type;
307
+
308
+ class myCharStoreBase
309
+ {
310
+ fielddef& m_fd;
311
+
312
+ public:
313
+ inline myCharStoreBase(fielddef& fd) : m_fd(fd) {};
314
+
315
+ inline size_t maxStoreBytes() const {return m_fd.len;};
316
+
317
+ inline int padChar() const {return 0x20;};
318
+
319
+ inline int storeOffsetBytes() const {return 0;};
320
+
321
+ inline int maxCharNum() const {return m_fd.charNum();}
322
+
323
+ inline bool isNeedReadCopy() const {return true;}
324
+
325
+ };
326
+
327
+ typedef myCharStoreBase myWcharStore;
328
+ typedef myCharStoreBase myCharStore;
329
+
330
+ class myVarCharStoreBase
331
+ {
332
+ fielddef& m_fd;
333
+
334
+ public:
335
+ inline myVarCharStoreBase(fielddef& fd) : m_fd(fd) {};
336
+
337
+ inline size_t maxStoreBytes() const {return m_fd.len - m_fd.varLenBytes();};
338
+
339
+ inline int padChar() const {return -1;};
340
+
341
+ inline int storeOffsetBytes() const {return m_fd.varLenBytes();};
342
+
343
+ inline int maxCharNum() const {return m_fd.charNum();}
344
+
345
+ inline bool isNeedReadCopy() const {return true;}
346
+
347
+ };
348
+
349
+ typedef myVarCharStoreBase myWvarCharStore;
350
+ typedef myVarCharStoreBase myVarCharStore;
351
+
352
+
353
+ class myVarBinaryStoreBase
354
+ {
355
+ fielddef& m_fd;
356
+
357
+ public:
358
+ inline myVarBinaryStoreBase(fielddef& fd) : m_fd(fd) {};
359
+
360
+ inline size_t maxStoreBytes() const {return m_fd.len - m_fd.varLenBytes();};
361
+
362
+ inline int padChar() const {return -1;};
363
+
364
+ inline int storeOffsetBytes() const {return m_fd.varLenBytes();};
365
+
366
+ inline int maxCharNum() const {return -1;}
367
+
368
+ inline bool isNeedReadCopy() const {return true;}
369
+ };
370
+
371
+
372
+ typedef myVarBinaryStoreBase myWvarBinaryStore;
373
+ typedef myVarBinaryStoreBase myVarBinaryStore;
374
+
375
+ class myBinaryStoreBase
376
+ {
377
+ fielddef& m_fd;
378
+
379
+ public:
380
+ inline myBinaryStoreBase(fielddef& fd) : m_fd(fd) {};
381
+
382
+ inline size_t maxStoreBytes() const {return m_fd.len;};
383
+
384
+ inline int padChar() const {return 0;};
385
+
386
+ inline int storeOffsetBytes() const {return 0;};
387
+
388
+ inline int maxCharNum() const {return -1;}
389
+
390
+ inline bool isNeedReadCopy() const {return true;}
391
+ };
392
+
393
+ typedef myBinaryStoreBase myWbinaryStore;
394
+ typedef myBinaryStoreBase myBinaryStore;
395
+
396
+ class zstringStore
397
+ {
398
+ fielddef& m_fd;
399
+
400
+ public:
401
+ inline zstringStore(fielddef& fd) : m_fd(fd) {};
402
+
403
+ inline size_t maxStoreBytes() const {return m_fd.len - 1;};
404
+
405
+ inline int padChar() const {return 0;};
406
+
407
+ inline int storeOffsetBytes() const {return 0;};
408
+
409
+ inline int maxCharNum() const {return -1;}
410
+
411
+ inline bool isNeedReadCopy() const {return false;}
412
+ };
413
+
414
+ class wzstringStore
415
+ {
416
+ fielddef& m_fd;
417
+
418
+ public:
419
+ inline wzstringStore(fielddef& fd) : m_fd(fd) {};
420
+
421
+ inline size_t maxStoreBytes() const {return m_fd.len -sizeof(short);};
422
+
423
+ inline int padChar() const {return 0;};
424
+
425
+ inline int storeOffsetBytes() const {return 0;};
426
+
427
+ inline int maxCharNum() const {return -1;}
428
+
429
+ inline bool isNeedReadCopy() const {return false;}
430
+ };
431
+
432
+ class stringStoreBase
433
+ {
434
+ fielddef& m_fd;
435
+
436
+ public:
437
+ inline stringStoreBase(fielddef& fd) : m_fd(fd) {};
438
+
439
+ inline size_t maxStoreBytes() const {return m_fd.len;};
440
+
441
+ inline int padChar() const {return 0x20;};
442
+
443
+ inline int storeOffsetBytes() const {return 0;};
444
+
445
+ inline int maxCharNum() const {return -1;}
446
+
447
+ inline bool isNeedReadCopy() const {return true;}
448
+ };
449
+
450
+
451
+ typedef stringStoreBase wstringStore;
452
+ typedef stringStoreBase stringStore;
453
+
454
+
455
+ inline size_t strlen_t(const WCHAR* p) {return strlen16(p);}
456
+
457
+ inline size_t strlen_t(const char* p) {return strlen(p);}
458
+
459
+ inline void* memcpy_t(void *dest, const void *src, size_t count) {return memcpy(dest, src, count);}
460
+
461
+ inline WCHAR* memcpy_t(WCHAR* dest, const WCHAR *src, size_t count) {
462
+ return wmemcpy(dest, src, count);}
463
+
464
+ inline void* memset_t(void *dest, int c, size_t count) {return memset(dest, c, count);}
465
+
466
+ inline WCHAR* memset_t(WCHAR* dest, int c, size_t count) {return wmemset16(dest, (WCHAR)c, count);}
467
+
468
+ template<typename _SF, typename store_type, typename T>
469
+ void store(char* ptr, const T* data, fielddef& fd, stringConverter* cv, bool usePad = true)
470
+ {
471
+ _SF sf(fd);
472
+
473
+ size_t maxlen = sf.maxStoreBytes() / sizeof(store_type);
474
+ size_t len = strlen_t(data);
475
+ int offset = sf.storeOffsetBytes();
476
+ store_type* strPtr = (store_type*)(ptr + offset);
477
+
478
+ if (len == 0)
479
+ strPtr[0] = 0x00;
480
+ else
481
+ {
482
+ // convert
483
+ if ((typeid(T) != typeid(store_type)) ||
484
+ (cv->isNeedConvert() && (typeid(T) == typeid(char))))
485
+ len = cv->convert(strPtr, maxlen, data, len);
486
+ else
487
+ {
488
+ len = std::min<size_t>(maxlen, len);
489
+ memcpy_t(strPtr, data, len);
490
+ }
491
+ }
492
+ int fc = usePad ? sf.padChar() : -1;
493
+
494
+ // Trim by max charctor number (not char type length) and invalid mbc lead byte.
495
+ int maxCharnum = sf.maxCharNum();
496
+ if (maxCharnum != -1)
497
+ len = charNumTrim(fd.codePage(), strPtr, len, maxCharnum, fc);
498
+ else if (maxlen == len)
499
+ len = validateTrim(fd.codePage(), strPtr, maxlen, fc);
500
+ else
501
+ strPtr[len] = 0x00;
502
+ // fill after byte.
503
+ if ((fc != -1) && (maxlen != len))
504
+ memset_t((store_type*)(strPtr + len), fc, (maxlen - len));
505
+
506
+ if (offset)
507
+ {
508
+ len *= sizeof(store_type);
509
+ memcpy(ptr, &len, offset);
510
+ }
511
+ }
512
+
513
+ template<class T>
514
+ T* trim(T* src, T* end, int padChar)
515
+ {
516
+ while (src <= --end)
517
+ {
518
+ if (*end != padChar)
519
+ break;
520
+ *end = 0x00;
521
+ }
522
+ return src;
523
+ }
524
+
525
+ #pragma warn -8008
526
+ #pragma warn -8066
527
+
528
+ template<class _SF, typename store_type, typename T>
529
+ const T* read(char* ptr, ::bzs::rtl::stringBuffer* strBufs, fielddef& fd, stringConverter* cv,
530
+ bool isTrimPadChar = false)
531
+ {
532
+ _SF sf(fd);
533
+
534
+ int offset = sf.storeOffsetBytes();
535
+ T* result = (T*)(ptr + offset);
536
+ //convert
537
+ size_t len;
538
+ if ((typeid(T) != typeid(store_type)) || (cv->isNeedConvert() && (typeid(T) == typeid(char))))
539
+ {
540
+ len = fd.dataLen((const uchar_td*)ptr) / sizeof(store_type);
541
+ size_t olen = len * 2 * sizeof(store_type) + 1; // utf8�ւ�2�{�̉”\��������
542
+ result = strBufs->getPtr<T>(olen);
543
+ len = cv->revert(result, olen, (const store_type*)(ptr + offset), len);
544
+
545
+ }
546
+ else if (sf.isNeedReadCopy())
547
+ {
548
+ len = fd.dataLen((const uchar_td*)ptr);
549
+ if (len == sf.maxStoreBytes())
550
+ {
551
+ result = (T*)strBufs->getPtrA(len + 2);
552
+ memcpy(result, ptr + offset, len);
553
+ }
554
+ len /= sizeof(store_type);
555
+
556
+ }
557
+ else
558
+ return result; // zstring;
559
+ result[len] = 0x00;
560
+ if (sf.padChar() && isTrimPadChar)
561
+ trim(result, result + len, sf.padChar());
562
+ return result;
563
+ }
564
+ #pragma warn .8008
565
+ #pragma warn .8066
566
+
567
+ template<typename T>
568
+ char* blobStore(char* ptr, const T* data, fielddef& fd, stringConverter* cv)
569
+ {
570
+ size_t len = strlen_t(data);
571
+ int offset = fd.len - 8;
572
+ char* p = NULL;
573
+ size_t maxlen = (offset == 1) ? 255 : (offset == 2) ? USHRT_MAX : (offset == 3) ?
574
+ USHRT_MAX * 255 : UINT_MAX;
575
+ if (len != 0)
576
+ {
577
+ if ((typeid(T) != typeid(char)) || (cv->isNeedConvert() && (typeid(T) == typeid(char))))
578
+ {
579
+ maxlen = std::min<size_t>(maxlen, len * 2 * sizeof(T) + 1);
580
+ p = new char[maxlen];
581
+ len = cv->convert(p, maxlen, data, len);
582
+
583
+ }
584
+ else
585
+ {
586
+ maxlen = std::min<size_t>(maxlen, len + 1);
587
+ p = new char[maxlen];
588
+ memcpy_t(p, data, len);
589
+ }
590
+ }
591
+ memset(ptr, 0, fd.len);
592
+ memcpy(ptr, &len, offset);
593
+ if (p)
594
+ memcpy(ptr + offset, &(p), sizeof(char*));
595
+ return p;
596
+
597
+ }
598
+ #pragma warn -8004
599
+ template<typename T>
600
+ const T* readBlob(char* ptr, ::bzs::rtl::stringBuffer* strBufs, fielddef& fd, stringConverter* cv)
601
+ {
602
+
603
+ int offset = fd.len - 8;
604
+ T* result = (T*)(ptr + offset);
605
+ char** pc = (char**)(ptr + fd.blobLenBytes());
606
+
607
+ if ((typeid(T) != typeid(char)) || (cv->isNeedConvert() && (typeid(T) == typeid(char))))
608
+ {
609
+ size_t len = fd.blobDataLen((const uchar_td*)ptr);
610
+ size_t olen = len * 2 + 1;
611
+ result = strBufs->getPtr<T>(olen);
612
+ len = cv->revert(result, olen, *pc, len);
613
+ result[len] = 0x00;
614
+
615
+ }
616
+ else
617
+ result = (T*)*pc;
618
+ return result;
619
+ }
620
+ #pragma warn .8004
621
+
622
+ }// namespace client
623
+ }// namespace tdap
624
+ }// namespace protocol
625
+ }// namespace db
626
+ }// namespace bzs
627
+ #endif //BZS_DB_PROTOCOL_TDAP_CLIENT_STRINGCONVERTER_H