transactd 3.1.0 → 3.2.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.
- checksums.yaml +4 -4
- data/bin/common/tdclc_32_3_2.dll +0 -0
- data/bin/common/{tdclc_64_3_1.dll → tdclc_64_3_2.dll} +0 -0
- data/build/swig/ruby/ruby.swg +3 -0
- data/build/swig/ruby/tdclrb_wrap.cpp +2413 -126
- data/build/swig/tdcl.i +120 -9
- data/build/tdclc/tdclc.cbproj +4 -1
- data/build/tdclc/tdclc.rc +4 -4
- data/build/tdclcpp/tdclcpp.rc +4 -4
- data/build/tdclcpp/tdclcpp_bc.cbproj +8 -1
- data/build/tdclrb/tdclrb.rc +4 -4
- data/source/bzs/db/engine/mysql/database.cpp +138 -130
- data/source/bzs/db/engine/mysql/database.h +43 -48
- data/source/bzs/db/engine/mysql/dbManager.cpp +81 -96
- data/source/bzs/db/engine/mysql/dbManager.h +13 -22
- data/source/bzs/db/engine/mysql/mysqlInternal.h +157 -291
- data/source/bzs/db/engine/mysql/mysqlProtocol.cpp +425 -0
- data/source/bzs/db/engine/mysql/mysqlProtocol.h +72 -0
- data/source/bzs/db/engine/mysql/mysqlThd.cpp +8 -6
- data/source/bzs/db/protocol/hs/hsCommandExecuter.cpp +7 -3
- data/source/bzs/db/protocol/hs/hsCommandExecuter.h +1 -0
- data/source/bzs/db/protocol/tdap/client/client.h +22 -8
- data/source/bzs/db/protocol/tdap/client/connMgr.cpp +225 -21
- data/source/bzs/db/protocol/tdap/client/connMgr.h +42 -16
- data/source/bzs/db/protocol/tdap/client/database.cpp +58 -15
- data/source/bzs/db/protocol/tdap/client/database.h +3 -3
- data/source/bzs/db/protocol/tdap/client/dbDef.cpp +93 -85
- data/source/bzs/db/protocol/tdap/client/dbDef.h +1 -2
- data/source/bzs/db/protocol/tdap/client/dllmain.cpp +9 -5
- data/source/bzs/db/protocol/tdap/client/filter.h +2 -2
- data/source/bzs/db/protocol/tdap/client/groupComp.h +2 -2
- data/source/bzs/db/protocol/tdap/client/memRecord.cpp +1 -1
- data/source/bzs/db/protocol/tdap/client/nsDatabase.cpp +71 -12
- data/source/bzs/db/protocol/tdap/client/nsDatabase.h +7 -1
- data/source/bzs/db/protocol/tdap/client/nsTable.cpp +35 -2
- data/source/bzs/db/protocol/tdap/client/nsTable.h +1 -0
- data/source/bzs/db/protocol/tdap/client/recordset.cpp +5 -1
- data/source/bzs/db/protocol/tdap/client/recordset.h +15 -0
- data/source/bzs/db/protocol/tdap/client/recordsetImple.h +21 -16
- data/source/bzs/db/protocol/tdap/client/serializer.cpp +32 -11
- data/source/bzs/db/protocol/tdap/client/serializer.h +4 -1
- data/source/bzs/db/protocol/tdap/client/sqlBuilder.cpp +3 -2
- data/source/bzs/db/protocol/tdap/client/sqlBuilder.h +3 -0
- data/source/bzs/db/protocol/tdap/client/table.cpp +18 -14
- data/source/bzs/db/protocol/tdap/client/trdboostapi.h +8 -3
- data/source/bzs/db/protocol/tdap/mysql/characterset.cpp +1 -0
- data/source/bzs/db/protocol/tdap/mysql/databaseSchema.cpp +83 -43
- data/source/bzs/db/protocol/tdap/mysql/databaseSchema.h +3 -1
- data/source/bzs/db/protocol/tdap/mysql/recordsetReader.h +7 -7
- data/source/bzs/db/protocol/tdap/mysql/tdapCommandExecuter.cpp +247 -137
- data/source/bzs/db/protocol/tdap/mysql/tdapCommandExecuter.h +9 -9
- data/source/bzs/db/protocol/tdap/tdapSchema.cpp +1 -4
- data/source/bzs/db/protocol/tdap/tdapSchema.h +3 -7
- data/source/bzs/db/protocol/tdap/tdapcapi.h +23 -3
- data/source/bzs/db/protocol/tdap/uri.h +40 -0
- data/source/bzs/db/transactd/appModule.cpp +14 -5
- data/source/bzs/db/transactd/appModule.h +10 -1
- data/source/bzs/db/transactd/connManager.cpp +93 -48
- data/source/bzs/db/transactd/connManager.h +10 -7
- data/source/bzs/db/transactd/connectionRecord.h +114 -19
- data/source/bzs/env/tstring.h +2 -0
- data/source/bzs/example/changeSchema.cpp +1 -1
- data/source/bzs/example/changeSchema_c.cpp +1 -1
- data/source/bzs/example/insertRecords.cpp +2 -1
- data/source/bzs/example/insertRecords_c.cpp +2 -1
- data/source/bzs/example/queryData.cpp +5 -2
- data/source/bzs/netsvc/server/IAppModule.h +6 -0
- data/source/bzs/test/tdclatl/test_v3.js +75 -0
- data/source/bzs/test/tdclphp/transactd_v3_Test.php +104 -7
- data/source/bzs/test/tdclrb/transactd_v3_spec.rb +84 -0
- data/source/bzs/test/trdclengn/testField.h +66 -6
- data/source/bzs/test/trdclengn/test_tdclcpp_v3.cpp +10 -1
- data/source/bzs/test/trdclengn/test_trdclengn.cpp +85 -0
- data/source/bzs/test/trdclengn/testbase.h +1 -1
- data/source/global/tdclatl/BinlogPos.cpp +64 -0
- data/source/global/tdclatl/BinlogPos.h +84 -0
- data/source/global/tdclatl/ConnMgr.cpp +285 -0
- data/source/global/tdclatl/ConnMgr.h +83 -0
- data/source/global/tdclatl/ConnRecord.cpp +123 -0
- data/source/global/tdclatl/ConnRecord.h +69 -0
- data/source/global/tdclatl/ConnRecords.cpp +57 -0
- data/source/global/tdclatl/ConnRecords.h +55 -0
- data/source/global/tdclatl/Database.cpp +36 -0
- data/source/global/tdclatl/Database.h +4 -0
- data/source/global/tdclatl/Table.cpp +14 -1
- data/source/global/tdclatl/Table.h +1 -0
- data/source/global/tdclatl/resource.h +0 -0
- data/source/global/tdclatl/tdclatl.idl +148 -4
- metadata +14 -4
- data/bin/common/tdclc_32_3_1.dll +0 -0
|
@@ -0,0 +1,425 @@
|
|
|
1
|
+
/* =================================================================
|
|
2
|
+
Copyright (C) 2016 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
|
+
/* MySQL 5.5 and Mariadb are no-rtti */
|
|
20
|
+
#ifdef __GNUC__
|
|
21
|
+
# pragma implementation "mysqlInternal.h"
|
|
22
|
+
#endif
|
|
23
|
+
|
|
24
|
+
#include "mysqlProtocol.h"
|
|
25
|
+
#include "mysqlThd.h"
|
|
26
|
+
#include <bzs/env/crosscompile.h>
|
|
27
|
+
#include <bzs/db/protocol/tdap/tdapcapi.h>
|
|
28
|
+
|
|
29
|
+
#if defined(USE_BINLOG_VAR) && (!defined(MARIADB_BASE_VERSION) && MYSQL_VERSION_ID > 50600)
|
|
30
|
+
# include "sql/binlog.h"
|
|
31
|
+
#endif
|
|
32
|
+
|
|
33
|
+
//----------------------------------------------------------------------
|
|
34
|
+
// Implement dummyProtocol
|
|
35
|
+
//----------------------------------------------------------------------
|
|
36
|
+
#if defined(MYSQL_5_7)
|
|
37
|
+
# define Protocol_mysql Protocol
|
|
38
|
+
# define CP_PROTOCOL PROTOCOL_PLUGIN
|
|
39
|
+
#else
|
|
40
|
+
# define Protocol_mysql Protocol
|
|
41
|
+
# define CP_PROTOCOL PROTOCOL_BINARY
|
|
42
|
+
#endif
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
#pragma GCC diagnostic ignored "-Woverloaded-virtual"
|
|
46
|
+
|
|
47
|
+
class dummyProtocol : public Protocol_mysql
|
|
48
|
+
{
|
|
49
|
+
THD* m_thd;
|
|
50
|
+
Protocol_mysql* m_backup;
|
|
51
|
+
|
|
52
|
+
public:
|
|
53
|
+
#if defined(MYSQL_5_7)
|
|
54
|
+
inline dummyProtocol(THD *thd_arg) : Protocol_mysql()
|
|
55
|
+
{
|
|
56
|
+
m_thd = thd_arg;
|
|
57
|
+
m_backup = m_thd->get_protocol();
|
|
58
|
+
m_thd->set_protocol(this);
|
|
59
|
+
}
|
|
60
|
+
inline virtual ~dummyProtocol()
|
|
61
|
+
{
|
|
62
|
+
m_thd->set_protocol(m_backup);
|
|
63
|
+
}
|
|
64
|
+
#else
|
|
65
|
+
inline dummyProtocol(THD *thd_arg) : Protocol_mysql(thd_arg)
|
|
66
|
+
{
|
|
67
|
+
m_thd = thd_arg;
|
|
68
|
+
m_backup = m_thd->protocol;
|
|
69
|
+
m_thd->protocol = this;
|
|
70
|
+
}
|
|
71
|
+
inline virtual ~dummyProtocol()
|
|
72
|
+
{
|
|
73
|
+
m_thd->protocol = m_backup;
|
|
74
|
+
}
|
|
75
|
+
#endif
|
|
76
|
+
bool send_result_set_metadata(List<Item> *list, uint flags){return false;}
|
|
77
|
+
virtual bool write(){return false;};
|
|
78
|
+
virtual void prepare_for_resend(){}
|
|
79
|
+
virtual bool store_null(){return false;}
|
|
80
|
+
virtual bool store_tiny(longlong from){return store_longlong(from, false);}
|
|
81
|
+
virtual bool store_short(longlong from){return store_longlong(from, false);}
|
|
82
|
+
virtual bool store_long(longlong from){return store_longlong(from, false);}
|
|
83
|
+
virtual bool store_decimal(const my_decimal *){return false;}
|
|
84
|
+
virtual bool store(float from, uint32 decimals, String *buffer){return false;}
|
|
85
|
+
virtual bool store(double from, uint32 decimals, String *buffer){return false;}
|
|
86
|
+
virtual bool store(MYSQL_TIME *time, uint precision){return false;}
|
|
87
|
+
virtual bool store_date(MYSQL_TIME *time){return false;}
|
|
88
|
+
virtual bool store_time(MYSQL_TIME *time, uint precision){return false;}
|
|
89
|
+
virtual bool store(Field *field){return false;}
|
|
90
|
+
virtual bool store(const char *from, size_t length, const CHARSET_INFO *fromcs,
|
|
91
|
+
const CHARSET_INFO* /*tocs*/){return false;}
|
|
92
|
+
|
|
93
|
+
virtual bool send_out_parameters(List<Item_param> *sp_params){return false;}
|
|
94
|
+
virtual Protocol::enum_protocol_type type(void){ return CP_PROTOCOL; };
|
|
95
|
+
#ifdef MARIADB_BASE_VERSION //Mariadb 5.5 10.0 10.1
|
|
96
|
+
virtual bool store(MYSQL_TIME *time, int decimals){return false;}
|
|
97
|
+
virtual bool store_time(MYSQL_TIME *time, int decimals){ return false;}
|
|
98
|
+
#elif defined(MYSQL_5_5)
|
|
99
|
+
virtual bool store_time(MYSQL_TIME *time){return true;};
|
|
100
|
+
virtual bool store(MYSQL_TIME *time){return true;}
|
|
101
|
+
virtual bool store(const char *from, size_t length,
|
|
102
|
+
CHARSET_INFO *fromcs, CHARSET_INFO *tocs){return false;}
|
|
103
|
+
#elif defined(MYSQL_5_7)
|
|
104
|
+
bool store_decimal(const my_decimal *, uint, uint){ return true; }
|
|
105
|
+
bool store(Proto_field *){ return true; }
|
|
106
|
+
void start_row(){}
|
|
107
|
+
int read_packet(void){ return 0; }
|
|
108
|
+
int get_command(COM_DATA *, enum_server_command *){ return m_thd->lex->sql_command; }
|
|
109
|
+
enum_vio_type connection_type(void){ return VIO_TYPE_PLUGIN; }
|
|
110
|
+
ulong get_client_capabilities(void){ return 0; }
|
|
111
|
+
bool has_client_capability(unsigned long){ return false; }
|
|
112
|
+
bool connection_alive(void){ return false; }
|
|
113
|
+
bool end_row(void){ return false; }
|
|
114
|
+
void abort_row(void){}
|
|
115
|
+
void end_partial_result_set(void){}
|
|
116
|
+
int shutdown(bool){ return 0; }
|
|
117
|
+
SSL_handle get_ssl(void){ return NULL; }
|
|
118
|
+
uint get_rw_status(void){ return 0; }
|
|
119
|
+
bool get_compression(void){ return false; }
|
|
120
|
+
bool start_result_metadata(uint, uint, const CHARSET_INFO *){ return false; }
|
|
121
|
+
bool send_field_metadata(Send_field *, const CHARSET_INFO *){ return false; }
|
|
122
|
+
bool end_result_metadata(void){ return false; }
|
|
123
|
+
bool send_ok(uint, uint, ulonglong, ulonglong, const char *){ return false; }
|
|
124
|
+
bool send_eof(uint, uint){ return false; }
|
|
125
|
+
bool send_error(uint, const char *, const char *){ return false; }
|
|
126
|
+
#endif
|
|
127
|
+
};
|
|
128
|
+
|
|
129
|
+
//----------------------------------------------------------------------
|
|
130
|
+
// class masterStatus for windows mysql 5.6 only
|
|
131
|
+
//----------------------------------------------------------------------
|
|
132
|
+
#if defined(NOTUSE_BINLOG_VAR)
|
|
133
|
+
class masterStatus : public dummyProtocol
|
|
134
|
+
{
|
|
135
|
+
binlogPos* m_bpos;
|
|
136
|
+
bool m_writed;
|
|
137
|
+
public:
|
|
138
|
+
inline masterStatus(THD *thd_arg, binlogPos* bpos) :
|
|
139
|
+
dummyProtocol(thd_arg), m_bpos(bpos), m_writed(false) {}
|
|
140
|
+
bool store_longlong(longlong from, bool unsigned_flag)
|
|
141
|
+
{
|
|
142
|
+
m_bpos->pos = (ulonglong)from;
|
|
143
|
+
m_bpos->type = REPL_POSTYPE_POS;
|
|
144
|
+
return false;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
#if (MYSQL_VERSION_ID < 50600 || defined(MARIADB_BASE_VERSION)) // mariadb 5.5
|
|
148
|
+
bool store(const char *from, size_t length, CHARSET_INFO *cs)
|
|
149
|
+
{
|
|
150
|
+
if (!m_writed)
|
|
151
|
+
{
|
|
152
|
+
strncpy(m_bpos->filename, from, BINLOGNAME_SIZE);
|
|
153
|
+
m_writed = true;
|
|
154
|
+
}
|
|
155
|
+
return false;
|
|
156
|
+
}
|
|
157
|
+
#else
|
|
158
|
+
bool store(const char *from, size_t length, const CHARSET_INFO *cs)
|
|
159
|
+
{
|
|
160
|
+
if (!m_writed)
|
|
161
|
+
{
|
|
162
|
+
strncpy(m_bpos->filename, from, BINLOGNAME_SIZE);
|
|
163
|
+
m_writed = true;
|
|
164
|
+
}
|
|
165
|
+
return false;
|
|
166
|
+
}
|
|
167
|
+
#endif
|
|
168
|
+
};
|
|
169
|
+
#endif // NOTUSE_BINLOG_VAR
|
|
170
|
+
|
|
171
|
+
//----------------------------------------------------------------------
|
|
172
|
+
// class safe_commit_lock commit lock for binlogPos
|
|
173
|
+
//----------------------------------------------------------------------
|
|
174
|
+
safe_commit_lock::safe_commit_lock(THD* thd): m_thd(thd), m_commits_lock(NULL)
|
|
175
|
+
{
|
|
176
|
+
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
bool safe_commit_lock::lock()
|
|
180
|
+
{
|
|
181
|
+
if (m_thd)
|
|
182
|
+
{
|
|
183
|
+
MDL_request mdl_request;
|
|
184
|
+
#if ((MYSQL_VERSION_NUM > 50700) && !defined(MARIADB_BASE_VERSION))
|
|
185
|
+
mdl_request.init_with_source(MDL_key::COMMIT, "", "", MDL_SHARED, MDL_EXPLICIT, __FILE__, __LINE__);
|
|
186
|
+
#else
|
|
187
|
+
mdl_request.init(MDL_key::COMMIT, "", "", MDL_SHARED, MDL_EXPLICIT);
|
|
188
|
+
#endif
|
|
189
|
+
if (m_thd->mdl_context.acquire_lock(&mdl_request,
|
|
190
|
+
m_thd->variables.lock_wait_timeout))
|
|
191
|
+
return false;
|
|
192
|
+
m_commits_lock = mdl_request.ticket;
|
|
193
|
+
}
|
|
194
|
+
return true;
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
safe_commit_lock::~safe_commit_lock()
|
|
198
|
+
{
|
|
199
|
+
if (m_commits_lock)
|
|
200
|
+
{
|
|
201
|
+
m_thd->mdl_context.release_lock(m_commits_lock);
|
|
202
|
+
m_commits_lock= NULL;
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
|
|
207
|
+
#ifdef NOTUSE_BINLOG_VAR
|
|
208
|
+
inline short getBinlogPosInternal(THD* currentThd, binlogPos* bpos, THD* tmpThd)
|
|
209
|
+
{
|
|
210
|
+
short result = 0;
|
|
211
|
+
{
|
|
212
|
+
attachThd(tmpThd);
|
|
213
|
+
copyGrant(tmpThd, currentThd, NULL);
|
|
214
|
+
masterStatus p(tmpThd, bpos);
|
|
215
|
+
cp_query_command(tmpThd, "show master status");
|
|
216
|
+
if (tmpThd->is_error())
|
|
217
|
+
result = tmpThd->cp_get_sql_error();
|
|
218
|
+
cp_lex_clear(tmpThd);
|
|
219
|
+
}
|
|
220
|
+
attachThd(currentThd);
|
|
221
|
+
return result;
|
|
222
|
+
}
|
|
223
|
+
#endif
|
|
224
|
+
|
|
225
|
+
#ifdef USE_BINLOG_GTID
|
|
226
|
+
inline short getBinlogPosInternal(THD* currentThd, binlogPos* bpos, THD* /*tmpThd*/)
|
|
227
|
+
{
|
|
228
|
+
if (mysql_bin_log.is_open())
|
|
229
|
+
{
|
|
230
|
+
rpl_gtid gtid;
|
|
231
|
+
bpos->type = REPL_POSTYPE_MARIA_GTID;
|
|
232
|
+
if (mysql_bin_log.lookup_domain_in_binlog_state(currentThd->variables.gtid_domain_id, >id))
|
|
233
|
+
{
|
|
234
|
+
sprintf_s(bpos->gtid, GTID_SIZE, "%u-%u-%llu", gtid.domain_id, gtid.server_id, gtid.seq_no);
|
|
235
|
+
size_t dir_len = dirname_length(mysql_bin_log.get_log_fname());
|
|
236
|
+
strncpy(bpos->filename, mysql_bin_log.get_log_fname() + dir_len, BINLOGNAME_SIZE);
|
|
237
|
+
bpos->pos = my_b_tell(mysql_bin_log.get_log_file());
|
|
238
|
+
bpos->filename[BINLOGNAME_SIZE-1] = 0x00;
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
return 0;
|
|
242
|
+
}
|
|
243
|
+
#endif
|
|
244
|
+
|
|
245
|
+
#ifdef USE_BINLOG_VAR
|
|
246
|
+
// Linux MySQL can access to the mysql_bin_log variable
|
|
247
|
+
inline short getBinlogPosInternal(THD* , binlogPos* bpos, THD* /*tmpThd*/)
|
|
248
|
+
{
|
|
249
|
+
if (mysql_bin_log.is_open())
|
|
250
|
+
{
|
|
251
|
+
size_t dir_len = dirname_length(mysql_bin_log.get_log_fname());
|
|
252
|
+
strncpy(bpos->filename, mysql_bin_log.get_log_fname() + dir_len, BINLOGNAME_SIZE);
|
|
253
|
+
bpos->pos = my_b_tell(mysql_bin_log.get_log_file());
|
|
254
|
+
bpos->filename[BINLOGNAME_SIZE-1] = 0x00;
|
|
255
|
+
bpos->type = REPL_POSTYPE_POS;
|
|
256
|
+
}
|
|
257
|
+
return 0;
|
|
258
|
+
}
|
|
259
|
+
#endif //USE_BINLOG_VAR
|
|
260
|
+
|
|
261
|
+
short getBinlogPos(THD* thd, binlogPos* bpos, THD* tmpThd)
|
|
262
|
+
{
|
|
263
|
+
#ifndef NOTUSE_BINLOG_VAR
|
|
264
|
+
safe_mysql_mutex_lock lck(mysql_bin_log.get_log_lock());
|
|
265
|
+
#endif
|
|
266
|
+
return getBinlogPosInternal(thd, bpos, tmpThd);
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
int execSql(THD* thd, const char* sql)
|
|
270
|
+
{
|
|
271
|
+
thd->variables.lock_wait_timeout = OPEN_TABLE_TIMEOUT_SEC;
|
|
272
|
+
thd->clear_error();
|
|
273
|
+
int result = cp_query_command(thd, (char*)sql);
|
|
274
|
+
if (thd->is_error())
|
|
275
|
+
result = thd->cp_get_sql_error();
|
|
276
|
+
cp_lex_clear(thd); // reset values for insert
|
|
277
|
+
return result;
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
//----------------------------------------------------------------------
|
|
281
|
+
// slaveStatus
|
|
282
|
+
//----------------------------------------------------------------------
|
|
283
|
+
using namespace bzs::db::transactd;
|
|
284
|
+
class slaveStatus : public dummyProtocol
|
|
285
|
+
{
|
|
286
|
+
connection::records& m_records;
|
|
287
|
+
connection::record& getRec()
|
|
288
|
+
{
|
|
289
|
+
m_records.push_back(connection::record());
|
|
290
|
+
return m_records[m_records.size() - 1];
|
|
291
|
+
}
|
|
292
|
+
public:
|
|
293
|
+
inline slaveStatus(THD *thd_arg, connection::records& recs) :
|
|
294
|
+
dummyProtocol(thd_arg), m_records(recs)
|
|
295
|
+
{
|
|
296
|
+
m_records.clear();
|
|
297
|
+
}
|
|
298
|
+
bool store_longlong(longlong from, bool unsigned_flag)
|
|
299
|
+
{
|
|
300
|
+
connection::record& rec = getRec();
|
|
301
|
+
rec.type = 0;
|
|
302
|
+
rec.longValue = from;
|
|
303
|
+
return false;
|
|
304
|
+
}
|
|
305
|
+
bool store_null()
|
|
306
|
+
{
|
|
307
|
+
connection::record& rec = getRec();
|
|
308
|
+
rec.type = 1;
|
|
309
|
+
strncpy(rec.value, "NULL", CON_REC_VALUE_SIZE);
|
|
310
|
+
return false;
|
|
311
|
+
}
|
|
312
|
+
#if (MYSQL_VERSION_ID < 50600 || defined(MARIADB_BASE_VERSION)) // MySQL 5.5
|
|
313
|
+
bool store(const char *from, size_t length, CHARSET_INFO *cs)
|
|
314
|
+
{
|
|
315
|
+
connection::record& rec = getRec();
|
|
316
|
+
rec.type = 1;
|
|
317
|
+
if (length && from)
|
|
318
|
+
strncpy(rec.value, from, CON_REC_VALUE_SIZE);
|
|
319
|
+
return false;
|
|
320
|
+
}
|
|
321
|
+
#else
|
|
322
|
+
bool store(const char *from, size_t length, const CHARSET_INFO *cs)
|
|
323
|
+
{
|
|
324
|
+
connection::record& rec = getRec();
|
|
325
|
+
rec.type = 1;
|
|
326
|
+
if (length && from)
|
|
327
|
+
strncpy(rec.value, from, CON_REC_VALUE_SIZE);
|
|
328
|
+
return false;
|
|
329
|
+
}
|
|
330
|
+
#endif
|
|
331
|
+
};
|
|
332
|
+
|
|
333
|
+
int getSlaveStatus(THD* thd, connection::records& recs)
|
|
334
|
+
{
|
|
335
|
+
slaveStatus ss(thd, recs);
|
|
336
|
+
return execSql(thd, "show slave status");
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
#pragma GCC diagnostic warning "-Woverloaded-virtual"
|
|
340
|
+
|
|
341
|
+
|
|
342
|
+
//----------------------------------------------------------------------
|
|
343
|
+
// database list
|
|
344
|
+
//----------------------------------------------------------------------
|
|
345
|
+
inline void appenDbList(connection::records& recs, LEX_STRING* db_name)
|
|
346
|
+
{
|
|
347
|
+
recs.push_back(connection::record());
|
|
348
|
+
connection::record& rec = recs[recs.size() - 1];
|
|
349
|
+
strncpy(rec.name, db_name->str, 64);
|
|
350
|
+
rec.name[64] = 0x00;
|
|
351
|
+
}
|
|
352
|
+
|
|
353
|
+
void readDbList(THD* thd, connection::records& recs)
|
|
354
|
+
{
|
|
355
|
+
SQL_Strings files;
|
|
356
|
+
db_list(thd, &files);
|
|
357
|
+
#if (defined(MARIADB_10_0) || defined(MARIADB_10_1))
|
|
358
|
+
for (int i = 0; i < (int)files.elements(); ++i)
|
|
359
|
+
appenDbList(recs, files.at(i));
|
|
360
|
+
#else
|
|
361
|
+
List_iterator_fast<LEX_STRING> it(files);
|
|
362
|
+
LEX_STRING* db_name;
|
|
363
|
+
while ((db_name = it++))
|
|
364
|
+
appenDbList(recs, db_name);
|
|
365
|
+
#endif
|
|
366
|
+
}
|
|
367
|
+
|
|
368
|
+
//----------------------------------------------------------------------
|
|
369
|
+
// security
|
|
370
|
+
//----------------------------------------------------------------------
|
|
371
|
+
|
|
372
|
+
bool setGrant(THD* thd, const char* host, const char* user, const char* db)
|
|
373
|
+
{
|
|
374
|
+
// sctx->master_access and sctx->db_access
|
|
375
|
+
return (acl_getroot(cp_security_ctx(thd), cp_strdup(user, MYF(0)),
|
|
376
|
+
cp_strdup(host, MYF(0)), cp_strdup(host, MYF(0)), (char*)db)) == false;
|
|
377
|
+
}
|
|
378
|
+
|
|
379
|
+
bool copyGrant(THD* thd, THD* thdSrc, const char* db)
|
|
380
|
+
{
|
|
381
|
+
Security_context* sctx = cp_security_ctx(thdSrc);
|
|
382
|
+
if (sctx->cp_master_accsess() == (ulong)~NO_ACCESS)
|
|
383
|
+
{
|
|
384
|
+
cp_security_ctx(thd)->skip_grants();
|
|
385
|
+
return true;
|
|
386
|
+
}
|
|
387
|
+
return setGrant(thd, sctx->cp_priv_host(), sctx->cp_priv_user(), db);
|
|
388
|
+
}
|
|
389
|
+
|
|
390
|
+
void setDbName(THD* thd, const char* name)
|
|
391
|
+
{
|
|
392
|
+
cp_set_db(thd, name);
|
|
393
|
+
}
|
|
394
|
+
|
|
395
|
+
/*
|
|
396
|
+
class safe_global_read_lock
|
|
397
|
+
{
|
|
398
|
+
THD* m_thd;
|
|
399
|
+
public:
|
|
400
|
+
safe_global_read_lock(THD* thd): m_thd(thd){}
|
|
401
|
+
bool lock()
|
|
402
|
+
{
|
|
403
|
+
if (m_thd->global_read_lock.lock_global_read_lock(m_thd))
|
|
404
|
+
{
|
|
405
|
+
m_thd = NULL;
|
|
406
|
+
return false;
|
|
407
|
+
}
|
|
408
|
+
#ifdef NOTUSE_BINLOG_VAR
|
|
409
|
+
close_cached_tables(NULL, NULL, FALSE , 50000000L);
|
|
410
|
+
if (m_thd->global_read_lock.make_global_read_lock_block_commit(m_thd))
|
|
411
|
+
{
|
|
412
|
+
m_thd->global_read_lock.unlock_global_read_lock(m_thd);
|
|
413
|
+
m_thd = NULL;
|
|
414
|
+
return false;
|
|
415
|
+
}
|
|
416
|
+
#endif
|
|
417
|
+
return true;
|
|
418
|
+
}
|
|
419
|
+
~safe_global_read_lock()
|
|
420
|
+
{
|
|
421
|
+
if (m_thd)
|
|
422
|
+
m_thd->global_read_lock.unlock_global_read_lock(m_thd);
|
|
423
|
+
}
|
|
424
|
+
};*/
|
|
425
|
+
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
#ifndef BZS_DB_ENGINE_MYSQL_MYSQLPROTOCOL_H
|
|
2
|
+
#define BZS_DB_ENGINE_MYSQL_MYSQLPROTOCOL_H
|
|
3
|
+
/* =================================================================
|
|
4
|
+
Copyright (C) 2016 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
|
+
#include "mysqlInternal.h"
|
|
22
|
+
#include <bzs/env/compiler.h>
|
|
23
|
+
#include <bzs/db/transactd/connectionRecord.h>
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
#if (MYSQL_VERSION_ID > 100000)
|
|
27
|
+
# define USE_BINLOG_GTID 1 // like 0-1-50
|
|
28
|
+
#elif (!defined(_WIN32) || MYSQL_VERSION_ID > 50700 || MYSQL_VERSION_ID < 50600) // Linux or MySQL 5.5 5.7
|
|
29
|
+
# define USE_BINLOG_VAR 1
|
|
30
|
+
#else // MySQL 5.6 on windows On windows MySQL 5.6 can not access mysql_bin_log variable
|
|
31
|
+
# define NOTUSE_BINLOG_VAR 1
|
|
32
|
+
#endif
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
// REPL_POS_TYPE
|
|
36
|
+
#define BINLOGNAME_SIZE 119
|
|
37
|
+
#define GTID_SIZE 64
|
|
38
|
+
|
|
39
|
+
#define REPL_POSTYPE_MARIA_GTID 1 // see tdapapi.h
|
|
40
|
+
#define REPL_POSTYPE_POS 2 // see tdapapi.h
|
|
41
|
+
|
|
42
|
+
#define OPEN_TABLE_TIMEOUT_SEC 2
|
|
43
|
+
|
|
44
|
+
pragma_pack1
|
|
45
|
+
struct binlogPos
|
|
46
|
+
{
|
|
47
|
+
my_off_t pos;
|
|
48
|
+
char type;
|
|
49
|
+
char filename[BINLOGNAME_SIZE];
|
|
50
|
+
char gtid[GTID_SIZE];
|
|
51
|
+
};
|
|
52
|
+
pragma_pop
|
|
53
|
+
|
|
54
|
+
class safe_commit_lock
|
|
55
|
+
{
|
|
56
|
+
THD* m_thd;
|
|
57
|
+
MDL_ticket* m_commits_lock;
|
|
58
|
+
public:
|
|
59
|
+
safe_commit_lock(THD* thd);
|
|
60
|
+
bool lock();
|
|
61
|
+
~safe_commit_lock();
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
short getBinlogPos(THD* thd, binlogPos* pos, THD* tmpThd);
|
|
65
|
+
int getSlaveStatus(THD* thd, bzs::db::transactd::connection::records& recs);
|
|
66
|
+
int execSql(THD* thd, const char* sql);
|
|
67
|
+
void readDbList(THD* thd, bzs::db::transactd::connection::records& recs);
|
|
68
|
+
bool setGrant(THD* thd, const char* host, const char* user, const char* db);
|
|
69
|
+
bool copyGrant(THD* thd, THD* thdSrc, const char* db);
|
|
70
|
+
void setDbName(THD* thd, const char* name);
|
|
71
|
+
|
|
72
|
+
#endif // BZS_DB_ENGINE_MYSQL_MYSQLPROTOCOL_H
|
|
@@ -151,8 +151,6 @@ THD* buildTHD()
|
|
|
151
151
|
g_lock_wait_timeout);
|
|
152
152
|
cp_query_command(thd, tmp);
|
|
153
153
|
|
|
154
|
-
|
|
155
|
-
cp_set_db(thd, td_strdup("bizstation", MYF(0)));
|
|
156
154
|
if (thd->variables.sql_log_bin)
|
|
157
155
|
thd->set_current_stmt_binlog_format_row();
|
|
158
156
|
return thd;
|
|
@@ -192,8 +190,12 @@ THD* createThdForThread()
|
|
|
192
190
|
|
|
193
191
|
void deleteThdForThread(THD* thd)
|
|
194
192
|
{
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
193
|
+
try
|
|
194
|
+
{
|
|
195
|
+
cp_restore_globals(thd);
|
|
196
|
+
cp_thd_release_resources(thd);
|
|
197
|
+
cp_dec_dbcount(thd);
|
|
198
|
+
releaseTHD(thd);
|
|
199
|
+
}
|
|
200
|
+
catch(...) {};
|
|
199
201
|
}
|
|
@@ -234,6 +234,10 @@ inline void setKeyValues(request& req, engine::mysql::table* tb, int index)
|
|
|
234
234
|
tb->setKeyValues(req.table.key.values, -1);
|
|
235
235
|
}
|
|
236
236
|
|
|
237
|
+
dbExecuter::dbExecuter(netsvc::server::IAppModule* mod)
|
|
238
|
+
:engine::mysql::dbManager(mod){}
|
|
239
|
+
|
|
240
|
+
|
|
237
241
|
void dbExecuter::doRecordOperation(request& req, engine::mysql::table* tb,
|
|
238
242
|
resultBuffer& buf, changeFunc func)
|
|
239
243
|
{
|
|
@@ -307,7 +311,7 @@ int dbExecuter::commandExec(std::vector<request>& requests,
|
|
|
307
311
|
checkNewHandle(req.handle);
|
|
308
312
|
bool created;
|
|
309
313
|
database* db = getDatabase(req.db.name, 0 /*cid*/, created);
|
|
310
|
-
m_tb = db->openTable(req.table.name, req.table.openMode, NULL);
|
|
314
|
+
m_tb = db->openTable(req.table.name, req.table.openMode, NULL, "");
|
|
311
315
|
if (m_tb)
|
|
312
316
|
{
|
|
313
317
|
addHandle(getDatabaseID(0 /*cid*/), m_tb->id(), req.handle);
|
|
@@ -570,8 +574,8 @@ inline void setFilterVal(const std::string& src, int& parseMode, request* req)
|
|
|
570
574
|
parseMode = PARSEREAD_FL_TYPE;
|
|
571
575
|
}
|
|
572
576
|
|
|
573
|
-
commandExecuter::commandExecuter(netsvc::server::IAppModule*
|
|
574
|
-
: m_dbExec(new dbExecuter())
|
|
577
|
+
commandExecuter::commandExecuter(netsvc::server::IAppModule* mod)
|
|
578
|
+
: m_dbExec(new dbExecuter(mod))
|
|
575
579
|
{
|
|
576
580
|
}
|
|
577
581
|
|
|
@@ -188,6 +188,7 @@ class dbExecuter : public engine::mysql::dbManager
|
|
|
188
188
|
resultBuffer& buf, changeFunc func);
|
|
189
189
|
|
|
190
190
|
public:
|
|
191
|
+
dbExecuter(netsvc::server::IAppModule* mod);
|
|
191
192
|
int commandExec(std::vector<request>& requests,
|
|
192
193
|
netsvc::server::netWriter* nw);
|
|
193
194
|
int errorCode(int ha_error) { return 0; };
|
|
@@ -82,6 +82,13 @@ class client
|
|
|
82
82
|
|
|
83
83
|
std::vector<char> m_sendbuf;
|
|
84
84
|
|
|
85
|
+
bool checkVersion(int major, int ninor)
|
|
86
|
+
{
|
|
87
|
+
const clsrv_ver* v = ver();
|
|
88
|
+
if (!v) return false;
|
|
89
|
+
return (v->srvMajor > major) || ((v->srvMajor == major) && (v->srvMinor >= ninor));
|
|
90
|
+
}
|
|
91
|
+
|
|
85
92
|
bool checkVersion(clsrv_ver& ver)
|
|
86
93
|
{
|
|
87
94
|
if ((ver.srvMajor < 2) || ((ver.srvMajor == 2) && (ver.srvMinor < 3)))
|
|
@@ -231,11 +238,7 @@ public:
|
|
|
231
238
|
inline bool isSupportFunction(short op)
|
|
232
239
|
{
|
|
233
240
|
if (op == TD_GET_SCHEMA)
|
|
234
|
-
|
|
235
|
-
const clsrv_ver* v = ver();
|
|
236
|
-
if (!v) return false;
|
|
237
|
-
return (v->srvMajor > 2) || ((v->srvMajor == 2) && (v->srvMinor >= 6));
|
|
238
|
-
}
|
|
241
|
+
return checkVersion(2, 6);
|
|
239
242
|
return false;
|
|
240
243
|
}
|
|
241
244
|
|
|
@@ -366,8 +369,12 @@ public:
|
|
|
366
369
|
else if ((m_req.keyNum == CR_SUBOP_BY_SQL) ||
|
|
367
370
|
(m_req.keyNum == CR_SUBOP_BY_SQL_NOCKECK)) // make by sql
|
|
368
371
|
{
|
|
369
|
-
m_sql = (char*)m_req.data;
|
|
370
372
|
m_req.keyNum -= 4; // -1= exists check 0 = no exists check
|
|
373
|
+
if (charsetIndexServer != CHARSET_UTF8 && charsetIndexServer != CHARSET_UTF8B4)
|
|
374
|
+
m_sql = sqlBuilder::convertString(mysql::codePage(charsetIndexServer), 65001,
|
|
375
|
+
(const char*)m_req.data);
|
|
376
|
+
else
|
|
377
|
+
m_sql = (const char*)m_req.data;
|
|
371
378
|
}
|
|
372
379
|
else
|
|
373
380
|
m_sql = sqlBuilder::sqlCreateTable(name.c_str(), (fileSpec*)m_req.data,
|
|
@@ -420,7 +427,13 @@ public:
|
|
|
420
427
|
|
|
421
428
|
inline void cmdConnect()
|
|
422
429
|
{
|
|
423
|
-
if
|
|
430
|
+
if(m_req.keyNum == LG_SUBOP_ASSOCIATE)
|
|
431
|
+
{
|
|
432
|
+
clientID* cid = (clientID*)m_req.keybuf;
|
|
433
|
+
cid->con->addref();
|
|
434
|
+
setCon(cid->con);
|
|
435
|
+
}
|
|
436
|
+
else if ((m_req.keyNum == LG_SUBOP_CONNECT) ||
|
|
424
437
|
(m_req.keyNum == LG_SUBOP_NEWCONNECT))
|
|
425
438
|
{
|
|
426
439
|
if (con())
|
|
@@ -462,7 +475,8 @@ public:
|
|
|
462
475
|
{
|
|
463
476
|
if (con())
|
|
464
477
|
con()->cleanup();
|
|
465
|
-
}
|
|
478
|
+
}else
|
|
479
|
+
m_preResult = STATUS_NOSUPPORT_OP;
|
|
466
480
|
|
|
467
481
|
m_req.paramMask = P_MASK_KEYONLY;
|
|
468
482
|
}
|