transactd 2.1.0 → 2.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/bin/common/tdclc_32_2_2.dll +0 -0
- data/bin/common/tdclc_64_2_2.dll +0 -0
- data/build/swig/ruby/generate.cmd +45 -0
- data/build/swig/ruby/generate.sh +40 -0
- data/build/swig/ruby/tdclrb_wrap.cpp +406 -969
- data/build/swig/tdcl.i +88 -0
- data/build/tdclc/CMakeLists.txt +5 -1
- data/build/tdclc/tdclc.cbproj +1 -1
- data/build/tdclc/tdclc.rc +4 -4
- data/build/tdclcpp/tdclcpp.rc +4 -4
- data/build/tdclcpp/tdclcpp_bc.cbproj +1 -1
- data/build/tdclrb/tdclrb.rc +4 -4
- data/source/bzs/db/engine/mysql/database.cpp +165 -74
- data/source/bzs/db/engine/mysql/database.h +19 -5
- data/source/bzs/db/engine/mysql/dbManager.cpp +33 -11
- data/source/bzs/db/engine/mysql/dbManager.h +6 -1
- data/source/bzs/db/engine/mysql/mydebuglog.h +12 -0
- data/source/bzs/db/engine/mysql/mysqlInternal.h +10 -3
- data/source/bzs/db/engine/mysql/mysqlThd.cpp +20 -8
- data/source/bzs/db/protocol/hs/hsCommandExecuter.cpp +12 -7
- data/source/bzs/db/protocol/hs/hsCommandExecuter.h +1 -1
- data/source/bzs/db/protocol/tdap/client/activeTableImple.h +1 -0
- data/source/bzs/db/protocol/tdap/client/client.cpp +17 -15
- data/source/bzs/db/protocol/tdap/client/client.h +102 -30
- data/source/bzs/db/protocol/tdap/client/connectionPool.cpp +1 -1
- data/source/bzs/db/protocol/tdap/client/database.cpp +32 -10
- data/source/bzs/db/protocol/tdap/client/database.h +1 -0
- data/source/bzs/db/protocol/tdap/client/databaseFactory.cpp +0 -2
- data/source/bzs/db/protocol/tdap/client/dbDef.cpp +2 -0
- data/source/bzs/db/protocol/tdap/client/dllmain.cpp +47 -42
- data/source/bzs/db/protocol/tdap/client/fields.h +3 -1
- data/source/bzs/db/protocol/tdap/client/filter.h +3 -3
- data/source/bzs/db/protocol/tdap/client/nsDatabase.cpp +18 -2
- data/source/bzs/db/protocol/tdap/client/nsDatabase.h +3 -2
- data/source/bzs/db/protocol/tdap/client/nsTable.cpp +14 -6
- data/source/bzs/db/protocol/tdap/client/nsTable.h +12 -12
- data/source/bzs/db/protocol/tdap/client/recordsetImple.h +6 -3
- data/source/bzs/db/protocol/tdap/client/request.h +1 -0
- data/source/bzs/db/protocol/tdap/client/sqlBuilder.cpp +101 -64
- data/source/bzs/db/protocol/tdap/client/sqlBuilder.h +3 -0
- data/source/bzs/db/protocol/tdap/client/stringConverter.h +9 -13
- data/source/bzs/db/protocol/tdap/client/table.cpp +73 -56
- data/source/bzs/db/protocol/tdap/client/table.h +8 -8
- data/source/bzs/db/protocol/tdap/client/trdboostapi.h +52 -100
- data/source/bzs/db/protocol/tdap/mysql/databaseSchema.cpp +8 -1
- data/source/bzs/db/protocol/tdap/mysql/request.h +6 -0
- data/source/bzs/db/protocol/tdap/mysql/tdapCommandExecuter.cpp +349 -189
- data/source/bzs/db/protocol/tdap/mysql/tdapCommandExecuter.h +28 -12
- data/source/bzs/db/protocol/tdap/tdapRequest.h +5 -4
- data/source/bzs/db/protocol/tdap/tdapSchema.h +6 -1
- data/source/bzs/db/protocol/tdap/tdapcapi.h +29 -4
- data/source/bzs/db/protocol/tdap/uri.h +297 -0
- data/source/bzs/db/transactd/appModule.cpp +41 -16
- data/source/bzs/db/transactd/appModule.h +1 -2
- data/source/bzs/db/transactd/transactd.cpp +37 -14
- data/source/bzs/env/crosscompile.h +1 -3
- data/source/bzs/example/queryData.cpp +2 -2
- data/source/bzs/netsvc/client/iconnection.h +3 -1
- data/source/bzs/netsvc/client/tcpClient.cpp +75 -28
- data/source/bzs/netsvc/client/tcpClient.h +94 -62
- data/source/bzs/netsvc/server/IAppModule.h +2 -2
- data/source/bzs/netsvc/server/serverCpt.cpp +17 -10
- data/source/bzs/netsvc/server/serverPipe.cpp +26 -19
- data/source/bzs/netsvc/server/serverTpool.cpp +8 -2
- data/source/bzs/rtl/debuglog.cpp +21 -5
- data/source/bzs/rtl/debuglog.h +1 -1
- data/source/bzs/test/tdclphp/transactd_Test.php +183 -37
- data/source/bzs/test/tdclphp/transactd_pool_Test.php +1 -2
- data/source/bzs/test/tdclrb/transactd_spec.rb +183 -39
- data/source/bzs/test/transactdBench/scaling_bench.cpp +3 -3
- data/source/bzs/test/trdclengn/test_trdclengn.cpp +172 -57
- data/source/global/boost/sha1.hpp +223 -0
- data/source/global/tdclatl/ConnectParams.cpp +2 -2
- data/source/global/tdclatl/ConnectParams.h +1 -1
- data/source/global/tdclatl/Database.cpp +18 -0
- data/source/global/tdclatl/Database.h +5 -0
- data/source/global/tdclatl/tdclatl.idl +23 -1
- data/source/linux/linuxTypes.h +2 -0
- metadata +8 -6
- data/bin/common/tdclc_32_2_1.dll +0 -0
- data/bin/common/tdclc_64_2_1.dll +0 -0
- data/source/bzs/db/protocol/tdap/client/memRecordset.cpp +0 -448
- data/source/bzs/db/protocol/tdap/client/memRecordset.h +0 -159
@@ -74,7 +74,7 @@ public:
|
|
74
74
|
std::string smartDbsReopen::removeName = "";
|
75
75
|
|
76
76
|
|
77
|
-
dbManager::dbManager() : m_autoHandle(0)
|
77
|
+
dbManager::dbManager() : m_autoHandle(0), m_authChecked(false)
|
78
78
|
{
|
79
79
|
}
|
80
80
|
|
@@ -139,7 +139,13 @@ database* dbManager::useDataBase(int id) const
|
|
139
139
|
|
140
140
|
database* dbManager::createDatabase(const char* dbname, short cid) const
|
141
141
|
{
|
142
|
-
|
142
|
+
database* db = new database(dbname, cid);
|
143
|
+
if (m_authChecked)
|
144
|
+
{
|
145
|
+
if (m_host != "")
|
146
|
+
db->setGrant(m_host.c_str(), m_user.c_str());
|
147
|
+
}
|
148
|
+
return db;
|
143
149
|
}
|
144
150
|
|
145
151
|
handle* dbManager::getHandle(int handle) const
|
@@ -149,7 +155,9 @@ handle* dbManager::getHandle(int handle) const
|
|
149
155
|
if (m_handles[i].id == handle)
|
150
156
|
return &m_handles[i];
|
151
157
|
}
|
152
|
-
|
158
|
+
char tmp[256];
|
159
|
+
sprintf(tmp, "Invalid handle. handle = %d", handle);
|
160
|
+
THROW_BZS_ERROR_WITH_CODEMSG(1, tmp);
|
153
161
|
}
|
154
162
|
|
155
163
|
int dbManager::getDatabaseID(short cid) const
|
@@ -166,21 +174,26 @@ database* dbManager::getDatabaseCid(short cid) const
|
|
166
174
|
{
|
167
175
|
int id = getDatabaseID(cid);
|
168
176
|
if (id == -1)
|
169
|
-
|
170
|
-
|
177
|
+
{
|
178
|
+
char tmp[256];
|
179
|
+
sprintf(tmp, "Can not get database object. cid = %d", cid);
|
180
|
+
THROW_BZS_ERROR_WITH_CODEMSG(1, tmp);
|
181
|
+
}
|
171
182
|
return useDataBase(id);
|
172
183
|
}
|
173
184
|
|
174
|
-
database* dbManager::getDatabase(const char* dbname, short cid) const
|
185
|
+
database* dbManager::getDatabase(const char* dbname, short cid, bool& created) const
|
175
186
|
{
|
187
|
+
created = false;
|
176
188
|
int id = getDatabaseID(cid);
|
177
189
|
if (id == -1)
|
178
190
|
{
|
179
191
|
boost::shared_ptr<database> db(createDatabase(dbname, cid));
|
180
192
|
if (db == NULL)
|
181
193
|
THROW_BZS_ERROR_WITH_CODEMSG(1, "Can not create database object.");
|
194
|
+
id = (int)m_dbs.size();
|
182
195
|
m_dbs.push_back(db);
|
183
|
-
|
196
|
+
created = true;
|
184
197
|
}
|
185
198
|
return useDataBase(id);
|
186
199
|
}
|
@@ -188,10 +201,12 @@ database* dbManager::getDatabase(const char* dbname, short cid) const
|
|
188
201
|
table* dbManager::getTable(int hdl, enum_sql_command cmd, engine::mysql::rowLockMode* lck) const
|
189
202
|
{
|
190
203
|
handle* h = getHandle(hdl);
|
191
|
-
if (
|
204
|
+
if ((h->db < (int)m_dbs.size()))
|
192
205
|
return useDataBase(h->db)->useTable(h->tb, cmd, lck);
|
193
206
|
|
194
|
-
|
207
|
+
char tmp[256];
|
208
|
+
sprintf(tmp, "Invalid handle. handle = %d db = %d tb = %d", hdl, h->db, h->tb);
|
209
|
+
THROW_BZS_ERROR_WITH_CODEMSG(1, tmp);
|
195
210
|
}
|
196
211
|
|
197
212
|
int dbManager::addHandle(int dbid, int tableid, int assignid)
|
@@ -210,8 +225,8 @@ int dbManager::ddl_execSql(THD* thd, const std::string& sql_stmt)
|
|
210
225
|
thd->clear_error();
|
211
226
|
int result = dispatch_command(COM_QUERY, thd, (char*)sql_stmt.c_str(),
|
212
227
|
(uint)sql_stmt.size());
|
213
|
-
if (!thd->cp_isOk())
|
214
|
-
|
228
|
+
//if (!thd->cp_isOk())
|
229
|
+
// result = 1;
|
215
230
|
if (thd->is_error())
|
216
231
|
result = errorCode(thd->cp_get_sql_error());
|
217
232
|
return result;
|
@@ -270,6 +285,13 @@ int dbManager::ddl_dropTable(database* db, const std::string& tbname,
|
|
270
285
|
return ddl_execSql(db->thd(), cmd);
|
271
286
|
}
|
272
287
|
|
288
|
+
int dbManager::ddl_addIndex(database* db, const std::string& tbname,
|
289
|
+
const std::string& cmd)
|
290
|
+
{
|
291
|
+
std::string c = "ALTER TABLE `" + db->name() + "`." + cmd;
|
292
|
+
return ddl_execSql(db->thd(), c);
|
293
|
+
}
|
294
|
+
|
273
295
|
int dbManager::ddl_renameTable(database* db, const std::string& oldName,
|
274
296
|
const std::string& dbSqlName,
|
275
297
|
const std::string& oldSqlName,
|
@@ -58,11 +58,14 @@ protected:
|
|
58
58
|
mutable std::vector<handle> m_handles;
|
59
59
|
|
60
60
|
table* m_tb;
|
61
|
+
std::string m_user;
|
62
|
+
std::string m_host;
|
63
|
+
bool m_authChecked;
|
61
64
|
|
62
65
|
database* createDatabase(const char* dbname, short cid) const;
|
63
66
|
void releaseDatabase(short cid);
|
64
67
|
handle* getHandle(int handle) const;
|
65
|
-
database* getDatabase(const char* dbname, short cid) const;
|
68
|
+
database* getDatabase(const char* dbname, short cid, bool& created) const;
|
66
69
|
database* getDatabaseCid(short cid) const;
|
67
70
|
int getDatabaseID(short cid) const;
|
68
71
|
table* getTable(int handle, enum_sql_command cmd = SQLCOM_SELECT, engine::mysql::rowLockMode* lck=NULL) const;
|
@@ -78,6 +81,8 @@ protected:
|
|
78
81
|
int ddl_dropTable(database* db, const std::string& tbname,
|
79
82
|
const std::string& sqldbname,
|
80
83
|
const std::string& sqltbname);
|
84
|
+
int ddl_addIndex(database* db, const std::string& tbname,
|
85
|
+
const std::string& cmd);
|
81
86
|
int ddl_renameTable(database* db, const std::string& oldName,
|
82
87
|
const std::string& dbSqlName,
|
83
88
|
const std::string& oldSqlName,
|
@@ -89,6 +89,18 @@ extern char msg[1024];
|
|
89
89
|
#define DEBUG_RECORDS_END(WRITER)
|
90
90
|
#endif
|
91
91
|
|
92
|
+
|
93
|
+
#ifdef DEBUG_LOG_ERR
|
94
|
+
#define DEBUG_ERROR_MEMDUMP(RESULT, MSG, PTR, SIZE) \
|
95
|
+
if (RESULT) \
|
96
|
+
{ \
|
97
|
+
char tmp[50]; \
|
98
|
+
sprintf(tmp, "error %d", RESULT); \
|
99
|
+
((debugdb*)debuglog::get())->writeDump(tmp, (const char*)PTR, SIZE); \
|
100
|
+
}
|
101
|
+
#else
|
102
|
+
#define DEBUG_ERROR_MEMDUMP(RESULT, MSG, PTR, SIZE)
|
103
|
+
#endif
|
92
104
|
} // namespace mysql
|
93
105
|
} // namespace engine
|
94
106
|
} // namespace db
|
@@ -50,9 +50,11 @@
|
|
50
50
|
#endif
|
51
51
|
|
52
52
|
#include <my_config.h>
|
53
|
-
#include <mysql/plugin.h>
|
54
53
|
#include <mysql_version.h>
|
55
54
|
#include <sql/sql_const.h>
|
55
|
+
#include "my_global.h"
|
56
|
+
#include "sql/sql_class.h"
|
57
|
+
#include <mysql/plugin.h>
|
56
58
|
#include "sql/mysqld.h"
|
57
59
|
|
58
60
|
#if ((MYSQL_VERSION_ID >= 50600) && !defined(MARIADB_BASE_VERSION))
|
@@ -63,11 +65,9 @@
|
|
63
65
|
#include "sql/sql_cache.h"
|
64
66
|
#include "sql/structs.h"
|
65
67
|
#include "sql/sql_priv.h"
|
66
|
-
#include "sql/sql_class.h"
|
67
68
|
#include "sql/unireg.h"
|
68
69
|
#include "sql/lock.h"
|
69
70
|
#include "sql/key.h"
|
70
|
-
#include "my_global.h"
|
71
71
|
#include "sql/transaction.h"
|
72
72
|
#include "sql/sql_base.h"
|
73
73
|
#include "sql/sql_parse.h"
|
@@ -75,6 +75,13 @@
|
|
75
75
|
#include "sql/sql_db.h"
|
76
76
|
#include "sql_acl.h"
|
77
77
|
#include "mysqld_error.h"
|
78
|
+
#include <password.h>
|
79
|
+
|
80
|
+
/* mysql.user password field index */
|
81
|
+
#ifndef MYSQL_USER_FIELD_PASSWORD
|
82
|
+
#define MYSQL_USER_FIELD_PASSWORD 2
|
83
|
+
#endif
|
84
|
+
|
78
85
|
|
79
86
|
#if ((MYSQL_VERSION_ID > 50700) && !defined(MARIADB_BASE_VERSION))
|
80
87
|
#include "sql/log.h"
|
@@ -25,6 +25,7 @@ unsigned int g_openDatabases = 0;
|
|
25
25
|
|
26
26
|
extern unsigned int g_lock_wait_timeout;
|
27
27
|
extern char* g_transaction_isolation;
|
28
|
+
static unsigned int transaction_isolation_cache = -1;
|
28
29
|
|
29
30
|
#ifdef USETLS
|
30
31
|
tls_key g_tlsiID;
|
@@ -100,6 +101,24 @@ void waitForServerStart()
|
|
100
101
|
mysql_mutex_unlock(&LOCK_server_started);
|
101
102
|
}
|
102
103
|
|
104
|
+
unsigned int getTransactdIsolation()
|
105
|
+
{
|
106
|
+
if (transaction_isolation_cache != -1)
|
107
|
+
return transaction_isolation_cache;
|
108
|
+
else if (strcmp(g_transaction_isolation, "READ-COMMITTED") == 0)
|
109
|
+
return transaction_isolation_cache = ISO_READ_COMMITTED;
|
110
|
+
else if (strcmp(g_transaction_isolation, "REPEATABLE-READ") == 0)
|
111
|
+
return transaction_isolation_cache = ISO_REPEATABLE_READ;
|
112
|
+
else if (strcmp(g_transaction_isolation, "SERIALIZABLE") == 0)
|
113
|
+
return transaction_isolation_cache = ISO_SERIALIZABLE;
|
114
|
+
return transaction_isolation_cache = ISO_READ_UNCOMMITTED;
|
115
|
+
}
|
116
|
+
|
117
|
+
unsigned int getTransactdLockWaitTimeout()
|
118
|
+
{
|
119
|
+
return g_lock_wait_timeout;
|
120
|
+
}
|
121
|
+
|
103
122
|
THD* buildTHD()
|
104
123
|
{
|
105
124
|
if (!mysqld_server_started)
|
@@ -121,14 +140,7 @@ THD* buildTHD()
|
|
121
140
|
thd->net = v;
|
122
141
|
|
123
142
|
thd->variables.option_bits |= OPTION_BIN_LOG;
|
124
|
-
|
125
|
-
thd->variables.tx_isolation = ISO_READ_COMMITTED;
|
126
|
-
else if (strcmp(g_transaction_isolation, "REPEATABLE-READ") == 0)
|
127
|
-
thd->variables.tx_isolation = ISO_REPEATABLE_READ;
|
128
|
-
else if (strcmp(g_transaction_isolation, "READ-UNCOMMITTED") == 0)
|
129
|
-
thd->variables.tx_isolation = ISO_READ_UNCOMMITTED;
|
130
|
-
else if (strcmp(g_transaction_isolation, "SERIALIZABLE") == 0)
|
131
|
-
thd->variables.tx_isolation = ISO_SERIALIZABLE;
|
143
|
+
thd->variables.tx_isolation = getTransactdIsolation();
|
132
144
|
|
133
145
|
thd->clear_error();
|
134
146
|
char tmp[256];
|
@@ -305,13 +305,18 @@ int dbExecuter::commandExec(std::vector<request>& requests,
|
|
305
305
|
case HS_OP_OPEN:
|
306
306
|
{
|
307
307
|
checkNewHandle(req.handle);
|
308
|
-
|
308
|
+
bool created;
|
309
|
+
database* db = getDatabase(req.db.name, 0 /*cid*/, created);
|
309
310
|
m_tb = db->openTable(req.table.name, req.table.openMode, NULL);
|
310
|
-
|
311
|
-
|
312
|
-
|
313
|
-
|
314
|
-
|
311
|
+
if (m_tb)
|
312
|
+
{
|
313
|
+
addHandle(getDatabaseID(0 /*cid*/), m_tb->id(), req.handle);
|
314
|
+
m_tb = getTable(req.handle);
|
315
|
+
m_tb->setUseFieldList(req.table.fields);
|
316
|
+
m_tb->setKeyNum(req.table.key.name);
|
317
|
+
writeStatus(m_tb->stat(), buf, 1);
|
318
|
+
}else
|
319
|
+
writeStatus(db->stat(), buf, 1);
|
315
320
|
break;
|
316
321
|
}
|
317
322
|
case HS_OP_INSERT:
|
@@ -565,7 +570,7 @@ inline void setFilterVal(const std::string& src, int& parseMode, request* req)
|
|
565
570
|
parseMode = PARSEREAD_FL_TYPE;
|
566
571
|
}
|
567
572
|
|
568
|
-
commandExecuter::commandExecuter(
|
573
|
+
commandExecuter::commandExecuter(netsvc::server::IAppModule* /*mod*/)
|
569
574
|
: m_dbExec(new dbExecuter())
|
570
575
|
{
|
571
576
|
}
|
@@ -203,7 +203,7 @@ class commandExecuter : public ICommandExecuter,
|
|
203
203
|
mutable std::vector<request> m_requests;
|
204
204
|
|
205
205
|
public:
|
206
|
-
commandExecuter(
|
206
|
+
commandExecuter(netsvc::server::IAppModule* mod);
|
207
207
|
~commandExecuter();
|
208
208
|
size_t perseRequestEnd(const char* p, size_t size, bool& comp) const;
|
209
209
|
size_t getAcceptMessage(char* message, size_t size) { return 0; };
|
@@ -258,6 +258,7 @@ class activeTableImple : public activeObject<map_orm>
|
|
258
258
|
template <class Container>
|
259
259
|
void doJoin(bool innner, Container& mdls, pq_handle& stmt, const _TCHAR* fns[8], int fnsCount)
|
260
260
|
{
|
261
|
+
if (mdls.size() == 0) return;
|
261
262
|
stmt->clearSeeks();
|
262
263
|
mraResetter mras(m_tb);
|
263
264
|
typename Container::iterator it = mdls.begin(), ite = mdls.end();
|
@@ -41,12 +41,6 @@ tls_key g_tlsiID;
|
|
41
41
|
__THREAD client* __THREAD_BCB g_client = NULL;
|
42
42
|
#endif
|
43
43
|
|
44
|
-
bool checkVersion(trdVersiton& ver)
|
45
|
-
{
|
46
|
-
if ((ver.srvMajor < 2) || ((ver.srvMajor == 2) && (ver.srvMinor < 1)))
|
47
|
-
return false;
|
48
|
-
return true;
|
49
|
-
}
|
50
44
|
|
51
45
|
int client::getServerCharsetIndex()
|
52
46
|
{
|
@@ -65,7 +59,6 @@ int client::getServerCharsetIndex()
|
|
65
59
|
ver.clMajor = (ushort_td)atoi(C_INTERFACE_VER_MAJOR);
|
66
60
|
ver.clMinor = (ushort_td)atoi(C_INTERFACE_VER_MINOR);
|
67
61
|
ver.clRelease = (ushort_td)atoi(C_INTERFACE_VER_RELEASE);
|
68
|
-
|
69
62
|
uint_td len = sizeof(trdVersiton);
|
70
63
|
req.op = TD_GETSERVER_CHARSET;
|
71
64
|
req.data = &ver;
|
@@ -79,7 +72,7 @@ int client::getServerCharsetIndex()
|
|
79
72
|
if (req.result == 0)
|
80
73
|
{
|
81
74
|
if (!checkVersion(ver))
|
82
|
-
return
|
75
|
+
return -1;
|
83
76
|
c->setCharsetServer(mysql::charsetIndex(ver.cherserServer));
|
84
77
|
return c->charsetServer();
|
85
78
|
}
|
@@ -104,15 +97,24 @@ bool client::buildDualChasetKeybuf()
|
|
104
97
|
if (charsetIndexServer == -1)
|
105
98
|
return false;
|
106
99
|
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
100
|
+
// remove auth info
|
101
|
+
{
|
102
|
+
_TCHAR tmp[MAX_KEYLEN+128]={0};
|
103
|
+
m_serverCharData = stripAuth((const char*)m_req.keybuf, tmp, MAX_KEYLEN);
|
104
|
+
|
105
|
+
if (CHARSET_UTF8 != charsetIndexServer)
|
106
|
+
addSecondCharsetData(mysql::codePage(charsetIndexServer),
|
107
|
+
m_serverCharData);
|
108
|
+
else
|
109
|
+
m_serverCharData += std::string("\t") + tmp;
|
110
|
+
}
|
111
|
+
//Add Auth infomation
|
112
|
+
if (m_cryptPwd)
|
113
|
+
m_serverCharData += std::string("\t") +
|
114
|
+
std::string(m_cryptPwd, strlen(m_cryptPwd + 20) + MYSQL_SCRAMBLE_LENGTH);
|
113
115
|
|
114
116
|
m_req.keybuf = (void_td*)m_serverCharData.c_str();
|
115
|
-
m_req.keylen = (keylen_td)m_serverCharData.size()
|
117
|
+
m_req.keylen = (keylen_td)m_serverCharData.size();
|
116
118
|
return true;
|
117
119
|
}
|
118
120
|
|
@@ -25,6 +25,7 @@
|
|
25
25
|
#include <bzs/db/protocol/tdap/tdapSchema.h>
|
26
26
|
#include <bzs/netsvc/client/tcpClient.h>
|
27
27
|
#include <bzs/db/protocol/tdap/tdapcapi.h>
|
28
|
+
#include <bzs/db/protocol/tdap/uri.h>
|
28
29
|
#include <bzs/db/protocol/tdap/mysql/characterset.h>
|
29
30
|
#include <bzs/env/compiler.h>
|
30
31
|
#include <bzs/rtl/stl_uty.h>
|
@@ -64,7 +65,7 @@ class client
|
|
64
65
|
ushort_td m_preResult;
|
65
66
|
std::string m_sql;
|
66
67
|
std::string m_serverCharData;
|
67
|
-
|
68
|
+
char* m_cryptPwd;
|
68
69
|
blobBuffer m_blobBuffer;
|
69
70
|
uint_td m_tmplen;
|
70
71
|
bool m_logout;
|
@@ -73,6 +74,13 @@ class client
|
|
73
74
|
|
74
75
|
std::vector<char> m_sendbuf;
|
75
76
|
|
77
|
+
bool checkVersion(trdVersiton& ver)
|
78
|
+
{
|
79
|
+
if ((ver.srvMajor < 2) || ((ver.srvMajor == 2) && (ver.srvMinor < 1)))
|
80
|
+
return false;
|
81
|
+
return true;
|
82
|
+
}
|
83
|
+
|
76
84
|
inline bzs::netsvc::client::connection* con() { return m_req.cid->con; };
|
77
85
|
|
78
86
|
inline void setCon(bzs::netsvc::client::connection* con)
|
@@ -82,22 +90,21 @@ class client
|
|
82
90
|
|
83
91
|
inline void disconnect()
|
84
92
|
{
|
85
|
-
|
93
|
+
bzs::netsvc::client::connection* c = con();
|
94
|
+
if (!c)
|
86
95
|
m_req.result = 1;
|
87
96
|
else
|
88
97
|
{
|
89
|
-
m_disconnected = m_cons->disconnect(con());
|
90
98
|
setCon(NULL);
|
99
|
+
//Release connection refCount
|
100
|
+
m_disconnected = m_cons->disconnect(c);
|
91
101
|
}
|
92
102
|
}
|
93
103
|
|
94
104
|
std::string getHostName(const char* uri)
|
95
105
|
{
|
96
|
-
|
97
|
-
|
98
|
-
if (ss.size() < 3)
|
99
|
-
return "";
|
100
|
-
return ss[2];
|
106
|
+
_TCHAR tmp[MAX_PATH];
|
107
|
+
return hostName(uri, tmp, MAX_PATH);
|
101
108
|
}
|
102
109
|
|
103
110
|
std::string getTableName(const char* uri)
|
@@ -123,8 +130,57 @@ class client
|
|
123
130
|
static void addSecondCharsetData(unsigned int destCodePage,
|
124
131
|
std::string& src);
|
125
132
|
|
133
|
+
bool handshake(bzs::netsvc::client::connection* c)
|
134
|
+
{
|
135
|
+
//Implements handshake here
|
136
|
+
handshale_t* hst = (handshale_t*)c->read();
|
137
|
+
bool auth = (hst->size == sizeof(handshale_t));
|
138
|
+
bool min = (hst->size == (sizeof(handshale_t)
|
139
|
+
- sizeof(hst->scramble)));
|
140
|
+
|
141
|
+
if (min || auth)
|
142
|
+
{
|
143
|
+
if (!checkVersion(hst->ver))
|
144
|
+
return false;
|
145
|
+
c->setCharsetServer(mysql::charsetIndex(hst->ver.cherserServer));
|
146
|
+
m_req.cid->lock_wait_timeout = hst->lock_wait_timeout;
|
147
|
+
m_req.cid->transaction_isolation = hst->transaction_isolation;
|
148
|
+
}
|
149
|
+
if (auth)
|
150
|
+
{
|
151
|
+
char user[50];
|
152
|
+
char pwd[MAX_PATH];
|
153
|
+
char* p = (char*)m_req.keybuf;
|
154
|
+
userName(p, user, 50);
|
155
|
+
if (m_cryptPwd == NULL)
|
156
|
+
m_cryptPwd = new char[70];
|
157
|
+
passwd((const char*)m_req.keybuf, pwd, MAX_PATH);
|
158
|
+
if (pwd[0])
|
159
|
+
mysqlCryptPwd(m_cryptPwd, pwd, hst->scramble);
|
160
|
+
else
|
161
|
+
memset(m_cryptPwd, 0, MYSQL_SCRAMBLE_LENGTH);
|
162
|
+
strcpy_s(m_cryptPwd + MYSQL_SCRAMBLE_LENGTH, 50, user);
|
163
|
+
}else
|
164
|
+
{ // No auth
|
165
|
+
if (m_cryptPwd)
|
166
|
+
delete [] m_cryptPwd;
|
167
|
+
m_cryptPwd = NULL;
|
168
|
+
}
|
169
|
+
return true;
|
170
|
+
}
|
171
|
+
|
172
|
+
static bool handshakeCallback(bzs::netsvc::client::connection* c, void* data)
|
173
|
+
{
|
174
|
+
return ((client*)data)->handshake(c);
|
175
|
+
}
|
176
|
+
|
126
177
|
public:
|
127
|
-
client() : m_disconnected(true), m_connecting(false) {}
|
178
|
+
client() : m_cryptPwd(NULL), m_disconnected(true), m_connecting(false) {}
|
179
|
+
~client()
|
180
|
+
{
|
181
|
+
if (m_cryptPwd)
|
182
|
+
delete [] m_cryptPwd;
|
183
|
+
}
|
128
184
|
|
129
185
|
void cleanup()
|
130
186
|
{
|
@@ -182,11 +238,11 @@ public:
|
|
182
238
|
{
|
183
239
|
if (!m_req.cid->con)
|
184
240
|
{
|
185
|
-
|
186
241
|
std::string host = getHostName((const char*)m_req.keybuf);
|
187
242
|
if (host == "")
|
188
243
|
m_preResult = ERROR_TD_HOSTNAME_NOT_FOUND;
|
189
|
-
bzs::netsvc::client::connection* c = m_cons->connect(host
|
244
|
+
bzs::netsvc::client::connection* c = m_cons->connect(host,
|
245
|
+
client::handshakeCallback, this);
|
190
246
|
if (c)
|
191
247
|
{
|
192
248
|
setCon(c);
|
@@ -198,6 +254,21 @@ public:
|
|
198
254
|
m_disconnected = !m_req.cid->con;
|
199
255
|
}
|
200
256
|
|
257
|
+
inline void createIndex()
|
258
|
+
{
|
259
|
+
m_req.paramMask = P_MASK_NOKEYBUF;
|
260
|
+
int charsetIndexServer = getServerCharsetIndex();
|
261
|
+
unsigned char keynum = m_req.keyNum;
|
262
|
+
bool specifyKeyNum = (keynum >= 0x80);
|
263
|
+
if (keynum >= 0x80)
|
264
|
+
keynum -= 0x80;
|
265
|
+
m_sql = sqlCreateIndex((tabledef*)m_req.data, keynum,
|
266
|
+
specifyKeyNum, charsetIndexServer);
|
267
|
+
m_req.data = (ushort_td*)m_sql.c_str();
|
268
|
+
m_tmplen = (uint_td)(m_sql.size() + 1);
|
269
|
+
m_req.datalen = &m_tmplen;
|
270
|
+
}
|
271
|
+
|
201
272
|
inline void create()
|
202
273
|
{
|
203
274
|
m_req.paramMask = P_MASK_ALL;
|
@@ -206,8 +277,10 @@ public:
|
|
206
277
|
else if (m_req.keyNum >
|
207
278
|
CR_SUBOP_SWAPNAME) // -126 swap -127 is rename. -128 is drop.
|
208
279
|
{
|
280
|
+
_TCHAR tmp[MAX_PATH*2]={0};
|
281
|
+
stripAuth((const char*)m_req.keybuf, tmp, MAX_PATH);
|
209
282
|
m_req.paramMask &= ~P_MASK_POSBLK;
|
210
|
-
std::string name = getTableName(
|
283
|
+
std::string name = getTableName(tmp);
|
211
284
|
int charsetIndexServer = getServerCharsetIndex();
|
212
285
|
if ((m_req.keyNum == 1) || (m_req.keyNum == 2)) // make by tabledef
|
213
286
|
{
|
@@ -239,26 +312,25 @@ public:
|
|
239
312
|
if ((m_req.keyNum == LG_SUBOP_CONNECT) ||
|
240
313
|
(m_req.keyNum == LG_SUBOP_NEWCONNECT))
|
241
314
|
{
|
242
|
-
if (con()
|
243
|
-
|
244
|
-
|
315
|
+
if (con())
|
316
|
+
disconnect();
|
317
|
+
std::string host = getHostName((const char*)m_req.keybuf);
|
318
|
+
if (host == "")
|
319
|
+
m_preResult = ERROR_TD_HOSTNAME_NOT_FOUND;
|
320
|
+
bzs::netsvc::client::connection* c = m_cons->connect(
|
321
|
+
host, handshakeCallback, this,
|
322
|
+
(m_req.keyNum == LG_SUBOP_NEWCONNECT));
|
323
|
+
if (c)
|
245
324
|
{
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
host, (m_req.keyNum == LG_SUBOP_NEWCONNECT));
|
251
|
-
if (c)
|
252
|
-
{
|
253
|
-
setCon(c); // if error throw exception
|
254
|
-
if (getServerCharsetIndex() == -1)
|
255
|
-
m_preResult = SERVER_CLIENT_NOT_COMPATIBLE;
|
256
|
-
else
|
257
|
-
buildDualChasetKeybuf();
|
258
|
-
}
|
325
|
+
setCon(c); // if error throw exception
|
326
|
+
m_connecting = true;
|
327
|
+
if (getServerCharsetIndex() == -1)
|
328
|
+
m_preResult = SERVER_CLIENT_NOT_COMPATIBLE;
|
259
329
|
else
|
260
|
-
|
330
|
+
buildDualChasetKeybuf();
|
261
331
|
}
|
332
|
+
else
|
333
|
+
m_preResult = ERROR_TD_HOSTNAME_NOT_FOUND;
|
262
334
|
}
|
263
335
|
else if (m_req.keyNum == LG_SUBOP_DISCONNECT)
|
264
336
|
{
|
@@ -301,13 +373,13 @@ public:
|
|
301
373
|
p = c->asyncWriteRead(size);
|
302
374
|
m_req.parse(p, ex);
|
303
375
|
}
|
304
|
-
|
305
376
|
}
|
306
377
|
else
|
307
378
|
m_req.result = stat;
|
308
379
|
if (m_logout || (m_connecting && m_req.result))
|
309
380
|
disconnect();
|
310
381
|
m_preResult = m_req.result;
|
382
|
+
m_connecting = false;
|
311
383
|
}
|
312
384
|
}
|
313
385
|
return result();
|
@@ -24,6 +24,7 @@
|
|
24
24
|
#include <stdio.h>
|
25
25
|
#include <vector>
|
26
26
|
#include "stringConverter.h"
|
27
|
+
#include <bzs/db/protocol/tdap/uri.h>
|
27
28
|
|
28
29
|
#pragma package(smart_init)
|
29
30
|
|
@@ -218,7 +219,17 @@ void database::dropTable(const _TCHAR* TableName)
|
|
218
219
|
m_stat = STATUS_TABLENAME_NOTFOUND;
|
219
220
|
else
|
220
221
|
_tcscat(FullPath, m_impl->dbDef->tableDefs(index)->fileName());
|
221
|
-
|
222
|
+
|
223
|
+
int i = 0;
|
224
|
+
while (1)
|
225
|
+
{
|
226
|
+
nsdatabase::dropTable(FullPath);
|
227
|
+
if (m_stat != STATUS_LOCK_ERROR)
|
228
|
+
break;
|
229
|
+
if (++i == 10)
|
230
|
+
break;
|
231
|
+
Sleep(50);
|
232
|
+
}
|
222
233
|
}
|
223
234
|
|
224
235
|
void database::setDir(const _TCHAR* directory)
|
@@ -287,7 +298,7 @@ bool database::open(const _TCHAR* _uri, short type, short mode,
|
|
287
298
|
const _TCHAR* dir, const _TCHAR* ownername)
|
288
299
|
{
|
289
300
|
|
290
|
-
_TCHAR buf[MAX_PATH];
|
301
|
+
_TCHAR buf[MAX_PATH+50];
|
291
302
|
m_stat = STATUS_SUCCESS;
|
292
303
|
if (!m_impl->isOpened)
|
293
304
|
{
|
@@ -304,13 +315,10 @@ bool database::open(const _TCHAR* _uri, short type, short mode,
|
|
304
315
|
}
|
305
316
|
else
|
306
317
|
{
|
307
|
-
|
308
|
-
|
309
|
-
|
310
|
-
|
311
|
-
if (m_stat)
|
312
|
-
return false;
|
313
|
-
}
|
318
|
+
nstable::getDirURI(uri(), buf);
|
319
|
+
setDir(buf);
|
320
|
+
if (m_stat)
|
321
|
+
return false;
|
314
322
|
}
|
315
323
|
if (!m_impl->dbDef)
|
316
324
|
m_impl->dbDef = new dbdef(this, type);
|
@@ -347,6 +355,20 @@ bool database::open(const _TCHAR* _uri, short type, short mode,
|
|
347
355
|
return false;
|
348
356
|
}
|
349
357
|
|
358
|
+
short database::aclReload()
|
359
|
+
{
|
360
|
+
if (!m_impl->isOpened)
|
361
|
+
return STATUS_DB_YET_OPEN;
|
362
|
+
_TCHAR buf[MAX_PATH];
|
363
|
+
const _TCHAR* p = dbname(rootDir(), buf, MAX_PATH);
|
364
|
+
if (_tcscmp(p, _T("mysql")) != 0)
|
365
|
+
return m_stat = STATUS_DB_YET_OPEN;
|
366
|
+
_TCHAR posblk[128] = { 0x00 };
|
367
|
+
uint_td buflen = 0;
|
368
|
+
return m_stat =
|
369
|
+
m_btrcallid(TD_ACL_RELOAD, posblk, NULL, &buflen, 0, 0, 0, clientID());
|
370
|
+
}
|
371
|
+
|
350
372
|
char* database::getContinuousList(int option)
|
351
373
|
{
|
352
374
|
char* fileList = (char*)malloc(64000);
|
@@ -533,7 +555,7 @@ table* database::openTable(short FileNum, short mode, bool AutoCreate,
|
|
533
555
|
}
|
534
556
|
}
|
535
557
|
if (tb->m_stat == 0)
|
536
|
-
tb->init(
|
558
|
+
tb->init(m_impl->dbDef->tableDefPtr(FileNum), FileNum, regularDir);
|
537
559
|
|
538
560
|
if ((m_stat != 0) || (tb->m_stat != 0) ||
|
539
561
|
!onTableOpened(tb, FileNum, mode, NewFile))
|
@@ -112,6 +112,7 @@ public:
|
|
112
112
|
void drop();
|
113
113
|
void dropTable(const _TCHAR* tableName);
|
114
114
|
void close();
|
115
|
+
short aclReload();
|
115
116
|
short continuous(char_td op = TD_BACKUP_START, bool inclideRepfile = false);
|
116
117
|
short assignSchemaData(dbdef* src);
|
117
118
|
short copyTableData(table* dest, table* src, bool turbo, int offset = 0,
|