transactd 1.0.1

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 (218) hide show
  1. checksums.yaml +7 -0
  2. data/BUILD_UNIX-JA +174 -0
  3. data/BUILD_WIN-JA +256 -0
  4. data/CMakeLists.txt +96 -0
  5. data/COPYING +339 -0
  6. data/README +406 -0
  7. data/README-JA +424 -0
  8. data/bin/common/tdclc_32_1_0.dll +0 -0
  9. data/bin/common/tdclc_64_1_0.dll +0 -0
  10. data/build/common/check_for_link_iconv.cmake +73 -0
  11. data/build/common/copyifgreater.cmd +30 -0
  12. data/build/common/copyifgreater.js +290 -0
  13. data/build/common/get_boost_libs.cmake +106 -0
  14. data/build/common/get_ruby_path.cmake +115 -0
  15. data/build/common/options.cmake +127 -0
  16. data/build/common/smart_install.cmake +263 -0
  17. data/build/common/system.cmake +122 -0
  18. data/build/common/transactd.rc.in +52 -0
  19. data/build/common/transactd_cl_common.cmake +101 -0
  20. data/build/common/transactd_cl_output.cmake +93 -0
  21. data/build/common/transactd_common.cmake +237 -0
  22. data/build/common/transactd_required.cmake +28 -0
  23. data/build/swig/ruby/generate.cmake.in +35 -0
  24. data/build/swig/ruby/generate.cmd.in +19 -0
  25. data/build/swig/ruby/ruby.swg +101 -0
  26. data/build/swig/tdcl.i +188 -0
  27. data/build/tdclc/BUILDNUMBER.txt +1 -0
  28. data/build/tdclc/CMakeLists.txt +170 -0
  29. data/build/tdclc/tdclc_32.cbproj +181 -0
  30. data/build/tdclc/tdclc_64.cbproj +205 -0
  31. data/build/tdclcpp/BUILDNUMBER.txt +1 -0
  32. data/build/tdclcpp/CMakeLists.txt +142 -0
  33. data/build/tdclcpp/tdclcpp_bcb_32.cbproj +239 -0
  34. data/build/tdclcpp/tdclcpp_bcb_64.cbproj +304 -0
  35. data/build/tdclrb/BUILDNUMBER.txt +1 -0
  36. data/build/tdclrb/CMakeLists.txt +258 -0
  37. data/build/tdclrb/GEM_VERSION +3 -0
  38. data/build/tdclrb/bldgem/extconf.rb +123 -0
  39. data/build/tdclrb/gem/INSTALLLOG.win32 +9 -0
  40. data/build/tdclrb/gem/Makefile.win32-VS +65 -0
  41. data/build/tdclrb/gem/Makefile.win32-prebuilt +48 -0
  42. data/build/tdclrb/gem/detect.rb +31 -0
  43. data/build/tdclrb/gem/helper.rb +113 -0
  44. data/build/tdclrb/gem/transactd.rb +22 -0
  45. data/build/tdclrb/gem_output.cmake +44 -0
  46. data/source/bzs/db/IBlobBuffer.h +51 -0
  47. data/source/bzs/db/blobBuffer.h +177 -0
  48. data/source/bzs/db/blobStructs.h +85 -0
  49. data/source/bzs/db/engine/mysql/IReadRecords.h +52 -0
  50. data/source/bzs/db/engine/mysql/bookmark.h +195 -0
  51. data/source/bzs/db/engine/mysql/database.cpp +1882 -0
  52. data/source/bzs/db/engine/mysql/database.h +465 -0
  53. data/source/bzs/db/engine/mysql/dbManager.cpp +303 -0
  54. data/source/bzs/db/engine/mysql/dbManager.h +143 -0
  55. data/source/bzs/db/engine/mysql/errorMessage.cpp +75 -0
  56. data/source/bzs/db/engine/mysql/errorMessage.h +43 -0
  57. data/source/bzs/db/engine/mysql/fieldAccess.h +158 -0
  58. data/source/bzs/db/engine/mysql/mydebuglog.cpp +349 -0
  59. data/source/bzs/db/engine/mysql/mydebuglog.h +89 -0
  60. data/source/bzs/db/engine/mysql/mysqlInternal.h +171 -0
  61. data/source/bzs/db/engine/mysql/mysqlThd.cpp +169 -0
  62. data/source/bzs/db/engine/mysql/mysqlThd.h +35 -0
  63. data/source/bzs/db/engine/mysql/percentageKey.h +260 -0
  64. data/source/bzs/db/protocol/ICommandExecuter.h +49 -0
  65. data/source/bzs/db/protocol/hs/hsCommandExecuter.cpp +689 -0
  66. data/source/bzs/db/protocol/hs/hsCommandExecuter.h +228 -0
  67. data/source/bzs/db/protocol/tdap/btrDate.cpp +437 -0
  68. data/source/bzs/db/protocol/tdap/btrDate.h +227 -0
  69. data/source/bzs/db/protocol/tdap/client/bulkInsert.h +127 -0
  70. data/source/bzs/db/protocol/tdap/client/client.cpp +106 -0
  71. data/source/bzs/db/protocol/tdap/client/client.h +292 -0
  72. data/source/bzs/db/protocol/tdap/client/connMgr.cpp +144 -0
  73. data/source/bzs/db/protocol/tdap/client/connMgr.h +82 -0
  74. data/source/bzs/db/protocol/tdap/client/database.cpp +863 -0
  75. data/source/bzs/db/protocol/tdap/client/database.h +118 -0
  76. data/source/bzs/db/protocol/tdap/client/databaseFactory.cpp +100 -0
  77. data/source/bzs/db/protocol/tdap/client/dbDef.cpp +1640 -0
  78. data/source/bzs/db/protocol/tdap/client/dbDef.h +135 -0
  79. data/source/bzs/db/protocol/tdap/client/dllmain.cpp +434 -0
  80. data/source/bzs/db/protocol/tdap/client/errorMessage.cpp +92 -0
  81. data/source/bzs/db/protocol/tdap/client/errorMessage_ja.cpp +98 -0
  82. data/source/bzs/db/protocol/tdap/client/fieldDDF.cpp +174 -0
  83. data/source/bzs/db/protocol/tdap/client/fieldDDF.h +91 -0
  84. data/source/bzs/db/protocol/tdap/client/fileDDF.cpp +140 -0
  85. data/source/bzs/db/protocol/tdap/client/fileDDF.h +86 -0
  86. data/source/bzs/db/protocol/tdap/client/filter.cpp +527 -0
  87. data/source/bzs/db/protocol/tdap/client/filter.h +154 -0
  88. data/source/bzs/db/protocol/tdap/client/indexDDF.cpp +137 -0
  89. data/source/bzs/db/protocol/tdap/client/indexDDF.h +84 -0
  90. data/source/bzs/db/protocol/tdap/client/nsDatabase.cpp +724 -0
  91. data/source/bzs/db/protocol/tdap/client/nsDatabase.h +123 -0
  92. data/source/bzs/db/protocol/tdap/client/nsTable.cpp +899 -0
  93. data/source/bzs/db/protocol/tdap/client/nsTable.h +199 -0
  94. data/source/bzs/db/protocol/tdap/client/request.h +198 -0
  95. data/source/bzs/db/protocol/tdap/client/sharedData.cpp +58 -0
  96. data/source/bzs/db/protocol/tdap/client/sharedData.h +56 -0
  97. data/source/bzs/db/protocol/tdap/client/sqlBuilder.cpp +574 -0
  98. data/source/bzs/db/protocol/tdap/client/sqlBuilder.h +53 -0
  99. data/source/bzs/db/protocol/tdap/client/stringConverter.h +627 -0
  100. data/source/bzs/db/protocol/tdap/client/table.cpp +2613 -0
  101. data/source/bzs/db/protocol/tdap/client/table.h +221 -0
  102. data/source/bzs/db/protocol/tdap/client/trdboostapi.h +1096 -0
  103. data/source/bzs/db/protocol/tdap/client/trdboostapiInternal.h +179 -0
  104. data/source/bzs/db/protocol/tdap/client/trdclcppautolink.h +40 -0
  105. data/source/bzs/db/protocol/tdap/client/trnsctcl.def +11 -0
  106. data/source/bzs/db/protocol/tdap/myDateTime.cpp +500 -0
  107. data/source/bzs/db/protocol/tdap/mysql/characterset.cpp +184 -0
  108. data/source/bzs/db/protocol/tdap/mysql/characterset.h +60 -0
  109. data/source/bzs/db/protocol/tdap/mysql/databaseSchema.cpp +284 -0
  110. data/source/bzs/db/protocol/tdap/mysql/databaseSchema.h +53 -0
  111. data/source/bzs/db/protocol/tdap/mysql/debuglog.cpp +383 -0
  112. data/source/bzs/db/protocol/tdap/mysql/debuglog.h +106 -0
  113. data/source/bzs/db/protocol/tdap/mysql/recordsetReader.h +680 -0
  114. data/source/bzs/db/protocol/tdap/mysql/request.h +202 -0
  115. data/source/bzs/db/protocol/tdap/mysql/tdapCommandExecuter.cpp +1020 -0
  116. data/source/bzs/db/protocol/tdap/mysql/tdapCommandExecuter.h +141 -0
  117. data/source/bzs/db/protocol/tdap/tdapRequest.h +190 -0
  118. data/source/bzs/db/protocol/tdap/tdapSchema.cpp +295 -0
  119. data/source/bzs/db/protocol/tdap/tdapSchema.h +558 -0
  120. data/source/bzs/db/protocol/tdap/tdapcapi.h +423 -0
  121. data/source/bzs/db/transactd/appBuilderImple.h +55 -0
  122. data/source/bzs/db/transactd/appModule.cpp +183 -0
  123. data/source/bzs/db/transactd/appModule.h +80 -0
  124. data/source/bzs/db/transactd/connManager.cpp +201 -0
  125. data/source/bzs/db/transactd/connManager.h +60 -0
  126. data/source/bzs/db/transactd/connectionRecord.h +69 -0
  127. data/source/bzs/db/transactd/transactd.cpp +325 -0
  128. data/source/bzs/env/compiler.h +135 -0
  129. data/source/bzs/env/crosscompile.cpp +130 -0
  130. data/source/bzs/env/crosscompile.h +150 -0
  131. data/source/bzs/env/fileopen.h +36 -0
  132. data/source/bzs/env/mbcswchrLinux.cpp +40 -0
  133. data/source/bzs/env/mbcswchrLinux.h +88 -0
  134. data/source/bzs/env/tstring.h +183 -0
  135. data/source/bzs/example/changeSchema.cpp +117 -0
  136. data/source/bzs/example/changeSchema_c.cpp +78 -0
  137. data/source/bzs/example/connection_pool_c.cpp +171 -0
  138. data/source/bzs/example/createDatabase.cpp +305 -0
  139. data/source/bzs/example/createDatabase_c.cpp +202 -0
  140. data/source/bzs/example/deleteRecords.cpp +87 -0
  141. data/source/bzs/example/deleteRecords_c.cpp +57 -0
  142. data/source/bzs/example/dropDatabase.cpp +59 -0
  143. data/source/bzs/example/dropDatabase_c.cpp +34 -0
  144. data/source/bzs/example/insertRecords.cpp +212 -0
  145. data/source/bzs/example/insertRecords_c.cpp +153 -0
  146. data/source/bzs/example/readRecords.cpp +141 -0
  147. data/source/bzs/example/readRecords_c.cpp +107 -0
  148. data/source/bzs/example/updateRecords.cpp +99 -0
  149. data/source/bzs/example/updateRecords_c.cpp +71 -0
  150. data/source/bzs/example/update_with_transaction.cpp +104 -0
  151. data/source/bzs/example/update_with_transaction_c.cpp +80 -0
  152. data/source/bzs/netsvc/client/tcpClient.cpp +226 -0
  153. data/source/bzs/netsvc/client/tcpClient.h +489 -0
  154. data/source/bzs/netsvc/server/IAppModule.h +94 -0
  155. data/source/bzs/netsvc/server/iserver.h +65 -0
  156. data/source/bzs/netsvc/server/serverCpt.cpp +522 -0
  157. data/source/bzs/netsvc/server/serverCpt.h +88 -0
  158. data/source/bzs/netsvc/server/serverPipe.cpp +705 -0
  159. data/source/bzs/netsvc/server/serverPipe.h +96 -0
  160. data/source/bzs/netsvc/server/serverTpool.cpp +416 -0
  161. data/source/bzs/netsvc/server/serverTpool.h +84 -0
  162. data/source/bzs/rtl/benchmark.cpp +96 -0
  163. data/source/bzs/rtl/benchmark.h +65 -0
  164. data/source/bzs/rtl/datetime.cpp +375 -0
  165. data/source/bzs/rtl/datetime.h +53 -0
  166. data/source/bzs/rtl/debuglog.cpp +106 -0
  167. data/source/bzs/rtl/debuglog.h +97 -0
  168. data/source/bzs/rtl/exception.h +116 -0
  169. data/source/bzs/rtl/stl_uty.cpp +35 -0
  170. data/source/bzs/rtl/stl_uty.h +29 -0
  171. data/source/bzs/rtl/stringBuffers.cpp +101 -0
  172. data/source/bzs/rtl/stringBuffers.h +58 -0
  173. data/source/bzs/rtl/strtrim.cpp +135 -0
  174. data/source/bzs/rtl/strtrim.h +46 -0
  175. data/source/bzs/test/tdclatl/bench_tdclatl.js +445 -0
  176. data/source/bzs/test/tdclrb/bench_tdclcpp.rb +375 -0
  177. data/source/bzs/test/tdclrb/prepare.rb +226 -0
  178. data/source/bzs/test/tdclrb/transactd_datetime_spec.rb +172 -0
  179. data/source/bzs/test/tdclrb/transactd_kanjischema_spec.rb +208 -0
  180. data/source/bzs/test/tdclrb/transactd_spec.rb +1536 -0
  181. data/source/bzs/test/transactdBench/transactdBench.cpp +430 -0
  182. data/source/bzs/test/transactdBench/transactdBench2.cpp +342 -0
  183. data/source/bzs/test/trdclengn/test_trdclengn.cpp +2030 -0
  184. data/source/global/tdclatl/Database.cpp +503 -0
  185. data/source/global/tdclatl/Database.h +139 -0
  186. data/source/global/tdclatl/DbDef.cpp +242 -0
  187. data/source/global/tdclatl/DbDef.h +79 -0
  188. data/source/global/tdclatl/Field.cpp +92 -0
  189. data/source/global/tdclatl/Field.h +59 -0
  190. data/source/global/tdclatl/FieldDef.cpp +238 -0
  191. data/source/global/tdclatl/FieldDef.h +87 -0
  192. data/source/global/tdclatl/Flags.cpp +111 -0
  193. data/source/global/tdclatl/Flags.h +55 -0
  194. data/source/global/tdclatl/KeyDef.cpp +51 -0
  195. data/source/global/tdclatl/KeyDef.h +55 -0
  196. data/source/global/tdclatl/KeySegment.cpp +55 -0
  197. data/source/global/tdclatl/Table.cpp +600 -0
  198. data/source/global/tdclatl/Table.h +144 -0
  199. data/source/global/tdclatl/TableDef.cpp +291 -0
  200. data/source/global/tdclatl/TableDef.h +86 -0
  201. data/source/global/tdclatl/TdVersion.cpp +74 -0
  202. data/source/global/tdclatl/TdVersion.h +54 -0
  203. data/source/global/tdclatl/_IDatabaseEvents_CP.h +113 -0
  204. data/source/global/tdclatl/dllmain.cpp +30 -0
  205. data/source/global/tdclatl/dllmain.h +27 -0
  206. data/source/global/tdclatl/keySegment.h +57 -0
  207. data/source/global/tdclatl/resource.h +0 -0
  208. data/source/global/tdclatl/stdafx.cpp +2 -0
  209. data/source/global/tdclatl/stdafx.h +25 -0
  210. data/source/global/tdclatl/targetver.h +4 -0
  211. data/source/global/tdclatl/tdclatl.cpp +68 -0
  212. data/source/global/tdclatl/tdclatl.def +10 -0
  213. data/source/global/tdclatl/tdclatl.idl +1035 -0
  214. data/source/linux/charsetConvert.h +112 -0
  215. data/source/linux/linuxTypes.h +33 -0
  216. data/source/linux/tchar.h +428 -0
  217. data/transactd.gemspec +97 -0
  218. metadata +267 -0
@@ -0,0 +1,303 @@
1
+ /*=================================================================
2
+ Copyright (C) 2012 2013 BizStation Corp All rights reserved.
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.
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.
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
+ =================================================================*/
19
+
20
+ #include "dbManager.h"
21
+ #include <bzs/netsvc/server/IAppModule.h> //for result value macro.
22
+ #include <bzs/rtl/exception.h>
23
+ #include <time.h>
24
+
25
+
26
+ namespace bzs
27
+ {
28
+ namespace db
29
+ {
30
+ namespace engine
31
+ {
32
+ namespace mysql
33
+ {
34
+
35
+ std::string smartDbsReopen::removeName="";
36
+
37
+
38
+
39
+
40
+
41
+ dbManager::dbManager():m_autoHandle(0)
42
+ {
43
+ }
44
+
45
+
46
+ dbManager::~dbManager()
47
+ {
48
+
49
+ }
50
+
51
+ bool dbManager::isShutDown() const
52
+ {
53
+ boost::mutex::scoped_lock lck(m_mutex);
54
+ #if defined(MARIADB_BASE_VERSION)
55
+ killed_state st = NOT_KILLED;
56
+ #else
57
+ THD::killed_state st = THD::NOT_KILLED;
58
+ #endif
59
+ for (size_t i=0;i<m_dbs.size();i++)
60
+ if ((m_dbs[i]!=NULL) && (m_dbs[i]->thd()->killed != st))
61
+ return true;
62
+ return false;
63
+ }
64
+
65
+ void dbManager::checkNewHandle(int newHandle)const
66
+ {
67
+ for (size_t i=0;i<m_handles.size();i++)
68
+ if(m_handles[i].id == newHandle)
69
+ THROW_BZS_ERROR_WITH_CODEMSG(1, "Allready exits handle.");
70
+ }
71
+
72
+ void dbManager::releaseDatabse(short cid)
73
+ {
74
+ boost::mutex::scoped_lock lck(m_mutex);
75
+ int index = -1;
76
+ for (size_t i=0;i<m_dbs.size();i++)
77
+ {
78
+ if ((m_dbs[i]!=NULL) && (cid==m_dbs[i]->clientID()))
79
+ {
80
+ index = (int)i;
81
+ break;
82
+ }
83
+ }
84
+ if (index==-1)
85
+ return ;
86
+ //close tables release thd
87
+ m_dbs[index].reset();
88
+
89
+ //erase handles
90
+ for (int i=(int)m_handles.size()-1;i>=0;i--)
91
+ if(m_handles[i].db == index)
92
+ m_handles.erase(m_handles.begin()+i);
93
+
94
+ }
95
+
96
+ database* dbManager::useDataBase(int id) const
97
+ {
98
+ if (id >= (int)m_dbs.size())
99
+ THROW_BZS_ERROR_WITH_CODEMSG(1, "Invalid database id.");
100
+ if (m_dbs[id]==NULL)
101
+ THROW_BZS_ERROR_WITH_CODEMSG(1, "Invalid database id.");
102
+ m_dbs[id]->use();
103
+ return m_dbs[id].get();
104
+ }
105
+
106
+ database* dbManager::createDatabase(const char* dbname, short cid)const
107
+ {
108
+ return new database(dbname, cid);
109
+ }
110
+
111
+ handle* dbManager::getHandle(int handle)const
112
+ {
113
+ for (size_t i=0;i<m_handles.size();i++)
114
+ {
115
+ if(m_handles[i].id == handle)
116
+ return &m_handles[i];
117
+ }
118
+ THROW_BZS_ERROR_WITH_CODEMSG(1, "Invalid handle.");
119
+ }
120
+
121
+ int dbManager::getDatabaseID(short cid) const
122
+ {
123
+ for (size_t i=0;i<m_dbs.size();i++)
124
+ {
125
+ if (m_dbs[i]!=NULL && (m_dbs[i]->clientID()==cid))
126
+ return (int)i;
127
+ }
128
+ return -1;
129
+ }
130
+
131
+ database* dbManager::getDatabaseCid(short cid) const
132
+ {
133
+ int id = getDatabaseID(cid);
134
+ if (id == -1)
135
+ THROW_BZS_ERROR_WITH_CODEMSG(1, "Can not create database object.");
136
+
137
+ return useDataBase(id);
138
+ }
139
+
140
+ database* dbManager::getDatabase(const char* dbname, short cid) const
141
+ {
142
+ int id = getDatabaseID(cid);
143
+ if (id == -1)
144
+ {
145
+ boost::shared_ptr<database> db(createDatabase(dbname, cid));
146
+ if (db ==NULL)
147
+ THROW_BZS_ERROR_WITH_CODEMSG(1, "Can not create database object.");
148
+ m_dbs.push_back(db);
149
+ id = (int)m_dbs.size()-1;
150
+ }
151
+ return useDataBase(id);
152
+ }
153
+
154
+ table* dbManager::getTable(int hdl, enum_sql_command cmd)const
155
+ {
156
+ handle* h = getHandle(hdl);
157
+ if (h && (h->db < (int)m_dbs.size()))
158
+ return useDataBase(h->db)->useTable(h->tb, cmd);
159
+
160
+
161
+ THROW_BZS_ERROR_WITH_CODEMSG(1, "Invalid handle.");
162
+ }
163
+
164
+ int dbManager::addHandle(int dbid, int tableid,int assignid)
165
+ {
166
+ ++m_autoHandle;
167
+ if (assignid == -1)
168
+ assignid = m_autoHandle;
169
+ m_handles.push_back(handle(assignid, (short)dbid, (short)tableid));
170
+ return assignid;
171
+ }
172
+
173
+ int dbManager::ddl_execSql(THD* thd, const std::string& sql_stmt)
174
+ {
175
+ smartDbsReopen reopen(m_dbs);
176
+
177
+ thd->clear_error();
178
+ int result = dispatch_command(COM_QUERY, thd,(char*)sql_stmt.c_str() , (uint)sql_stmt.size());
179
+ if (!thd->cp_isOk())
180
+ result = 1;
181
+ if (thd->is_error())
182
+ result = errorCode(thd->cp_get_sql_error());
183
+ return result;
184
+ }
185
+
186
+ int dbManager::ddl_createDataBase(THD* thd, const std::string& dbname )
187
+ {
188
+ std::string cmd = "create database `" + dbname + "`";
189
+ return ddl_execSql(thd, cmd);
190
+
191
+ }
192
+
193
+ int dbManager::ddl_dropDataBase(THD* thd, const std::string& dbname, const std::string& dbSqlname)
194
+ {
195
+ std::string cmd = "drop database `" + dbSqlname + "`";
196
+ smartDbsReopen::removeName = dbname;
197
+ int ret = ddl_execSql(thd, cmd);
198
+ smartDbsReopen::removeName = "";
199
+ for (int i=(int)m_dbs.size()-1;i>=0;i--)
200
+ {
201
+ if (m_dbs[i] && (m_dbs[i]->name() == dbname))
202
+ m_dbs.erase(m_dbs.begin()+i);
203
+ }
204
+ return ret;
205
+ }
206
+
207
+ int dbManager::ddl_useDataBase(THD* thd, const std::string& dbSqlname)
208
+ {
209
+ std::string cmd = "use `" + dbSqlname + "`";
210
+ return ddl_execSql(thd, cmd);
211
+ }
212
+
213
+ int dbManager::closeCacheTable(database* db, const std::string& tbname)
214
+ {
215
+ if (database::tableRef.count(db->name(), tbname))
216
+ return DBM_ERROR_TABLE_USED;
217
+
218
+ TABLE_LIST tables;
219
+ tables.init_one_table(db->name().c_str(), db->name().size(), tbname.c_str(), tbname.size(), tbname.c_str(), TL_READ);
220
+ if(close_cached_tables(db->thd(), &tables, true, 50000000L))
221
+ return HA_ERR_LOCK_WAIT_TIMEOUT;
222
+ return 0;
223
+
224
+ }
225
+
226
+ int dbManager::ddl_dropTable(database* db, const std::string& tbname, const std::string& dbSqlname
227
+ , const std::string& tbSqlname)
228
+ {
229
+ db->closeTable(tbname.c_str(), true);
230
+ int ret = closeCacheTable(db, tbname);
231
+ if (ret) return ret;
232
+ db->thd()->variables.lock_wait_timeout = 0;
233
+ std::string cmd = "drop table `" + dbSqlname + "`.`" + tbSqlname + "`";
234
+ return ddl_execSql(db->thd(), cmd);
235
+
236
+ }
237
+
238
+ int dbManager::ddl_renameTable(database* db, const std::string& oldName, const std::string& dbSqlName
239
+ , const std::string& oldSqlName, const std::string& newSqlName)
240
+ {
241
+ db->closeTable(oldName.c_str(), true);
242
+ int ret = closeCacheTable(db, oldName);
243
+ if (ret) return ret;
244
+
245
+ std::string cmd = "rename table `" + dbSqlName + "`.`" + oldSqlName + "` to `" + dbSqlName + "`.`" + newSqlName + "`";
246
+ return ddl_execSql(db->thd(), cmd);
247
+ }
248
+
249
+ int dbManager::ddl_replaceTable(database* db , const std::string& name1, const std::string& name2
250
+ , const std::string& dbSqlName, const std::string& nameSql1, const std::string& nameSql2)
251
+ { // rename name1 to name2.
252
+ db->closeTable(name1.c_str(), true);
253
+ db->closeTable(name2.c_str(), true);
254
+ char nameSql3[255];
255
+
256
+ time_t timer_ = time(NULL);
257
+ struct tm* t = localtime(&timer_);
258
+ sprintf(nameSql3, "%s_trsctd_%4d%02d%02d_%02d%02d%02d", nameSql1.c_str()
259
+ , t->tm_year + 1900 , t->tm_mon + 1 , t->tm_mday
260
+ , t->tm_hour, t->tm_min, t->tm_sec);
261
+
262
+ int ret = closeCacheTable(db, name2);
263
+ if (ret) return ret;
264
+
265
+ std::string cmd = "rename table `" + dbSqlName + "`.`" + nameSql2 + "` to `" + dbSqlName + "`.`" + nameSql3
266
+ + "`,`" + dbSqlName + "`.`" + nameSql1 + "` to `" + dbSqlName + "`.`" + nameSql2 + "`";
267
+ ret = ddl_execSql(db->thd(), cmd);
268
+ if (ret == 0)
269
+ {
270
+ std::string cmd = "drop table `" + dbSqlName + "`.`" + nameSql3 + "`";
271
+ return ddl_execSql(db->thd(), cmd);
272
+ }
273
+ return ret;
274
+
275
+ }
276
+
277
+ std::string dbManager::makeSQLChangeTableComment(const std::string& dbSqlName, const std::string& tableSqlName, const char* comment)
278
+ {
279
+ std::string s = "alter table `" + dbSqlName + "`.`" + tableSqlName + "` comment \"" + comment + "\"";
280
+ return s;
281
+ }
282
+
283
+ /** Key name of multi byte charctord is not supported. Use only ascii.
284
+ */
285
+ std::string dbManager::makeSQLDropIndex(const std::string& dbSqlName, const std::string& tbSqlName, const char* name)
286
+ {
287
+ std::string s = "drop index `" + std::string(name) + "` on `" + dbSqlName + "`.`" +tbSqlName + "`";
288
+ return s;
289
+ }
290
+
291
+ void dbManager::clenupNoException()
292
+ {
293
+ try
294
+ {
295
+ if (m_tb)m_tb->unUse();
296
+ }
297
+ catch(...){}
298
+ }
299
+
300
+ }//namespace mysql
301
+ }//namespace engine
302
+ }//namespace db
303
+ }//namespace bzs
@@ -0,0 +1,143 @@
1
+ /*=================================================================
2
+ Copyright (C) 2012 2013 BizStation Corp All rights reserved.
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.
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.
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
+ =================================================================*/
19
+ #ifndef DBMANAGER_H
20
+ #define DBMANAGER_H
21
+
22
+ #include <boost/thread/mutex.hpp>
23
+ #include <bzs/db/engine/mysql/database.h>
24
+
25
+ /* dbManager original error code */
26
+ #define DBM_ERROR_TABLE_USED HA_ERR_LAST + 1
27
+
28
+ namespace bzs
29
+ {
30
+ namespace db
31
+ {
32
+ namespace engine
33
+ {
34
+ namespace mysql
35
+ {
36
+
37
+ struct handle
38
+ {
39
+ handle(int i, short d, short t):id(i),db(d),tb(t),cid(0){};
40
+ int id;
41
+ short db;
42
+ short tb;
43
+ short cid;
44
+ };
45
+
46
+ class smartDbsReopen
47
+ {
48
+ std::vector<boost::shared_ptr<database> >& m_dbs;
49
+
50
+ public:
51
+ static std::string removeName;
52
+
53
+ smartDbsReopen(std::vector<boost::shared_ptr<database> >& dbs)
54
+ :m_dbs(dbs)
55
+ {
56
+ for (size_t i=0;i<m_dbs.size();i++)
57
+ {
58
+ if (m_dbs[i])
59
+ {
60
+ m_dbs[i]->use();
61
+ m_dbs[i]->unUseTables(false);
62
+ m_dbs[i]->closeForReopen();
63
+ }
64
+ }
65
+ }
66
+
67
+ ~smartDbsReopen()
68
+ {
69
+ for (size_t i=0;i<m_dbs.size();i++)
70
+ {
71
+ if (m_dbs[i])
72
+ {
73
+ if (removeName != m_dbs[i]->name())
74
+ {
75
+ m_dbs[i]->use();
76
+ m_dbs[i]->reopen();
77
+ }
78
+ }
79
+ }
80
+ }
81
+
82
+ };
83
+
84
+ class dbManager;
85
+
86
+ class dbManager
87
+ {
88
+ mutable boost::mutex m_mutex;
89
+ int m_autoHandle;
90
+ protected:
91
+ mutable databases m_dbs;
92
+ mutable std::vector<handle> m_handles;
93
+ table* m_tb;
94
+
95
+ database* createDatabase(const char* dbname, short cid)const;
96
+ void releaseDatabse(short cid);
97
+ handle* getHandle(int handle)const;
98
+ database* getDatabase(const char* dbname, short cid) const ;
99
+ database* getDatabaseCid(short cid) const ;
100
+ int getDatabaseID(short cid) const ;
101
+ table* getTable(int handle, enum_sql_command cmd=SQLCOM_SELECT)const;
102
+ void checkNewHandle(int newHandle)const;
103
+ int addHandle(int dbid, int tableid, int assignid=-1);
104
+ database* useDataBase(int id) const;
105
+ int closeCacheTable(database* db, const std::string& tbname);
106
+ int ddl_execSql(THD* thd, const std::string& sql_stmt);
107
+ int ddl_createDataBase(THD* thd, const std::string& dbname );
108
+ int ddl_dropDataBase(THD* thd, const std::string& dbname, const std::string& dbSqlname );
109
+ int ddl_useDataBase(THD* thd, const std::string& dbSqlname);
110
+ int ddl_dropTable(database* db, const std::string& tbname, const std::string& sqldbname
111
+ , const std::string& sqltbname);
112
+ int ddl_renameTable(database* db, const std::string& oldName, const std::string& dbSqlName
113
+ , const std::string& oldSqlName, const std::string& newSqlName);
114
+ int ddl_replaceTable(database* db , const std::string& name1, const std::string& name2
115
+ , const std::string& dbSqlName, const std::string& nameSql1, const std::string& nameSql2);
116
+ std::string makeSQLChangeTableComment(const std::string& dbSqlName
117
+ , const std::string& tableSqlName, const char* comment);
118
+ std::string makeSQLDropIndex(const std::string& dbSqlName, const std::string& tbSqlName
119
+ , const char* name);
120
+ void clenupNoException();
121
+ virtual int errorCode(int ha_error)=0;
122
+ public:
123
+ dbManager();
124
+ virtual ~dbManager();
125
+ bool isShutDown() const;
126
+ const databases& dbs()const{return m_dbs;};
127
+
128
+ };
129
+
130
+ class igetDatabases
131
+ {
132
+ public:
133
+ virtual ~igetDatabases(){};
134
+ virtual const engine::mysql::databases& dbs() const = 0;
135
+ };
136
+
137
+ }//namespace mysql
138
+ }//namespace engine
139
+ }//namespace db
140
+ }//namespace bzs
141
+
142
+
143
+ #endif //DBMANAGER_H
@@ -0,0 +1,75 @@
1
+ /*=================================================================
2
+ Copyright (C) 2012 2013 BizStation Corp All rights reserved.
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.
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.
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
+ =================================================================*/
19
+
20
+ #include "errorMessage.h"
21
+ #include "mysqlInternal.h"
22
+ #include <bzs/db/protocol/tdap/tdapcapi.h>
23
+
24
+ namespace bzs
25
+ {
26
+ namespace db
27
+ {
28
+ namespace engine
29
+ {
30
+ namespace mysql
31
+ {
32
+
33
+ const char* errorMessage(int errorCode)
34
+ {
35
+ switch(errorCode)
36
+ {
37
+ case STATUS_PROGRAM_ERROR:
38
+ return "Program error";
39
+ case STATUS_CANNOT_LOCK_TABLE:
40
+ return "Can not open the table Allrady locked";
41
+ case STATUS_TABLE_NOTOPEN:
42
+ return "Can not open the table";
43
+ case STATUS_INVALID_KEYNAME:
44
+ return "Invalid key name";
45
+ case HA_ERR_KEY_NOT_FOUND:
46
+ return "Did not find key on read or update";
47
+ case STATUS_INVALID_LOCKTYPE:
48
+ return "locktype is diffarent to got locks";
49
+ case STATUS_INVALID_DATASIZE:
50
+ return "Invalid data buffer size";
51
+ case STATUS_TABLE_EXISTS_ERROR:
52
+ return "Can not check if exists table";
53
+ }
54
+ return "";
55
+ }
56
+
57
+ void printErrorMessage(const int* errorCode, const std::string* message)
58
+ {
59
+ int code = errorCode? *errorCode : 0;
60
+ std::string msg = errorMessage(code);
61
+ if (message)
62
+ msg += " :" + *message;
63
+
64
+ if ((code != STATUS_TABLE_NOTOPEN) && (code != STATUS_INVALID_BOOKMARK))
65
+ {
66
+ sql_print_error("%s", msg.c_str());
67
+ }
68
+ }
69
+
70
+
71
+ }//namespace mysql
72
+ }//namespace engine
73
+ }//namespace db
74
+ }//namespace bzs
75
+
@@ -0,0 +1,43 @@
1
+ #ifndef ERRORMESSAGE_H
2
+ #define ERRORMESSAGE_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
+ #include <string>
23
+ #include <bzs/rtl/exception.h>
24
+
25
+ namespace bzs
26
+ {
27
+ namespace db
28
+ {
29
+ namespace engine
30
+ {
31
+ namespace mysql
32
+ {
33
+
34
+ const char* errorMessage(int errorCode);
35
+ void printErrorMessage(const int* errorCode, const std::string* msg);
36
+
37
+ }//namespace mysql
38
+ }//namespace engine
39
+ }//namespace db
40
+ }//namespace bzs
41
+
42
+ #endif //ERRORMESSAGE_H
43
+