transactd 1.2.0 → 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (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
@@ -12,14 +12,15 @@
12
12
  GNU General Public License for more details.
13
13
 
14
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
15
+ along with this program; if not, write to the Free Software
16
+ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
17
17
  02111-1307, USA.
18
18
  =================================================================*/
19
19
  #ifndef BZS_DB_PROTOCOL_TDAP_MYSQL_RECORDSETREADER_H
20
20
  #define BZS_DB_PROTOCOL_TDAP_MYSQL_RECORDSETREADER_H
21
21
 
22
22
  #include "request.h"
23
+ #include <bzs/db/protocol/tdap/tdapSchema.h>
23
24
  #include <bzs/rtl/exception.h>
24
25
  #include <bzs/db/engine/mysql/IReadRecords.h>
25
26
  #include <bzs/db/engine/mysql/fieldAccess.h>
@@ -39,8 +40,8 @@ namespace tdap
39
40
  namespace mysql
40
41
  {
41
42
 
42
- #pragma option -a-
43
- pragma_pack1
43
+ #pragma pack(push, 1)
44
+ pragma_pack1;
44
45
 
45
46
  struct logicalField;
46
47
  struct resultField;
@@ -49,843 +50,1008 @@ struct resultField;
49
50
  */
50
51
  class position
51
52
  {
52
- engine::mysql::table* m_tb;
53
- const char* m_record;
53
+ engine::mysql::table* m_tb;
54
+ const char* m_record;
55
+
54
56
  public:
55
- inline position();
56
- inline void setTable(engine::mysql::table* tb);
57
- inline char* fieldPtr(const resultField* rf) const;
58
- inline bool isBlobField(const resultField* rf) const;
59
- inline void addBlobBuffer(int fieldNum){m_tb->addBlobBuffer(fieldNum);};
60
- inline void setBlobFieldCount(int v){m_tb->setBlobFieldCount(v);};
61
- inline unsigned short packLen(const resultField* rf) const;
62
- inline const char* record()const{return m_record;}
63
- inline ulong recordLenCl()const{return m_tb->recordLenCl();}
64
- inline int recordFormatType()const {return m_tb->recordFormatType();};
65
- inline uint recordPackCopy(char* buf, uint maxlen)const{return m_tb->recordPackCopy(buf, maxlen);}
66
- int getFieldNumByPos(unsigned short pos)const
67
- {
68
- for (int i=0;i<m_tb->fields();i++)
69
- {
70
- char* start = m_tb->fieldPos(0);
71
- if (m_tb->fieldPos(i)-start == pos)
72
- return i;
73
- }
74
- return -1;
75
- }
76
- inline uint fieldSizeByte(int fieldNum){return m_tb->fieldSizeByte(fieldNum);}
57
+ inline position();
58
+ inline void setTable(engine::mysql::table* tb);
59
+ inline char* fieldPtr(const resultField* rf) const;
60
+ inline bool isBlobField(const resultField* rf) const;
61
+ inline void addBlobBuffer(int fieldNum) { m_tb->addBlobBuffer(fieldNum); };
62
+ inline void setBlobFieldCount(int v) { m_tb->setBlobFieldCount(v); };
63
+ inline unsigned short packLen(const resultField* rf) const;
64
+ inline const char* record() const { return m_record; }
65
+ inline ulong recordLenCl() const { return m_tb->recordLenCl(); }
66
+ inline int recordFormatType() const { return m_tb->recordFormatType(); };
67
+ inline uint recordPackCopy(char* buf, uint maxlen) const
68
+ {
69
+ return m_tb->recordPackCopy(buf, maxlen);
70
+ }
71
+ int getFieldNumByPos(unsigned short pos) const
72
+ {
73
+ for (int i = 0; i < m_tb->fields(); i++)
74
+ {
75
+ char* start = m_tb->fieldPos(0);
76
+ if (m_tb->fieldPos(i) - start == pos)
77
+ return i;
78
+ }
79
+ return -1;
80
+ }
81
+ inline uint fieldSizeByte(int fieldNum)
82
+ {
83
+ return m_tb->fieldSizeByte(fieldNum);
84
+ }
85
+ inline ushort fieldPackCopy(unsigned char* dest, short filedNum)
86
+ {
87
+ return m_tb->fieldPackCopy(dest, filedNum);
88
+ }
77
89
  };
78
90
 
79
91
  /** If get all field then len = record length.
80
- *
92
+ *
81
93
  */
82
94
  struct resultField
83
95
  {
84
- unsigned short len;
85
- union
86
- {
87
- unsigned short pos;
88
- unsigned short fieldNum;
89
- };
96
+ unsigned short len;
97
+ union
98
+ {
99
+ unsigned short pos;
100
+ unsigned short fieldNum;
101
+ };
90
102
  };
91
103
 
92
104
  struct extResultDef
93
105
  {
94
- unsigned short maxRows;
95
- unsigned short fieldCount;
96
- resultField field[1]; //variable
106
+ unsigned short maxRows;
107
+ unsigned short fieldCount;
108
+ resultField field[1]; // variable
97
109
  };
98
110
 
99
-
100
-
101
-
102
- inline position::position():m_tb(NULL),m_record(NULL){};
103
- inline void position::setTable( engine::mysql::table* tb)
111
+ inline position::position() : m_tb(NULL), m_record(NULL){};
112
+ inline void position::setTable(engine::mysql::table* tb)
104
113
  {
105
- m_tb = tb;
106
- m_record = (const char*)m_tb->record();
114
+ m_tb = tb;
115
+ m_record = (const char*)m_tb->record();
107
116
  }
108
117
 
109
118
  inline char* position::fieldPtr(const resultField* rf) const
110
119
  {
111
- return m_tb->fieldPos(rf->fieldNum);
120
+ return m_tb->fieldPos(rf->fieldNum);
112
121
  }
113
122
 
114
123
  inline bool position::isBlobField(const resultField* rf) const
115
124
  {
116
- return db::engine::mysql::isBlobType(m_tb->fieldType(rf->fieldNum));
125
+ return db::engine::mysql::isBlobType(m_tb->fieldType(rf->fieldNum));
117
126
  }
118
127
 
119
-
120
128
  /** return data length as real rength.
121
129
  */
122
130
  inline unsigned short position::packLen(const resultField* rf) const
123
131
  {
124
- return m_tb->fieldDataLen(rf->fieldNum);
132
+ return m_tb->fieldDataLen(rf->fieldNum);
125
133
  }
126
134
 
127
135
  inline int compareUint24(const char* l, const char* r)
128
136
  {
129
- unsigned int lv = *((unsigned int*)l) & 0xFFFFFF;
130
- unsigned int rv = *((unsigned int*)r) & 0xFFFFFF;
131
- if (lv < rv)
132
- return -1;
133
- if (lv > rv)
134
- return 1;
135
- return 0;
137
+ unsigned int lv = *((unsigned int*)l) & 0xFFFFFF;
138
+ unsigned int rv = *((unsigned int*)r) & 0xFFFFFF;
139
+ if (lv < rv)
140
+ return -1;
141
+ if (lv > rv)
142
+ return 1;
143
+ return 0;
136
144
  }
137
145
 
138
146
  inline int compareInt24(const char* l, const char* r)
139
147
  {
140
- int lv = ((*((int*)l) & 0xFFFFFF) << 8) / 0x100;
141
- int rv = ((*((int*)r) & 0xFFFFFF) << 8) / 0x100;
142
-
143
- if (lv < rv)
144
- return -1;
145
- else if (lv > rv)
146
- return 1;
147
- return 0;
148
+ int lv = ((*((int*)l) & 0xFFFFFF) << 8) / 0x100;
149
+ int rv = ((*((int*)r) & 0xFFFFFF) << 8) / 0x100;
150
+
151
+ if (lv < rv)
152
+ return -1;
153
+ else if (lv > rv)
154
+ return 1;
155
+ return 0;
148
156
  }
149
157
 
150
- template <class T>
151
- inline int compare(const char* l, const char* r)
158
+ template <class T> inline int compare(const char* l, const char* r)
152
159
  {
153
- if (*((T*)l) < *((T*)r))
154
- return -1;
155
- else if (*((T*)l) > *((T*)r))
156
- return 1;
157
- return 0;
160
+ if (*((T*)l) < *((T*)r))
161
+ return -1;
162
+ else if (*((T*)l) > *((T*)r))
163
+ return 1;
164
+ return 0;
158
165
  }
159
166
 
160
- template <class T>
161
- inline int compare(T l, T r)
167
+ template <class T> inline int compare(T l, T r)
162
168
  {
163
- if (l < r)
164
- return -1;
165
- else if (l > r)
166
- return 1;
167
- return 0;
169
+ if (l < r)
170
+ return -1;
171
+ else if (l > r)
172
+ return 1;
173
+ return 0;
168
174
  }
169
175
 
170
176
  template <class T>
171
177
  inline int compareVartype(const char* l, const char* r, bool bin, char logType)
172
178
  {
173
- int llen = (*(T*)l);
174
- int rlen = (*(T*)r);
175
- int tmp = std::min(llen, rlen);
176
- if (logType & CMPLOGICAL_CASEINSENSITIVE)
177
- tmp = _strnicmp(l + sizeof(T), r + sizeof(T), tmp);
178
- else if (bin)
179
- tmp = memcmp(l + sizeof(T), r + sizeof(T), tmp);
180
- else
181
- tmp = strncmp(l + sizeof(T), r + sizeof(T), tmp);
182
-
183
- if (logType & CMPLOGICAL_VAR_COMP_ALL)
184
- return (tmp==0)?compare<int>(llen, rlen):tmp; //match complete
185
- return (tmp==0 && (llen < rlen))? -1:tmp; //match a part
179
+ int llen = (*(T*)l);
180
+ int rlen = (*(T*)r);
181
+ int tmp = std::min(llen, rlen);
182
+ if (logType & CMPLOGICAL_CASEINSENSITIVE)
183
+ tmp = _strnicmp(l + sizeof(T), r + sizeof(T), tmp);
184
+ else if (bin)
185
+ tmp = memcmp(l + sizeof(T), r + sizeof(T), tmp);
186
+ else
187
+ tmp = strncmp(l + sizeof(T), r + sizeof(T), tmp);
188
+
189
+ if (logType & CMPLOGICAL_VAR_COMP_ALL)
190
+ return (tmp == 0) ? compare<int>(llen, rlen) : tmp; // match complete
191
+ return (tmp == 0 && (llen < rlen)) ? -1 : tmp; // match a part
186
192
  }
187
193
 
188
194
  template <class T>
189
195
  inline int compareWvartype(const char* l, const char* r, bool bin, char logType)
190
196
  {
191
- int llen = (*(T*)l) / sizeof(char16_t);
192
- int rlen = (*(T*)r) / sizeof(char16_t);
193
- int tmp = std::min(llen, rlen);
194
- if (logType & CMPLOGICAL_CASEINSENSITIVE)
195
- tmp = wcsnicmp16((char16_t*)(l + sizeof(T)), (char16_t*)(r + sizeof(T)), tmp);
196
- else if (bin)
197
- tmp = memcmp((char16_t*)(l + sizeof(T)), (char16_t*)(r + sizeof(T)), tmp);
198
- else
199
- tmp = wcsncmp16((char16_t*)(l + sizeof(T)), (char16_t*)(r + sizeof(T)), tmp);
200
- if (logType & CMPLOGICAL_VAR_COMP_ALL)
201
- return (tmp==0)?compare<int>(llen, rlen):tmp; //match complete
202
- return (tmp==0 && (llen < rlen))? -1:tmp; //match a part
197
+ int llen = (*(T*)l) / sizeof(char16_t);
198
+ int rlen = (*(T*)r) / sizeof(char16_t);
199
+ int tmp = std::min(llen, rlen);
200
+ if (logType & CMPLOGICAL_CASEINSENSITIVE)
201
+ tmp = wcsnicmp16((char16_t*)(l + sizeof(T)), (char16_t*)(r + sizeof(T)),
202
+ tmp);
203
+ else if (bin)
204
+ tmp =
205
+ memcmp((char16_t*)(l + sizeof(T)), (char16_t*)(r + sizeof(T)), tmp);
206
+ else
207
+ tmp = wcsncmp16((char16_t*)(l + sizeof(T)), (char16_t*)(r + sizeof(T)),
208
+ tmp);
209
+ if (logType & CMPLOGICAL_VAR_COMP_ALL)
210
+ return (tmp == 0) ? compare<int>(llen, rlen) : tmp; // match complete
211
+ return (tmp == 0 && (llen < rlen)) ? -1 : tmp; // match a part
203
212
  }
204
213
 
205
- inline int compareBlobType(const char* l, const char* r, bool bin, char logType, int sizeByte)
206
- {
207
- int llen = 0;
208
- int rlen = 0;
209
- memcpy(&llen, l, sizeByte);
210
- memcpy(&rlen, r, sizeByte);
211
- int tmp = std::min(llen, rlen);
212
- const char* lptr = *((const char**)(l + sizeByte));
213
- const char* rptr = r + sizeByte;
214
- if (logType & CMPLOGICAL_CASEINSENSITIVE)
215
- tmp = _strnicmp(lptr, rptr, tmp);
216
- else if (bin)
217
- tmp = memcmp(lptr, rptr, tmp);
218
- else
219
- tmp = strncmp(lptr, rptr, tmp);
220
-
221
- if (logType & CMPLOGICAL_VAR_COMP_ALL)
222
- return (tmp==0)?compare<int>(llen, rlen):tmp;
223
- return (tmp==0 && (llen < rlen))? -1:tmp;
214
+ inline int compareBlobType(const char* l, const char* r, bool bin, char logType,
215
+ int sizeByte)
216
+ {
217
+ int llen = 0;
218
+ int rlen = 0;
219
+ memcpy(&llen, l, sizeByte);
220
+ memcpy(&rlen, r, sizeByte);
221
+ int tmp = std::min(llen, rlen);
222
+ const char* lptr = *((const char**)(l + sizeByte));
223
+ const char* rptr = r + sizeByte;
224
+ if (logType & CMPLOGICAL_CASEINSENSITIVE)
225
+ tmp = _strnicmp(lptr, rptr, tmp);
226
+ else if (bin)
227
+ tmp = memcmp(lptr, rptr, tmp);
228
+ else
229
+ tmp = strncmp(lptr, rptr, tmp);
230
+
231
+ if (logType & CMPLOGICAL_VAR_COMP_ALL)
232
+ return (tmp == 0) ? compare<int>(llen, rlen) : tmp;
233
+ return (tmp == 0 && (llen < rlen)) ? -1 : tmp;
224
234
  }
225
235
 
226
- #define REC_MACTH 0
227
- #define REC_NOMACTH 1
228
- #define REC_NOMACTH_NOMORE 2
236
+ #define REC_MACTH 0
237
+ #define REC_NOMACTH 1
238
+ #define REC_NOMACTH_NOMORE 2
229
239
 
230
240
  //#define COMP_USE_SWITCHCASE
231
241
  #ifndef COMP_USE_SWITCHCASE
232
- #define COMP_USE_FUNCTION_POINTER
242
+ #define COMP_USE_FUNCTION_POINTER
233
243
  #endif
234
244
 
245
+ struct seek
246
+ {
247
+ unsigned short len;
248
+ unsigned char ptr[1]; // variable
249
+ seek* next() const
250
+ {
251
+ return (seek*)((char*)this + len + sizeof(unsigned short));
252
+ }
253
+
254
+ extResultDef* resultDef(int count) const
255
+ {
256
+ const seek* s = this;
257
+ while (count--)
258
+ s = s->next();
259
+ return (extResultDef*)s;
260
+ }
261
+ };
262
+
235
263
  struct logicalField;
236
- typedef int (logicalField::*compFunc)(const char* l, const char* r, int sizeByte) const;
264
+ typedef int (logicalField::*compFunc)(const char* l, const char* r,
265
+ int sizeByte) const;
237
266
  struct logicalField
238
267
  {
239
-
268
+
269
+ public:
270
+ unsigned char type;
271
+ unsigned short len;
272
+ unsigned short pos;
273
+ char logType;
274
+ char opr;
275
+ union
276
+ {
277
+ unsigned short offset;
278
+ unsigned char ptr[2]; // variable
279
+ };
280
+
281
+ logicalField* next() const
282
+ {
283
+ return (logType & 64) ? (logicalField*)(ptr + 2)
284
+ : (logicalField*)(ptr + len);
285
+ }
286
+
240
287
  public:
241
- unsigned char type;
242
- unsigned short len;
243
- unsigned short pos;
244
- char logType;
245
- char opr;
246
- union
247
- {
248
- unsigned short offset;
249
- unsigned char ptr[2]; //variable
250
- };
251
-
252
- logicalField* next() const
253
- {
254
- return (logType & 64)?(logicalField*)(ptr + 2):(logicalField*)(ptr + len);
255
- }
256
-
257
- public:
258
288
  #ifdef COMP_USE_SWITCHCASE
259
- int comp(const char* record, int sizeByte) const
260
- {
261
- const char* r = (const char*) ptr;
262
- if (logType & CMPLOGICAL_FIELD)
263
- r = record + offset;
264
- const char* l = record + pos;
265
- switch(type)
266
- {
267
- case ft_integer:
268
- case ft_autoinc:
269
- case ft_currency:
270
- {
271
- switch(len)
272
- {
273
- case 1:return compare<char>(l, r);
274
- case 2:return compare<short>(l, r);
275
- case 3:return compareInt24(l, r);
276
- case 4:return compare<int>(l, r);
277
- case 8:return compare<__int64>(l, r);
278
- }
279
- }
280
- case ft_mychar:
281
- case ft_string:
282
- if (logType & CMPLOGICAL_CASEINSENSITIVE)
283
- return _strnicmp(l, r, len);
284
- return memcmp(l, r, len);
285
- case ft_zstring:
286
- case ft_note:
287
- if (logType & CMPLOGICAL_CASEINSENSITIVE)
288
- return _strnicmp(l, r, len);
289
- return strncmp(l, r, len);
290
- case ft_logical:
291
- case ft_uinteger:
292
- case ft_autoIncUnsigned:
293
- case ft_date:
294
- case ft_time:
295
- case ft_timestamp:
296
- case ft_mydate:
297
- {
298
- switch(len)
299
- {
300
- case 1:return compare<unsigned char>(l, r);
301
- case 2:return compare<unsigned short>(l, r);
302
- case 3:return compareUint24(l, r);
303
- case 4:return compare<unsigned int>(l, r);
304
- case 8:return compare<unsigned __int64>(l, r);
305
- }
306
- }
307
-
308
- case ft_mytime:
309
- case ft_mydatetime:
310
- case ft_mytimestamp:
311
- return memcmp(l, r, len);
312
- case ft_float:
313
- switch(len)
314
- {
315
- case 4:return compare<float>(l, r);
316
- case 8:return compare<double>(l, r);
317
- }
318
- case ft_mywchar:
319
- case ft_wstring:
320
- case ft_wzstring:
321
- if (logType & CMPLOGICAL_CASEINSENSITIVE)
322
- return wcsnicmp16((char16_t*)l, (char16_t*)r, len);
323
- if ((type==ft_wstring)||(type==ft_mywchar))
324
- return memcmp(l, r, len);
325
- return wcsncmp16((char16_t*)l, (char16_t*)r, len);
326
- case ft_lstring:
327
- case ft_myvarchar:
328
- case ft_myvarbinary:
329
- if (sizeByte==1)
330
- return compareVartype<unsigned char>(l, r, type==ft_myvarbinary, logType);
331
- return compareVartype<unsigned short>(l, r, type==ft_myvarbinary, logType);
332
- case ft_mywvarchar:
333
- case ft_mywvarbinary:
334
- if (sizeByte==1)
335
- return compareWvartype<unsigned char>(l, r, type==ft_mywvarbinary, logType);
336
- return compareWvartype<unsigned short>(l, r, type==ft_mywvarbinary, logType);
337
- case ft_mytext:
338
- case ft_myblob:
339
- return compareBlobType(l, r, type==ft_myblob, logType, sizeByte);
340
- }
341
- return 0;
342
- };
343
- #else //COMP_USE_FUNCTION_POINTER
344
-
345
- template <class T>
346
- int compNumber(const char* l, const char* r, int sizeByte) const
347
- {
348
- return compare<T>(l , r);
349
- }
350
-
351
- int compNumber24(const char* l, const char* r, int sizeByte) const
352
- {
353
- return compareInt24(l , r);
354
- }
355
-
356
- int compNumberU24(const char* l, const char* r, int sizeByte) const
357
- {
358
- return compareUint24(l , r);
359
- }
360
-
361
- int compMem(const char* l, const char* r, int sizeByte) const
362
- {
363
- return memcmp(l , r, len);
364
- }
365
-
366
- int compString(const char* l, const char* r, int sizeByte) const
367
- {
368
- return strncmp(l , r, len);
369
- }
370
-
371
- int compiString(const char* l, const char* r, int sizeByte) const
372
- {
373
- return _strnicmp(l , r, len);
374
- }
375
-
376
- int compWString(const char* l, const char* r, int sizeByte) const
377
- {
378
- return wcsncmp16((char16_t*)l , (char16_t*)r, len);
379
- }
380
-
381
- int compiWString(const char* l, const char* r, int sizeByte) const
382
- {
383
- return wcsnicmp16((char16_t*)l , (char16_t*)r, len);
384
- }
385
-
386
- template <class T>
387
- int compVarString(const char* l, const char* r, int sizeByte) const
388
- {
389
- return compareVartype<T>(l, r, type==ft_myvarbinary, logType);
390
- }
391
-
392
- template <class T>
393
- int compWVarString(const char* l, const char* r, int sizeByte) const
394
- {
395
- return compareWvartype<T>(l, r, type==ft_mywvarbinary, logType);
396
- }
397
-
398
- int compBlob(const char* l, const char* r, int sizeByte) const
399
- {
400
- return compareBlobType(l, r, type==ft_myblob, logType, sizeByte);
401
- }
402
-
403
- compFunc logicalField::getCompFunc(int sizeByte)
404
- {
405
- switch(type)
406
- {
407
- case ft_integer:
408
- case ft_autoinc:
409
- case ft_currency:
410
- {
411
- switch(len)
412
- {
413
- case 1:return &logicalField::compNumber<char>;
414
- case 2:return &logicalField::compNumber<short>;
415
- case 3:return &logicalField::compNumber24;
416
- case 4:return &logicalField::compNumber<int>;
417
- case 8:return &logicalField::compNumber<__int64>;
418
- }
419
- }
420
- case ft_mychar:
421
- case ft_string:
422
- if (logType & CMPLOGICAL_CASEINSENSITIVE)
423
- return &logicalField::compiString;
424
- return &logicalField::compMem;
425
- case ft_zstring:
426
- case ft_note:
427
- if (logType & CMPLOGICAL_CASEINSENSITIVE)
428
- return &logicalField::compiString;
429
- return &logicalField::compString;
430
- case ft_logical:
431
- case ft_uinteger:
432
- case ft_autoIncUnsigned:
433
- case ft_date:
434
- case ft_time:
435
- case ft_timestamp:
436
- case ft_mydate:
437
- {
438
- switch(len)
439
- {
440
- case 1:return &logicalField::compNumber<unsigned char>;
441
- case 2:return &logicalField::compNumber<unsigned short>;
442
- case 3:return &logicalField::compNumberU24;
443
- case 4:return &logicalField::compNumber<unsigned int>;
444
- case 8:return &logicalField::compNumber<unsigned __int64>;
445
- }
446
- }
447
- case ft_mytime:
448
- case ft_mydatetime:
449
- case ft_mytimestamp:
450
- return &logicalField::compMem;
451
- case ft_float:
452
- switch(len)
453
- {
454
- case 4:return &logicalField::compNumber<float>;
455
- case 8:return &logicalField::compNumber<double>;
456
- }
457
- case ft_mywchar:
458
- case ft_wstring:
459
- case ft_wzstring:
460
- if (logType & CMPLOGICAL_CASEINSENSITIVE)
461
- return &logicalField::compiWString;
462
- if ((type==ft_wstring)||(type==ft_mywchar))
463
- return &logicalField::compMem;
464
- return &logicalField::compWString;
465
- case ft_lstring:
466
- case ft_myvarchar:
467
- case ft_myvarbinary:
468
- if (sizeByte==1)
469
- return &logicalField::compVarString<unsigned char>;
470
- return &logicalField::compVarString<unsigned short>;
471
- case ft_mywvarchar:
472
- case ft_mywvarbinary:
473
- if (sizeByte==1)
474
- return &logicalField::compWVarString<unsigned char>;
475
- return &logicalField::compWVarString<unsigned short>;
476
- case ft_mytext:
477
- case ft_myblob:
478
- return &logicalField::compBlob;
479
- }
480
- return NULL;
481
- }
289
+ int comp(const char* record, int sizeByte) const
290
+ {
291
+ const char* r = (const char*)ptr;
292
+ if (logType & CMPLOGICAL_FIELD)
293
+ r = record + offset;
294
+ const char* l = record + pos;
295
+ switch (type)
296
+ {
297
+ case ft_integer:
298
+ case ft_autoinc:
299
+ case ft_currency:
300
+ {
301
+ switch (len)
302
+ {
303
+ case 1:
304
+ return compare<char>(l, r);
305
+ case 2:
306
+ return compare<short>(l, r);
307
+ case 3:
308
+ return compareInt24(l, r);
309
+ case 4:
310
+ return compare<int>(l, r);
311
+ case 8:
312
+ return compare<__int64>(l, r);
313
+ }
314
+ }
315
+ case ft_mychar:
316
+ case ft_string:
317
+ if (logType & CMPLOGICAL_CASEINSENSITIVE)
318
+ return _strnicmp(l, r, len);
319
+ return memcmp(l, r, len);
320
+ case ft_zstring:
321
+ case ft_note:
322
+ if (logType & CMPLOGICAL_CASEINSENSITIVE)
323
+ return _strnicmp(l, r, len);
324
+ return strncmp(l, r, len);
325
+ case ft_logical:
326
+ case ft_uinteger:
327
+ case ft_autoIncUnsigned:
328
+ case ft_date:
329
+ case ft_time:
330
+ case ft_timestamp:
331
+ case ft_mydate:
332
+ {
333
+ switch (len)
334
+ {
335
+ case 1:
336
+ return compare<unsigned char>(l, r);
337
+ case 2:
338
+ return compare<unsigned short>(l, r);
339
+ case 3:
340
+ return compareUint24(l, r);
341
+ case 4:
342
+ return compare<unsigned int>(l, r);
343
+ case 8:
344
+ return compare<unsigned __int64>(l, r);
345
+ }
346
+ }
347
+
348
+ case ft_mytime:
349
+ case ft_mydatetime:
350
+ case ft_mytimestamp:
351
+ return memcmp(l, r, len);
352
+ case ft_float:
353
+ switch (len)
354
+ {
355
+ case 4:
356
+ return compare<float>(l, r);
357
+ case 8:
358
+ return compare<double>(l, r);
359
+ }
360
+ case ft_mywchar:
361
+ case ft_wstring:
362
+ case ft_wzstring:
363
+ if (logType & CMPLOGICAL_CASEINSENSITIVE)
364
+ return wcsnicmp16((char16_t*)l, (char16_t*)r, len);
365
+ if ((type == ft_wstring) || (type == ft_mywchar))
366
+ return memcmp(l, r, len);
367
+ return wcsncmp16((char16_t*)l, (char16_t*)r, len);
368
+ case ft_lstring:
369
+ case ft_myvarchar:
370
+ case ft_myvarbinary:
371
+ if (sizeByte == 1)
372
+ return compareVartype<unsigned char>(
373
+ l, r, type == ft_myvarbinary, logType);
374
+ return compareVartype<unsigned short>(l, r, type == ft_myvarbinary,
375
+ logType);
376
+ case ft_mywvarchar:
377
+ case ft_mywvarbinary:
378
+ if (sizeByte == 1)
379
+ return compareWvartype<unsigned char>(
380
+ l, r, type == ft_mywvarbinary, logType);
381
+ return compareWvartype<unsigned short>(
382
+ l, r, type == ft_mywvarbinary, logType);
383
+ case ft_mytext:
384
+ case ft_myblob:
385
+ return compareBlobType(l, r, type == ft_myblob, logType, sizeByte);
386
+ }
387
+ return 0;
388
+ };
389
+ #else // COMP_USE_FUNCTION_POINTER
390
+
391
+ template <class T>
392
+ int compNumber(const char* l, const char* r, int sizeByte) const
393
+ {
394
+ return compare<T>(l, r);
395
+ }
396
+
397
+ int compNumber24(const char* l, const char* r, int sizeByte) const
398
+ {
399
+ return compareInt24(l, r);
400
+ }
401
+
402
+ int compNumberU24(const char* l, const char* r, int sizeByte) const
403
+ {
404
+ return compareUint24(l, r);
405
+ }
406
+
407
+ int compMem(const char* l, const char* r, int sizeByte) const
408
+ {
409
+ return memcmp(l, r, len);
410
+ }
411
+
412
+ int compString(const char* l, const char* r, int sizeByte) const
413
+ {
414
+ return strncmp(l, r, len);
415
+ }
416
+
417
+ int compiString(const char* l, const char* r, int sizeByte) const
418
+ {
419
+ return _strnicmp(l, r, len);
420
+ }
421
+
422
+ int compWString(const char* l, const char* r, int sizeByte) const
423
+ {
424
+ return wcsncmp16((char16_t*)l, (char16_t*)r, len);
425
+ }
426
+
427
+ int compiWString(const char* l, const char* r, int sizeByte) const
428
+ {
429
+ return wcsnicmp16((char16_t*)l, (char16_t*)r, len);
430
+ }
431
+
432
+ template <class T>
433
+ int compVarString(const char* l, const char* r, int sizeByte) const
434
+ {
435
+ return compareVartype<T>(l, r, type == ft_myvarbinary, logType);
436
+ }
437
+
438
+ template <class T>
439
+ int compWVarString(const char* l, const char* r, int sizeByte) const
440
+ {
441
+ return compareWvartype<T>(l, r, type == ft_mywvarbinary, logType);
442
+ }
443
+
444
+ int compBlob(const char* l, const char* r, int sizeByte) const
445
+ {
446
+ return compareBlobType(l, r, type == ft_myblob, logType, sizeByte);
447
+ }
448
+
449
+ compFunc getCompFunc(int sizeByte)
450
+ {
451
+ switch (type)
452
+ {
453
+ case ft_integer:
454
+ case ft_autoinc:
455
+ case ft_currency:
456
+ {
457
+ switch (len)
458
+ {
459
+ case 1:
460
+ return &logicalField::compNumber<char>;
461
+ case 2:
462
+ return &logicalField::compNumber<short>;
463
+ case 3:
464
+ return &logicalField::compNumber24;
465
+ case 4:
466
+ return &logicalField::compNumber<int>;
467
+ case 8:
468
+ return &logicalField::compNumber<__int64>;
469
+ }
470
+ }
471
+ case ft_mychar:
472
+ case ft_string:
473
+ if (logType & CMPLOGICAL_CASEINSENSITIVE)
474
+ return &logicalField::compiString;
475
+ return &logicalField::compMem;
476
+ case ft_zstring:
477
+ case ft_note:
478
+ if (logType & CMPLOGICAL_CASEINSENSITIVE)
479
+ return &logicalField::compiString;
480
+ return &logicalField::compString;
481
+ case ft_logical:
482
+ case ft_uinteger:
483
+ case ft_autoIncUnsigned:
484
+ case ft_date:
485
+ case ft_time:
486
+ case ft_timestamp:
487
+ case ft_mydate:
488
+ {
489
+ switch (len)
490
+ {
491
+ case 1:
492
+ return &logicalField::compNumber<unsigned char>;
493
+ case 2:
494
+ return &logicalField::compNumber<unsigned short>;
495
+ case 3:
496
+ return &logicalField::compNumberU24;
497
+ case 4:
498
+ return &logicalField::compNumber<unsigned int>;
499
+ case 8:
500
+ return &logicalField::compNumber<unsigned __int64>;
501
+ }
502
+ }
503
+ case ft_mytime:
504
+ case ft_mydatetime:
505
+ case ft_mytimestamp:
506
+ return &logicalField::compMem;
507
+ case ft_float:
508
+ switch (len)
509
+ {
510
+ case 4:
511
+ return &logicalField::compNumber<float>;
512
+ case 8:
513
+ return &logicalField::compNumber<double>;
514
+ }
515
+ case ft_mywchar:
516
+ case ft_wstring:
517
+ case ft_wzstring:
518
+ if (logType & CMPLOGICAL_CASEINSENSITIVE)
519
+ return &logicalField::compiWString;
520
+ if ((type == ft_wstring) || (type == ft_mywchar))
521
+ return &logicalField::compMem;
522
+ return &logicalField::compWString;
523
+ case ft_lstring:
524
+ case ft_myvarchar:
525
+ case ft_myvarbinary:
526
+ if (sizeByte == 1)
527
+ return &logicalField::compVarString<unsigned char>;
528
+ return &logicalField::compVarString<unsigned short>;
529
+ case ft_mywvarchar:
530
+ case ft_mywvarbinary:
531
+ if (sizeByte == 1)
532
+ return &logicalField::compWVarString<unsigned char>;
533
+ return &logicalField::compWVarString<unsigned short>;
534
+ case ft_mytext:
535
+ case ft_myblob:
536
+ return &logicalField::compBlob;
537
+ }
538
+ return NULL;
539
+ }
482
540
  #endif
483
- extResultDef* resultDef() const
484
- {
485
- if (opr == 0)
486
- return (extResultDef*)next();
487
- return next()->resultDef();
488
- }
541
+ extResultDef* resultDef() const
542
+ {
543
+ if (opr == 0)
544
+ return (extResultDef*)next();
545
+ return next()->resultDef();
546
+ }
489
547
  };
490
548
 
491
549
  struct extRequest
492
550
  {
493
- unsigned short len;
494
- char type[2];
495
- unsigned short rejectCount;
496
- unsigned short logicalCount;
497
- logicalField field;
498
-
499
- extResultDef* resultDef()const
500
- {
501
- if (logicalCount)
502
- return field.resultDef();
503
- return (extResultDef*)&field;
504
- }
551
+ int ilen : 28;
552
+ int itype : 4;
553
+ unsigned short rejectCount;
554
+ unsigned short logicalCount;
555
+ logicalField field;
556
+
557
+ extResultDef* resultDef() const
558
+ {
559
+ if (logicalCount)
560
+ return field.resultDef();
561
+ return (extResultDef*)&field;
562
+ }
563
+ };
505
564
 
565
+ struct extRequestSeeks
566
+ {
567
+ int ilen : 28;
568
+ int itype : 4;
569
+ unsigned short rejectCount;
570
+ unsigned short logicalCount;
571
+ seek seekData;
572
+
573
+ extResultDef* resultDef() const
574
+ {
575
+ if (logicalCount)
576
+ return seekData.resultDef(logicalCount);
577
+ return (extResultDef*)&seekData;
578
+ }
506
579
  };
507
580
 
508
- #pragma option -a
509
- pragma_pop
581
+ #pragma pack(pop)
582
+ pragma_pop;
510
583
 
511
- bool isMatch1(int v){return (v==0);}
512
- bool isMatch2(int v){return (v>0);}
513
- bool isMatch3(int v){return (v<0);}
514
- bool isMatch4(int v){return (v!=0);}
515
- bool isMatch5(int v){return (v>=0);}
516
- bool isMatch6(int v){return (v<=0);}
584
+ bool isMatch1(int v)
585
+ {
586
+ return (v == 0);
587
+ }
588
+ bool isMatch2(int v)
589
+ {
590
+ return (v > 0);
591
+ }
592
+ bool isMatch3(int v)
593
+ {
594
+ return (v < 0);
595
+ }
596
+ bool isMatch4(int v)
597
+ {
598
+ return (v != 0);
599
+ }
600
+ bool isMatch5(int v)
601
+ {
602
+ return (v >= 0);
603
+ }
604
+ bool isMatch6(int v)
605
+ {
606
+ return (v <= 0);
607
+ }
517
608
 
518
609
  class fields;
519
610
  class fieldAdapter
520
611
  {
521
- logicalField* m_fd;
522
- fieldAdapter* m_next;
523
- bool (*m_isMatchFunc)(int);
612
+ logicalField* m_fd;
613
+ fieldAdapter* m_next;
614
+ bool (*m_isMatchFunc)(int);
524
615
  #ifdef COMP_USE_FUNCTION_POINTER
525
- compFunc m_compFunc;
616
+ compFunc m_compFunc;
526
617
  #endif
527
- unsigned char m_keySeg;
528
- mutable bool m_judge;
529
- char m_judgeType;
530
- char m_sizeBytes;
531
- mutable bool m_matched;
618
+ unsigned char m_keySeg;
619
+ mutable bool m_judge;
620
+ char m_judgeType;
621
+ char m_sizeBytes;
622
+ mutable bool m_matched;
623
+
532
624
  public:
533
- friend class fields;
534
- fieldAdapter(): m_keySeg(0xff),m_judge(false)
535
- ,m_judgeType(0),m_sizeBytes(0),m_matched(false){}
536
-
537
- int init(logicalField* fd, position& position, const KEY* key, bool forword)
538
- {
539
- m_fd = fd;
540
- int num = position.getFieldNumByPos(fd->pos);
541
- if (num == -1)
542
- return STATUS_INVALID_FIELD_OFFSET;
543
- m_sizeBytes = (char)position.fieldSizeByte(num);
625
+ friend class fields;
626
+ fieldAdapter()
627
+ : m_keySeg(0xff), m_judge(false), m_judgeType(0), m_sizeBytes(0),
628
+ m_matched(false)
629
+ {
630
+ }
631
+
632
+ int init(logicalField* fd, position& position, const KEY* key, bool forword)
633
+ {
634
+ m_fd = fd;
635
+ int num = position.getFieldNumByPos(fd->pos);
636
+ if (num == -1)
637
+ return STATUS_INVALID_FIELD_OFFSET;
638
+ m_sizeBytes = (char)position.fieldSizeByte(num);
544
639
  #ifdef COMP_USE_FUNCTION_POINTER
545
- m_compFunc = fd->getCompFunc(m_sizeBytes);
640
+ m_compFunc = fd->getCompFunc(m_sizeBytes);
546
641
  #endif
547
- if (fd->opr == 2)
548
- {
549
- m_judgeType = 0;
550
- return 0;
551
- }
552
- int segmentIndex = 0;
553
- int segments = std::min<uint>(MAX_KEY_SEGMENT, key->user_defined_key_parts);
554
- while (segmentIndex < segments)
555
- {
556
- if (key->key_part[segmentIndex].field->field_index == num)
557
- {
558
- eCompType comp = (eCompType)(fd->logType);
559
- bool gt = (comp == greater)||(comp == greaterEq);
560
- bool le = (comp == less)||(comp == lessEq);
561
- bool valid = !(forword ? gt:le);
562
- if (valid)
563
- {
564
- m_keySeg = (unsigned char)segmentIndex+1;
565
- m_judgeType = (comp == equal) ? 2:1;
566
- }
567
- break;
568
- }
569
- ++segmentIndex;
570
- }
571
- return 0;
572
- }
573
-
574
- inline int checkNomore(bool typeNext, eCompType log)const
575
- {
576
- if (m_judge)
577
- {
578
- if ((log == equal) && m_matched)//==
579
- return REC_NOMACTH_NOMORE;
580
- else if (typeNext && (log == less || log==lessEq))
581
- return REC_NOMACTH_NOMORE;
582
- else if (!typeNext && (log == greater || log==greaterEq))
583
- return REC_NOMACTH_NOMORE;
584
- }
585
- return REC_NOMACTH;
586
- }
587
-
588
- int match(const char* record, bool typeNext) const
589
- {
642
+ if (fd->opr == 2)
643
+ {
644
+ m_judgeType = 0;
645
+ return 0;
646
+ }
647
+ if (key)
648
+ {
649
+ int segmentIndex = 0;
650
+ int segments =
651
+ std::min<uint>(MAX_KEY_SEGMENT, key->user_defined_key_parts);
652
+ while (segmentIndex < segments)
653
+ {
654
+ if (key->key_part[segmentIndex].field->field_index == num)
655
+ {
656
+ eCompType comp = (eCompType)(fd->logType & 0x0f);
657
+ bool gt = (comp == eGreater) || (comp == eGreaterEq);
658
+ bool le = (comp == eLess) || (comp == eLessEq);
659
+ bool valid = !(forword ? gt : le);
660
+ if (valid)
661
+ {
662
+ m_keySeg = (unsigned char)segmentIndex + 1;
663
+ m_judgeType = (comp == eEqual) ? 2 : 1;
664
+ }
665
+ break;
666
+ }
667
+ ++segmentIndex;
668
+ }
669
+ }
670
+ return 0;
671
+ }
672
+
673
+ inline int checkNomore(bool typeNext, eCompType log) const
674
+ {
675
+ if (m_judge)
676
+ {
677
+ if ((log == eEqual) && m_matched) //==
678
+ return REC_NOMACTH_NOMORE;
679
+ else if (typeNext && (log == eLess || log == eLessEq))
680
+ return REC_NOMACTH_NOMORE;
681
+ else if (!typeNext && (log == eGreater || log == eGreaterEq))
682
+ return REC_NOMACTH_NOMORE;
683
+ }
684
+ return REC_NOMACTH;
685
+ }
686
+
687
+ int match(const char* record, bool typeNext) const
688
+ {
590
689
  #ifdef COMP_USE_SWITCHCASE
591
- int v = m_fd->comp(record, m_sizeBytes);
592
- #else //COMP_USE_FUNCTION_POINTER
593
- const char* r = (const char*) m_fd->ptr;
594
- if (m_fd->logType & CMPLOGICAL_FIELD)
595
- r = record + m_fd->offset;
596
- const char* l = record + m_fd->pos;
597
- int v = (m_fd->*m_compFunc)(l, r , m_sizeBytes);
598
- #endif
599
- bool ret = m_isMatchFunc(v);
600
- if (ret && m_judgeType)
601
- {
602
- m_matched = true;
603
- // check is this logic range of max ?
604
- // if max then set judge node to next logic
605
- if ((m_fd->opr != 0) && m_judge && (v == 0) && m_next->m_judgeType)
606
- m_next->m_judge = true;
607
- }
608
- bool end = (m_fd->opr == 0)||(!ret && (m_fd->opr == 1))||(ret && (m_fd->opr == 2));
609
- if (!end)return m_next->match(record, typeNext);
610
- return ret ? REC_MACTH : checkNomore(typeNext, (eCompType)(m_fd->logType & 0xF));
611
- }
612
-
613
- bool operator<(const fieldAdapter& r)
614
- {
615
- if (m_judgeType != r.m_judgeType)
616
- return m_judgeType > r.m_judgeType;
617
- return m_keySeg < r.m_keySeg;
618
- }
690
+ int v = m_fd->comp(record, m_sizeBytes);
691
+ #else // COMP_USE_FUNCTION_POINTER
692
+ const char* r = (const char*)m_fd->ptr;
693
+ if (m_fd->logType & CMPLOGICAL_FIELD)
694
+ r = record + m_fd->offset;
695
+ const char* l = record + m_fd->pos;
696
+ int v = (m_fd->*m_compFunc)(l, r, m_sizeBytes);
697
+ #endif
698
+ bool ret = m_isMatchFunc(v);
699
+ if (ret && m_judgeType)
700
+ {
701
+ m_matched = true;
702
+ // check is this logic range of max ?
703
+ // if max then set judge node to next logic
704
+ if ((m_fd->opr != 0) && m_judge && (v == 0) && m_next->m_judgeType)
705
+ m_next->m_judge = true;
706
+ }
707
+ bool end = (m_fd->opr == 0) || (!ret && (m_fd->opr == 1)) ||
708
+ (ret && (m_fd->opr == 2));
709
+ if (!end)
710
+ return m_next->match(record, typeNext);
711
+ return ret ? REC_MACTH
712
+ : checkNomore(typeNext, (eCompType)(m_fd->logType & 0xF));
713
+ }
714
+
715
+ bool operator<(const fieldAdapter& r) const
716
+ {
717
+ if (m_judgeType != r.m_judgeType)
718
+ return m_judgeType > r.m_judgeType;
719
+ else if (m_keySeg == r.m_keySeg)
720
+ return this < &r; // no change order
721
+ return m_keySeg < r.m_keySeg;
722
+ }
619
723
  };
620
724
 
621
725
  class fields
622
726
  {
623
- fieldAdapter* m_fields;
727
+ fieldAdapter* m_fields;
624
728
 
625
729
  public:
626
- fields():m_fields(NULL){};
627
-
628
- ~fields()
629
- {
630
- delete [] m_fields;
631
- }
632
-
633
- void init(extRequest& req, position& position, const KEY* key, bool forword)
634
- {
635
- if (req.logicalCount==0) return ;
636
-
637
- logicalField* fd = &req.field;
638
- delete [] m_fields;
639
- m_fields = new fieldAdapter[req.logicalCount];
640
- int lastIndex = req.logicalCount;
641
- for (int i=0;i<req.logicalCount;++i)
642
- {
643
- fieldAdapter& fda = m_fields[i];
644
- fda.init(fd, position, key, forword);
645
- eCompType log = (eCompType)(fd->logType & 0xF);
646
- switch(log)
647
- {
648
- case 1:fda.m_isMatchFunc = isMatch1;break;
649
- case 2:fda.m_isMatchFunc = isMatch2;break;
650
- case 3:fda.m_isMatchFunc = isMatch3;break;
651
- case 4:fda.m_isMatchFunc = isMatch4;break;
652
- case 5:fda.m_isMatchFunc = isMatch5;break;
653
- case 6:fda.m_isMatchFunc = isMatch6;break;
654
- }
655
-
656
- fd = fd->next();
657
- if (fda.m_fd->opr == 2)
658
- lastIndex = i;
659
- }
660
- fieldAdapter* begin = &m_fields[0], *cur = &m_fields[0], *end = &m_fields[lastIndex];
661
- char tmpOpr = (lastIndex != req.logicalCount) ? end->m_fd->opr: 0;
662
- std::sort(begin, end);
663
- bool flag = true;
664
- while (cur != end)
665
- {
666
- cur->m_fd->opr = 1;//and
667
- if (flag && cur->m_judgeType == 2)
668
- cur->m_judge = true;
669
- else
670
- flag = false;
671
- ++cur;
672
- }
673
-
674
- //if first logic is first segmnet then first logic can judge.
675
- if ((begin->m_keySeg == 1) && begin->m_judgeType)
676
- begin->m_judge = true;
677
-
678
- if (lastIndex == req.logicalCount) --end;
679
- end->m_fd->opr = tmpOpr;
680
- for (int i=0;i<req.logicalCount-1;++i)
681
- m_fields[i].m_next = &m_fields[i+1];
682
- }
683
-
684
- int match(const char* record, bool typeNext) const
685
- {
686
- return m_fields[0].match(record, typeNext);
687
- }
730
+ fields() : m_fields(NULL){};
731
+
732
+ ~fields() { delete[] m_fields; }
733
+
734
+ void init(extRequest& req, position& position, const KEY* key, bool forword)
735
+ {
736
+ if (req.logicalCount == 0)
737
+ return;
738
+
739
+ logicalField* fd = &req.field;
740
+ delete[] m_fields;
741
+ m_fields = new fieldAdapter[req.logicalCount];
742
+ int lastIndex = req.logicalCount;
743
+ for (int i = 0; i < req.logicalCount; ++i)
744
+ {
745
+ fieldAdapter& fda = m_fields[i];
746
+ fda.init(fd, position, key, forword);
747
+ eCompType log = (eCompType)(fd->logType & 0xF);
748
+ switch (log)
749
+ {
750
+ case 1:
751
+ fda.m_isMatchFunc = isMatch1;
752
+ break;
753
+ case 2:
754
+ fda.m_isMatchFunc = isMatch2;
755
+ break;
756
+ case 3:
757
+ fda.m_isMatchFunc = isMatch3;
758
+ break;
759
+ case 4:
760
+ fda.m_isMatchFunc = isMatch4;
761
+ break;
762
+ case 5:
763
+ fda.m_isMatchFunc = isMatch5;
764
+ break;
765
+ case 6:
766
+ fda.m_isMatchFunc = isMatch6;
767
+ break;
768
+ }
769
+
770
+ fd = fd->next();
771
+ if (fda.m_fd->opr == 2 && (lastIndex == req.logicalCount))
772
+ lastIndex = i; // the first 'or' index
773
+ }
774
+ if (key)
775
+ {
776
+ fieldAdapter* begin = &m_fields[0], *cur = &m_fields[0],
777
+ *end = &m_fields[lastIndex];
778
+ char tmpOpr = (lastIndex != req.logicalCount) ? end->m_fd->opr : 0;
779
+ std::sort(begin, end);
780
+ bool flag = true;
781
+ while (cur != end)
782
+ {
783
+ cur->m_fd->opr = 1; // and
784
+ if (flag && cur->m_judgeType == 2)
785
+ cur->m_judge = true;
786
+ else
787
+ flag = false;
788
+ ++cur;
789
+ }
790
+
791
+ // if first logic is first segmnet then first logic can judge.
792
+ if ((begin->m_keySeg == 1) && begin->m_judgeType)
793
+ begin->m_judge = true;
794
+
795
+ if (lastIndex == req.logicalCount)
796
+ --end;
797
+ end->m_fd->opr = tmpOpr;
798
+ }
799
+ for (int i = 0; i < req.logicalCount - 1; ++i)
800
+ m_fields[i].m_next = &m_fields[i + 1];
801
+ }
802
+
803
+ int match(const char* record, bool typeNext) const
804
+ {
805
+ return m_fields[0].match(record, typeNext);
806
+ }
688
807
  };
689
808
 
690
809
  class resultWriter
691
810
  {
692
- char* m_buf;
693
- extResultDef* m_def;
694
- unsigned short m_rowsPos;
695
- unsigned short m_maxLen;
696
- unsigned short m_resultLen;
697
- bool m_writeFirst;
698
-
699
- short writeFirst( position* pos, unsigned int bookmark)
700
- {
701
- m_rowsPos = m_resultLen;
702
- *((unsigned short*)(m_buf + m_resultLen)) = 0;
703
- m_resultLen += sizeof(unsigned short);
704
- return doWrite(pos, bookmark);
705
- }
706
-
707
- short doWrite(position* pos, unsigned int bookmark)
708
- {
709
- // write rowCount
710
- unsigned short* rows = (unsigned short*) (m_buf + m_rowsPos);
711
- ++(*rows);
712
-
713
- //write recLength space;
714
- unsigned short recLen = 0;
715
- unsigned short recLenPos = m_resultLen;
716
- *((unsigned short*)(m_buf + m_resultLen)) = recLen;
717
- m_resultLen += sizeof(unsigned short);
718
-
719
- //write bookmark
720
- *((unsigned int*)(m_buf + m_resultLen)) = bookmark;
721
- m_resultLen += sizeof(unsigned int);
722
-
723
- //if pos ==NULL , that is not found record in a TD_KEY_SEEK_MULTI operation
724
- // and bookmark has error code also STATUS_NOT_FOUND_TI
725
- // in the client, fieldCount > 0 buf recLen=0 then this pattern
726
- if (pos)
727
- {
728
- if ((m_def->fieldCount == 1) && (m_def->field[0].len >= pos->recordLenCl()))
729
- { //write whole row
730
- int len = pos->recordLenCl();
731
- if (m_maxLen + RETBUF_EXT_RESERVE_SIZE >= m_resultLen + len)
732
- {
733
- int maxlen = m_maxLen + RETBUF_EXT_RESERVE_SIZE - m_resultLen;
734
- len = pos->recordPackCopy(m_buf + m_resultLen, maxlen);
735
- if (len == 0)
736
- return STATUS_BUFFERTOOSMALL;
737
- m_resultLen += len;
738
- recLen += len;
739
- }else
740
- return STATUS_BUFFERTOOSMALL;
741
- }else
742
- {
743
- //write each fields by field num.
744
- for (int i=0;i<m_def->fieldCount;i++)
745
- {
746
- resultField& fd = m_def->field[i];
747
- if (m_maxLen+RETBUF_EXT_RESERVE_SIZE>= m_resultLen + fd.len)
748
- {
749
- memcpy(m_buf + m_resultLen, pos->fieldPtr(&fd), fd.len);
750
- m_resultLen += fd.len;
751
- recLen += fd.len;
752
- if (pos->isBlobField(&fd))
753
- pos->addBlobBuffer(fd.fieldNum);
754
- }
755
- else
756
- return STATUS_BUFFERTOOSMALL;
757
- }
758
- }
759
- }
760
- //write recLength;
761
- *((unsigned short*)(m_buf + recLenPos)) = recLen;
762
- return 0;
763
- }
811
+ netsvc::server::netWriter* m_nw;
812
+ extResultDef* m_def;
813
+ bool m_noBookmark;
814
+
815
+ short doWrite(position* pos, unsigned int bookmark)
816
+ {
817
+ // write recLength space;
818
+ unsigned short recLen = 0;
819
+ unsigned short* recLenPos = (unsigned short*)m_nw->curPtr();
820
+ m_nw->asyncWrite((const char*)&recLen, 2);
821
+
822
+ // write bookmark
823
+ if (!m_noBookmark)
824
+ m_nw->asyncWrite((const char*)&bookmark, 4);
825
+
826
+ // if pos ==NULL , that is not found record in a TD_KEY_SEEK_MULTI
827
+ // operation
828
+ // and bookmark has error code also STATUS_NOT_FOUND_TI
829
+ // in the client, fieldCount > 0 buf recLen=0 then this pattern
830
+ if (pos)
831
+ {
832
+ if ((m_def->fieldCount == 1) &&
833
+ (m_def->field[0].len >= pos->recordLenCl()))
834
+ { // write whole row
835
+ int len = pos->recordPackCopy(m_nw->curPtr(),
836
+ (uint)m_nw->bufferSpace());
837
+ if (len == 0)
838
+ return STATUS_BUFFERTOOSMALL;
839
+ if (!m_nw->asyncWrite(NULL, len,
840
+ netsvc::server::netWriter::curSeekOnly))
841
+ return STATUS_BUFFERTOOSMALL;
842
+ recLen += len;
843
+ }
844
+ else
845
+ {
846
+ // write each fields by field num.
847
+ for (int i = 0; i < m_def->fieldCount; i++)
848
+ {
849
+ resultField& fd = m_def->field[i];
850
+ if (m_nw->bufferSpace() > fd.len)
851
+ {
852
+ uint len = pos->fieldPackCopy(
853
+ (unsigned char*)m_nw->curPtr(), fd.fieldNum);
854
+ m_nw->asyncWrite(
855
+ NULL, len, netsvc::server::netWriter::curSeekOnly);
856
+ recLen += len;
857
+ if (pos->isBlobField(&fd))
858
+ pos->addBlobBuffer(fd.fieldNum);
859
+ }
860
+ else
861
+ return STATUS_BUFFERTOOSMALL;
862
+ }
863
+ }
864
+ }
865
+
866
+ // write recLength;
867
+ *recLenPos = recLen;
868
+ m_nw->asyncWrite(NULL, 0, netsvc::server::netWriter::netwrite);
869
+ // rowCount
870
+ m_nw->incremetRows();
871
+ return 0;
872
+ }
873
+
764
874
  public:
765
- resultWriter(char* buf ,size_t offset, extResultDef* def, unsigned short maxlen)
766
- :m_buf(buf),m_def(def),m_rowsPos(0),m_maxLen(maxlen),m_writeFirst(true)
767
- {
768
- m_resultLen = (unsigned short)offset;
769
- }
770
-
771
- short write(position* pos, unsigned int bookmark)
772
- {
773
- if (m_writeFirst)
774
- {
775
- m_writeFirst = false;
776
- return writeFirst(pos, bookmark);
777
- }
778
- return doWrite(pos, bookmark);
779
- }
780
-
781
- unsigned short resultLen(){return m_resultLen;};
782
-
783
- const char* resultBuffer(){return m_buf;}
875
+ resultWriter(netsvc::server::netWriter* nw, extResultDef* def,
876
+ bool noBookmark)
877
+ : m_nw(nw), m_def(def), m_noBookmark(noBookmark)
878
+ {
879
+ }
880
+
881
+ short write(position* pos, unsigned int bookmark)
882
+ {
883
+ return doWrite(pos, bookmark);
884
+ }
885
+ inline unsigned int end()
886
+ {
887
+ m_nw->asyncWrite(NULL, 0, netsvc::server::netWriter::writeEnd);
888
+ return m_nw->resultLen();
889
+ }
890
+
891
+ const char* resultBuffer() { return m_nw->ptr(); }
784
892
  };
785
893
 
786
-
787
894
  class ReadRecordsHandler : public engine::mysql::IReadRecordsHandler
788
895
  {
789
- boost::shared_ptr<resultWriter> m_writer;
790
- extRequest* m_req;
791
- extResultDef* m_resultDef;
792
- position m_position;
793
- fields m_fields;
896
+ boost::shared_ptr<resultWriter> m_writer;
897
+ extRequest* m_req;
898
+ extResultDef* m_resultDef;
899
+ position m_position;
900
+ fields m_fields;
901
+ engine::mysql::fieldBitmap bm;
902
+ bool m_seeksMode;
794
903
 
795
904
  public:
796
- short begin(engine::mysql::table* tb, extRequest* req, bool fieldCache
797
- , char* buf,size_t offset, unsigned short maxlen, bool forword)
798
- {
799
- short ret = 0;
800
- m_position.setTable(tb);
801
- m_req = req;
802
- m_resultDef = m_req->resultDef();
803
- if (fieldCache)
804
- {
805
- const KEY* key = NULL;
806
- if (tb->keyNum() >= 0)
807
- key = &tb->keyDef(tb->keyNum());
808
- m_fields.init(*m_req, m_position, key, forword);
809
- }
810
- if (m_resultDef->fieldCount > 1)
811
- ret = convResultPosToFieldNum();
812
-
813
- m_writer.reset(new resultWriter(buf, offset, m_resultDef, maxlen));
814
- //DEBUG_RECORDS_BEGIN(m_resultDef, m_req)
815
- return ret;
816
- }
817
-
818
- //TODO This convert is move to client. but legacy app is need this
819
- short convResultPosToFieldNum()
820
- {
821
- int blobs = 0;
822
- for (int i=0;i<m_resultDef->fieldCount;i++)
823
- {
824
- resultField& fd = m_resultDef->field[i];
825
- int num = m_position.getFieldNumByPos(fd.pos);
826
- if (num == -1)
827
- return STATUS_INVALID_FIELD_OFFSET;
828
- fd.fieldNum = num;
829
- if (m_position.isBlobField(&fd))
830
- ++blobs;
831
-
832
- }
833
-
834
- m_position.setBlobFieldCount(blobs);
835
- return 0;
836
- }
837
-
838
- unsigned int end()
839
- {
840
- unsigned int len = m_writer->resultLen();
841
- //DEBUG_RECORDS_END(m_writer.get())
842
-
843
- m_writer.reset();
844
- return len;
845
- }
846
-
847
- int match(bool typeNext)const
848
- {
849
- if (m_req->logicalCount)
850
- return m_fields.match(m_position.record(), typeNext);
851
- return REC_MACTH;
852
- }
853
-
854
- short write(const unsigned char* bmPtr, unsigned int bmlen, short stat=0)
855
- {
856
- unsigned int bookmark = 0;
857
- //if bmPtr ==NULL , that is not found record in a TD_KEY_SEEK_MULTI operation
858
- // and set error code to bookmark also STATUS_NOT_FOUND_TI
859
- if (bmPtr == NULL)
860
- {
861
- bookmark = stat;
862
- return m_writer->write(NULL, bookmark);
863
- }
864
- else
865
- {
866
- switch(bmlen)
867
- {
868
- case 4:
869
- bookmark = *((unsigned int*)bmPtr);break;
870
- case 2:
871
- bookmark = *((unsigned short*)bmPtr);break;
872
- case 3:
873
- bookmark = *((unsigned int*)bmPtr) & 0x0FFFFFF;break;
874
- case 1:
875
- bookmark = *((unsigned short*)bmPtr) & 0x0FF;break;
876
- }
877
- return m_writer->write(&m_position, bookmark);
878
- }
879
-
880
- }
881
- unsigned short rejectCount(){return m_req->rejectCount;};
882
- unsigned short maxRows(){return m_resultDef->maxRows;};
905
+ short begin(engine::mysql::table* tb, extRequest* req, bool fieldCache,
906
+ netsvc::server::netWriter* nw, bool forword, bool noBookmark,
907
+ bool seeksMode)
908
+ {
909
+ short ret = 0;
910
+ m_seeksMode = seeksMode;
911
+ m_position.setTable(tb);
912
+ m_req = req;
913
+ m_resultDef = seeksMode ? ((extRequestSeeks*)m_req)->resultDef()
914
+ : m_req->resultDef();
915
+ if (fieldCache)
916
+ {
917
+ const KEY* key = NULL;
918
+ if (tb->keyNum() >= 0)
919
+ key = &tb->keyDef(tb->keyNum());
920
+ m_fields.init(*m_req, m_position, key, forword);
921
+ }
922
+ if ((m_resultDef->fieldCount > 1) ||
923
+ ((m_resultDef->fieldCount == 1) &&
924
+ (m_resultDef->field[0].len < m_position.recordLenCl())))
925
+ ret = convResultPosToFieldNum(tb, noBookmark, seeksMode);
926
+
927
+ nw->beginExt(tb->blobFields() != 0);
928
+ m_writer.reset(new resultWriter(nw, m_resultDef, noBookmark));
929
+ // DEBUG_RECORDS_BEGIN(m_resultDef, m_req)
930
+
931
+ return ret;
932
+ }
933
+
934
+ // TODO This convert is move to client. but legacy app is need this
935
+ short convResultPosToFieldNum(engine::mysql::table* tb, bool noBookmark,
936
+ bool seeksMode)
937
+ {
938
+ int blobs = 0;
939
+ bm.setTable(tb);
940
+ for (int i = 0; i < m_resultDef->fieldCount; i++)
941
+ {
942
+ resultField& fd = m_resultDef->field[i];
943
+ int num = m_position.getFieldNumByPos(fd.pos);
944
+ if (num == -1)
945
+ return STATUS_INVALID_FIELD_OFFSET;
946
+ fd.fieldNum = num;
947
+ bm.setReadBitmap(num);
948
+ if (m_position.isBlobField(&fd))
949
+ ++blobs;
950
+ }
951
+
952
+ if (!seeksMode)
953
+ {
954
+ logicalField* fd = &m_req->field;
955
+ for (int i = 0; i < m_req->logicalCount; ++i)
956
+ {
957
+ bm.setReadBitmap(m_position.getFieldNumByPos(fd->pos));
958
+ fd = fd->next();
959
+ }
960
+ }
961
+ else
962
+ {
963
+ const KEY* key = &tb->keyDef(tb->keyNum());
964
+ if (key)
965
+ {
966
+ int sgi = 0;
967
+ int segments = std::min<uint>(MAX_KEY_SEGMENT,
968
+ key->user_defined_key_parts);
969
+ while (sgi < segments)
970
+ {
971
+ bm.setReadBitmap(key->key_part[sgi].field->field_index);
972
+ ++sgi;
973
+ }
974
+ }
975
+ }
976
+
977
+ // if need bookmark , add primary key fields
978
+ if (!noBookmark)
979
+ {
980
+ const KEY* key = tb->primaryKey();
981
+ if (key)
982
+ {
983
+ int sgi = 0;
984
+ int segments = std::min<uint>(MAX_KEY_SEGMENT,
985
+ key->user_defined_key_parts);
986
+ while (sgi < segments)
987
+ {
988
+ bm.setReadBitmap(key->key_part[sgi].field->field_index);
989
+ ++sgi;
990
+ }
991
+ }
992
+ }
993
+
994
+ tb->indexInit();
995
+ m_position.setBlobFieldCount(blobs);
996
+ return 0;
997
+ }
998
+
999
+ unsigned int end()
1000
+ {
1001
+ unsigned int len = m_writer->end();
1002
+ // DEBUG_RECORDS_END(m_writer.get())
1003
+ m_writer.reset();
1004
+ bm.setTable(NULL);
1005
+ return len;
1006
+ }
1007
+
1008
+ int match(bool typeNext) const
1009
+ {
1010
+ if (m_req->logicalCount)
1011
+ return m_fields.match(m_position.record(), typeNext);
1012
+ return REC_MACTH;
1013
+ }
1014
+
1015
+ short write(const unsigned char* bmPtr,
1016
+ unsigned int bmlen /*, short stat=0*/)
1017
+ {
1018
+ unsigned int bookmark = 0;
1019
+ // if bmPtr ==NULL , that is not found record in a TD_KEY_SEEK_MULTI
1020
+ // operation
1021
+ // and set error code to bookmark also STATUS_NOT_FOUND_TI
1022
+ if (bmPtr == NULL)
1023
+ {
1024
+ // bookmark = stat;
1025
+ return m_writer->write(NULL, bookmark);
1026
+ }
1027
+ else
1028
+ {
1029
+ switch (bmlen)
1030
+ {
1031
+ case 4:
1032
+ bookmark = *((unsigned int*)bmPtr);
1033
+ break;
1034
+ case 2:
1035
+ bookmark = *((unsigned short*)bmPtr);
1036
+ break;
1037
+ case 3:
1038
+ bookmark = *((unsigned int*)bmPtr) & 0x0FFFFFF;
1039
+ break;
1040
+ case 1:
1041
+ bookmark = *((unsigned short*)bmPtr) & 0x0FF;
1042
+ break;
1043
+ }
1044
+ return m_writer->write(&m_position, bookmark);
1045
+ }
1046
+ }
1047
+ unsigned short rejectCount() const { return m_req->rejectCount; };
1048
+ unsigned short maxRows() const { return m_resultDef->maxRows; };
883
1049
  };
884
1050
 
885
- }//namespace mysql
886
- }//namespace protocol
887
- }//namespace db
888
- }//namespace tdap
889
- }//namespace bzs
1051
+ } // namespace mysql
1052
+ } // namespace protocol
1053
+ } // namespace db
1054
+ } // namespace tdap
1055
+ } // namespace bzs
890
1056
 
891
- #endif //BZS_DB_PROTOCOL_TDAP_MYSQL_RECORDSETREADER_H
1057
+ #endif // BZS_DB_PROTOCOL_TDAP_MYSQL_RECORDSETREADER_H