mysql_native_connection_wrapper.cpp
10.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
/*
Copyright (c) 2009, 2010, Oracle and/or its affiliates. All rights reserved.
The MySQL Connector/C++ is licensed under the terms of the GPLv2
<http://www.gnu.org/licenses/old-licenses/gpl-2.0.html>, like most
MySQL Connectors. There are special exceptions to the terms and
conditions of the GPLv2 as it is applied to this software, see the
FLOSS License Exception
<http://www.mysql.com/about/legal/licensing/foss-exception.html>.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published
by the Free Software Foundation; version 2 of the License.
This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include <sqlstring.h>
#include <exception.h>
#include <boost/scoped_array.hpp>
#include "../mysql_util.h"
#include "../mysql_connection_options.h"
#include "mysql_client_api.h"
#include "mysql_native_resultset_wrapper.h"
#include "mysql_native_statement_wrapper.h"
#include "mysql_native_connection_wrapper.h"
namespace sql
{
namespace mysql
{
namespace NativeAPI
{
/* {{{ MySQL_NativeConnectionWrapper::MySQL_NativeConnectionWrapper() */
MySQL_NativeConnectionWrapper::MySQL_NativeConnectionWrapper(boost::shared_ptr<IMySQLCAPI> _api)
: api(_api), mysql(api->init(NULL))
{
if (mysql == NULL) {
throw sql::SQLException("Insufficient memory: cannot create MySQL handle using mysql_init()");
}
}
/* }}} */
/* {{{ MySQL_NativeConnectionWrapper::~MySQL_NativeConnectionWrapper() */
MySQL_NativeConnectionWrapper::~MySQL_NativeConnectionWrapper()
{
api->close(mysql);
}
/* }}} */
/* {{{ MySQL_NativeConnectionWrapper::affected_rows() */
uint64_t
MySQL_NativeConnectionWrapper::affected_rows()
{
return api->affected_rows(mysql);
}
/* }}} */
/* {{{ MySQL_NativeConnectionWrapper::autocommit() */
bool
MySQL_NativeConnectionWrapper::autocommit(bool mode)
{
return (api->autocommit(mysql, mode) != '\0');
}
/* }}} */
/* {{{ MySQL_NativeConnectionWrapper::connect() */
bool
MySQL_NativeConnectionWrapper::connect(const ::sql::SQLString& host,
const ::sql::SQLString& user,
const ::sql::SQLString& passwd,
const ::sql::SQLString& db,
unsigned int port,
const ::sql::SQLString& socket_or_pipe,
unsigned long client_flag)
{
return (NULL != api->real_connect(mysql, nullIfEmpty(host), user.c_str(),
nullIfEmpty(passwd),
nullIfEmpty(db), port,
nullIfEmpty(socket_or_pipe), client_flag));
}
/* }}} */
/* {{{ MySQL_NativeConnectionWrapper::commit() */
bool
MySQL_NativeConnectionWrapper::commit()
{
return (api->commit(mysql) != '\0');
}
/* }}} */
/* {{{ MySQL_NativeConnectionWrapper::debug() */
void
MySQL_NativeConnectionWrapper::debug(const SQLString& debug)
{
api->debug(debug.c_str());
}
/* }}} */
/* {{{ MySQL_NativeConnectionWrapper::errNo() */
unsigned int
MySQL_NativeConnectionWrapper::errNo()
{
return api->mysql_errno(mysql);
}
/* }}} */
/* {{{ MySQL_NativeConnectionWrapper::escapeString() */
SQLString
MySQL_NativeConnectionWrapper::escapeString(const SQLString& s)
{
boost::scoped_array< char > buffer(new char[s.length() * 2 + 1]);
if (!buffer.get()) {
return "";
}
unsigned long return_len = api->real_escape_string(mysql, buffer.get(), s.c_str(), (unsigned long) s.length());
return sql::SQLString(buffer.get(), return_len);
}
/* }}} */
/* {{{ MySQL_NativeConnectionWrapper::error() */
SQLString
MySQL_NativeConnectionWrapper::error()
{
return api->error(mysql);
}
/* }}} */
/* {{{ MySQL_NativeConnectionWrapper::field_count() */
unsigned int
MySQL_NativeConnectionWrapper::field_count()
{
return api->field_count(mysql);
}
/* }}} */
/* {{{ MySQL_NativeConnectionWrapper::get_client_version() */
unsigned long
MySQL_NativeConnectionWrapper::get_client_version()
{
return api->get_client_version();
}
/* }}} */
/* {{{ MySQL_NativeConnectionWrapper::get_server_info() */
const SQLString&
MySQL_NativeConnectionWrapper::get_server_info()
{
serverInfo = api->get_server_info(mysql);
return serverInfo;
}
/* }}} */
/* {{{ MySQL_NativeConnectionWrapper::get_server_version() */
unsigned long
MySQL_NativeConnectionWrapper::get_server_version()
{
return api->get_server_version(mysql);
}
/* }}} */
/* {{{ MySQL_NativeConnectionWrapper::more_results() */
bool
MySQL_NativeConnectionWrapper::more_results()
{
return (api->more_results(mysql) != '\0');
}
/* }}} */
/* {{{ MySQL_NativeConnectionWrapper::next_result() */
int
MySQL_NativeConnectionWrapper::next_result()
{
return api->next_result(mysql);
}
/* }}} */
/* {{{ MySQL_NativeConnectionWrapper::options() */
int
MySQL_NativeConnectionWrapper::options(::sql::mysql::MySQL_Connection_Options option, const void* value)
{
return api->options(mysql, static_cast< mysql_option >(option), value);
}
/* }}} */
/* {{{ MySQL_NativeConnectionWrapper::query() */
int
MySQL_NativeConnectionWrapper::query(const SQLString& stmt_str)
{
return api->real_query(mysql, stmt_str.c_str(), stmt_str.length());
}
/* }}} */
/* {{{ MySQL_NativeConnectionWrapper::ping() */
int
MySQL_NativeConnectionWrapper::ping()
{
return api->ping(mysql);
}
/* }}} */
/* {{{ MySQL_NativeConnectionWrapper::rollback() */
bool
MySQL_NativeConnectionWrapper::rollback()
{
return (api->rollback(mysql) != '\0');
}
/* }}} */
/* {{{ MySQL_NativeConnectionWrapper::sqlstate() */
SQLString
MySQL_NativeConnectionWrapper::sqlstate()
{
return api->sqlstate(mysql);
}
/* }}} */
/* {{{ MySQL_NativeConnectionWrapper::ssl_set() */
bool
MySQL_NativeConnectionWrapper::ssl_set(const SQLString& key,
const SQLString& cert,
const SQLString& ca,
const SQLString& capath,
const SQLString& cipher)
{
return ('\0' != api->ssl_set(mysql, nullIfEmpty(key), nullIfEmpty(cert),
nullIfEmpty(ca), nullIfEmpty(capath), nullIfEmpty(cipher)));
}
/* }}} */
/* {{{ MySQL_NativeConnectionWrapper::store_result() */
NativeResultsetWrapper*
MySQL_NativeConnectionWrapper::store_result()
{
::st_mysql_res* raw = api->store_result(mysql);
if (raw == NULL) {
/*CPP_ERR_FMT("Error during %s_result : %d:(%s) %s", resultset_type == sql::ResultSet::TYPE_FORWARD_ONLY? "use":"store",
this->errNo(), this->sqlstate(), this->error());*/
return NULL;
}
return new MySQL_NativeResultsetWrapper(raw, api);
}
/* }}} */
/* {{{ MySQL_NativeConnectionWrapper::use_result() */
NativeResultsetWrapper*
MySQL_NativeConnectionWrapper::use_result()
{
::st_mysql_res* raw = api->use_result(mysql);
if (raw == NULL) {
/*CPP_ERR_FMT("Error during %s_result : %d:(%s) %s", resultset_type == sql::ResultSet::TYPE_FORWARD_ONLY? "use":"store",
this->errNo(), this->sqlstate(), this->error());*/
return NULL;
}
return new MySQL_NativeResultsetWrapper(raw, api);
}
/* }}} */
/* {{{ MySQL_NativeConnectionWrapper::stmt_init() */
NativeStatementWrapper&
MySQL_NativeConnectionWrapper::stmt_init()
{
::st_mysql_stmt* raw = api->stmt_init(mysql);
if (raw == NULL) {
/*CPP_ERR_FMT("No statement : %d:(%s) %s", e->errNo(), proxy->sqlstate(), proxy->error());*/
::sql::mysql::util::throwSQLException(*this);
}
return *(new MySQL_NativeStatementWrapper(raw, api, this));
}
/* }}} */
} /* namespace NativeAPI */
} /* namespace mysql */
} /* namespace sql */
/*
* Local variables:
* tab-width: 4
* c-basic-offset: 4
* End:
* vim600: noet sw=4 ts=4 fdm=marker
* vim<600: noet sw=4 ts=4
*/