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,21 +1,21 @@
1
- /*=================================================================
2
- Copyright (C) 2012 2013 BizStation Corp All rights reserved.
1
+ /* =================================================================
2
+ Copyright (C) 2012 2013 BizStation Corp All rights reserved.
3
3
 
4
- This program is free software; you can redistribute it and/or
5
- modify it under the terms of the GNU General Public License
6
- as published by the Free Software Foundation; either version 2
7
- of the License, or (at your option) any later version.
4
+ This program is free software; you can redistribute it and/or
5
+ modify it under the terms of the GNU General Public License
6
+ as published by the Free Software Foundation; either version 2
7
+ of the License, or (at your option) any later version.
8
8
 
9
- This program is distributed in the hope that it will be useful,
10
- but WITHOUT ANY WARRANTY; without even the implied warranty of
11
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
- GNU General Public License for more details.
9
+ This program is distributed in the hope that it will be useful,
10
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
11
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
+ GNU General Public License for more details.
13
13
 
14
- You should have received a copy of the GNU General Public License
15
- along with this program; if not, write to the Free Software
16
- Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
17
- 02111-1307, USA.
18
- =================================================================*/
14
+ You should have received a copy of the GNU General Public License
15
+ along with this program; if not, write to the Free Software
16
+ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
17
+ 02111-1307, USA.
18
+ ================================================================= */
19
19
 
20
20
  #include "sqlBuilder.h"
21
21
  #include <bzs/rtl/stl_uty.h>
@@ -42,534 +42,555 @@ namespace tdap
42
42
  namespace client
43
43
  {
44
44
 
45
-
46
45
  /** Remove extention
47
46
  * To lower_case
48
47
  */
49
48
  std::string getFileName(const char* name)
50
49
  {
51
- const char* st = name;
52
- const char* en = st + strlen(name);
53
- const char* p = strrchr(name, '.');
54
- if (p)
55
- en = p;
56
- p = strrchr(name, PSEPARATOR_C);
57
- if (p)
58
- st = p+1;
59
- p = strrchr(name, '=');
60
- if (p && p+1 > st)
61
- st = p+1;
62
-
63
- char tableName[MYSQL_TBNAME_SIZE]={0x00};
64
- strncpy_s(tableName, MYSQL_TBNAME_SIZE, st, en-st);
65
- _strlwr_s(tableName, MYSQL_TBNAME_SIZE);
66
- return tableName;
50
+ const char* st = name;
51
+ const char* en = st + strlen(name);
52
+ const char* p = strrchr(name, '.');
53
+ if (p)
54
+ en = p;
55
+ p = strrchr(name, PSEPARATOR_C);
56
+ if (p)
57
+ st = p + 1;
58
+ p = strrchr(name, '=');
59
+ if (p && p + 1 > st)
60
+ st = p + 1;
61
+
62
+ char tableName[MYSQL_TBNAME_SIZE] = { 0x00 };
63
+ strncpy_s(tableName, MYSQL_TBNAME_SIZE, st, en - st);
64
+ _strlwr_s(tableName, MYSQL_TBNAME_SIZE);
65
+ return tableName;
67
66
  }
68
67
 
69
68
  #define TMP_BUFSIZE 100
70
69
  char g_buf[TMP_BUFSIZE];
71
70
 
72
71
  #define NOTE_TYPE 12
73
- #define VAR_TYPE 13
72
+ #define VAR_TYPE 13
74
73
 
75
74
  const char* getFieldTypeName(uchar_td fieldType, int size, bool nobinary,
76
- const char* charsetName)
75
+ const char* charsetName)
77
76
  {
78
- const char* bin_ptr = nobinary ? "" : "binary";
79
- char charsetString[128] = {" CHARACTER SET "};
80
- if (charsetName[0])
81
- strcat_s(charsetString, 128, charsetName);
82
- else
83
- charsetString[0] = 0x00;
84
-
85
- switch(fieldType)
86
- {
87
-
88
- case ft_integer:
89
- case ft_autoinc:
90
- case ft_currency:
91
- case ft_date:
92
- case ft_time:
93
- case ft_timestamp:
94
- if (size==1)return "TINYINT";
95
- if (size==2)return "SMALLINT";
96
- if (size==4)return "INT";
97
- if (size==8)return "BIGINT";
98
- case ft_uinteger:
77
+ const char* bin_ptr = nobinary ? "" : "binary";
78
+ char charsetString[128] = { " CHARACTER SET " };
79
+ if (charsetName[0])
80
+ strcat_s(charsetString, 128, charsetName);
81
+ else
82
+ charsetString[0] = 0x00;
83
+
84
+ switch (fieldType)
85
+ {
86
+
87
+ case ft_integer:
88
+ case ft_autoinc:
89
+ case ft_currency:
90
+ case ft_date:
91
+ case ft_time:
92
+ case ft_timestamp:
93
+ if (size == 1)
94
+ return "TINYINT";
95
+ if (size == 2)
96
+ return "SMALLINT";
97
+ if (size == 4)
98
+ return "INT";
99
+ if (size == 8)
100
+ return "BIGINT";
101
+ case ft_uinteger:
99
102
  case ft_autoIncUnsigned:
100
- if (size==1)return "TINYINT UNSIGNED";
101
- if (size==2)return "SMALLINT UNSIGNED";
102
- if (size==4)return "INT UNSIGNED";
103
- if (size==8)return "BIGINT UNSIGNED";
104
- case ft_logical:return "TINYINT UNSIGNED";
105
- case ft_mydate:return "DATE";
106
- case ft_mytime:
107
- sprintf_s(g_buf, TMP_BUFSIZE, "TIME(%d)", (size-3)*2);
108
- return g_buf;
109
- case ft_mydatetime:
110
- sprintf_s(g_buf, TMP_BUFSIZE, "DATETIME(%d)", (size-5)*2);
111
- return g_buf;
112
- case ft_mytimestamp:
113
-
114
- sprintf_s(g_buf, TMP_BUFSIZE, "TIMESTAMP(%d)", (size-4)*2);
115
- return g_buf;
116
- case ft_mytext:
117
- if (size-8 == 4)
118
- return "LONGTEXT";
119
- else if (size-8 == 3)
120
- return "MEDIUMTEXT";
121
- else if (size-8 == 2)
122
- return "TEXT";
123
- return "TINYTEXT";
124
- case ft_myblob:
125
- if (size-8 == 4)
126
- return "LONGBLOB";
127
- else if (size-8 == 3)
128
- return "MEDIUMBLOB";
129
- else if (size-8 == 2)
130
- return "BLOB";
131
- return "TINYBLOB";
132
- case ft_float:
133
- if (size==4)return "FLOAT";
134
- if (size==8)return "DOUBLE";
135
- case ft_string:
136
- sprintf_s(g_buf, TMP_BUFSIZE, "BINARY(%d)", size);
137
- return g_buf;
138
- case ft_zstring:
139
- case ft_wzstring:
140
- sprintf_s(g_buf, TMP_BUFSIZE, "BINARY(%d)", size);
141
- return g_buf;
142
- case ft_note: //note can not use key
143
- case ft_lvar: //var
144
- sprintf_s(g_buf, TMP_BUFSIZE, "VARBINARY(%d)", size);
145
- return g_buf;
146
- case ft_myvarbinary:
147
- sprintf_s(g_buf, TMP_BUFSIZE, "VARBINARY(%d)", size);
148
- return g_buf;
149
- case ft_mywvarbinary:
150
- sprintf_s(g_buf, TMP_BUFSIZE, "VARBINARY(%d)", size);
151
- return g_buf;
152
-
153
- case ft_mywvarchar:
154
- sprintf_s(g_buf, TMP_BUFSIZE, "VARCHAR(%d) %s CHARACTER SET utf16le", size, bin_ptr);
155
- return g_buf;
156
- case ft_myvarchar:
157
- sprintf_s(g_buf, TMP_BUFSIZE, "VARCHAR(%d) %s%s", size, bin_ptr, charsetString);
158
- return g_buf;
159
- case ft_mychar:
160
- sprintf_s(g_buf, TMP_BUFSIZE, "CHAR(%d) %s%s", size, bin_ptr, charsetString);
161
- return g_buf;
162
- case ft_mywchar:
163
- sprintf_s(g_buf, TMP_BUFSIZE, "CHAR(%d) %s CHARACTER SET utf16le", size, bin_ptr);
164
- return g_buf;
165
- case ft_decimal:
166
- case ft_money:
167
- case ft_numeric:
168
- case ft_bfloat:
169
- case ft_numericsts:
170
- case ft_numericsa:
171
- case ft_guid:
172
- sprintf_s(g_buf, TMP_BUFSIZE, "BINARY(%d)", size);
173
- return g_buf;
174
- }
175
- return "";
103
+ if (size == 1)
104
+ return "TINYINT UNSIGNED";
105
+ if (size == 2)
106
+ return "SMALLINT UNSIGNED";
107
+ if (size == 4)
108
+ return "INT UNSIGNED";
109
+ if (size == 8)
110
+ return "BIGINT UNSIGNED";
111
+ case ft_logical:
112
+ return "TINYINT UNSIGNED";
113
+ case ft_mydate:
114
+ return "DATE";
115
+ case ft_mytime:
116
+ sprintf_s(g_buf, TMP_BUFSIZE, "TIME(%d)", (size - 3) * 2);
117
+ return g_buf;
118
+ case ft_mydatetime:
119
+ sprintf_s(g_buf, TMP_BUFSIZE, "DATETIME(%d)", (size - 5) * 2);
120
+ return g_buf;
121
+ case ft_mytimestamp:
122
+
123
+ sprintf_s(g_buf, TMP_BUFSIZE, "TIMESTAMP(%d)", (size - 4) * 2);
124
+ return g_buf;
125
+ case ft_mytext:
126
+ if (size - 8 == 4)
127
+ return "LONGTEXT";
128
+ else if (size - 8 == 3)
129
+ return "MEDIUMTEXT";
130
+ else if (size - 8 == 2)
131
+ return "TEXT";
132
+ return "TINYTEXT";
133
+ case ft_myblob:
134
+ if (size - 8 == 4)
135
+ return "LONGBLOB";
136
+ else if (size - 8 == 3)
137
+ return "MEDIUMBLOB";
138
+ else if (size - 8 == 2)
139
+ return "BLOB";
140
+ return "TINYBLOB";
141
+ case ft_float:
142
+ if (size == 4)
143
+ return "FLOAT";
144
+ if (size == 8)
145
+ return "DOUBLE";
146
+ case ft_string:
147
+ sprintf_s(g_buf, TMP_BUFSIZE, "BINARY(%d)", size);
148
+ return g_buf;
149
+ case ft_zstring:
150
+ case ft_wzstring:
151
+ sprintf_s(g_buf, TMP_BUFSIZE, "BINARY(%d)", size);
152
+ return g_buf;
153
+ case ft_note: // note can not use key
154
+ case ft_lvar: // var
155
+ sprintf_s(g_buf, TMP_BUFSIZE, "VARBINARY(%d)", size);
156
+ return g_buf;
157
+ case ft_myvarbinary:
158
+ case ft_myfixedbinary:
159
+ sprintf_s(g_buf, TMP_BUFSIZE, "VARBINARY(%d)", size);
160
+ return g_buf;
161
+ case ft_mywvarbinary:
162
+ sprintf_s(g_buf, TMP_BUFSIZE, "VARBINARY(%d)", size);
163
+ return g_buf;
164
+
165
+ case ft_mywvarchar:
166
+ sprintf_s(g_buf, TMP_BUFSIZE, "VARCHAR(%d) %s CHARACTER SET utf16le",
167
+ size, bin_ptr);
168
+ return g_buf;
169
+ case ft_myvarchar:
170
+ sprintf_s(g_buf, TMP_BUFSIZE, "VARCHAR(%d) %s%s", size, bin_ptr,
171
+ charsetString);
172
+ return g_buf;
173
+ case ft_mychar:
174
+ sprintf_s(g_buf, TMP_BUFSIZE, "CHAR(%d) %s%s", size, bin_ptr,
175
+ charsetString);
176
+ return g_buf;
177
+ case ft_mywchar:
178
+ sprintf_s(g_buf, TMP_BUFSIZE, "CHAR(%d) %s CHARACTER SET utf16le", size,
179
+ bin_ptr);
180
+ return g_buf;
181
+ case ft_decimal:
182
+ case ft_money:
183
+ case ft_numeric:
184
+ case ft_bfloat:
185
+ case ft_numericsts:
186
+ case ft_numericsa:
187
+ case ft_guid:
188
+ sprintf_s(g_buf, TMP_BUFSIZE, "BINARY(%d)", size);
189
+ return g_buf;
190
+ }
191
+ return "";
176
192
  }
177
193
 
178
194
  FLAGS getKeyFlags(tabledef* table, short fieldNum)
179
195
  {
180
- for (int i=0;i<table->keyCount;i++)
181
- {
182
- keydef& key = table->keyDefs[i];
183
- for (int j=0;j<key.segmentCount;j++)
184
- {
185
- if (key.segments[j].fieldNum == fieldNum)
186
- return key.segments[j].flags;
187
- }
188
- }
189
- FLAGS a;
190
- a.all = 0;
191
- return a;
196
+ for (int i = 0; i < table->keyCount; i++)
197
+ {
198
+ keydef& key = table->keyDefs[i];
199
+ for (int j = 0; j < key.segmentCount; j++)
200
+ {
201
+ if (key.segments[j].fieldNum == fieldNum)
202
+ return key.segments[j].flags;
203
+ }
204
+ }
205
+ FLAGS a;
206
+ a.all = 0;
207
+ return a;
192
208
  }
193
209
 
194
210
  bool isNumericFieldName(const char* name)
195
211
  {
196
- if (name )
197
- {
198
- if (name[0] >= '0' && name[0] <= '9')
199
- return true;
200
- }
201
- return false;
212
+ if (name)
213
+ {
214
+ if (name[0] >= '0' && name[0] <= '9')
215
+ return true;
216
+ }
217
+ return false;
202
218
  }
203
219
 
204
220
  bool isNULLKeySegment(tabledef* table, short fieldIndex)
205
221
  {
206
- bool ret = 0;
207
- for (int i=0;i<table->keyCount;i++)
208
- {
209
- keydef& key = table->keyDefs[i];
210
- for (int j=0;j<key.segmentCount;j++)
211
- {
212
- if (key.segments[j].fieldNum == fieldIndex)
213
- {
214
- // bit3 all segment NULL key
215
- // bit9 part segment NULL key
216
- // if fd.nullValue != 0x00 then this field is type of not null .
217
- const fielddef& fd = table->fieldDefs[fieldIndex];
218
- if (((key.segments[j].flags.bit3 || key.segments[j].flags.bit9))
219
- && (fd.nullValue == 0x00))
220
- ret = true;
221
- else
222
- return false;
223
- }
224
- }
225
- }
226
- return ret;
222
+ bool ret = 0;
223
+ for (int i = 0; i < table->keyCount; i++)
224
+ {
225
+ keydef& key = table->keyDefs[i];
226
+ for (int j = 0; j < key.segmentCount; j++)
227
+ {
228
+ if (key.segments[j].fieldNum == fieldIndex)
229
+ {
230
+ // bit3 all segment NULL key
231
+ // bit9 part segment NULL key
232
+ // if fd.nullValue != 0x00 then this field is type of not null .
233
+ const fielddef& fd = table->fieldDefs[fieldIndex];
234
+ if (((key.segments[j].flags.bit3 ||
235
+ key.segments[j].flags.bit9)) &&
236
+ (fd.nullValue == 0x00))
237
+ ret = true;
238
+ else
239
+ return false;
240
+ }
241
+ }
242
+ }
243
+ return ret;
227
244
  }
228
245
 
229
246
  std::string getFiledList(tabledef* table, std::vector<std::string>& fdl)
230
247
  {
231
- std::string s;
232
- int len;
233
- for (int i=0;i<table->fieldCount;i++)
234
- {
235
- fielddef& fd = table->fieldDefs[i];
236
- s += "`";
237
- s += fdl[i];
238
- s += "` ";
239
- len = fd.len - fd.varLenBytes();
240
-
241
- /*
242
- Although len is a number of bytes in BDF, it becomes the number of characters in MySQL.
243
- Moreover, unicode cannot be specified by charset of the field. */
244
- if (fd.charsetIndex() == 0)
245
- fd.setCharsetIndex(table->charsetIndex);
246
- if ((fd.type== ft_myvarchar)||(fd.type== ft_mychar))
247
- len /= mysql::charsize(fd.charsetIndex());
248
- else if ((fd.type== ft_mywvarchar)|| (fd.type== ft_mywchar))
249
- len /= mysql::charsize(CHARSET_UTF16LE);
250
-
251
- FLAGS f = getKeyFlags(table, i);
252
- const char* charsetName = "";
253
- if (fd.charsetIndex() != table->charsetIndex)
254
- charsetName = mysql::charsetName(fd.charsetIndex());
255
-
256
- s += getFieldTypeName(fd.type, len, f.bitA, charsetName);
257
- if (isNULLKeySegment(table, i))
258
- s += " NULL";
259
- else
260
- s += " NOT NULL";
261
- if ((fd.type == ft_autoinc)||(fd.type == ft_autoIncUnsigned))
262
- s += " AUTO_INCREMENT";
263
- s += ",";
264
- }
265
- return s;
248
+ std::string s;
249
+ int len;
250
+ for (int i = 0; i < table->fieldCount; i++)
251
+ {
252
+ fielddef& fd = table->fieldDefs[i];
253
+ s += "`";
254
+ s += fdl[i];
255
+ s += "` ";
256
+ len = fd.len - fd.varLenBytes();
257
+
258
+ /*
259
+ Although len is a number of bytes in BDF, it becomes the number of
260
+ characters in MySQL.
261
+ Moreover, unicode cannot be specified by charset of the field. */
262
+ if (fd.charsetIndex() == 0)
263
+ fd.setCharsetIndex(table->charsetIndex);
264
+ if ((fd.type == ft_myvarchar) || (fd.type == ft_mychar))
265
+ len /= mysql::charsize(fd.charsetIndex());
266
+ else if ((fd.type == ft_mywvarchar) || (fd.type == ft_mywchar))
267
+ len /= mysql::charsize(CHARSET_UTF16LE);
268
+
269
+ FLAGS f = getKeyFlags(table, i);
270
+ const char* charsetName = "";
271
+ if (fd.charsetIndex() != table->charsetIndex)
272
+ charsetName = mysql::charsetName(fd.charsetIndex());
273
+
274
+ s += getFieldTypeName(fd.type, len, f.bitA, charsetName);
275
+ if (isNULLKeySegment(table, i))
276
+ s += " NULL";
277
+ else
278
+ s += " NOT NULL";
279
+ if ((fd.type == ft_autoinc) || (fd.type == ft_autoIncUnsigned))
280
+ s += " AUTO_INCREMENT";
281
+ s += ",";
282
+ }
283
+ return s;
266
284
  }
267
285
 
268
- void insertNisFields(tabledef* table, std::vector<std::string>& fdl, std::string& s)
286
+ void insertNisFields(tabledef* table, std::vector<std::string>& fdl,
287
+ std::string& s)
269
288
  {
270
- char buf[20];
271
- for (int i=0;i<table->keyCount;i++)
272
- {
273
- _ltoa_s(i, buf, 20, 10);
274
- std::string fddef="";
275
- keydef& key = table->keyDefs[i];
276
- if (key.segmentCount > 1)
277
- {
278
- if (key.segments[0].flags.bit9)
279
- fddef = std::string("`") + "$nfn" + buf + "` TINYINT UNSIGNED NULL," ;
280
- else if (key.segments[0].flags.bit3)
281
- fddef = std::string("`") + "$nfa" + buf + "` TINYINT UNSIGNED NULL," ;
282
-
283
- }
284
- if (fddef!="")
285
- s += fddef;
286
- }
289
+ char buf[20];
290
+ for (int i = 0; i < table->keyCount; i++)
291
+ {
292
+ _ltoa_s(i, buf, 20, 10);
293
+ std::string fddef = "";
294
+ keydef& key = table->keyDefs[i];
295
+ if (key.segmentCount > 1)
296
+ {
297
+ if (key.segments[0].flags.bit9)
298
+ fddef = std::string("`") + "$nfn" + buf +
299
+ "` TINYINT UNSIGNED NULL,";
300
+ else if (key.segments[0].flags.bit3)
301
+ fddef = std::string("`") + "$nfa" + buf +
302
+ "` TINYINT UNSIGNED NULL,";
303
+ }
304
+ if (fddef != "")
305
+ s += fddef;
306
+ }
287
307
  }
288
308
 
289
309
  std::string getKeyList(tabledef* table, std::vector<std::string>& fdl)
290
310
  {
291
- char buf[20];
292
- std::string s;
293
-
294
- for (int i=0;i<table->keyCount;i++)
295
- {
296
- keydef& key = table->keyDefs[i];
297
- _ltoa_s(i, buf, 20, 10);
298
- if ((table->primaryKeyNum==i)
299
- && (fdl[key.segments[0].fieldNum]=="auto_id_field"))
300
- s += " PRIMARY KEY ";
301
- else
302
- {
303
- if(key.segments[0].flags.bit0==false)
304
- s += " UNIQUE ";
305
- else
306
- s += " INDEX ";
307
- s += "key";
308
-
309
- s += buf;
310
- }
311
- s += "(";
312
-
313
-
314
- //"nf" segment is added to a head.
315
- if (key.segmentCount > 1)
316
- {
317
- //If a first segment is not 1 byte of Logical
318
- fielddef& fd = table->fieldDefs[key.segments[0].fieldNum];
319
- if (!((fd.len == 1) && (fd.type == ft_logical)))
320
- {
321
- if (key.segments[0].flags.bit9)
322
- s += std::string("`") + "$nfn" + buf + "`," ;
323
- else if (key.segments[0].flags.bit3)
324
- s += std::string("`") + "$nfa" + buf + "`," ;
325
- }
326
- }
327
- for (int j=0;j<key.segmentCount;j++)
328
- {
329
- s += "`" ;
330
- s += fdl[key.segments[j].fieldNum];
331
- s += "`" ;
332
-
333
- //part key
334
- fielddef& fd = table->fieldDefs[key.segments[j].fieldNum];
335
- if (fd.keylen && ((fd.keylen != fd.len)||fd.blobLenBytes()))
336
- {
337
- sprintf_s(buf, 20, "(%d)", fd.keylen);
338
- s += buf;
339
- }
340
-
341
- if (key.segments[j].flags.bit6)
342
- s += " DESC";
343
- s += ",";
344
- }
345
- s.erase(s.end()-1);
346
- s += "),";
347
- }
348
- return s;
311
+ char buf[20];
312
+ std::string s;
313
+
314
+ for (int i = 0; i < table->keyCount; i++)
315
+ {
316
+ keydef& key = table->keyDefs[i];
317
+ _ltoa_s(i, buf, 20, 10);
318
+ if ((table->primaryKeyNum == i) &&
319
+ (fdl[key.segments[0].fieldNum] == "auto_id_field"))
320
+ s += " PRIMARY KEY ";
321
+ else
322
+ {
323
+ if (key.segments[0].flags.bit0 == false)
324
+ s += " UNIQUE ";
325
+ else
326
+ s += " INDEX ";
327
+ s += "key";
328
+
329
+ s += buf;
330
+ }
331
+ s += "(";
332
+
333
+ // "nf" segment is added to a head.
334
+ if (key.segmentCount > 1)
335
+ {
336
+ // If a first segment is not 1 byte of Logical
337
+ fielddef& fd = table->fieldDefs[key.segments[0].fieldNum];
338
+ if (!((fd.len == 1) && (fd.type == ft_logical)))
339
+ {
340
+ if (key.segments[0].flags.bit9)
341
+ s += std::string("`") + "$nfn" + buf + "`,";
342
+ else if (key.segments[0].flags.bit3)
343
+ s += std::string("`") + "$nfa" + buf + "`,";
344
+ }
345
+ }
346
+ for (int j = 0; j < key.segmentCount; j++)
347
+ {
348
+ s += "`";
349
+ s += fdl[key.segments[j].fieldNum];
350
+ s += "`";
351
+
352
+ // part key
353
+ fielddef& fd = table->fieldDefs[key.segments[j].fieldNum];
354
+ if (fd.keylen && ((fd.keylen != fd.len) || fd.blobLenBytes()))
355
+ {
356
+ sprintf_s(buf, 20, "(%d)", fd.keylen);
357
+ s += buf;
358
+ }
359
+
360
+ if (key.segments[j].flags.bit6)
361
+ s += " DESC";
362
+ s += ",";
363
+ }
364
+ s.erase(s.end() - 1);
365
+ s += "),";
366
+ }
367
+ return s;
349
368
  }
350
369
 
351
- std::string convertString(unsigned int toPage, unsigned int fromPage, const char* p)
370
+ std::string convertString(unsigned int toPage, unsigned int fromPage,
371
+ const char* p)
352
372
  {
353
- std::string s;
354
- stringConverter cv(toPage, fromPage);
355
- int osize = (int)strlen(p)*3;
356
- char* srvchar = new char[osize];
357
- size_t len = cv.convert(srvchar, osize, p, strlen(p));
358
- srvchar[len] = 0x00;
359
- s = srvchar;
360
- delete [] srvchar;
361
- return s;
373
+ std::string s;
374
+ stringConverter cv(toPage, fromPage);
375
+ int osize = (int)strlen(p) * 3;
376
+ char* srvchar = new char[osize];
377
+ size_t len = cv.convert(srvchar, osize, p, strlen(p));
378
+ srvchar[len] = 0x00;
379
+ s = srvchar;
380
+ delete[] srvchar;
381
+ return s;
362
382
  }
363
383
 
364
- std::string sqlCreateTable(const char* name/*utf8*/, tabledef* table, uchar_td charsetIndexServer)
384
+ std::string sqlCreateTable(const char* name /* utf8 */, tabledef* table,
385
+ uchar_td charsetIndexServer)
365
386
  {
366
- //Duplication of a name is inspected and, in duplication, _1 is added.
367
- //It does not correspond to two or more duplications.
368
- std::vector<std::string> fdl;
369
- std::vector<std::string> fds;
370
- char tmp[1024];
371
- char num[10];
372
- for (int i=0;i<table->fieldCount;i++)
373
- {
374
- fielddef& fd = table->fieldDefs[i];
375
- strcpy_s(tmp, 256, fd.nameA());
376
- _strlwr_s(tmp, 256);
377
- if (std::find(fdl.begin(), fdl.end(), tmp) != fdl.end())
378
- {
379
- _ltoa_s(i, num, 10, 10);
380
- strcat_s(tmp, 256, num);
381
- fds.push_back(std::string(fd.nameA())+ num);
382
- }else
383
- fds.push_back(fd.nameA());
384
- fdl.push_back(tmp);
385
-
386
- }
387
- uint_td schemaCodePage = table->schemaCodePage ? table->schemaCodePage : GetACP();
388
- std::string s = "CREATE TABLE `";
389
- if ((name && name[0]))
390
- {
391
- std::string name2 = name;
392
- if (schemaCodePage != CP_UTF8)
393
- name2 = convertString(schemaCodePage, CP_UTF8, name);
394
- s += getFileName(name2.c_str()) + "` (";
395
- }
396
- else
397
- s += getFileName(table->fileNameA()) + "` (";
398
- s += getFiledList(table, fds);
399
- insertNisFields(table, fds, s);
400
- s += getKeyList(table, fds);
401
- if (s[s.size()-1] == ',')
402
- s.erase(s.end()-1);
403
- s += ") ENGINE=InnoDB default charset="+ std::string(mysql::charsetName(table->charsetIndex));
387
+ // Duplication of a name is inspected and, in duplication, _1 is added.
388
+ // It does not correspond to two or more duplications.
389
+ std::string s = "CREATE TABLE `";
390
+
391
+ std::vector<std::string> fdl;
392
+ std::vector<std::string> fds;
393
+ char tmp[256];
394
+ char num[10];
395
+ for (int i = 0; i < table->fieldCount; i++)
396
+ {
397
+ fielddef& fd = table->fieldDefs[i];
398
+ strcpy_s(tmp, 256, fd.nameA());
399
+ _strlwr_s(tmp, 256);
400
+ if (std::find(fdl.begin(), fdl.end(), tmp) != fdl.end())
401
+ {
402
+ _ltoa_s(i, num, 10, 10);
403
+ strcat_s(tmp, 256, num);
404
+ fds.push_back(std::string(fd.nameA()) + num);
405
+ }
406
+ else
407
+ fds.push_back(fd.nameA());
408
+ fdl.push_back(tmp);
409
+ }
410
+ uint_td schemaCodePage =
411
+ table->schemaCodePage ? table->schemaCodePage : GetACP();
412
+ if ((name && name[0]))
413
+ {
414
+ std::string name2 = name;
415
+ if (schemaCodePage != CP_UTF8)
416
+ name2 = convertString(schemaCodePage, CP_UTF8, name);
417
+ s += getFileName(name2.c_str()) + "` (";
418
+ }
419
+ else
420
+ s += getFileName(table->fileNameA()) + "` (";
421
+ s += getFiledList(table, fds);
422
+ insertNisFields(table, fds, s);
423
+ s += getKeyList(table, fds);
424
+ if (s[s.size() - 1] == ',')
425
+ s.erase(s.end() - 1);
426
+ s += ") ENGINE=InnoDB default charset=" +
427
+ std::string(mysql::charsetName(table->charsetIndex));
404
428
 
405
429
  // create statement charset must be server default charset.
406
430
  // server default charset writen in my.cnf.
407
- if (schemaCodePage != mysql::codePage(charsetIndexServer))
408
- s = convertString(mysql::codePage(charsetIndexServer), schemaCodePage, s.c_str());
409
- return s;
431
+ if (schemaCodePage != mysql::codePage(charsetIndexServer))
432
+ s = convertString(mysql::codePage(charsetIndexServer), schemaCodePage,
433
+ s.c_str());
434
+ return s;
410
435
  }
411
436
 
412
-
413
437
  int findFieldNum(std::vector<fielddef>& fds, int pos)
414
438
  {
415
- for (int i=0;i<(int)fds.size();i++)
416
- {
417
- if (fds[i].pos==pos)
418
- return i;
419
- }
420
- return -1;
439
+ for (int i = 0; i < (int)fds.size(); i++)
440
+ {
441
+ if (fds[i].pos == pos)
442
+ return i;
443
+ }
444
+ return -1;
421
445
  }
422
446
 
423
447
  void makeField(std::vector<fielddef>& fds, keySpec* ks, int keynum, int seg)
424
448
  {
425
- char buf[100];
426
- fielddef fd ;
427
- memset(&fd, 0x00, sizeof(fielddef));
428
- sprintf_s(buf, 100, "key%d_%d", keynum, seg);
429
- fd.setNameA(buf);
430
- fd.len = ks->keyLen;
431
- fd.type = ks->keyType;
432
- fd.pos = ks->keyPos;
433
- fds.push_back(fd);
449
+ char buf[100];
450
+ fielddef fd;
451
+ memset(&fd, 0x00, sizeof(fielddef));
452
+ sprintf_s(buf, 100, "key%d_%d", keynum, seg);
453
+ fd.setNameA(buf);
454
+ fd.len = ks->keyLen;
455
+ fd.type = ks->keyType;
456
+ fd.pos = ks->keyPos;
457
+ fds.push_back(fd);
434
458
  }
435
459
 
436
460
  bool field_sort(const fielddef& l, const fielddef& r)
437
461
  {
438
- if (l.pos < r.pos)
439
- return 1;
440
- return 0;
462
+ if (l.pos < r.pos)
463
+ return 1;
464
+ return 0;
441
465
  }
442
466
 
443
467
  void completeFields(std::vector<fielddef>& fds, int reclen, bool valiableLen)
444
468
  {
445
- char buf[100];
446
- int pos = 1;
447
- for (int i=0;i<(int)fds.size();i++)
448
- {
449
- if (fds[i].pos > pos)
450
- {
451
- fielddef fd;
452
- memset(&fd, 0x00, sizeof(fielddef));
453
- sprintf_s(buf, 100, "field%d",i);
454
- fd.setNameA(buf);
455
- fd.pos = pos;
456
- fd.len = fds[i].pos - pos;
457
- fd.type = (fd.len > 255)? ft_note:ft_zstring;
458
- fds.insert(fds.begin() + i, fd);
459
- i++;
460
- }
461
- pos = fds[i].pos + fds[i].len;
462
- }
463
- if (pos <= reclen)
464
- {
465
- fielddef fd;
466
- memset(&fd, 0x00, sizeof(fielddef));
467
-
468
- sprintf_s(buf, 100, "field%d",(int)fds.size());
469
- fd.setNameA(buf);
470
- fd.pos = pos;
471
- fd.len = reclen - pos + 1;
472
- fd.type = (fd.len > 255)? ft_note:ft_zstring;
473
- if (fd.type == NOTE_TYPE)
474
- fd.len = 57000 - pos + 1;
475
- fds.push_back(fd);
476
- pos = fd.pos + fd.len;
477
- }
478
- //In the case of a variable-length record, the last must have a variable length field.
479
- if (valiableLen)
480
- {
481
- if (fds[fds.size()-1].type != ft_note)
482
- {
483
- fielddef fd;
484
- memset(&fd, 0x00, sizeof(fielddef));
485
- sprintf_s(buf, 100, "field%d",(int)fds.size());
486
- fd.setNameA(buf);
487
- fd.pos = pos;
488
- fd.len = 57000 - pos + 1;
489
- fd.type = NOTE_TYPE;
490
- fds.push_back(fd);
491
- }
492
- }
493
-
494
-
469
+ char buf[100];
470
+ int pos = 1;
471
+ for (int i = 0; i < (int)fds.size(); i++)
472
+ {
473
+ if (fds[i].pos > pos)
474
+ {
475
+ fielddef fd;
476
+ memset(&fd, 0x00, sizeof(fielddef));
477
+ sprintf_s(buf, 100, "field%d", i);
478
+ fd.setNameA(buf);
479
+ fd.pos = pos;
480
+ fd.len = fds[i].pos - pos;
481
+ fd.type = (fd.len > 255) ? ft_note : ft_zstring;
482
+ fds.insert(fds.begin() + i, fd);
483
+ i++;
484
+ }
485
+ pos = fds[i].pos + fds[i].len;
486
+ }
487
+ if (pos <= reclen)
488
+ {
489
+ fielddef fd;
490
+ memset(&fd, 0x00, sizeof(fielddef));
491
+
492
+ sprintf_s(buf, 100, "field%d", (int)fds.size());
493
+ fd.setNameA(buf);
494
+ fd.pos = pos;
495
+ fd.len = reclen - pos + 1;
496
+ fd.type = (fd.len > 255) ? ft_note : ft_zstring;
497
+ if (fd.type == NOTE_TYPE)
498
+ fd.len = 57000 - pos + 1;
499
+ fds.push_back(fd);
500
+ pos = fd.pos + fd.len;
501
+ }
502
+ // In the case of a variable-length record, the last must have a variable
503
+ // length field.
504
+ if (valiableLen)
505
+ {
506
+ if (fds[fds.size() - 1].type != ft_note)
507
+ {
508
+ fielddef fd;
509
+ memset(&fd, 0x00, sizeof(fielddef));
510
+ sprintf_s(buf, 100, "field%d", (int)fds.size());
511
+ fd.setNameA(buf);
512
+ fd.pos = pos;
513
+ fd.len = 57000 - pos + 1;
514
+ fd.type = NOTE_TYPE;
515
+ fds.push_back(fd);
516
+ }
517
+ }
495
518
  }
496
519
 
497
520
  void makeTableDef(tabledef* TableDef, fileSpec* fs, std::vector<fielddef>& fds)
498
521
  {
499
- TableDef->keyCount = (uchar_td)fs->indexCount;
500
- TableDef->flags.all = fs->fileFlag.all;
501
- TableDef->fixedRecordLen = fs->recLen;
502
-
503
- int k=0;
504
- int seg = 0;
505
- int keynum = 0;
506
- while(keynum<TableDef->keyCount)
507
- {
508
- keySpec* ks = &(fs->keySpecs[k++]);
509
- //key flag
510
- TableDef->keyDefs[keynum].segments[seg].flags.all = ks->keyFlag.all;
511
- TableDef->keyDefs[keynum].segmentCount = seg+1;
512
-
513
- //field info
514
- if (findFieldNum(fds, ks->keyPos)==-1)
515
- makeField(fds, ks, keynum, seg);
516
- seg++;
517
- if (ks->keyFlag.bit4==false)
518
- {
519
- keynum++;
520
- seg = 0;
521
- }
522
- }
523
- //Sort by position.
524
- std::sort(fds.begin(), fds.end(), field_sort);
525
-
526
- //Fields are added to non key spaces
527
- completeFields(fds, fs->recLen, (fs->fileFlag.all & 1));
528
- //Assignment of a field number
529
- k=0;
530
- seg = 0;
531
- keynum = 0;
532
- while(keynum<TableDef->keyCount)
533
- {
534
- keySpec* ks = &(fs->keySpecs[k++]);
535
- TableDef->keyDefs[keynum].segments[seg].fieldNum = findFieldNum(fds, ks->keyPos);
522
+ TableDef->keyCount = (uchar_td)fs->indexCount;
523
+ TableDef->flags.all = fs->fileFlag.all;
524
+ TableDef->fixedRecordLen = fs->recLen;
525
+
526
+ int k = 0;
527
+ int seg = 0;
528
+ int keynum = 0;
529
+ while (keynum < TableDef->keyCount)
530
+ {
531
+ keySpec* ks = &(fs->keySpecs[k++]);
532
+ // key flag
533
+ TableDef->keyDefs[keynum].segments[seg].flags.all = ks->keyFlag.all;
534
+ TableDef->keyDefs[keynum].segmentCount = seg + 1;
535
+
536
+ // field info
537
+ if (findFieldNum(fds, ks->keyPos) == -1)
538
+ makeField(fds, ks, keynum, seg);
536
539
  seg++;
537
- if (ks->keyFlag.bit4==false)
538
- {
539
- keynum++;
540
- seg = 0;
541
- }
542
- }
543
-
544
- //Copy of field info.
545
- TableDef->fieldDefs = &fds[0];
546
- TableDef->fieldCount = (ushort_td)fds.size();
547
-
540
+ if (ks->keyFlag.bit4 == false)
541
+ {
542
+ keynum++;
543
+ seg = 0;
544
+ }
545
+ }
546
+ // Sort by position.
547
+ std::sort(fds.begin(), fds.end(), field_sort);
548
+
549
+ // Fields are added to non key spaces
550
+ completeFields(fds, fs->recLen, (fs->fileFlag.all & 1));
551
+ // Assignment of a field number
552
+ k = 0;
553
+ seg = 0;
554
+ keynum = 0;
555
+ while (keynum < TableDef->keyCount)
556
+ {
557
+ keySpec* ks = &(fs->keySpecs[k++]);
558
+ TableDef->keyDefs[keynum].segments[seg].fieldNum =
559
+ findFieldNum(fds, ks->keyPos);
560
+ seg++;
561
+ if (ks->keyFlag.bit4 == false)
562
+ {
563
+ keynum++;
564
+ seg = 0;
565
+ }
566
+ }
567
+
568
+ // Copy of field info.
569
+ TableDef->fieldDefs = &fds[0];
570
+ TableDef->fieldCount = (ushort_td)fds.size();
548
571
  }
549
572
 
550
- std::string sqlCreateTable(const char* fileName, fileSpec* fs, uchar_td charsetIndexServer)
573
+ std::string sqlCreateTable(const char* fileName, fileSpec* fs,
574
+ uchar_td charsetIndexServer)
551
575
  {
552
- tabledef table;
553
- memset(&table, 0, sizeof(tabledef));
554
- table.setFileNameA(fileName);
555
- table.charsetIndex = mysql::charsetIndex(GetACP());
556
- table.schemaCodePage = CP_UTF8;
557
- std::vector<fielddef> fds;
558
- std::vector<keydef> kds;
559
- for (int i=0;i<fs->indexCount;i++)
560
- kds.push_back(keydef());
561
- if (fs->indexCount)
562
- table.keyDefs = &kds[0];
563
- makeTableDef(&table, fs, fds);
564
-
565
- return sqlCreateTable(fileName, &table, charsetIndexServer);
566
-
576
+ tabledef table;
577
+ memset(&table, 0, sizeof(tabledef));
578
+ table.setFileNameA(fileName);
579
+ table.charsetIndex = mysql::charsetIndex(GetACP());
580
+ table.schemaCodePage = CP_UTF8;
581
+ std::vector<fielddef> fds;
582
+ std::vector<keydef> kds;
583
+ for (int i = 0; i < fs->indexCount; i++)
584
+ kds.push_back(keydef());
585
+ if (fs->indexCount)
586
+ table.keyDefs = &kds[0];
587
+ makeTableDef(&table, fs, fds);
588
+
589
+ return sqlCreateTable(fileName, &table, charsetIndexServer);
567
590
  }
568
591
 
569
- }//namespace client
570
- }//namespace tdap
571
- }//namespace protocol
572
- }//namespace db
573
- }//namespace bzs
574
-
575
-
592
+ } // namespace client
593
+ } // namespace tdap
594
+ } // namespace protocol
595
+ } // namespace db
596
+ } // namespace bzs