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,171 @@
1
+ #include <bzs/db/protocol/tdap/client/trdboostapi.h>
2
+ #include <iostream>
3
+ #include <vector>
4
+ #include <boost/thread/thread.hpp>
5
+ #include <boost/thread/condition.hpp>
6
+
7
+
8
+
9
+ using namespace bzs::db::protocol::tdap::client;
10
+ using namespace bzs::db::protocol::tdap;
11
+ using namespace boost;
12
+
13
+ /**
14
+ @brief make connection pool example
15
+
16
+
17
+ This program makes connection pool of four databases.
18
+ And execute ten worker jobs with each thread.
19
+ Each worker shows the connection object pointer.
20
+
21
+ */
22
+
23
+
24
+ struct clientID
25
+ {
26
+
27
+ #ifdef __x86_64__
28
+ void* con;
29
+ char_td reserved[4];
30
+ #else
31
+ void* con;
32
+ char_td reserved[8];
33
+ #endif
34
+ char_td aid[2];
35
+ ushort_td id;
36
+ };
37
+
38
+
39
+ /** connection pool class
40
+ Hold database instance and delivery.
41
+ */
42
+ class connectionPool
43
+ {
44
+ std::vector<database_ptr> m_dbs;
45
+ mutable mutex m_mutex;
46
+ mutable mutex m_mutex2;
47
+
48
+ mutable condition m_busy;
49
+
50
+ public:
51
+ connectionPool(){};
52
+
53
+ /** delivery database instance*/
54
+ database_ptr get()const
55
+ {
56
+ mutex::scoped_lock lck(m_mutex);
57
+ while (1)
58
+ {
59
+ for (size_t i = 0;i<m_dbs.size();i++)
60
+ {
61
+ if (m_dbs[i].use_count() == 1)
62
+ return m_dbs[i];
63
+
64
+ }
65
+ mutex::scoped_lock lck(m_mutex2);
66
+ m_busy.wait(lck);
67
+
68
+ }
69
+ }
70
+
71
+ /** create database and login the server with each connection*/
72
+ void create(size_t size, const connectParams& param)
73
+ {
74
+ for (size_t i =0;i<size;++i)
75
+ {
76
+ database_ptr db = createDatadaseObject();
77
+ connect(db, param, true/* new connection*/);
78
+ openDatabase(db, param);
79
+ m_dbs.push_back(db);
80
+ }
81
+ }
82
+
83
+ void releaseOne()
84
+ {
85
+ m_busy.notify_one();
86
+ }
87
+
88
+ };
89
+
90
+ connectionPool cpool;
91
+
92
+ void releaseConnection(connectionPool* pool)
93
+ {
94
+ pool->releaseOne();
95
+ }
96
+
97
+ class worker
98
+ {
99
+ int m_id;
100
+ int m_worktime;
101
+ static mutex m_mutex;
102
+ public:
103
+ worker(int id, int worktime):m_id(id),m_worktime(worktime){};
104
+ void execute()
105
+ {
106
+ try
107
+ {
108
+ shared_ptr<connectionPool> pool(&cpool, releaseConnection);
109
+ {
110
+ database_ptr db = pool->get();
111
+
112
+ clientID* cid = (clientID*)db->clientID();
113
+
114
+ {
115
+ mutex::scoped_lock lck(m_mutex);
116
+ std::cout << "worker strat id = " << m_id
117
+ << " connection = 0x" << std::hex << cid->con << std::endl;
118
+ }
119
+
120
+ Sleep(m_worktime);
121
+ if (m_id == 4) throw "error"; //throw error example
122
+
123
+ {
124
+ mutex::scoped_lock lck(m_mutex);
125
+ std::cout << "worker finish id = " << m_id
126
+ << " connection = 0x" << std::hex << cid->con << std::endl;
127
+ }
128
+ } // release database
129
+
130
+ delete this;
131
+ } //call releaseConnection
132
+
133
+ catch(...)
134
+ {
135
+ mutex::scoped_lock lck(m_mutex);
136
+ std::cout << "worker error id = " << m_id << std::endl;
137
+ delete this;
138
+ }
139
+ }
140
+
141
+ };
142
+ mutex worker::m_mutex;
143
+
144
+ static const worktime[10] = {5, 1, 3, 5, 4, 1, 2, 5, 4, 1};
145
+
146
+ #pragma argsused
147
+ int _tmain(int argc, _TCHAR* argv[])
148
+ {
149
+ try
150
+ {
151
+ connectParams param(_T("tdap"), _T("localhost"), _T("test"), _T("test"));
152
+ //create four databases
153
+ cpool.create(4, param);
154
+
155
+ //Execute 10 workers with each thread.
156
+ thread_group threads;
157
+ for (int i=0;i<10;++i)
158
+ {
159
+ worker* w = new worker(i+1, worktime[i]*100);
160
+ threads.create_thread( bind(&worker::execute, w));
161
+ }
162
+ threads.join_all();
163
+ return 0;
164
+ }
165
+
166
+ catch(bzs::rtl::exception& e)
167
+ {
168
+ std::tcout << *bzs::rtl::getMsg(e) << std::endl;
169
+ }
170
+ return 1;
171
+ }
@@ -0,0 +1,305 @@
1
+ #include <stdio.h>
2
+ #include <bzs/db/protocol/tdap/client/database.h>
3
+ #include <bzs/db/protocol/tdap/client/table.h>
4
+ #include <bzs/db/protocol/tdap/client/dbdef.h>
5
+
6
+ using namespace bzs::db::protocol::tdap::client;
7
+ using namespace bzs::db::protocol::tdap;
8
+
9
+
10
+ /**
11
+ @brief create database example
12
+
13
+ This program create "test" database and
14
+ "test" table. The table of "test" has schema data.
15
+ And it call "schaem table".
16
+
17
+ database name : 'test'
18
+
19
+ table 'user' tableid = 1
20
+ -------------------------------------------------
21
+ No.| Filed name | type | size
22
+ -------------------------------------------------
23
+ 0 | id | integer | 4byte
24
+ 1 | name | var | 97byte (32 charctors)
25
+ 2 | groupid | integer | 4byte
26
+ -------------------------------------------------
27
+ -------------------------------------------------
28
+ index No.| type | segment0(size) | segment1(size)
29
+ -------------------------------------------------
30
+ 0 | primary| id(4) | -
31
+ 1 | | groupid(4) | -
32
+
33
+
34
+
35
+ table 'group1' tableid = 2
36
+ -------------------------------------------------
37
+ No.| Filed name | type | size
38
+ -------------------------------------------------
39
+ 0 | id | integer | 4byte
40
+ 1 | name | var | 97byte (32 charctors)
41
+ -------------------------------------------------
42
+ -------------------------------------------------
43
+ index No.| type | segment0(size) | segment1(size)
44
+ -------------------------------------------------
45
+ 0 | primary| id(4) | -
46
+
47
+
48
+ table 'picture' tableid = 3
49
+ -------------------------------------------------
50
+ No.| Filed name | type | size
51
+ -------------------------------------------------
52
+ 0 | type | integer | 2byte
53
+ 0 | id | integer | 4byte
54
+ 1 | picture | myblob | 11 MIDIUMBLOB
55
+ -------------------------------------------------
56
+ -------------------------------------------------
57
+ index No.| type | segment0(size) | segment1(size)
58
+ -------------------------------------------------
59
+ 0 | primary| type(2) | id(4)
60
+
61
+
62
+ */
63
+
64
+
65
+ /** show database operation error
66
+ */
67
+ void showError(const _TCHAR* caption,const _TCHAR* tableName, short statusCode)
68
+ {
69
+ _TCHAR tmp[1024]={0x00};
70
+ nstable::tdapErr(0x00, statusCode, tableName, tmp);
71
+ _tprintf(_T("%s error No.%ld %s\n"),caption, statusCode, tmp);
72
+ }
73
+
74
+ /** Create mysql database and empty schema table
75
+ */
76
+ bool createBatabase(database* db, const _TCHAR* uri)
77
+ {
78
+ db->create(uri);
79
+ if (db->stat() != 0)
80
+ {
81
+ showError(_T("createDatabse"), NULL, db->stat());
82
+ return false;
83
+ }
84
+ return true;
85
+ }
86
+
87
+ /** Open database and empty schema table
88
+ */
89
+ bool openDbExclusive(database* db, const _TCHAR* uri)
90
+ {
91
+ db->open(uri, TYPE_SCHEMA_BDF, TD_OPEN_EXCLUSIVE);
92
+ if (db->stat() != 0)
93
+ {
94
+ showError(_T("openBatabase"), NULL, db->stat());
95
+ return false;
96
+ }
97
+ return true;
98
+ }
99
+
100
+ /** Create user table schema and write
101
+ */
102
+ bool createUserTableSchema(dbdef* def)
103
+ {
104
+
105
+ //Insert table
106
+ tabledef td;
107
+ td.setTableName(L"user");
108
+ td.setFileName(L"user.dat");
109
+ td.id =1;
110
+ td.charsetIndex = CHARSET_UTF8B4;
111
+ def->insertTable(&td);
112
+ if (def->stat() != 0)
113
+ {
114
+ showError(_T("create schema table user"), NULL, def->stat());
115
+ return false;
116
+ }
117
+
118
+ //Insert field
119
+ short fieldNum = 0;
120
+ fielddef* fd = def->insertField(td.id, fieldNum);
121
+ fd->setName(_T("id"));
122
+ fd->type = ft_integer;
123
+ fd->len = (ushort_td)4;
124
+
125
+ fd = def->insertField(td.id, ++fieldNum);
126
+ fd->setName(_T("name"));
127
+ fd->type = ft_myvarchar;
128
+ fd->setLenByCharnum(32);
129
+
130
+ fd = def->insertField(td.id, ++fieldNum);
131
+ fd->setName(_T("group"));
132
+ fd->type = ft_integer;
133
+ fd->len = (ushort_td)4;
134
+
135
+ //Insert index
136
+ uchar_td keyNum = 0;
137
+ keydef* kd = def->insertKey(td.id, keyNum);
138
+ kd->segments[0].fieldNum = 0;
139
+ kd->segments[0].flags.bit8 = true;//extended type
140
+ kd->segments[0].flags.bit1 = true;//updateable
141
+ kd->segmentCount = 1;
142
+ def->tableDefs(td.id)->primaryKeyNum = keyNum;
143
+
144
+ keyNum = 1;
145
+ kd = def->insertKey(td.id, keyNum);
146
+ kd->segments[0].fieldNum = 2;//groupid
147
+ kd->segments[0].flags.bit8 = true;//extended type
148
+ kd->segments[0].flags.bit1 = true;//updateable
149
+ kd->segments[0].flags.bit0 = true;//duplicateable
150
+ kd->segmentCount = 1;
151
+
152
+ //write schema table
153
+ def->updateTableDef(td.id);
154
+ if (def->stat() != 0)
155
+ {
156
+ showError(_T("edit schema table"), NULL, def->stat());
157
+ return false;
158
+ }
159
+ return true;
160
+
161
+ }
162
+
163
+ /** Create group table schema and write
164
+ */
165
+ bool createGroupTableSchema(dbdef* def)
166
+ {
167
+
168
+ //Insert table
169
+ tabledef td;
170
+ td.setTableName(L"group1");
171
+ td.setFileName(L"group1.dat");
172
+ td.id = 2;
173
+ td.charsetIndex = CHARSET_UTF8B4;
174
+ def->insertTable(&td);
175
+ if (def->stat() != 0)
176
+ {
177
+ showError(_T("create schema table group1"), NULL, def->stat());
178
+ return false;
179
+ }
180
+
181
+ //Insert field
182
+ short fieldNum = 0;
183
+ fielddef* fd = def->insertField(td.id, fieldNum);
184
+ fd->setName(_T("id"));
185
+ fd->type = ft_integer;
186
+ fd->len = (ushort_td)4;
187
+
188
+ fd = def->insertField(td.id, ++fieldNum);
189
+ fd->setName(_T("name"));
190
+ fd->type = ft_myvarchar;
191
+ fd->setLenByCharnum(32);
192
+
193
+ //Insert index
194
+ uchar_td keyNum = 0;
195
+ keydef* kd = def->insertKey(td.id, keyNum);
196
+ kd->segments[0].fieldNum = 0;
197
+ kd->segments[0].flags.bit8 = true;//extended type
198
+ kd->segments[0].flags.bit1 = true;//updateable
199
+ kd->segmentCount = 1;
200
+ def->tableDefs(td.id)->primaryKeyNum = keyNum;
201
+
202
+ //write schema table
203
+ def->updateTableDef(td.id);
204
+ if (def->stat() != 0)
205
+ {
206
+ showError(_T("edit schema table"), NULL, def->stat());
207
+ return false;
208
+ }
209
+ return true;
210
+
211
+ }
212
+
213
+ /** Create picture table schema and write
214
+ */
215
+ bool createPictureTableSchema(dbdef* def)
216
+ {
217
+ //Insert table
218
+ tabledef td;
219
+ td.setTableName(L"picture");
220
+ td.setFileName(L"picture.dat");
221
+ td.id = 3;
222
+ td.charsetIndex = CHARSET_LATIN1;
223
+ def->insertTable(&td);
224
+ if (def->stat() != 0)
225
+ {
226
+ showError(_T("create schema table picture"), NULL, def->stat());
227
+ return false;
228
+ }
229
+
230
+ //Insert 3 fields
231
+ short fieldNum = 0;
232
+ fielddef* fd = def->insertField(td.id, fieldNum);
233
+ fd->setName(_T("type"));
234
+ fd->type = ft_integer;
235
+ fd->len = (ushort_td)2;
236
+
237
+ fd = def->insertField(td.id, ++fieldNum);
238
+ fd->setName(_T("id"));
239
+ fd->type = ft_integer;
240
+ fd->len = (ushort_td)4;
241
+
242
+
243
+ fd = def->insertField(td.id, ++fieldNum);
244
+ fd->setName(_T("picture"));
245
+ fd->type = ft_myblob;
246
+ fd->len = (ushort_td)11;
247
+
248
+
249
+ //Insert index
250
+ uchar_td keyNum = 0;
251
+ keydef* kd = def->insertKey(td.id, keyNum);
252
+ keySegment* ks = &kd->segments[0];
253
+ ks->fieldNum = 0; //type
254
+ ks->flags.bit8 = true;//extended type
255
+ ks->flags.bit1 = true;//updateable
256
+ ks->flags.bit4 = true;//segment part
257
+
258
+ ks = &kd->segments[1];
259
+ ks->fieldNum = 1; //id
260
+ ks->flags.bit8 = true;//extended type
261
+ ks->flags.bit1 = true;//updateable
262
+
263
+ kd->segmentCount = 2;
264
+ def->tableDefs(td.id)->primaryKeyNum = keyNum;
265
+
266
+ //write schema table
267
+ def->updateTableDef(td.id);
268
+ if (def->stat() != 0)
269
+ {
270
+ showError(_T("edit schema table"), NULL, def->stat());
271
+ return false;
272
+ }
273
+ return true;
274
+
275
+ }
276
+
277
+ #pragma argsused
278
+ int _tmain(int argc, _TCHAR* argv[])
279
+ {
280
+
281
+ int result = 1;
282
+ static const _TCHAR* uri = _T("tdap://localhost/test?dbfile=test.bdf");
283
+
284
+ database* db = database::create();
285
+ if (createBatabase(db, uri))
286
+ {
287
+ if (openDbExclusive(db, uri))
288
+ {
289
+ if (createUserTableSchema(db->dbDef()))
290
+ {
291
+ if (createGroupTableSchema(db->dbDef()))
292
+ {
293
+ if (createPictureTableSchema(db->dbDef()))
294
+ {
295
+ _tprintf(_T("create databse success. \n"));
296
+ result = 0;
297
+ }
298
+ }
299
+ }
300
+ db->close();
301
+ }
302
+ }
303
+ database::destroy(db);
304
+ return result;
305
+ }
@@ -0,0 +1,202 @@
1
+ #include <bzs/db/protocol/tdap/client/trdboostapi.h>
2
+ #include <iostream>
3
+ #include <bzs/env/tstring.h>
4
+
5
+ using namespace bzs::db::protocol::tdap::client;
6
+ using namespace bzs::db::protocol::tdap;
7
+
8
+
9
+ /**
10
+ @brief create database example
11
+
12
+ This program create "test" database and
13
+ "test" table. The table of "test" has schema data.
14
+ And it is called "schaem table".
15
+
16
+
17
+ database name : 'test'
18
+
19
+ table 'user' tableid = 1
20
+ -------------------------------------------------
21
+ No.| Filed name | type | size
22
+ -------------------------------------------------
23
+ 0 | id | integer | 4byte
24
+ 1 | name | var | 97byte (32 charctors)
25
+ 2 | groupid | integer | 4byte
26
+ -------------------------------------------------
27
+ -------------------------------------------------
28
+ index No.| type | segment0(size) | segment1(size)
29
+ -------------------------------------------------
30
+ 0 | primary| id(4) | -
31
+ 1 | | groupid(4) | -
32
+
33
+
34
+
35
+ table 'group1' tableid = 2
36
+ -------------------------------------------------
37
+ No.| Filed name | type | size
38
+ -------------------------------------------------
39
+ 0 | id | integer | 4byte
40
+ 1 | name | var | 97byte (32 charctors)
41
+ -------------------------------------------------
42
+ -------------------------------------------------
43
+ index No.| type | segment0(size) | segment1(size)
44
+ -------------------------------------------------
45
+ 0 | primary| id(4) | -
46
+
47
+
48
+ table 'picture' tableid = 3
49
+ -------------------------------------------------
50
+ No.| Filed name | type | size
51
+ -------------------------------------------------
52
+ 0 | type | integer | 2byte
53
+ 0 | id | integer | 4byte
54
+ 1 | picture | myblob | 11 MIDIUMBLOB
55
+ -------------------------------------------------
56
+ -------------------------------------------------
57
+ index No.| type | segment0(size) | segment1(size)
58
+ -------------------------------------------------
59
+ 0 | primary| type(2) | id(4)
60
+
61
+
62
+ */
63
+
64
+
65
+ /** Create user table schema and write
66
+ */
67
+ void createUserTableSchema(dbdef* def)
68
+ {
69
+ //Insert table
70
+ short tableid = 1;
71
+ const _TCHAR* name = _T("user");
72
+ insertTable(def, tableid, name, CHARSET_UTF8B4);
73
+
74
+ //Insert 3 fields
75
+ short fieldNum = 0;
76
+ insertField(def, tableid, fieldNum, _T("id"), ft_integer, 4);
77
+
78
+ int size = lenByCharnum(ft_myvarchar, CHARSET_UTF8B4, 32);
79
+ insertField(def, tableid, ++fieldNum, _T("name"), ft_myvarchar, size);
80
+ insertField(def, tableid, ++fieldNum, _T("group"), ft_integer, 4);
81
+
82
+ //Insert index
83
+ short keyNum = 0;
84
+ keydef* kd = insertKey(def, tableid, keyNum);
85
+ keySegment* ks = &kd->segments[0];
86
+ ks->fieldNum = 0;//id
87
+ ks->flags.bit8 = true;//extended type
88
+ ks->flags.bit1 = true;//updateable
89
+ kd->segmentCount = 1;
90
+ def->tableDefs(tableid)->primaryKeyNum = keyNum;
91
+
92
+ keyNum = 1;
93
+ kd = insertKey(def, tableid, keyNum);
94
+ ks = &kd->segments[0];
95
+ ks->fieldNum = 2;//groupid
96
+ ks->flags.bit8 = true;//extended type
97
+ ks->flags.bit1 = true;//updateable
98
+ ks->flags.bit0 = true;//duplicateable
99
+ kd->segmentCount = 1;
100
+
101
+
102
+ //write schema table
103
+ updateTableDef(def, tableid);
104
+
105
+ }
106
+
107
+ /** Create group table schema and write
108
+ */
109
+ void createGroupTableSchema(dbdef* def)
110
+ {
111
+ //Insert table
112
+ short tableid = 2;
113
+ const _TCHAR* name = _T("group1");
114
+ insertTable(def, tableid, name, CHARSET_UTF8B4);
115
+
116
+ //Insert 2 fields
117
+ short fieldNum = 0;
118
+ insertField(def, tableid, fieldNum, _T("id"), ft_integer, 4);
119
+ int size = lenByCharnum(ft_myvarchar, CHARSET_UTF8B4, 32);
120
+ insertField(def, tableid, ++fieldNum, _T("name"), ft_myvarchar, size);
121
+
122
+ //Insert index
123
+ short keyNum = 0;
124
+ keydef* kd = insertKey(def, tableid, keyNum);
125
+ keySegment* ks = &kd->segments[0];
126
+ ks->fieldNum = 0; //id
127
+ ks->flags.bit8 = true;//extended type
128
+ ks->flags.bit1 = true;//updateable
129
+ kd->segmentCount = 1;
130
+ def->tableDefs(tableid)->primaryKeyNum = keyNum;
131
+ //write schema table
132
+ updateTableDef(def, tableid);
133
+
134
+ }
135
+
136
+ /** Create picture table schema and write
137
+ */
138
+ void createPictureTableSchema(dbdef* def)
139
+ {
140
+ //Insert table
141
+ short tableid = 3;
142
+ const _TCHAR* name = _T("picture");
143
+ insertTable(def, tableid, name, CHARSET_LATIN1);
144
+
145
+ //Insert 3 fields
146
+ short fieldNum = 0;
147
+
148
+ insertField(def, tableid, fieldNum, _T("type"), ft_integer, 2);
149
+ insertField(def, tableid, ++fieldNum, _T("id"), ft_integer, 4);
150
+ insertField(def, tableid, ++fieldNum, _T("picture"), ft_myblob, 11);
151
+
152
+ //Insert index
153
+ short keyNum = 0;
154
+ keydef* kd = insertKey(def, tableid, keyNum);
155
+ keySegment* ks = &kd->segments[0];
156
+ ks->fieldNum = 0; //type
157
+ ks->flags.bit8 = true;//extended type
158
+ ks->flags.bit1 = true;//updateable
159
+ ks->flags.bit4 = true;//segment part
160
+
161
+ ks = &kd->segments[1];
162
+ ks->fieldNum = 1; //id
163
+ ks->flags.bit8 = true;//extended type
164
+ ks->flags.bit1 = true;//updateable
165
+
166
+ kd->segmentCount = 2;
167
+ def->tableDefs(tableid)->primaryKeyNum = keyNum;
168
+
169
+ //write schema table
170
+ updateTableDef(def, tableid);
171
+
172
+ }
173
+
174
+ #pragma argsused
175
+ int _tmain(int argc, _TCHAR* argv[])
176
+ {
177
+ database_ptr db = createDatadaseObject();
178
+ try
179
+ {
180
+ connectParams prams(_T("tdap"), _T("localhost"), _T("test"), _T("test"));
181
+ prams.setMode(TD_OPEN_EXCLUSIVE);
182
+
183
+ createDatabase(db, prams);
184
+
185
+ openDatabase(db, prams);
186
+
187
+ createUserTableSchema(db->dbDef());
188
+
189
+ createGroupTableSchema(db->dbDef());
190
+
191
+ createPictureTableSchema(db->dbDef());
192
+
193
+ std::cout << "create databse success." << std::endl;
194
+ return 0;
195
+ }
196
+
197
+ catch(bzs::rtl::exception& e)
198
+ {
199
+ std::tcout << *bzs::rtl::getMsg(e) << std::endl;
200
+ }
201
+ return 1;
202
+ }