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
@@ -1,25 +1,23 @@
1
- #ifndef DATABASE_H
2
- #define DATABASE_H
3
- /*=================================================================
4
- Copyright (C) 2012 2013 BizStation Corp All rights reserved.
5
-
6
- This program is free software; you can redistribute it and/or
7
- modify it under the terms of the GNU General Public License
8
- as published by the Free Software Foundation; either version 2
9
- of the License, or (at your option) any later version.
10
-
11
- This program is distributed in the hope that it will be useful,
12
- but WITHOUT ANY WARRANTY; without even the implied warranty of
13
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
- GNU General Public License for more details.
15
-
16
- You should have received a copy of the GNU General Public License
17
- along with this program; if not, write to the Free Software
18
- Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
19
- 02111-1307, USA.
20
- =================================================================*/
21
-
22
-
1
+ #ifndef BZS_DB_ENGINE_MYSQL_DATABASE_H
2
+ #define BZS_DB_ENGINE_MYSQL_DATABASE_H
3
+ /* =================================================================
4
+ Copyright (C) 2012 2013 BizStation Corp All rights reserved.
5
+
6
+ This program is free software; you can redistribute it and/or
7
+ modify it under the terms of the GNU General Public License
8
+ as published by the Free Software Foundation; either version 2
9
+ of the License, or (at your option) any later version.
10
+
11
+ This program is distributed in the hope that it will be useful,
12
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
13
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
+ GNU General Public License for more details.
15
+
16
+ You should have received a copy of the GNU General Public License
17
+ along with this program; if not, write to the Free Software
18
+ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
19
+ 02111-1307, USA.
20
+ ================================================================= */
23
21
 
24
22
  #include <boost/noncopyable.hpp>
25
23
  #include <boost/shared_ptr.hpp>
@@ -35,8 +33,9 @@ class THD;
35
33
  struct TABLE;
36
34
 
37
35
  #ifndef MAX_KEYLEN
38
- #define MAX_KEYLEN 1023
36
+ #define MAX_KEYLEN 1023
39
37
  #endif
38
+
40
39
  namespace bzs
41
40
  {
42
41
  namespace db
@@ -46,21 +45,26 @@ namespace engine
46
45
  namespace mysql
47
46
  {
48
47
 
48
+ /*
49
+ Please comment out the following,
50
+ when you emulate btrv variable length record of btrv with a server.
51
+
52
+ #define USE_BTRV_VARIABLE_LEN
53
+ */
49
54
 
50
55
  #define READ_RECORD_GETNEXT 1
51
56
  #define READ_RECORD_GETPREV 2
52
57
  #define READ_RECORD_STEPNEXT 3
53
58
  #define READ_RECORD_STEPPREV 4
54
59
 
55
- #define RF_FIXED_LEN 0
56
- #define RF_FIXED_PLUS_VALIABLE_LEN 1
57
- #define RF_VALIABLE_LEN 2
58
- #define RF_INCLUDE_NIS 4
60
+ #define RF_FIXED_LEN 0
61
+ #define RF_FIXED_PLUS_VALIABLE_LEN 1
62
+ #define RF_VALIABLE_LEN 2
63
+ #define RF_INCLUDE_NIS 4
59
64
 
60
65
  #define TRN_RECORD_LOCK_SINGLE 0
61
66
  #define TRN_RECORD_LOCK_MUILTI 1
62
67
 
63
-
64
68
  /** bookmark size
65
69
  * btreive API is MAX 4 byte
66
70
  */
@@ -73,65 +77,83 @@ extern bool g_safe_share_mode;
73
77
  */
74
78
  class tableCacheCounter
75
79
  {
76
- std::vector<int> m_tables;
77
- std::vector<int> m_counts;
80
+ std::vector<int> m_tables;
81
+ std::vector<int> m_counts;
78
82
 
79
- boost::mutex m_mutex;
80
- int getHash(const std::string& dbname, const std::string& tbname);
81
- size_t getCounterIndex(const std::string& dbname, const std::string& tbname);
82
- public:
83
- tableCacheCounter();
84
- void addref(const std::string& dbname, const std::string& tbname);
85
- int count(const std::string& dbname, const std::string& tbname);
86
- void release(const std::string& dbname, const std::string& tbname);
83
+ boost::mutex m_mutex;
84
+ int getHash(const std::string& dbname, const std::string& tbname);
85
+ size_t getCounterIndex(const std::string& dbname,
86
+ const std::string& tbname);
87
87
 
88
+ public:
89
+ tableCacheCounter();
90
+ void addref(const std::string& dbname, const std::string& tbname);
91
+ int count(const std::string& dbname, const std::string& tbname);
92
+ void release(const std::string& dbname, const std::string& tbname);
88
93
  };
89
94
 
90
95
  class database : private boost::noncopyable
91
96
  {
92
- friend class table;
93
- friend class smartDbReopen;
94
- std::string m_dbname;
95
-
96
- mutable THD* m_thd;
97
- short m_cid;
98
- int m_inTransaction;
99
- int m_inSnapshot;
100
- int m_stat;
101
- short m_trnType;
102
-
103
- std::vector<boost::shared_ptr<table> > m_tables;
104
- TABLE* doOpenTable(const std::string& name, short mode, const char* ownerName);
105
-
106
- void unUseTable(table* tb);
97
+ friend class table;
98
+ friend class smartDbReopen;
99
+
100
+ std::string m_dbname;
101
+
102
+ mutable THD* m_thd;
103
+ short m_cid;
104
+ int m_inTransaction;
105
+ int m_inSnapshot;
106
+ int m_stat;
107
+ short m_trnType;
108
+
109
+ std::vector<boost::shared_ptr<table> > m_tables;
110
+ TABLE* doOpenTable(const std::string& name, short mode,
111
+ const char* ownerName);
112
+
113
+ void unUseTable(table* tb);
114
+
107
115
  public:
108
- database(const char* name, short cid);
109
- ~database();
110
- int stat(){return m_stat;};
111
- THD* thd()const{return m_thd;};
112
- void use() const;
113
- short clientID()const{return m_cid;}
114
- table* openTable(const std::string& name, short mode, const char* ownerName);
115
- const std::string& name()const{return m_dbname;};
116
- table* useTable(int index, enum_sql_command cmd);
117
- bool beginTrn(short type);
118
- bool commitTrn();
119
- bool abortTrn();
120
- bool inTransaction()const{return (m_inTransaction!=0);}
121
- short transactionType()const{return m_trnType;}
122
- bool beginSnapshot();
123
- bool endSnapshot();
124
- bool inSnapshot()const{return m_inSnapshot!=0;}
125
- bool existsTable(const std::string& name);
126
- bool existsDatabase();
127
- void closeTable(const std::string& name, bool drop);
128
- void closeTable(table* tb);
129
- void unUseTables(bool rollback);
130
- void closeForReopen();
131
- void reopen();
132
- void cleanTable();
133
- const std::vector<boost::shared_ptr<table> >& tables() const {return m_tables;};
134
- static tableCacheCounter tableRef;
116
+ database(const char* name, short cid);
117
+ ~database();
118
+
119
+ int stat() { return m_stat; }
120
+
121
+ THD* thd() const { return m_thd; }
122
+ void use() const;
123
+
124
+ short clientID() const { return m_cid; }
125
+
126
+ const std::string& name() const { return m_dbname; }
127
+
128
+ bool inTransaction() const { return (m_inTransaction != 0); }
129
+
130
+ short transactionType() const { return m_trnType; }
131
+
132
+ bool inSnapshot() const { return m_inSnapshot != 0; }
133
+
134
+ const std::vector<boost::shared_ptr<table> >& tables() const
135
+ {
136
+ return m_tables;
137
+ }
138
+
139
+ bool beginSnapshot();
140
+ bool endSnapshot();
141
+ table* openTable(const std::string& name, short mode,
142
+ const char* ownerName);
143
+ table* useTable(int index, enum_sql_command cmd);
144
+ bool beginTrn(short type);
145
+ bool commitTrn();
146
+ bool abortTrn();
147
+ bool existsTable(const std::string& name);
148
+ bool existsDatabase();
149
+ void closeTable(const std::string& name, bool drop);
150
+ void closeTable(table* tb);
151
+ void unUseTables(bool rollback);
152
+ void closeForReopen();
153
+ void reopen();
154
+ void cleanTable();
155
+
156
+ static tableCacheCounter tableRef;
135
157
  };
136
158
 
137
159
  typedef std::vector<boost::shared_ptr<database> > databases;
@@ -140,326 +162,542 @@ class IReadRecordsHandler;
140
162
  class bookmarks;
141
163
 
142
164
  /*
143
- * Since it differs from the key number which a client specifies
165
+ * Since it differs from the key number which a client specifies
144
166
  * , and an internal key number, it changes.
145
- * As for the key name, it is a premise that it is keyNN.
167
+ * As for the key name, it is a premise that it is keyNN.
146
168
  * NN is client specifies key number.
147
169
  */
148
170
  class keynumConvert
149
171
  {
150
- KEY* m_key;
151
- int m_keyCount;
152
- char m_keyNum;
153
- char m_convNum;
154
-
172
+ KEY* m_key;
173
+ int m_keyCount;
174
+ char m_keyNum;
175
+ char m_convNum;
176
+
155
177
  public:
156
- keynumConvert(KEY* key, int count):m_key(key),m_keyCount(count),m_keyNum(-1){}
157
- void setKey(KEY* key){m_key=key;};
158
- char keyNumByMakeOrder(char num)
159
- {
160
- if (m_keyNum==num)
161
- return m_convNum;
162
-
163
- m_keyNum = num;
164
- for (int i=0;i<m_keyCount;i++)
165
- if (strstr(m_key[i].name, "key") && m_key[i].name[3] == num + '0')
166
- return m_convNum = i;
167
- return m_convNum = num;//If not found, a value as it is is returned.
168
- }
178
+ keynumConvert(KEY* key, int count)
179
+ : m_key(key), m_keyCount(count), m_keyNum(-1), m_convNum(-1)
180
+ {
181
+ }
182
+
183
+ void setKey(KEY* key) { m_key = key; }
184
+
185
+ char keyNumByMakeOrder(char num)
186
+ {
187
+ if (m_keyNum == num)
188
+ return m_convNum;
189
+
190
+ m_keyNum = num;
191
+ for (int i = 0; i < m_keyCount; i++)
192
+ if (strstr(m_key[i].name, "key") && m_key[i].name[3] == num + '0')
193
+ return m_convNum = i;
194
+ return m_convNum = num; // If not found, a value as it is is returned.
195
+ }
169
196
  };
170
197
 
171
198
  class table : private boost::noncopyable
172
199
  {
173
- friend class database;
174
-
175
-
176
- TABLE* m_table;
177
- std::string m_name;
178
- const short m_mode;
179
- int m_recordFormatType;
180
- int m_id;
181
- unsigned short m_nullFields;
182
- uint m_recordLenCl;
183
- uint m_lastVarLenBytes;
184
-
185
- database& m_db;
186
- table(TABLE* table, database& db, const std::string& name, short mode, int id);
187
- char m_keyNum;
188
- mutable boost::scoped_array<unsigned char> m_keybuf;
189
- mutable boost::scoped_array<unsigned char> m_nonNccKeybuf;
190
- bool m_nonNcc;
191
- int m_stat;
192
- bool m_validCursor;
193
- bool m_cursor;
194
- bool m_locked;
195
- bool m_changed;
196
- bool m_nounlock;
197
- bool m_bulkInserting;
198
- int m_percentResult;
199
- boost::shared_ptr<bookmarks> m_bms;
200
- String m_str;
201
- keynumConvert m_keyconv;
202
- IblobBuffer* m_blobBuffer;
203
- std::vector<Field*> m_nonKeySegNullFields;
204
-
205
- void moveKey(boost::function<int()> func);
206
- void readRecords(IReadRecordsHandler* handler, bool includeCurrent, int type);
207
-
208
- bool keyCheckForPercent();
209
- inline bool keynumCheck(char num);
210
- void preBuildPercent(uchar* first, uchar* last);
211
- inline key_part_map keymap(){return (1U << m_table->key_info[m_keyNum].user_defined_key_parts) -1;}
212
- void seekPos(const uchar* pos);
213
- int setKeyNullFlags();
214
- void setFiledNullFlags();
215
-
216
- bookmarks* bms();
217
- int percentage(uchar* first, uchar* last, uchar* cur);
218
-
219
- bool setNonKey(bool scan=false);
220
- void fillNull(uchar* ptr, int size);
221
- inline void* keybuf()const{return &m_keybuf[0];}
222
- inline uint keylen()const{return m_table->key_info[m_keyNum].key_length;};
223
- void setKeyValues(const uchar* ptr, int size);
224
- void setBlobFieldPointer(const bzs::db::blobHeader* hd);
225
- inline void unlockRow();
200
+ friend class database;
201
+ TABLE* m_table;
202
+
203
+ std::string m_name;
204
+
205
+ const short m_mode;
206
+ int m_id;
207
+ unsigned short m_nullFields;
208
+ uint m_recordLenCl;
209
+ int m_recordFormatType;
210
+ #ifdef USE_BTRV_VARIABLE_LEN
211
+ uint m_lastVarLenBytes;
212
+ #endif
213
+ database& m_db;
214
+ char m_keyNum;
215
+
216
+ mutable boost::scoped_array<unsigned char> m_keybuf;
217
+ mutable boost::scoped_array<unsigned char> m_nonNccKeybuf;
218
+
219
+ bool m_nonNcc;
220
+ int m_stat;
221
+ bool m_validCursor;
222
+ bool m_cursor;
223
+ bool m_locked;
224
+ bool m_changed;
225
+ bool m_nounlock;
226
+ bool m_bulkInserting;
227
+ int m_percentResult;
228
+
229
+ boost::shared_ptr<bookmarks> m_bms;
230
+
231
+ String m_str;
232
+ keynumConvert m_keyconv;
233
+ IblobBuffer* m_blobBuffer;
234
+
235
+ std::vector<Field*> m_nonKeySegNullFields;
236
+
237
+ table(TABLE* table, database& db, const std::string& name, short mode,
238
+ int id);
239
+ void moveKey(boost::function<int()> func);
240
+ void readRecords(IReadRecordsHandler* handler, bool includeCurrent,
241
+ int type, bool noBookmark);
242
+
243
+ bool keyCheckForPercent();
244
+ inline bool keynumCheck(char num);
245
+ void preBuildPercent(uchar* first, uchar* last);
246
+ void seekPos(const uchar* pos);
247
+ int setKeyNullFlags();
248
+ void setFiledNullFlags();
249
+
250
+ bookmarks* bms();
251
+ int percentage(uchar* first, uchar* last, uchar* cur);
252
+
253
+ bool setNonKey(bool scan = false);
254
+ void fillNull(uchar* ptr, int size);
255
+
256
+ inline void* keybuf() const { return &m_keybuf[0]; }
257
+
258
+ inline uint keylen() const
259
+ {
260
+ return m_table->key_info[m_keyNum].key_length;
261
+ }
262
+ void setKeyValues(const uchar* ptr, int size);
263
+ void setBlobFieldPointer(const bzs::db::blobHeader* hd);
264
+ inline void unlockRow();
265
+
266
+ inline void initHandler()
267
+ {
268
+ if ((m_db.m_inSnapshot == 0) &&
269
+ (m_table->reginfo.lock_type != TL_WRITE))
270
+ m_table->file->init_table_handle_for_HANDLER();
271
+ }
226
272
 
227
273
  #ifdef USE_HANDLERSOCKET
228
- std::vector<int> m_useFields;
229
- void checkFiledIndex(int index);
230
- int fieldIndexByName(const char* name)const;
231
- void addUseField(int index){m_useFields.push_back(index);};
274
+ std::vector<int> m_useFields;
275
+ void checkFiledIndex(int index);
276
+ int fieldIndexByName(const char* name) const;
277
+
278
+ void addUseField(int index) { m_useFields.push_back(index); };
232
279
 
233
280
  public:
234
- std::vector<int>& useFields(){return m_useFields;};
235
- void setUseFieldList(const std::string& csv);
236
- void setKeyValues(const std::vector<std::string>& values
237
- , int keypart, const std::string* inValue=NULL);
238
- void setValue(int index, const std::string& v, int type);
239
- void setUseValues(const std::vector<std::string>& values, int type);
240
-
241
- #define UPDATE_REPLACE 0
242
- #define UPDATE_INC 1
243
- #define UPDATE_DEC 2
281
+ std::vector<int>& useFields() { return m_useFields; };
282
+ void setUseFieldList(const std::string& csv);
283
+ void setKeyValues(const std::vector<std::string>& values, int keypart,
284
+ const std::string* inValue = NULL);
285
+ void setValue(int index, const std::string& v, int type);
286
+ void setUseValues(const std::vector<std::string>& values, int type);
287
+
288
+ #define UPDATE_REPLACE 0
289
+ #define UPDATE_INC 1
290
+ #define UPDATE_DEC 2
244
291
 
245
292
  #endif
293
+
246
294
  public:
247
- static bool noKeybufResult;
248
-
249
- ~table();
250
-
251
- inline void setBlobBuffer(IblobBuffer* blobBuffer){m_blobBuffer = blobBuffer;};
252
- inline IblobBuffer* blobBuffer(IblobBuffer* blobBuffer){return m_blobBuffer;};
253
-
254
- inline short mode()const {return m_mode;};
255
- inline bool islocked(){return m_locked;}
256
- inline void setLocked(bool value){m_locked = value;}
257
- inline bool isChanged(){return m_changed;}
258
- int id(){return m_id;};
259
- inline void unUse(){m_db.unUseTable(this);}
260
- void resetTransctionInfo(THD* thd);
261
- void resetInternalTable(TABLE* table);
262
- inline const std::string& name()const{return m_name;};
263
- inline int recordFormatType()const {return m_recordFormatType;};
264
- inline int blobFields()const {return m_table->s->blob_fields;};
265
-
266
- /** if call close then table is deleten.
267
- */
268
- inline void close()
269
- {
270
- m_table->file->ha_index_or_rnd_end();
271
- m_db.closeTable(this);
272
- }
273
- inline char keyNum()const {return m_keyNum;}
274
-
275
- /*
276
- * Since it differs from the key number which a client specifies
277
- * , and an internal key number, it changes.
278
- * As for the key name, it is a premise that it is keyNN.
279
- * NN is client specifies key number.
280
- */
281
- inline char keyNumByMakeOrder(char num)
282
- {
283
- return m_keyconv.keyNumByMakeOrder(num);
284
- }
285
-
286
- bool setKeyNum(char num, bool sorted = true);
287
- inline void setKeyNum(const char* name, bool sorted = true){setKeyNum(keynumByName(name), sorted);};
288
- bool isNisKey(char num)const;
289
- void seekKey(enum ha_rkey_function find_flag);
290
- void getNextSame();
291
- void getLast();
292
- void getFirst();
293
- void getNext();
294
- void getPrev();
295
- void getByPercentage(unsigned short per);
296
- void calcPercentage();
297
- inline int* percentResult(){return &m_percentResult;};
298
-
299
- void stepLast();
300
- void stepFirst();
301
- void stepNext();
302
- void stepPrev();
303
- void movePos(const uchar* pos, char keyNum, bool sureRawValue=false);
304
-
305
- inline void getNextExt(IReadRecordsHandler* handler, bool includeCurrent)
306
- {
307
- readRecords(handler, includeCurrent, READ_RECORD_GETNEXT);
308
- }
309
-
310
- inline void getPrevExt(IReadRecordsHandler* handler, bool includeCurrent)
311
- {
312
- readRecords(handler, includeCurrent, READ_RECORD_GETPREV);
313
- }
314
-
315
- inline void stepNextExt(IReadRecordsHandler* handler, bool includeCurrent)
316
- {
317
- readRecords(handler, includeCurrent, READ_RECORD_STEPNEXT);
318
- }
319
-
320
- inline void stepPrevExt(IReadRecordsHandler* handler, bool includeCurrent)
321
- {
322
- readRecords(handler, includeCurrent, READ_RECORD_STEPPREV);
323
- }
324
-
325
- void clearBuffer();
326
- void clearKeybuf(){memset(&m_keybuf[0], 0x00, MAX_KEYLEN);};
327
-
328
- __int64 insert(bool ncc);
329
- void update(bool ncc);
330
- void updateDirectkey();
331
- void beginUpdate(char keyNum);
332
- void del();
333
- void beginDel();
334
-
335
- int keynumByName(const char* name)const;
336
- int stat(){return m_stat;};
337
- void setKeyValuesPacked(const uchar* ptr, int size);
338
- void* record()const;
339
-
340
- uint keyPackCopy(uchar* ptr);
341
-
342
- void setRecord(void* ptr, unsigned short size, int offset=0);
343
- void setRecordFromPacked(const uchar* packedPtr, uint size, const bzs::db::blobHeader* hd);
344
- uint recordPackCopy(char* buf, uint maxsize=0);
345
-
346
- uint fieldSizeByte(int fieldNum){return var_bytes_if(m_table->field[fieldNum]);}
347
- unsigned short fieldDataLen(int fieldNum)const;
348
-
349
- inline unsigned short fieldLen(int fieldNum)const
350
- {
351
- return m_table->field[fieldNum]->pack_length();
352
- }
353
-
354
- inline unsigned short filedVarLenBytes(int fieldNum)const {return var_bytes_if(m_table->field[fieldNum]);}
355
- inline char* fieldPos(int fieldNum)const{return (char*)m_table->field[fieldNum]->ptr;};
356
- inline enum enum_field_types fieldType(int fieldNum) const {return m_table->field[fieldNum]->type();};
357
- inline unsigned int fieldFlags(int fieldNum) const {return m_table->field[fieldNum]->flags;};
358
- inline unsigned short fields()const{return m_table->s->fields;};
359
- inline unsigned int nisFields()const {return m_nullFields;}
360
- inline const char* fieldName(int fieldNum)const {return m_table->s->field[fieldNum]->field_name;};
361
- inline const CHARSET_INFO& fieldCharset(int fieldNum)const {return *m_table->s->field[fieldNum]->charset();}
362
- inline uint lastVarFiledNum()const{return m_table->s->fields-1-nisFields();}
363
- inline const Field* lastVarFiled ()const{return m_table->s->field[lastVarFiledNum()];}
364
- unsigned short lastVarLenBytes()const{return m_lastVarLenBytes;};
365
- unsigned short lastVarFieldPos()const;
366
- inline unsigned short lastVarFieldDataLen()const{return fieldDataLen(lastVarFiledNum());}
367
- /*number of key.*/
368
- inline unsigned short keys()const{return m_table->s->keys;};
369
- inline const KEY& keyDef(char keyNum)const{return m_table->key_info[keyNum];};
370
- inline Field* field(int fieldNum)const{return m_table->field[fieldNum];};
371
- inline char primarykey()const{return m_table->s->primary_key;};
372
- /** is this view. not table*/
373
- inline bool isView()const{return m_table->s->is_view;}
374
-
375
- /** char set of this table.*/
376
- inline const CHARSET_INFO& charset()const {return *m_table->s->table_charset;}
377
-
378
- ha_rows recordCount(bool estimate);
379
- inline ulong recordLen()const{return m_table->s->reclength;}
380
-
381
- /** record length for client side. exclude null flag segmnet
382
- * ,lastVarLenBytes and NIS fields from recordLen()
383
- */
384
- inline uint recordLenCl()const{return m_recordLenCl;}
385
- inline uint nullBytes()const{return (uint)(m_table->s->null_fields>0);}
386
- /** bookmark length*/
387
- uint posPtrLen()const;
388
-
389
- /** bookmark */
390
- const uchar* position(bool raw=false);
391
- const char* keyName(char keyNum);
392
- inline void errorMessage(String *buf){m_table->file->get_error_message(m_stat, buf);}
393
-
394
- void startBulkInsert(ha_rows rows);
395
- void endBulkInsert();
396
-
397
- inline TABLE* internalTable(){return m_table;} ///for debuglog
398
- const char* valStr(int index, int &size); ///for debuglog
399
-
400
- /** add blob field list.
401
- * @param fieldNum field index if it is -1 then all fields of cureent row;
402
- * @return field count of listed.
403
- */
404
- uint makeBlobFieldList(int fieldNum);
405
-
406
- inline void addBlobBuffer(int fieldNum)
407
- {
408
- Field* fd = m_table->field[fieldNum];
409
- m_blobBuffer->addBlob(blob_len(fd), fd->field_index, blobBodyPtr(fd));
410
- }
411
-
412
- inline void setBlobFieldCount(uint num){m_blobBuffer->setFieldCount(num);};
295
+ static bool noKeybufResult;
296
+
297
+ ~table();
298
+
299
+ inline void setBlobBuffer(IblobBuffer* blobBuffer)
300
+ {
301
+ m_blobBuffer = blobBuffer;
302
+ }
303
+
304
+ inline IblobBuffer* blobBuffer(IblobBuffer* blobBuffer)
305
+ {
306
+ return m_blobBuffer;
307
+ }
308
+
309
+ inline short mode() const { return m_mode; }
310
+
311
+ inline bool islocked() { return m_locked; }
312
+
313
+ inline void setLocked(bool value) { m_locked = value; }
314
+
315
+ inline bool isChanged() { return m_changed; }
316
+
317
+ int id() { return m_id; };
318
+
319
+ inline void unUse() { m_db.unUseTable(this); }
320
+
321
+ inline const std::string& name() const { return m_name; }
322
+
323
+ inline int recordFormatType() const { return m_recordFormatType; }
324
+ void resetTransctionInfo(THD* thd);
325
+ void resetInternalTable(TABLE* table);
326
+
327
+ #ifdef USE_BTRV_VARIABLE_LEN
328
+
329
+ inline uint lastVarFiledNum() const
330
+ {
331
+ return m_table->s->fields - 1 - nisFields();
332
+ }
333
+
334
+ inline const Field* lastVarFiled() const
335
+ {
336
+ return m_table->s->field[lastVarFiledNum()];
337
+ }
413
338
 
339
+ unsigned short lastVarLenBytes() const { return m_lastVarLenBytes; }
340
+
341
+ inline unsigned short lastVarFieldDataLen() const
342
+ {
343
+ return fieldDataLen(lastVarFiledNum());
344
+ }
345
+
346
+ unsigned short lastVarFieldPos() const;
347
+ #endif
348
+
349
+ inline int blobFields() const { return m_table->s->blob_fields; }
350
+
351
+ /** if call close then table is deleten.
352
+ */
353
+ inline void close()
354
+ {
355
+ m_table->file->ha_index_or_rnd_end();
356
+ m_db.closeTable(this);
357
+ }
358
+
359
+ inline char keyNum() const { return m_keyNum; }
360
+
361
+ inline bool isUniqueKey()
362
+ {
363
+ return (m_table->key_info[m_keyNum].flags & HA_NOSAME);
364
+ }
365
+
366
+ /*
367
+ * Since it differs from the key number which a client specifies
368
+ * , and an internal key number, it changes.
369
+ * As for the key name, it is a premise that it is keyNN.
370
+ * NN is client specifies key number.
371
+ */
372
+ inline char keyNumByMakeOrder(char num)
373
+ {
374
+ return m_keyconv.keyNumByMakeOrder(num);
375
+ }
376
+
377
+ bool setKeyNum(char num, bool sorted = true);
378
+
379
+ inline void setKeyNum(const char* name, bool sorted = true)
380
+ {
381
+ setKeyNum(keynumByName(name), sorted);
382
+ }
383
+ bool isNisKey(char num) const;
384
+
385
+ inline key_part_map keymap()
386
+ {
387
+ return (1U << m_table->key_info[m_keyNum].user_defined_key_parts) - 1;
388
+ }
389
+ void seekKey(enum ha_rkey_function find_flag, key_part_map keyMap);
390
+ void getNextSame(key_part_map keyMap);
391
+ void getLast();
392
+ void getFirst();
393
+ void getNext();
394
+ void getPrev();
395
+ void getByPercentage(unsigned short per);
396
+ void calcPercentage();
397
+
398
+ inline int* percentResult() { return &m_percentResult; }
399
+
400
+ void stepLast();
401
+ void stepFirst();
402
+ void stepNext();
403
+ void stepPrev();
404
+ void movePos(const uchar* pos, char keyNum, bool sureRawValue = false);
405
+
406
+ inline void getNextExt(IReadRecordsHandler* handler, bool includeCurrent,
407
+ bool noBookmark)
408
+ {
409
+ readRecords(handler, includeCurrent, READ_RECORD_GETNEXT, noBookmark);
410
+ }
411
+
412
+ inline void getPrevExt(IReadRecordsHandler* handler, bool includeCurrent,
413
+ bool noBookmark)
414
+ {
415
+ readRecords(handler, includeCurrent, READ_RECORD_GETPREV, noBookmark);
416
+ }
417
+
418
+ inline void stepNextExt(IReadRecordsHandler* handler, bool includeCurrent,
419
+ bool noBookmark)
420
+ {
421
+ if (m_table->file->inited != handler::RND)
422
+ setNonKey(true);
423
+ readRecords(handler, includeCurrent, READ_RECORD_STEPNEXT, noBookmark);
424
+ }
425
+
426
+ inline void stepPrevExt(IReadRecordsHandler* handler, bool includeCurrent,
427
+ bool noBookmark)
428
+ {
429
+ if (m_table->file->inited != handler::RND)
430
+ setNonKey(true);
431
+ readRecords(handler, includeCurrent, READ_RECORD_STEPPREV, noBookmark);
432
+ }
433
+
434
+ void clearBuffer();
435
+
436
+ inline void clearKeybuf() { memset(&m_keybuf[0], 0x00, MAX_KEYLEN); }
437
+
438
+ __int64 insert(bool ncc);
439
+ void update(bool ncc);
440
+ void updateDirectkey();
441
+ void beginUpdate(char keyNum);
442
+ void del();
443
+ void beginDel();
444
+
445
+ int keynumByName(const char* name) const;
446
+
447
+ inline int stat() { return m_stat; }
448
+ short setKeyValuesPacked(const uchar* ptr, int size);
449
+ void* record() const;
450
+
451
+ uint keyPackCopy(uchar* ptr);
452
+
453
+ void setRecord(void* ptr, unsigned short size, int offset = 0);
454
+ void setRecordFromPacked(const uchar* packedPtr, uint size,
455
+ const bzs::db::blobHeader* hd);
456
+ uint recordPackCopy(char* buf, uint maxsize = 0);
457
+
458
+ ushort fieldPackCopy(unsigned char* dest, short filedNum);
459
+
460
+ inline uint fieldSizeByte(int fieldNum)
461
+ {
462
+ return var_bytes_if(m_table->field[fieldNum]);
463
+ }
464
+ unsigned short fieldDataLen(int fieldNum) const;
465
+
466
+ inline unsigned short fieldLen(int fieldNum) const
467
+ {
468
+ return m_table->field[fieldNum]->pack_length();
469
+ }
470
+
471
+ inline unsigned short filedVarLenBytes(int fieldNum) const
472
+ {
473
+ return var_bytes_if(m_table->field[fieldNum]);
474
+ }
475
+
476
+ inline char* fieldPos(int fieldNum) const
477
+ {
478
+ return (char*)m_table->field[fieldNum]->ptr;
479
+ }
480
+
481
+ inline enum enum_field_types fieldType(int fieldNum) const
482
+ {
483
+ return m_table->field[fieldNum]->type();
484
+ }
485
+
486
+ inline unsigned int fieldFlags(int fieldNum) const
487
+ {
488
+ return m_table->field[fieldNum]->flags;
489
+ }
490
+
491
+ inline unsigned short fields() const { return m_table->s->fields; }
492
+
493
+ inline unsigned int nisFields() const { return m_nullFields; }
494
+
495
+ inline const char* fieldName(int fieldNum) const
496
+ {
497
+ return m_table->s->field[fieldNum]->field_name;
498
+ }
499
+
500
+ inline const CHARSET_INFO& fieldCharset(int fieldNum) const
501
+ {
502
+ return *m_table->s->field[fieldNum]->charset();
503
+ }
504
+
505
+ /* number of key. */
506
+ inline unsigned short keys() const { return m_table->s->keys; }
507
+
508
+ inline const KEY& keyDef(char keyNum) const
509
+ {
510
+ return m_table->key_info[keyNum];
511
+ }
512
+
513
+ inline const KEY* primaryKey() const
514
+ {
515
+ return (m_table->s->primary_key != MAX_KEY)
516
+ ? &m_table->key_info[m_table->s->primary_key]
517
+ : NULL;
518
+ }
519
+
520
+ inline Field* field(int fieldNum) const { return m_table->field[fieldNum]; }
521
+
522
+ inline char primarykey() const { return m_table->s->primary_key; }
523
+
524
+ /** is this view. not table */
525
+ inline bool isView() const { return m_table->s->is_view; }
526
+
527
+ /** char set of this table. */
528
+ inline const CHARSET_INFO& charset() const
529
+ {
530
+ return *m_table->s->table_charset;
531
+ }
532
+
533
+ ha_rows recordCount(bool estimate);
534
+
535
+ inline ulong recordLen() const { return m_table->s->reclength; }
536
+
537
+ /** record length for client side. exclude null flag segmnet
538
+ * ,lastVarLenBytes and NIS fields from recordLen()
539
+ */
540
+ inline uint recordLenCl() const { return m_recordLenCl; }
541
+
542
+ inline uint nullBytes() const
543
+ {
544
+ return (uint)(m_table->s->null_fields > 0);
545
+ }
546
+ /** bookmark length */
547
+ uint posPtrLen() const;
548
+
549
+ /** bookmark */
550
+ const uchar* position(bool raw = false);
551
+ const char* keyName(char keyNum);
552
+
553
+ inline void errorMessage(String* buf)
554
+ {
555
+ m_table->file->get_error_message(m_stat, buf);
556
+ }
557
+
558
+ void startBulkInsert(ha_rows rows);
559
+ void endBulkInsert();
560
+
561
+ inline TABLE* internalTable() { return m_table; }
562
+ /// for debuglog
563
+ const char* valStr(int index, int& size);
564
+ /// for debuglog
565
+
566
+ /** add blob field list.
567
+ * @param fieldNum field index if it is -1 then all fields of cureent row;
568
+ * @return field count of listed.
569
+ */
570
+ uint makeBlobFieldList(int fieldNum);
571
+
572
+ inline void addBlobBuffer(int fieldNum)
573
+ {
574
+ Field* fd = m_table->field[fieldNum];
575
+ m_blobBuffer->addBlob(blob_len(fd), fd->field_index, blobBodyPtr(fd));
576
+ }
577
+
578
+ inline void setBlobFieldCount(uint num)
579
+ {
580
+ m_blobBuffer->setFieldCount(num);
581
+ }
582
+
583
+ inline void indexInit()
584
+ {
585
+ int ret = m_table->file->ha_index_or_rnd_end();
586
+ assert(ret == 0);
587
+ if (m_keyNum >= 0)
588
+ ret = m_table->file->ha_index_init(m_keyNum, true);
589
+ else
590
+ ret = m_table->file->ha_rnd_init(true);
591
+ assert(ret == 0);
592
+ }
414
593
  };
415
594
 
416
- //smart wrapper for exception
417
- class smartBulkInsert
595
+ class fieldBitmap
418
596
  {
419
- table* m_tb;
597
+ TABLE* m_table;
598
+ bool m_keyRead;
599
+
420
600
  public:
421
- smartBulkInsert(table* tb, ha_rows rows):m_tb(tb)
422
- {
423
- m_tb->startBulkInsert(rows);
424
- }
425
-
426
- ~smartBulkInsert()
427
- {
428
- m_tb->endBulkInsert();
429
- }
601
+ inline fieldBitmap(TABLE* table) : m_table(table), m_keyRead(false)
602
+ {
603
+ m_table->read_set = &m_table->tmp_set;
604
+ m_table->write_set = &m_table->tmp_set;
605
+ bitmap_clear_all(m_table->read_set);
606
+ }
607
+
608
+ inline fieldBitmap() : m_table(NULL), m_keyRead(false) {}
609
+
610
+ inline void setTable(table* tb)
611
+ {
612
+ if (tb)
613
+ {
614
+ m_table = tb->internalTable();
615
+ m_table->read_set = &m_table->tmp_set;
616
+ m_table->write_set = &m_table->tmp_set;
617
+ bitmap_clear_all(m_table->read_set);
618
+ }
619
+ else if (m_table)
620
+ {
621
+ if (m_keyRead)
622
+ m_table->file->extra(HA_EXTRA_NO_KEYREAD);
623
+ m_table->read_set = &m_table->s->all_set;
624
+ m_table->write_set = &m_table->s->all_set;
625
+ m_table = NULL;
626
+ }
627
+ }
628
+
629
+ inline ~fieldBitmap()
630
+ {
631
+ if (m_table)
632
+ {
633
+ if (m_keyRead)
634
+ m_table->file->extra(HA_EXTRA_NO_KEYREAD);
635
+ m_table->read_set = &m_table->s->all_set;
636
+ m_table->write_set = &m_table->s->all_set;
637
+ }
638
+ }
639
+
640
+ inline void setKeyRead(bool v)
641
+ {
642
+ assert(m_table);
643
+ if (v)
644
+ m_table->file->extra(HA_EXTRA_KEYREAD);
645
+ else if (m_keyRead)
646
+ m_table->file->extra(HA_EXTRA_NO_KEYREAD);
647
+ m_keyRead = v;
648
+ }
649
+
650
+ inline void setReadBitmap(uint bit)
651
+ {
652
+ assert(m_table);
653
+ bitmap_set_bit(m_table->read_set, bit);
654
+ }
430
655
  };
431
656
 
432
- class smartTransction
657
+ // smart wrapper for exception
658
+ class smartBulkInsert
433
659
  {
434
- database* m_db;
435
- short m_type;
660
+ table* m_tb;
661
+
436
662
  public:
437
- smartTransction(database* db, short type=TRN_RECORD_LOCK_SINGLE):m_db(db)
438
- {
439
- m_db->beginTrn(type);
440
- }
441
-
442
- void end()
443
- {
444
- m_db->commitTrn();
445
- m_db=NULL;
446
- }
447
-
448
- ~smartTransction()
449
- {
450
- if (m_db)
451
- m_db->abortTrn();
452
- }
663
+ smartBulkInsert(table* tb, ha_rows rows) : m_tb(tb)
664
+ {
665
+ m_tb->startBulkInsert(rows);
666
+ }
453
667
 
668
+ ~smartBulkInsert() { m_tb->endBulkInsert(); }
454
669
  };
455
670
 
456
- #define BUILINSERT_SCOPE
671
+ class smartTransction
672
+ {
673
+ database* m_db;
674
+ short m_type;
457
675
 
458
- }//namespace mysql
459
- }//namespace engine
460
- }//namespace db
461
- }//namespace bzs
676
+ public:
677
+ smartTransction(database* db, short type = TRN_RECORD_LOCK_SINGLE)
678
+ : m_db(db)
679
+ {
680
+ m_db->beginTrn(type);
681
+ }
682
+
683
+ void end()
684
+ {
685
+ m_db->commitTrn();
686
+ m_db = NULL;
687
+ }
688
+
689
+ ~smartTransction()
690
+ {
691
+ if (m_db)
692
+ m_db->abortTrn();
693
+ }
694
+ };
462
695
 
463
- #endif //DATABASE_H
696
+ #define BUILINSERT_SCOPE
464
697
 
698
+ } // namespace mysql
699
+ } // namespace engine
700
+ } // namespace db
701
+ } // namespace bzs
465
702
 
703
+ #endif // BZS_DB_ENGINE_MYSQL_DATABASE_H