transactd 1.2.0 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (306) hide show
  1. checksums.yaml +4 -4
  2. data/BUILD_UNIX-JA +46 -67
  3. data/BUILD_WIN-JA +106 -63
  4. data/CMakeLists.txt +40 -15
  5. data/README +219 -75
  6. data/README-JA +207 -76
  7. data/README_ORMSRCGEN +118 -0
  8. data/README_ORMSRCGEN-JA +115 -0
  9. data/bin/common/tdclc_32_2_0.dll +0 -0
  10. data/bin/common/tdclc_64_2_0.dll +0 -0
  11. data/build/common/check_for_link_iconv.cmake +18 -14
  12. data/build/common/create_symlink.cmake.in +25 -0
  13. data/build/common/get_boost_libs.cmake +23 -23
  14. data/build/common/options.cmake +0 -66
  15. data/build/common/smart_install.cmake +3 -3
  16. data/build/common/transactd.rc.in +15 -5
  17. data/build/common/transactd_cl_common.cmake +37 -18
  18. data/build/common/transactd_cl_output.cmake +55 -13
  19. data/build/common/transactd_common.cmake +108 -31
  20. data/build/swig/php/generate.cmake.in +15 -17
  21. data/build/swig/php/generate.cmd.in +15 -9
  22. data/build/swig/php/php.swg +124 -82
  23. data/build/swig/php/transactd.no_yield.php +4494 -0
  24. data/build/swig/php/transactd.no_yield.php.git.patch +685 -0
  25. data/build/swig/php/transactd.no_yield.php.patch +685 -0
  26. data/build/swig/php/transactd.yield.php +4461 -0
  27. data/build/swig/php/transactd.yield.php.git.patch +652 -0
  28. data/build/swig/php/transactd.yield.php.patch +652 -0
  29. data/build/swig/referencecounter.h +79 -0
  30. data/build/swig/ruby/ruby.swg +226 -76
  31. data/build/swig/ruby/threadBlockRegionWrapper.h +71 -0
  32. data/build/swig/ruby/without_gvl.swg +87 -0
  33. data/build/swig/tdcl.i +659 -170
  34. data/build/swig/validatablepointer.h +91 -0
  35. data/build/tdclc/CMakeLists.txt +49 -34
  36. data/build/tdclc/{tdclc_64.cbproj → tdclc.cbproj} +65 -20
  37. data/build/tdclc/tdclc.rc +0 -0
  38. data/build/tdclcpp/CMakeLists.txt +84 -20
  39. data/build/tdclcpp/tdclcpp.rc +0 -0
  40. data/build/tdclcpp/{tdclcpp_bcb_64.cbproj → tdclcpp_bc.cbproj} +168 -44
  41. data/build/tdclrb/CMakeLists.txt +84 -66
  42. data/build/tdclrb/bldgem/extconf.rb +28 -3
  43. data/build/tdclrb/gem/helper.rb +11 -1
  44. data/build/tdclrb/gem_output.cmake +20 -16
  45. data/index_ja.html +15 -0
  46. data/source/bzs/db/IBlobBuffer.h +15 -17
  47. data/source/bzs/db/blobBuffer.h +186 -140
  48. data/source/bzs/db/blobStructs.h +37 -37
  49. data/source/bzs/db/engine/mysql/IReadRecords.h +34 -34
  50. data/source/bzs/db/engine/mysql/bookmark.h +150 -147
  51. data/source/bzs/db/engine/mysql/database.cpp +1721 -1526
  52. data/source/bzs/db/engine/mysql/database.h +608 -370
  53. data/source/bzs/db/engine/mysql/dbManager.cpp +213 -201
  54. data/source/bzs/db/engine/mysql/dbManager.h +115 -104
  55. data/source/bzs/db/engine/mysql/errorMessage.cpp +49 -50
  56. data/source/bzs/db/engine/mysql/errorMessage.h +25 -26
  57. data/source/bzs/db/engine/mysql/fieldAccess.h +55 -61
  58. data/source/bzs/db/engine/mysql/mydebuglog.cpp +326 -292
  59. data/source/bzs/db/engine/mysql/mydebuglog.h +63 -55
  60. data/source/bzs/db/engine/mysql/mysqlInternal.h +182 -125
  61. data/source/bzs/db/engine/mysql/mysqlThd.cpp +121 -121
  62. data/source/bzs/db/engine/mysql/mysqlThd.h +20 -20
  63. data/source/bzs/db/engine/mysql/percentageKey.h +241 -228
  64. data/source/bzs/db/protocol/ICommandExecuter.h +18 -17
  65. data/source/bzs/db/protocol/hs/hsCommandExecuter.cpp +543 -514
  66. data/source/bzs/db/protocol/hs/hsCommandExecuter.h +155 -158
  67. data/source/bzs/db/protocol/tdap/btrDate.cpp +213 -180
  68. data/source/bzs/db/protocol/tdap/btrDate.h +39 -37
  69. data/source/bzs/db/protocol/tdap/client/activeTable.cpp +173 -0
  70. data/source/bzs/db/protocol/tdap/client/activeTable.h +165 -0
  71. data/source/bzs/db/protocol/tdap/client/activeTableImple.h +370 -0
  72. data/source/bzs/db/protocol/tdap/client/bulkInsert.h +13 -23
  73. data/source/bzs/db/protocol/tdap/client/client.cpp +81 -68
  74. data/source/bzs/db/protocol/tdap/client/client.h +361 -320
  75. data/source/bzs/db/protocol/tdap/client/connMgr.cpp +17 -22
  76. data/source/bzs/db/protocol/tdap/client/connMgr.h +17 -19
  77. data/source/bzs/db/protocol/tdap/client/connectionPool.cpp +243 -0
  78. data/source/bzs/db/protocol/tdap/client/connectionPool.h +109 -0
  79. data/source/bzs/db/protocol/tdap/client/database.cpp +327 -219
  80. data/source/bzs/db/protocol/tdap/client/database.h +141 -118
  81. data/source/bzs/db/protocol/tdap/client/databaseFactory.cpp +60 -62
  82. data/source/bzs/db/protocol/tdap/client/databaseManager.h +255 -0
  83. data/source/bzs/db/protocol/tdap/client/dbDef.cpp +315 -202
  84. data/source/bzs/db/protocol/tdap/client/dbDef.h +40 -32
  85. data/source/bzs/db/protocol/tdap/client/dllmain.cpp +390 -371
  86. data/source/bzs/db/protocol/tdap/client/errorMessage.cpp +148 -56
  87. data/source/bzs/db/protocol/tdap/client/errorMessage_ja.cpp +149 -57
  88. data/source/bzs/db/protocol/tdap/client/export.h +35 -0
  89. data/source/bzs/db/protocol/tdap/client/field.cpp +1985 -0
  90. data/source/bzs/db/protocol/tdap/client/field.h +393 -0
  91. data/source/bzs/db/protocol/tdap/client/fieldDDF.cpp +14 -14
  92. data/source/bzs/db/protocol/tdap/client/fieldDDF.h +11 -14
  93. data/source/bzs/db/protocol/tdap/client/fieldNameAlias.cpp +123 -0
  94. data/source/bzs/db/protocol/tdap/client/fieldNameAlias.h +58 -0
  95. data/source/bzs/db/protocol/tdap/client/fields.h +178 -0
  96. data/source/bzs/db/protocol/tdap/client/fileDDF.cpp +13 -16
  97. data/source/bzs/db/protocol/tdap/client/fileDDF.h +11 -17
  98. data/source/bzs/db/protocol/tdap/client/filter.h +423 -259
  99. data/source/bzs/db/protocol/tdap/client/groupComp.h +117 -0
  100. data/source/bzs/db/protocol/tdap/client/groupQuery.cpp +818 -0
  101. data/source/bzs/db/protocol/tdap/client/groupQuery.h +281 -0
  102. data/source/bzs/db/protocol/tdap/client/indexDDF.cpp +14 -17
  103. data/source/bzs/db/protocol/tdap/client/indexDDF.h +11 -14
  104. data/source/bzs/db/protocol/tdap/client/memRecord.cpp +231 -0
  105. data/source/bzs/db/protocol/tdap/client/memRecord.h +145 -0
  106. data/source/bzs/db/protocol/tdap/client/memRecordset.cpp +448 -0
  107. data/source/bzs/db/protocol/tdap/client/memRecordset.h +159 -0
  108. data/source/bzs/db/protocol/tdap/client/nsDatabase.cpp +300 -173
  109. data/source/bzs/db/protocol/tdap/client/nsDatabase.h +53 -36
  110. data/source/bzs/db/protocol/tdap/client/nsTable.cpp +171 -128
  111. data/source/bzs/db/protocol/tdap/client/nsTable.h +121 -87
  112. data/source/bzs/db/protocol/tdap/client/pooledDatabaseManager.h +173 -0
  113. data/source/bzs/db/protocol/tdap/client/recordset.cpp +209 -0
  114. data/source/bzs/db/protocol/tdap/client/recordset.h +86 -0
  115. data/source/bzs/db/protocol/tdap/client/recordsetImple.h +596 -0
  116. data/source/bzs/db/protocol/tdap/client/request.h +227 -170
  117. data/source/bzs/db/protocol/tdap/client/serializer.cpp +1288 -0
  118. data/source/bzs/db/protocol/tdap/client/serializer.h +295 -0
  119. data/source/bzs/db/protocol/tdap/client/sharedData.cpp +9 -12
  120. data/source/bzs/db/protocol/tdap/client/sharedData.h +18 -16
  121. data/source/bzs/db/protocol/tdap/client/sqlBuilder.cpp +494 -473
  122. data/source/bzs/db/protocol/tdap/client/sqlBuilder.h +51 -53
  123. data/source/bzs/db/protocol/tdap/client/stringConverter.h +214 -148
  124. data/source/bzs/db/protocol/tdap/client/table.cpp +929 -1665
  125. data/source/bzs/db/protocol/tdap/client/table.h +413 -87
  126. data/source/bzs/db/protocol/tdap/client/trdboostapi.h +642 -534
  127. data/source/bzs/db/protocol/tdap/client/trdboostapiInternal.h +25 -40
  128. data/source/bzs/db/protocol/tdap/client/trdclcppautolink.h +11 -15
  129. data/source/bzs/db/protocol/tdap/client/trdormapi.h +378 -437
  130. data/source/bzs/db/protocol/tdap/client/trnsctcl.def +1 -1
  131. data/source/bzs/db/protocol/tdap/fieldComp.h +127 -0
  132. data/source/bzs/db/protocol/tdap/myDateTime.cpp +352 -345
  133. data/source/bzs/db/protocol/tdap/mysql/characterset.cpp +75 -78
  134. data/source/bzs/db/protocol/tdap/mysql/characterset.h +18 -19
  135. data/source/bzs/db/protocol/tdap/mysql/databaseSchema.cpp +216 -199
  136. data/source/bzs/db/protocol/tdap/mysql/databaseSchema.h +23 -14
  137. data/source/bzs/db/protocol/tdap/mysql/debuglog.cpp +354 -314
  138. data/source/bzs/db/protocol/tdap/mysql/debuglog.h +57 -47
  139. data/source/bzs/db/protocol/tdap/mysql/recordsetReader.h +905 -739
  140. data/source/bzs/db/protocol/tdap/mysql/request.h +152 -159
  141. data/source/bzs/db/protocol/tdap/mysql/tdapCommandExecuter.cpp +1044 -879
  142. data/source/bzs/db/protocol/tdap/mysql/tdapCommandExecuter.h +87 -81
  143. data/source/bzs/db/protocol/tdap/tdapRequest.h +162 -130
  144. data/source/bzs/db/protocol/tdap/tdapSchema.cpp +368 -166
  145. data/source/bzs/db/protocol/tdap/tdapSchema.h +702 -566
  146. data/source/bzs/db/protocol/tdap/tdapcapi.h +387 -353
  147. data/source/bzs/db/transactd/appBuilderImple.h +21 -20
  148. data/source/bzs/db/transactd/appModule.cpp +350 -98
  149. data/source/bzs/db/transactd/appModule.h +31 -37
  150. data/source/bzs/db/transactd/connManager.cpp +138 -135
  151. data/source/bzs/db/transactd/connManager.h +28 -21
  152. data/source/bzs/db/transactd/connectionRecord.h +39 -39
  153. data/source/bzs/db/transactd/transactd.cpp +217 -203
  154. data/source/bzs/env/boost_bcb_link.h +131 -0
  155. data/source/bzs/env/compiler.h +136 -79
  156. data/source/bzs/env/crosscompile.cpp +57 -57
  157. data/source/bzs/env/crosscompile.h +130 -115
  158. data/source/bzs/env/fileopen.h +7 -8
  159. data/source/bzs/env/mbcswchrLinux.cpp +4 -9
  160. data/source/bzs/env/mbcswchrLinux.h +37 -34
  161. data/source/bzs/env/tcharMinGW.h +59 -0
  162. data/source/bzs/env/tstring.h +90 -95
  163. data/source/bzs/example/changeSchema.cpp +22 -23
  164. data/source/bzs/example/changeSchema_c.cpp +22 -24
  165. data/source/bzs/example/connection_pool_c.cpp +49 -104
  166. data/source/bzs/example/createDatabase.cpp +40 -47
  167. data/source/bzs/example/createDatabase_c.cpp +38 -43
  168. data/source/bzs/example/deleteRecords.cpp +10 -15
  169. data/source/bzs/example/deleteRecords_c.cpp +10 -14
  170. data/source/bzs/example/dropDatabase.cpp +3 -9
  171. data/source/bzs/example/dropDatabase_c.cpp +5 -6
  172. data/source/bzs/example/insertRecords.cpp +37 -29
  173. data/source/bzs/example/insertRecords_c.cpp +19 -25
  174. data/source/bzs/example/ormap_c.cpp +621 -0
  175. data/source/bzs/example/queryData.cpp +371 -0
  176. data/source/bzs/example/queryData.h +16 -0
  177. data/source/bzs/example/query_c.cpp +109 -0
  178. data/source/bzs/example/readRecords.cpp +27 -27
  179. data/source/bzs/example/readRecords_c.cpp +25 -23
  180. data/source/bzs/example/updateRecords.cpp +16 -21
  181. data/source/bzs/example/updateRecords_c.cpp +8 -12
  182. data/source/bzs/example/update_with_transaction.cpp +21 -24
  183. data/source/bzs/example/update_with_transaction_c.cpp +12 -15
  184. data/source/bzs/example/useORMRecord.cpp +177 -0
  185. data/source/bzs/netsvc/client/tcpClient.cpp +167 -156
  186. data/source/bzs/netsvc/client/tcpClient.h +541 -489
  187. data/source/bzs/netsvc/server/IAppModule.h +119 -32
  188. data/source/bzs/netsvc/server/iserver.h +21 -23
  189. data/source/bzs/netsvc/server/serverCpt.cpp +421 -391
  190. data/source/bzs/netsvc/server/serverCpt.h +41 -43
  191. data/source/bzs/netsvc/server/serverPipe.cpp +580 -565
  192. data/source/bzs/netsvc/server/serverPipe.h +44 -45
  193. data/source/bzs/netsvc/server/serverTpool.cpp +333 -303
  194. data/source/bzs/netsvc/server/serverTpool.h +38 -43
  195. data/source/bzs/rtl/benchmark.cpp +91 -31
  196. data/source/bzs/rtl/benchmark.h +76 -22
  197. data/source/bzs/rtl/datetime.cpp +231 -233
  198. data/source/bzs/rtl/datetime.h +16 -16
  199. data/source/bzs/rtl/debuglog.cpp +48 -51
  200. data/source/bzs/rtl/debuglog.h +55 -44
  201. data/source/bzs/rtl/exception.h +55 -48
  202. data/source/bzs/rtl/stl_uty.cpp +27 -28
  203. data/source/bzs/rtl/stl_uty.h +28 -29
  204. data/source/bzs/rtl/stringBuffers.cpp +8 -6
  205. data/source/bzs/rtl/stringBuffers.h +16 -9
  206. data/source/bzs/rtl/strtrim.cpp +90 -91
  207. data/source/bzs/rtl/strtrim.h +14 -16
  208. data/source/bzs/test/tdclatl/bench_query_atl.js +647 -0
  209. data/source/bzs/test/tdclatl/bench_tdclatl.js +303 -303
  210. data/source/bzs/test/tdclatl/test_query_atl.js +669 -0
  211. data/source/bzs/test/tdclphp/bench.php +357 -0
  212. data/source/bzs/test/tdclphp/transactd_Test.php +907 -303
  213. data/source/bzs/test/tdclphp/transactd_blob_Test.php +21 -49
  214. data/source/bzs/test/tdclphp/transactd_datetime_Test.php +41 -75
  215. data/source/bzs/test/tdclphp/transactd_kanjischema_Test.php +23 -37
  216. data/source/bzs/test/tdclphp/transactd_pool_Test.php +120 -0
  217. data/source/bzs/test/tdclrb/bench_tdclcpp.rb +4 -6
  218. data/source/bzs/test/tdclrb/prepare.rb +15 -12
  219. data/source/bzs/test/tdclrb/transactd_blob_spec.rb +29 -32
  220. data/source/bzs/test/tdclrb/transactd_datetime_spec.rb +0 -29
  221. data/source/bzs/test/tdclrb/transactd_kanjischema_spec.rb +18 -19
  222. data/source/bzs/test/tdclrb/transactd_pool_spec.rb +107 -0
  223. data/source/bzs/test/tdclrb/transactd_spec.rb +734 -142
  224. data/source/bzs/test/transactdBench/query_bench.cpp +156 -0
  225. data/source/bzs/test/transactdBench/scaling_bench.cpp +265 -0
  226. data/source/bzs/test/transactdBench/transactdBench.cpp +107 -83
  227. data/source/bzs/test/transactdBench/transactdBench2.cpp +122 -83
  228. data/source/bzs/test/transactdBench/workerBase.cpp +5 -0
  229. data/source/bzs/test/transactdBench/workerBase.h +88 -0
  230. data/source/bzs/test/transactdBench/workerMySQLImple.h +333 -0
  231. data/source/bzs/test/transactdBench/workerTransactdImple.h +201 -0
  232. data/source/bzs/test/trdclengn/test_blob.cpp +121 -73
  233. data/source/bzs/test/trdclengn/test_trdclengn.cpp +1244 -426
  234. data/source/global/ormsrcgen/confParam.h +80 -0
  235. data/source/global/ormsrcgen/fieldName.cpp +77 -0
  236. data/source/global/ormsrcgen/fieldName.h +43 -0
  237. data/source/global/ormsrcgen/main.cpp +196 -0
  238. data/source/global/ormsrcgen/srcgen.cpp +763 -0
  239. data/source/global/ormsrcgen/srcgen.h +72 -0
  240. data/source/global/ormsrcgen/template/fieldNameList_sample.txt +2 -0
  241. data/source/global/ormsrcgen/template/ormDataClass_template.cpp +48 -0
  242. data/source/global/ormsrcgen/template/ormDataClass_template.h +34 -0
  243. data/source/global/ormsrcgen/template/ormMapClass_template.cpp +51 -0
  244. data/source/global/ormsrcgen/template/ormMapClass_template.h +62 -0
  245. data/source/global/ormsrcgen/template/template.cnf +38 -0
  246. data/source/global/querystmts/querystmts.cpp +237 -0
  247. data/source/global/tdclatl/ConnectParams.cpp +77 -0
  248. data/source/global/tdclatl/ConnectParams.h +70 -0
  249. data/source/global/tdclatl/Database.cpp +132 -128
  250. data/source/global/tdclatl/Database.h +60 -49
  251. data/source/global/tdclatl/DbDef.cpp +68 -64
  252. data/source/global/tdclatl/DbDef.h +36 -36
  253. data/source/global/tdclatl/Field.cpp +12 -17
  254. data/source/global/tdclatl/Field.h +15 -12
  255. data/source/global/tdclatl/FieldDef.cpp +75 -36
  256. data/source/global/tdclatl/FieldDef.h +38 -19
  257. data/source/global/tdclatl/FieldDefs.cpp +74 -0
  258. data/source/global/tdclatl/FieldDefs.h +56 -0
  259. data/source/global/tdclatl/FieldNames.cpp +99 -0
  260. data/source/global/tdclatl/FieldNames.h +66 -0
  261. data/source/global/tdclatl/Flags.cpp +75 -37
  262. data/source/global/tdclatl/Flags.h +13 -12
  263. data/source/global/tdclatl/GroupQuery.cpp +119 -0
  264. data/source/global/tdclatl/GroupQuery.h +65 -0
  265. data/source/global/tdclatl/KeyDef.cpp +15 -14
  266. data/source/global/tdclatl/KeyDef.h +20 -17
  267. data/source/global/tdclatl/KeySegment.cpp +13 -12
  268. data/source/global/tdclatl/PooledDbManager.cpp +223 -0
  269. data/source/global/tdclatl/PooledDbManager.h +76 -0
  270. data/source/global/tdclatl/QueryBase.cpp +206 -127
  271. data/source/global/tdclatl/QueryBase.h +55 -59
  272. data/source/global/tdclatl/Record.cpp +214 -0
  273. data/source/global/tdclatl/Record.h +96 -0
  274. data/source/global/tdclatl/Recordset.cpp +278 -0
  275. data/source/global/tdclatl/Recordset.h +83 -0
  276. data/source/global/tdclatl/RecordsetQuery.cpp +118 -0
  277. data/source/global/tdclatl/RecordsetQuery.h +126 -0
  278. data/source/global/tdclatl/Table.cpp +57 -60
  279. data/source/global/tdclatl/Table.h +32 -29
  280. data/source/global/tdclatl/TableDef.cpp +63 -62
  281. data/source/global/tdclatl/TableDef.h +20 -22
  282. data/source/global/tdclatl/TdVersion.cpp +3 -3
  283. data/source/global/tdclatl/TdVersion.h +15 -11
  284. data/source/global/tdclatl/_IDatabaseEvents_CP.h +99 -92
  285. data/source/global/tdclatl/activeTable.cpp +355 -0
  286. data/source/global/tdclatl/activeTable.h +79 -0
  287. data/source/global/tdclatl/dllmain.cpp +4 -3
  288. data/source/global/tdclatl/dllmain.h +7 -6
  289. data/source/global/tdclatl/keySegment.h +22 -18
  290. data/source/global/tdclatl/resource.h +0 -0
  291. data/source/global/tdclatl/stdafx.h +6 -4
  292. data/source/global/tdclatl/targetver.h +0 -1
  293. data/source/global/tdclatl/tdclatl.cpp +10 -5
  294. data/source/global/tdclatl/tdclatl.idl +530 -14
  295. data/source/linux/charsetConvert.h +78 -79
  296. data/source/linux/linuxTypes.h +9 -12
  297. data/source/linux/tchar.h +168 -166
  298. data/transactd.gemspec +24 -16
  299. metadata +98 -12
  300. data/bin/common/tdclc_32_1_2.dll +0 -0
  301. data/bin/common/tdclc_64_1_2.dll +0 -0
  302. data/build/tdclc/tdclc_32.cbproj +0 -173
  303. data/build/tdclcpp/tdclcpp_bcb_32.cbproj +0 -232
  304. data/build/tdclrb/GEM_VERSION +0 -3
  305. data/source/bzs/db/protocol/tdap/client/filter.cpp +0 -43
  306. data/source/bzs/example/useORM.cpp +0 -585
@@ -19,12 +19,12 @@
19
19
  02111-1307, USA.
20
20
  ================================================================= */
21
21
  #include "table.h"
22
+ #include "fields.h"
22
23
  #include <assert.h>
23
24
  #include <vector>
24
25
  #include <boost/algorithm/string.hpp>
25
26
  #include <boost/tokenizer.hpp>
26
27
 
27
-
28
28
  namespace bzs
29
29
  {
30
30
  namespace db
@@ -40,12 +40,13 @@ namespace client
40
40
  #define BOOKMARK_SIZE 4
41
41
  #define DATASIZE_BYTE 2
42
42
 
43
- #define MAX_DATA_SIZE 57000
44
-
43
+ #define BTRV_MAX_DATA_SIZE 57000
44
+ #define TDAP_MAX_DATA_SIZE 6291456 // 3Mbyte
45
45
 
46
46
  inline ushort_td varlenForFilter(const fielddef& fd)
47
47
  {
48
- if (((fd.type >= ft_myvarchar) && (fd.type <= ft_mywvarbinary)) || fd.type == ft_lstring)
48
+ if (((fd.type >= ft_myvarchar) && (fd.type <= ft_mywvarbinary)) ||
49
+ fd.type == ft_lstring)
49
50
  return fd.len < 256 ? 1 : 2;
50
51
  else if ((fd.type == ft_myblob) || (fd.type == ft_mytext))
51
52
  return fd.len - 8;
@@ -60,7 +61,8 @@ inline uint_td compDataLen(const fielddef& fd, const uchar_td* ptr, bool part)
60
61
  uint_td length = fd.keyDataLen(ptr);
61
62
  if (part)
62
63
  {
63
- if ((fd.type == ft_string) || (fd.type == ft_zstring) || (fd.type == ft_note))
64
+ if ((fd.type == ft_string) || (fd.type == ft_zstring) ||
65
+ (fd.type == ft_note))
64
66
  length = (uint_td)strlen((const char*)ptr);
65
67
  else if ((fd.type == ft_wstring) || (fd.type == ft_wzstring))
66
68
  length = (uint_td)wcslen((const wchar_t*)ptr);
@@ -70,21 +72,21 @@ inline uint_td compDataLen(const fielddef& fd, const uchar_td* ptr, bool part)
70
72
 
71
73
  bool verType(uchar_td type)
72
74
  {
73
- if (((type >= ft_myvarchar) && (type <= ft_mywvarbinary)) || type == ft_lstring)
75
+ if (((type >= ft_myvarchar) && (type <= ft_mywvarbinary)) ||
76
+ type == ft_lstring)
74
77
  return true;
75
78
  return false;
76
79
  }
77
80
 
78
-
79
- #pragma option -a-
80
- pragma_pack1
81
+ #pragma pack(push, 1)
82
+ pragma_pack1;
81
83
 
82
84
  struct resultField
83
85
  {
84
- unsigned short len;
86
+ unsigned short len;
85
87
  unsigned short pos;
86
88
 
87
- bool setParam(table* tb, const _TCHAR* name)
89
+ int setParam(table* tb, const _TCHAR* name)
88
90
  {
89
91
  short fieldNum = tb->fieldNumByName(name);
90
92
  if (fieldNum != -1)
@@ -92,63 +94,94 @@ struct resultField
92
94
  fielddef* fd = &tb->tableDef()->fieldDefs[fieldNum];
93
95
  len = fd->len;
94
96
  pos = fd->pos;
95
- return true;
97
+ return fieldNum;
96
98
  }
97
- return false;
99
+ return -1;
98
100
  }
99
101
  unsigned char* writeBuffer(unsigned char* p, bool estimate)
100
102
  {
101
103
  int n = sizeof(resultField);
102
- if (!estimate) memcpy(p, this, n);
103
- return p+n;
104
+ if (!estimate)
105
+ memcpy(p, this, n);
106
+ return p + n;
104
107
  }
105
108
  };
106
109
 
107
110
  struct resultDef
108
111
  {
109
- resultDef()
110
- {
111
- reset();
112
- }
112
+ resultDef() { reset(); }
113
113
  void reset()
114
114
  {
115
115
  maxRows = 0;
116
116
  fieldCount = 0;
117
117
  }
118
- unsigned short maxRows;
119
- unsigned short fieldCount;
118
+ unsigned short maxRows;
119
+ unsigned short fieldCount;
120
120
  unsigned char* writeBuffer(unsigned char* p, bool estimate)
121
121
  {
122
122
  int n = sizeof(resultDef);
123
- if (!estimate) memcpy(p, this, n);
123
+ if (!estimate)
124
+ memcpy(p, this, n);
124
125
  return p + n;
125
126
  }
126
127
  friend class filter;
127
128
  };
128
129
 
129
- struct logic
130
+ struct seek
130
131
  {
131
- unsigned char type;
132
- unsigned short len;
133
- unsigned short pos;
134
- unsigned char logType;
135
- char opr;
136
- unsigned char* data;
132
+ unsigned char* data;
133
+ unsigned short len;
137
134
 
138
135
  public:
139
- logic():data(NULL){}
136
+ size_t getLength() { return sizeof(len) + len; }
140
137
 
141
- ~logic()
138
+ // setParam from keyValue
139
+ bool setParam(uchar_td* buf, ushort_td keylen)
142
140
  {
143
- delete [] data;
141
+ len = keylen;
142
+ data = buf;
143
+ return true;
144
144
  }
145
145
 
146
+ unsigned char* writeBuffer(unsigned char* p, bool estimate, bool end,
147
+ bool isTransactd) const
148
+ {
149
+ int n = sizeof(len);
150
+ if (!estimate)
151
+ {
152
+ if (isTransactd)
153
+ memcpy(p, &len, n);
154
+ else
155
+ n = 0;
156
+ memcpy(p + n, data, len);
157
+ }
158
+ else if (!isTransactd)
159
+ n = 0;
160
+
161
+ return p + n + len;
162
+ }
163
+ };
164
+
165
+ struct logic
166
+ {
167
+ unsigned char type;
168
+ unsigned short len;
169
+ unsigned short pos;
170
+ unsigned char logType;
171
+ char opr;
172
+ unsigned char* data;
173
+
174
+ public:
175
+ logic() : data(NULL) {}
176
+
177
+ ~logic() { delete[] data; }
178
+
146
179
  size_t getLength()
147
180
  {
148
181
  return sizeof(logic) - sizeof(unsigned char*) + getDatalen();
149
182
  }
150
183
 
151
- void setFieldParam(fielddef* fd )
184
+ void setFieldParam(fielddef* fd)
152
185
  {
153
186
  type = fd->type;
154
187
  len = fd->len;
@@ -157,50 +190,31 @@ public:
157
190
 
158
191
  int getDatalen() const
159
192
  {
160
- if (logType & 64)
193
+ if (logType & CMPLOGICAL_FIELD)
161
194
  return 2;
162
195
  return len;
163
196
  }
164
197
 
165
198
  bool setCompFiled(table* tb, short index, const _TCHAR* name)
166
199
  {
167
- short tmp = tb->fieldNumByName(name);
168
- if (tmp !=-1)
169
- {
170
- memcpy(data, &tmp, 2);
200
+ short tmp = tb->fieldNumByName(name);
201
+ if (tmp != -1)
202
+ {
203
+ allocBuffer(2);
204
+ fielddef& fd = tb->tableDef()->fieldDefs[tmp];
205
+ memcpy(data, &(fd.pos), 2);
171
206
  logType |= CMPLOGICAL_FIELD;
172
207
  return true;
173
- }
174
- return false;
175
- }
176
-
177
- bool isPart(table* tb, short index)
178
- {
179
- fielddef* fd = &tb->tableDef()->fieldDefs[index];
180
- bool ret = false;
181
- if (fd->isStringType())
182
- {
183
- _TCHAR* p = (_TCHAR*)tb->getFVstr(index);
184
- if (p)
185
- {
186
- size_t n = _tcslen(p);
187
- if ((ret = (p[n-1] == _T('*')))!=0)
188
- {
189
- p[n-1] = 0x00;
190
- tb->setFV(index, p);
191
- }
192
- }else
193
- tb->setFV(index, _T(""));
194
208
  }
195
- return ret;
209
+ return false;
196
210
  }
197
211
 
198
212
  void allocBuffer(int size)
199
213
  {
200
- if (data)
201
- delete [] data;
202
- data = new unsigned char[size + 2];
203
- memset(data, 0, size + 2);
214
+ if (data)
215
+ delete[] data;
216
+ data = new unsigned char[size + 2];
217
+ memset(data, 0, size + 2);
204
218
  }
205
219
 
206
220
  void copyToBuffer(table* tb, short index, bool part)
@@ -217,67 +231,50 @@ public:
217
231
  memcpy(to + varlen, fd->keyData(ptr), copylen);
218
232
 
219
233
  if (!part && (fd->varLenBytes() || fd->blobLenBytes()))
220
- logType |= CMPLOGICAL_VAR_COMP_ALL; //match complate
234
+ logType |= CMPLOGICAL_VAR_COMP_ALL; // match complate
221
235
  }
222
236
 
223
- bool setParam(table* tb, const _TCHAR* name
224
- , const _TCHAR* type, const _TCHAR* value, char combine, bool compField = false)
237
+ bool setParam(table* tb, const _TCHAR* name, const _TCHAR* type,
238
+ const _TCHAR* value, char combine, bool compField = false)
225
239
  {
226
240
  logType = getFilterLogicTypeCode(type);
227
241
  opr = combine;
228
242
  short fieldNum = tb->fieldNumByName(name);
229
- if ((logType!=255) && (fieldNum != -1))
243
+ if ((logType != 255) && (fieldNum != -1))
230
244
  {
231
245
  bool ret = true;
232
246
  fielddef* fd = &tb->tableDef()->fieldDefs[fieldNum];
233
247
  setFieldParam(fd);
234
- unsigned char* tmp = new unsigned char[len];
235
-
236
- //backup
237
- memcpy(tmp, tb->fieldPtr(fieldNum), len);
238
248
 
239
249
  if (compField)
240
- ret = setCompFiled(tb, fieldNum, value);// value is field name
250
+ ret = setCompFiled(tb, fieldNum, value); // value is field name
241
251
  else
242
252
  {
243
- tb->setFV(fieldNum, value);
244
- bool part = isPart(tb, fieldNum);
253
+ fields fds(*tb);
254
+ field fd = fds[fieldNum];
255
+ fd = value;
256
+ bool part = fd.isCompPartAndMakeValue();
245
257
  copyToBuffer(tb, fieldNum, part);
246
258
  }
247
- //restore
248
- memcpy(tb->fieldPtr(fieldNum),tmp, len);
249
- delete [] tmp;
250
259
  return ret;
251
260
  }
252
261
  return false;
253
262
  }
254
263
 
255
- //setParam from keyValue
256
- bool setParam(void* keyValue, ushort_td keylen)
257
- {
258
- logType = 1;// '=' type
259
- opr = eCor;
260
- len = keylen;
261
- type = ft_string;// this value is ignored.
262
- pos = 0;
263
- allocBuffer(len);
264
- memcpy(data, keyValue, len);
265
- return true;
266
- }
267
-
268
- unsigned char* writeBuffer(unsigned char* p, bool estimate, bool end)
264
+ unsigned char* writeBuffer(unsigned char* p, bool estimate, bool end) const
269
265
  {
270
266
  int n = sizeof(logic) - sizeof(unsigned char*);
271
267
  if (!estimate)
272
268
  {
273
269
  memcpy(p, this, n);
274
270
  if (end)
275
- *(p+n-1) = eCend;
271
+ *(p + n - 1) = eCend;
276
272
  }
277
273
  p += n;
278
274
 
279
275
  n = getDatalen();
280
- if (!estimate) memcpy(p, data, n);
276
+ if (!estimate)
277
+ memcpy(p, data, n);
281
278
  return p + n;
282
279
  }
283
280
 
@@ -286,16 +283,11 @@ public:
286
283
  bool flag = true;
287
284
  if (after)
288
285
  flag = (opr == 1);
289
- return (flag
290
- && (logType == 1)
291
- && (type != ft_zstring)
292
- && !verType(type));
286
+ return (flag && (logType == 1) && (type != ft_zstring) &&
287
+ !verType(type));
293
288
  }
294
289
 
295
- bool isNextFiled(logic* src)
296
- {
297
- return ((pos + len) == src->pos);
298
- }
290
+ bool isNextFiled(logic* src) { return ((pos + len) == src->pos); }
299
291
 
300
292
  void joinAfter(logic* src)
301
293
  {
@@ -306,92 +298,155 @@ public:
306
298
  memcpy(data, tmp, len);
307
299
  memcpy(data + len, src->data, src->len);
308
300
  len += src->len;
309
- type = ft_string; //compare by memcmp
301
+ type = ft_string; // compare by memcmp
310
302
  opr = src->opr;
311
- delete [] tmp;
303
+ delete[] tmp;
312
304
  }
313
305
  };
314
306
 
315
307
  struct header
316
308
  {
317
- unsigned short len;
318
- char type[2];
319
- unsigned short rejectCount;
320
- unsigned short logicalCount;
321
- header(){reset();};
309
+ private:
310
+ union
311
+ {
312
+ struct
313
+ {
314
+ unsigned short len;
315
+ char type[2];
316
+ };
317
+ struct
318
+ {
319
+ int ilen : 28;
320
+ int itype : 4;
321
+ };
322
+ };
323
+
324
+ public:
325
+ unsigned short rejectCount;
326
+ unsigned short logicalCount;
327
+ header() : len(0), rejectCount(1), logicalCount(0)
328
+ {
329
+ type[0] = 0x00;
330
+ type[1] = 0x00;
331
+ }
332
+
322
333
  void reset()
323
334
  {
324
335
  rejectCount = 1;
325
336
  logicalCount = 0;
326
337
  len = 0;
327
- setPositionType(true);
338
+ type[0] = 0x00;
339
+ type[1] = 0x00;
328
340
  }
329
341
 
330
- void setPositionType(bool incCurrent)
342
+ void setPositionType(bool incCurrent, bool withBookmark, bool isTransactd)
331
343
  {
332
- if (incCurrent)
344
+ if (isTransactd)
333
345
  {
334
- type[0] = 'U';
335
- type[1] = 'C';
346
+ itype = incCurrent ? FILTER_CURRENT_TYPE_INC
347
+ : FILTER_CURRENT_TYPE_NOTINC;
348
+ if (!withBookmark)
349
+ itype |= FILTER_CURRENT_TYPE_NOBOOKMARK;
336
350
  }
337
351
  else
338
352
  {
339
- type[0] = 'E';
340
- type[1] = 'G';
353
+ if (incCurrent)
354
+ {
355
+ type[0] = 'U';
356
+ type[1] = 'C';
357
+ }
358
+ else
359
+ {
360
+ type[0] = 'E';
361
+ type[1] = 'G';
362
+ }
341
363
  }
342
364
  }
343
365
 
344
- bool positionTypeNext() const
366
+ int bookmarkSize(bool isTransactd) const
367
+ {
368
+ if (isTransactd)
369
+ return (itype & FILTER_CURRENT_TYPE_NOBOOKMARK) ? 0 : BOOKMARK_SIZE;
370
+ assert(type[0]);
371
+ // if (type[1] == 'N') return 0;
372
+ return BOOKMARK_SIZE;
373
+ }
374
+
375
+ bool positionTypeNext(bool isTransactd) const
345
376
  {
377
+ if (isTransactd)
378
+ return !(itype & FILTER_CURRENT_TYPE_INC);
346
379
  return (type[0] == 'E');
347
380
  }
348
381
 
349
- unsigned char* writeBuffer(unsigned char* p, bool estimate)
382
+ void setLen(int size, bool isTransactd)
383
+ {
384
+ if (isTransactd)
385
+ ilen = size;
386
+ else
387
+ len = size;
388
+ }
389
+
390
+ unsigned char* writeBuffer(unsigned char* p, bool estimate) const
350
391
  {
351
392
  int n = sizeof(header);
352
- if (!estimate) memcpy(p, this, n);
393
+ if (!estimate)
394
+ memcpy(p, this, n);
353
395
  return p + n;
354
396
  }
355
397
  };
356
- #pragma option -a
357
- pragma_pop
398
+ #pragma pack(pop)
399
+ pragma_pop;
400
+
401
+ class recordBackup
402
+ {
403
+ char* m_buf;
404
+ table* m_tb;
358
405
 
406
+ public:
407
+ recordBackup(table* tb) : m_tb(tb)
408
+ {
409
+ m_buf = new char[m_tb->buflen()];
410
+ memcpy(m_buf, m_tb->fieldPtr(0), m_tb->buflen());
411
+ }
359
412
 
413
+ ~recordBackup()
414
+ {
415
+ memcpy(m_tb->fieldPtr(0), m_buf, m_tb->buflen());
416
+ delete[] m_buf;
417
+ }
418
+ };
360
419
 
361
420
  class filter
362
421
  {
363
-
364
422
  table* m_tb;
365
423
  header m_hd;
366
424
  resultDef m_ret;
367
425
  std::vector<resultField*> m_fields;
368
- std::vector<logic*> m_logics;
426
+ std::vector<short> m_selectFieldIndexes;
427
+ std::vector<logic> m_logics;
428
+ std::vector<seek> m_seeks;
429
+ uchar_td* m_seeksDataBuffer;
430
+
369
431
  int m_extendBuflen;
370
- std::_tstring m_str;
371
432
  bool m_ignoreFields;
372
433
  bool m_seeksMode;
373
434
  bool m_useOptimize;
435
+ bool m_withBookmark;
374
436
  size_t m_seeksWritedCount;
375
437
  size_t m_logicalLimitCount;
376
438
  table::eFindType m_direction;
377
- std::vector<std::_tstring> m_keyValuesCache;
378
-
379
- bool addWhere(const _TCHAR* name, const _TCHAR* type, const _TCHAR* value, char combine, bool compField = false)
439
+ bool m_isTransactd;
440
+ bool m_hasManyJoin;
441
+ inline int maxDataBuffer()
380
442
  {
381
- logic* l = new logic();
382
- if (l->setParam(m_tb, name, type, value, combine, compField))
383
- {
384
- m_logics.push_back(l);
385
- return true;
386
- }
387
- delete l;
388
- return false;
443
+ return m_isTransactd ? TDAP_MAX_DATA_SIZE : BTRV_MAX_DATA_SIZE;
389
444
  }
390
445
 
391
446
  void addAllFields()
392
447
  {
393
448
  resultField* r = new resultField();
394
- r->len = (ushort_td) m_tb->tableDef()->maxRecordLen;
449
+ r->len = (ushort_td)m_tb->tableDef()->maxRecordLen;
395
450
  r->pos = 0;
396
451
  m_fields.push_back(r);
397
452
  }
@@ -399,9 +454,11 @@ class filter
399
454
  bool addSelect(const _TCHAR* name)
400
455
  {
401
456
  resultField* r = new resultField();
402
- if (r->setParam(m_tb, name))
457
+ int fieldNum = r->setParam(m_tb, name);
458
+ if (fieldNum != -1)
403
459
  {
404
460
  m_fields.push_back(r);
461
+ m_selectFieldIndexes.push_back(fieldNum);
405
462
  return true;
406
463
  }
407
464
  delete r;
@@ -410,7 +467,7 @@ class filter
410
467
 
411
468
  bool setSelect(const std::vector<std::_tstring>& selects)
412
469
  {
413
- for (size_t i=0;i < selects.size();++i)
470
+ for (size_t i = 0; i < selects.size(); ++i)
414
471
  {
415
472
  if (!addSelect(selects[i].c_str()))
416
473
  return false;
@@ -420,66 +477,117 @@ class filter
420
477
 
421
478
  bool setWhere(const std::vector<std::_tstring>& where)
422
479
  {
423
- if (where.size() == 0) return true;
424
- if (where.size() < 3) return false;
480
+ if (where.size() == 0)
481
+ return true;
482
+ if (where.size() < 3)
483
+ return false;
484
+ m_logics.resize(m_logics.size() + (where.size() + 1) / 4);
425
485
 
426
- for (size_t i=0;i<where.size();i+=4)
486
+ int index = 0;
487
+ for (size_t i = 0; i < where.size(); i += 4)
427
488
  {
489
+ if (i + 2 >= where.size())
490
+ return false;
428
491
  char combine = eCend;
429
- std::_tstring value = where[i+2];
430
- bool compField = (value[0] == _T('['));
492
+ std::_tstring value = where[i + 2];
493
+ bool compField = (value.size() && (value[0] == _T('[')));
431
494
  if (compField)
432
495
  {
433
496
  value.erase(value.begin());
434
497
  value.erase(value.end() - 1);
435
498
  }
436
- if (i+3 < where.size())
499
+ if (i + 3 < where.size())
437
500
  {
438
- std::_tstring s = where[i+3];
501
+ std::_tstring s = where[i + 3];
439
502
  boost::algorithm::to_lower(s);
440
- if (s == _T("or")) combine = eCor;
503
+ if (s == _T("or"))
504
+ combine = eCor;
441
505
  else if (s == _T("and"))
442
506
  combine = eCand;
443
507
  else
444
508
  return false;
445
509
  }
446
- if (!addWhere(where[i].c_str(), where[i+1].c_str()
447
- , value.c_str(), combine, compField))
510
+ if (!m_logics[index++].setParam(m_tb, where[i].c_str(),
511
+ where[i + 1].c_str(), value.c_str(),
512
+ combine, compField))
448
513
  return false;
449
514
  }
450
515
  return true;
516
+ }
451
517
 
518
+ inline void setSeekValue(short fieldNum, const std::_tstring& s)
519
+ {
520
+ m_tb->setFV(fieldNum, s.c_str());
452
521
  }
453
522
 
523
+ inline void setSeekValue(short fieldNum, const keyValuePtr& v)
524
+ {
525
+ if (v.type & KEYVALUE_STR)
526
+ m_tb->setFV(fieldNum, (_TCHAR*)v.ptr);
527
+ else
528
+ {
529
+ fielddef& fd = m_tb->tableDef()->fieldDefs[fieldNum];
530
+ void* p = m_tb->fieldPtr(fieldNum);
531
+
532
+ ushort_td len = std::min<ushort_td>(v.len, fd.len);
533
+ memset(p, 0, fd.len);
534
+ memcpy(p, v.ptr, len);
535
+ }
536
+ }
454
537
 
455
- bool setSeeks(const std::vector<std::_tstring>& keyValues)
538
+ template <class vector_type>
539
+ bool setSeeks(const vector_type& keyValues, const queryBase* q)
456
540
  {
457
- //Check key values
541
+ int keySize = q->getJoinKeySize();
542
+ // Check key values
458
543
  keydef* kd = &m_tb->tableDef()->keyDefs[m_tb->keyNum()];
459
- if (keyValues.size() % kd->segmentCount)
544
+ int joinKeySize = kd->segmentCount;
545
+ if (keySize != 0)
546
+ {
547
+ // Check specify key size is smoller than kd->segmentCount or equal
548
+ if (kd->segmentCount < keySize)
549
+ return false;
550
+ joinKeySize = keySize;
551
+ m_withBookmark = m_hasManyJoin =
552
+ (kd->segmentCount != joinKeySize) || kd->segments[0].flags.bit0;
553
+
554
+ // Check when m_hasManyJoin need set joinHasOneOrHasMany
555
+ if (m_hasManyJoin &&
556
+ !(q->getOptimize() & queryBase::joinHasOneOrHasMany))
557
+ return false;
558
+ }
559
+
560
+ if (keyValues.size() % joinKeySize)
460
561
  return false;
461
- //Check uniqe key
462
- if (kd->segments[0].flags.bit0)
562
+ // Check uniqe key
563
+ if (kd->segments[0].flags.bit0 && !queryBase::joinHasOneOrHasMany)
463
564
  return false;
464
-
465
- m_keyValuesCache = keyValues;
466
- for (size_t i=0;i<keyValues.size();i+= kd->segmentCount)
565
+ m_seeks.resize(keyValues.size() / joinKeySize);
566
+ int maxKeylen = 0;
567
+ for (int j = 0; j < joinKeySize; ++j)
568
+ maxKeylen +=
569
+ m_tb->tableDef()->fieldDefs[kd->segments[j].fieldNum].len + 2;
570
+
571
+ // alloc databuffer
572
+ if (m_seeksDataBuffer)
573
+ delete[] m_seeksDataBuffer;
574
+
575
+ m_seeksDataBuffer = new uchar_td[maxKeylen * m_seeks.size()];
576
+ memset(m_seeksDataBuffer, 0, maxKeylen * m_seeks.size());
577
+ uchar_td* dataBuf = m_seeksDataBuffer;
578
+
579
+ int index = 0;
580
+ for (size_t i = 0; i < keyValues.size(); i += joinKeySize)
467
581
  {
468
- for (int j=0;j<kd->segmentCount;++j)
469
- m_tb->setFV(kd->segments[j].fieldNum, keyValues[i+j].c_str());
470
-
471
- logic* l = new logic();
472
- ushort_td len = m_tb->writeKeyData();
473
- if (l->setParam(m_tb->m_keybuf, len))
474
- m_logics.push_back(l);
475
- else
476
- {
477
- delete l;
582
+ for (int j = 0; j < joinKeySize; ++j)
583
+ setSeekValue(kd->segments[j].fieldNum, keyValues[i + j]);
584
+ seek* l = &m_seeks[index];
585
+ ushort_td len = m_tb->writeKeyDataTo(dataBuf, joinKeySize);
586
+ if (!l->setParam(dataBuf, len))
478
587
  return false;
479
- }
588
+ dataBuf += len;
589
+ ++index;
480
590
  }
481
- if (m_logics.size())
482
- m_logics[m_logics.size() -1]->opr = eCend;
483
591
  m_seeksMode = true;
484
592
  m_seeksWritedCount = 0;
485
593
  return true;
@@ -491,7 +599,10 @@ class filter
491
599
  setRejectCount(q->getReject());
492
600
  setMaxRows(q->getLimit());
493
601
  m_direction = q->getDirection();
494
- m_useOptimize = q->isOptimize();
602
+ m_useOptimize = ((q->getOptimize() & queryBase::combineCondition) ==
603
+ queryBase::combineCondition);
604
+ m_withBookmark = q->isBookmarkAlso();
605
+ recordBackup recb(m_tb);
495
606
 
496
607
  if (q->isAll())
497
608
  addAllFields();
@@ -502,53 +613,57 @@ class filter
502
613
  else if (!setSelect(q->getSelects()))
503
614
  return false;
504
615
 
505
- //seeks or where
616
+ // seeks or where
506
617
  if (q->getSeekKeyValues().size() && q->getWheres().size())
507
618
  return false;
508
619
 
509
620
  if (q->getSeekKeyValues().size())
510
- return setSeeks(q->getSeekKeyValues());
621
+ return setSeeks(q->getSeekKeyValues(), q);
622
+ else if (q->getSeekValuesPtr().size())
623
+ return setSeeks(q->getSeekValuesPtr(), q);
511
624
  else if (q->getWheres().size())
512
625
  return setWhere(q->getWheres());
513
626
  }
514
627
  return true;
515
628
  }
516
629
 
517
- ushort_td resultRowSize(bool ignoreFields)
630
+ int resultRowSize(bool ignoreFields) const
518
631
  {
519
632
 
520
- ushort_td recordLen = BOOKMARK_SIZE + DATASIZE_BYTE;
633
+ int recordLen = m_hd.bookmarkSize(m_isTransactd) + DATASIZE_BYTE;
521
634
  if (!ignoreFields)
522
635
  {
523
- for (size_t i=0;i< m_fields.size();++i)
636
+ for (size_t i = 0; i < m_fields.size(); ++i)
524
637
  recordLen += m_fields[i]->len;
525
638
  }
526
639
  return recordLen;
527
640
  }
528
641
 
529
- ushort_td calcMaxRows()
642
+ int calcMaxRows()
530
643
  {
531
- return (ushort_td)(MAX_DATA_SIZE / resultRowSize(m_ignoreFields));
644
+ return maxDataBuffer() / resultRowSize(m_ignoreFields);
532
645
  }
533
646
 
534
- ushort_td resultBufferNeedSize()
647
+ int resultBufferNeedSize()
535
648
  {
536
649
  return (m_ret.maxRows * resultRowSize(m_ignoreFields)) + DATASIZE_BYTE;
537
650
  }
538
651
 
539
652
  void joinLogic()
540
653
  {
541
- if (m_seeksMode || !m_useOptimize) return;
654
+ if (m_seeksMode || !m_useOptimize)
655
+ return;
542
656
 
543
- for (int i= (int)m_logics.size()-2;i>=0;--i)
657
+ for (int i = (int)m_logics.size() - 2; i >= 0; --i)
544
658
  {
545
- logic* la = m_logics[i+1];
546
- logic* lb = m_logics[i];
547
- if (la->canJoin(false) && lb->canJoin(true) && lb->isNextFiled(la))
659
+
660
+ logic& la = m_logics[i + 1];
661
+ logic& lb = m_logics[i];
662
+ if (la.canJoin(false) && lb.canJoin(true) && lb.isNextFiled(&la))
548
663
  {
549
- lb->joinAfter(la);
550
- delete la;
551
- m_logics.erase(m_logics.begin()+i+1);
664
+ lb.joinAfter(&la);
665
+ // delete la;
666
+ m_logics.erase(m_logics.begin() + i + 1);
552
667
  }
553
668
  }
554
669
  }
@@ -558,7 +673,7 @@ class filter
558
673
  unsigned char* p = (unsigned char*)m_tb->dataBak();
559
674
  unsigned char* start = p;
560
675
 
561
- m_hd.logicalCount = (ushort_td)m_logicalLimitCount;
676
+ m_hd.logicalCount = (ushort_td)m_logicalLimitCount;
562
677
  if (m_ignoreFields)
563
678
  m_ret.fieldCount = 0;
564
679
  else
@@ -568,45 +683,62 @@ class filter
568
683
  if (m_seeksMode)
569
684
  {
570
685
  first = m_seeksWritedCount;
571
- last = std::min<size_t>(calcMaxRows() + m_seeksWritedCount, m_logicalLimitCount);
686
+ last = std::min<size_t>(calcMaxRows() + m_seeksWritedCount,
687
+ m_logicalLimitCount);
572
688
  m_hd.rejectCount = 0;
573
- m_ret.maxRows = m_hd.logicalCount = (ushort_td)(last - first);
689
+ if (m_hasManyJoin)
690
+ m_ret.maxRows = 0;
691
+ else
692
+ m_ret.maxRows = m_hd.logicalCount = (ushort_td)(last - first);
574
693
  }
575
694
  if (m_ret.maxRows == 0)
576
- m_ret.maxRows = calcMaxRows();
695
+ m_ret.maxRows =
696
+ (unsigned short)std::min<int>(calcMaxRows(), USHRT_MAX);
577
697
 
578
- p = m_hd.writeBuffer(p, estimate);
579
- for (size_t i=first;i< last;++i)
580
- p = m_logics[i]->writeBuffer(p, estimate, (i==(last-1)));
581
- if (m_seeksMode && !estimate)
582
- m_seeksWritedCount += m_hd.logicalCount;
698
+ p = m_hd.writeBuffer(p, estimate);
699
+ if (m_seeksMode)
700
+ {
701
+ for (size_t i = first; i < last; ++i)
702
+ p = m_seeks[i].writeBuffer(p, estimate, (i == (last - 1)),
703
+ true);
704
+ if (!estimate)
705
+ m_seeksWritedCount += m_hd.logicalCount;
706
+ }
707
+ else
708
+ {
709
+ for (size_t i = first; i < last; ++i)
710
+ p = m_logics[i].writeBuffer(p, estimate, (i == (last - 1)));
711
+ }
583
712
 
584
- p = m_ret.writeBuffer(p, estimate);
713
+ p = m_ret.writeBuffer(p, estimate);
585
714
 
586
715
  if (!m_ignoreFields)
587
716
  {
588
- for (size_t i=0;i< m_fields.size();++i)
717
+ for (size_t i = 0; i < m_fields.size(); ++i)
589
718
  p = m_fields[i]->writeBuffer(p, estimate);
590
719
  }
591
720
 
592
- //write total length
721
+ // write total length
593
722
  int len = (int)(p - start);
594
- unsigned short* s = (unsigned short*)start;
595
723
  if (!estimate)
596
- *s = len;
724
+ {
725
+ m_hd.setLen(len, m_isTransactd);
726
+ m_hd.writeBuffer(start, false);
727
+ }
597
728
  return len;
598
729
  }
599
730
 
731
+ // use seeksMode only
600
732
  int calcLogicalCutsize(int oversize)
601
733
  {
602
734
  int cutsize = 0;
603
- for (size_t i=m_hd.logicalCount-1;i!=0;--i)
735
+ for (size_t i = m_hd.logicalCount - 1; i != 0; --i)
604
736
  {
605
- cutsize += (int)m_logics[i+m_seeksWritedCount]->getLength();
737
+ cutsize += (int)m_seeks[i + m_seeksWritedCount].getLength();
606
738
  if (oversize - cutsize < 0)
607
739
  {
608
740
  m_logicalLimitCount = i;
609
- return cutsize;
741
+ return cutsize;
610
742
  }
611
743
  }
612
744
  return 0;
@@ -615,62 +747,70 @@ class filter
615
747
  bool allocDataBuffer()
616
748
  {
617
749
  joinLogic();
618
- m_logicalLimitCount = m_logics.size();
750
+ m_logicalLimitCount = m_seeksMode ? m_seeks.size() : m_logics.size();
619
751
  int len = doWriteBuffer(true);
620
- if (len > (int)MAX_DATA_SIZE)
752
+ if (len > maxDataBuffer())
621
753
  {
622
754
  if (m_seeksMode)
623
- len -= calcLogicalCutsize(len - MAX_DATA_SIZE + 1);
755
+ len -= calcLogicalCutsize(len - maxDataBuffer() + 1);
624
756
  else
625
757
  return false;
626
758
  }
627
- m_hd.len = len;
628
- int resultLen = resultBufferNeedSize();
629
- if (resultLen > MAX_DATA_SIZE)
759
+ // m_hd.len = len;//lost 2byte data at transactd
760
+ int resultLen = (int)resultBufferNeedSize();
761
+ if (resultLen > maxDataBuffer())
630
762
  {
763
+ /* change the max rows fit to a max buffer size */
631
764
  m_ret.maxRows = calcMaxRows();
632
765
  resultLen = resultBufferNeedSize();
633
766
  }
634
- m_extendBuflen = std::max<int>((int)m_hd.len, resultLen);
635
- m_extendBuflen = std::max<int>(m_extendBuflen, m_tb->tableDef()->maxRecordLen);
636
- if ((m_fields.size() != 1) || m_tb->valiableFormatType())
767
+
768
+ m_extendBuflen = std::max<int>((int)len, resultLen);
769
+ m_extendBuflen =
770
+ std::max<int>(m_extendBuflen, m_tb->tableDef()->maxRecordLen);
771
+ if (fieldSelected() || m_tb->valiableFormatType())
637
772
  m_extendBuflen += m_tb->buflen();
638
773
 
639
774
  if ((int)m_tb->buflen() < m_extendBuflen)
640
775
  {
641
- m_tb->setDataBak((void*) realloc(m_tb->dataBak(), m_extendBuflen));
776
+ m_tb->setDataBak((void*)realloc(m_tb->dataBak(), m_extendBuflen));
642
777
  m_tb->setData(m_tb->dataBak());
643
778
  }
644
779
  return true;
645
780
  }
646
781
 
647
782
  public:
648
- filter(table* tb):m_tb(tb),m_ignoreFields(false)
649
- ,m_seeksMode(false),m_seeksWritedCount(0),m_useOptimize(true){}
650
- ~filter()
783
+ filter(table* tb)
784
+ : m_tb(tb), m_seeksDataBuffer(NULL), m_ignoreFields(false),
785
+ m_seeksMode(false), m_useOptimize(true), m_withBookmark(true),
786
+ m_seeksWritedCount(0), m_hasManyJoin(false)
651
787
  {
652
- cleanup();
788
+ m_isTransactd = m_tb->isUseTransactd();
653
789
  }
654
790
 
791
+ ~filter() { cleanup(); }
792
+
655
793
  void cleanup()
656
794
  {
657
- for (size_t i=0;i < m_logics.size();++i)
658
- delete m_logics[i];
659
- for (size_t i=0;i < m_fields.size();++i)
795
+ for (size_t i = 0; i < m_fields.size(); ++i)
660
796
  delete m_fields[i];
661
- m_logics.erase(m_logics.begin(), m_logics.end());
662
- m_fields.erase(m_fields.begin(), m_fields.end());
797
+ m_selectFieldIndexes.clear();
798
+ m_fields.clear();
799
+ m_logics.clear();
800
+ m_seeks.clear();
663
801
  m_hd.reset();
664
802
  m_ret.reset();
665
803
  m_ignoreFields = false;
666
804
  m_seeksMode = false;
667
805
  m_seeksWritedCount = 0;
668
806
  m_useOptimize = true;
807
+ delete[] m_seeksDataBuffer;
808
+ m_seeksDataBuffer = NULL;
809
+ m_hasManyJoin = false;
669
810
  }
670
811
 
671
812
  bool setQuery(const queryBase* q)
672
813
  {
673
- m_str = q->toString();
674
814
  bool ret = doSetFilter(q);
675
815
  if (!ret)
676
816
  cleanup();
@@ -679,39 +819,47 @@ public:
679
819
 
680
820
  bool isWriteComleted() const
681
821
  {
682
- if (!m_seeksMode) return true;
683
- return (m_seeksWritedCount == m_logics.size());
822
+ if (!m_seeksMode)
823
+ return true;
824
+ return (m_seeksWritedCount == m_seeks.size());
684
825
  }
685
- void resetSeeksWrited(){m_seeksWritedCount = 0;}
686
826
 
687
- void setPositionType(bool incCurrent){m_hd.setPositionType(incCurrent);}
827
+ inline bool hasManyJoin() const { return m_hasManyJoin; }
688
828
 
689
- bool positionTypeNext() const{return m_hd.positionTypeNext();}
829
+ inline void resetSeeksWrited() { m_seeksWritedCount = 0; }
830
+
831
+ void setPositionType(bool incCurrent)
832
+ {
833
+ m_hd.setPositionType(incCurrent, m_withBookmark, m_isTransactd);
834
+ }
835
+
836
+ bool positionTypeNext() const
837
+ {
838
+ return m_hd.positionTypeNext(m_isTransactd);
839
+ }
690
840
 
691
- void setRejectCount(ushort_td v){m_hd.rejectCount = v;}
692
- ushort_td rejectCount()const {return m_hd.rejectCount;}
841
+ void setRejectCount(ushort_td v) { m_hd.rejectCount = v; }
842
+ ushort_td rejectCount() const { return m_hd.rejectCount; }
693
843
 
694
- void setMaxRows(ushort_td v){m_ret.maxRows = v;}
695
- ushort_td maxRows()const {return m_ret.maxRows;}
844
+ void setMaxRows(ushort_td v) { m_ret.maxRows = v; }
845
+ ushort_td maxRows() const { return m_ret.maxRows; }
696
846
 
697
- ushort_td recordCount()const {return maxRows();}
847
+ ushort_td recordCount() const { return maxRows(); }
698
848
 
699
- void setPosTypeNext(bool v){setPositionType(!v);}
849
+ void setPosTypeNext(bool v) { setPositionType(!v); }
700
850
 
701
851
  uint_td exDataBufLen() const
702
852
  {
703
- if ((m_fields.size() != 1) || m_tb->valiableFormatType())
853
+ if (fieldSelected() || m_tb->valiableFormatType())
704
854
  return m_extendBuflen - m_tb->buflen();
705
855
  return m_extendBuflen;
706
856
  }
707
857
 
708
858
  void init(table* pBao){};
709
859
 
710
- const _TCHAR* filterStr(){return m_str.c_str();}
711
-
712
- ushort_td fieldCount() const {return m_ret.fieldCount;}
860
+ ushort_td fieldCount() const { return m_ret.fieldCount; }
713
861
 
714
- void setFieldCount(ushort_td v){m_ret.fieldCount = v;}
862
+ void setFieldCount(ushort_td v) { m_ret.fieldCount = v; }
715
863
 
716
864
  ushort_td fieldLen(int index) const
717
865
  {
@@ -719,6 +867,20 @@ public:
719
867
  return m_fields[index]->len;
720
868
  }
721
869
 
870
+ ushort_td totalFieldLen() const
871
+ {
872
+ return resultRowSize(false) - m_hd.bookmarkSize(m_isTransactd) -
873
+ DATASIZE_BYTE;
874
+ }
875
+
876
+ ushort_td totalSelectFieldLen() const
877
+ {
878
+ ushort_td recordLen = 0;
879
+ for (size_t i = 0; i < m_fields.size(); ++i)
880
+ recordLen += m_fields[i]->len;
881
+ return recordLen;
882
+ }
883
+
722
884
  ushort_td fieldOffset(int index) const
723
885
  {
724
886
  assert(index < (int)m_fields.size());
@@ -732,35 +894,37 @@ public:
732
894
  return false;
733
895
  }
734
896
 
735
- ushort_td extendBuflen() const{return m_extendBuflen;}
897
+ ushort_td extendBuflen() const { return m_extendBuflen; }
736
898
 
737
899
  bool fieldSelected() const
738
900
  {
739
- return !((m_fields.size() == 1) && (m_fields[0]->pos == 0));
901
+ return !((m_fields.size() == 1) && (m_fields[0]->pos == 0) &&
902
+ (m_fields[0]->len ==
903
+ (ushort_td)m_tb->tableDef()->maxRecordLen));
740
904
  }
741
905
 
742
- bool ignoreFields() const {return m_ignoreFields;}
906
+ bool ignoreFields() const { return m_ignoreFields; }
907
+
908
+ int bookmarkSize() const { return m_hd.bookmarkSize(m_isTransactd); }
743
909
 
744
910
  /* The Ignore fields option don't use with multi seek operation.
745
911
  because if a server are not found a record then a server return
746
912
  error code in a bookmark field.
747
913
  */
748
- void setIgnoreFields(bool v){m_ignoreFields = v;}
749
- bool isSeeksMode()const {return m_seeksMode;}
750
- table::eFindType direction() const{return m_direction;}
751
- void setDirection(table::eFindType v) {m_direction = v;}
752
- const std::vector<std::_tstring>& keyValuesCache(){return m_keyValuesCache;};
753
-
754
-
914
+ void setIgnoreFields(bool v) { m_ignoreFields = v; }
915
+ bool isSeeksMode() const { return m_seeksMode; }
916
+ table::eFindType direction() const { return m_direction; }
917
+ void setDirection(table::eFindType v) { m_direction = v; }
918
+ const std::vector<short>& selectFieldIndexes()
919
+ {
920
+ return m_selectFieldIndexes;
921
+ }
922
+ const std::vector<seek>& seeks() const { return m_seeks; }
755
923
  };
756
924
 
757
-
758
-
759
-
760
-
761
- }// namespace client
762
- }// namespace tdap
763
- }// namespace protocol
764
- }// namespace db
765
- }// namespace bzs
766
- #endif//BZS_DB_PROTOCOL_TDAP_CLIENT_FILTER_H
925
+ } // namespace client
926
+ } // namespace tdap
927
+ } // namespace protocol
928
+ } // namespace db
929
+ } // namespace bzs
930
+ #endif // BZS_DB_PROTOCOL_TDAP_CLIENT_FILTER_H