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 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375
|
/***********************************************************************
options.cpp - Implements the Option class hierarchy.
Copyright © 2007-2009, 2018 by Educational Technology Resources, Inc.
Others may also hold copyrights on code in this file. See the
CREDITS file in the top directory of the distribution for details.
This file is part of MySQL++.
MySQL++ is free software; you can redistribute it and/or modify it
under the terms of the GNU Lesser General Public License as published
by the Free Software Foundation; either version 2.1 of the License, or
(at your option) any later version.
MySQL++ 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 Lesser General Public
License for more details.
You should have received a copy of the GNU Lesser General Public
License along with MySQL++; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301
USA
***********************************************************************/
#define MYSQLPP_NOT_HEADER
#include "options.h"
#include "dbdriver.h"
namespace mysqlpp {
#if !defined(DOXYGEN_IGNORE)
// We're hiding all the Option subclass internals from Doxygen. All the
// upper-level classes are documented fully, and each leaf class itself
// is documented. It's just the ctors and set() methods we're refusing
// to document over and over again.
Option::Error
CompressOption::set(DBDriver* dbd)
{
return dbd->connected() ? Option::err_connected :
dbd->set_option(MYSQL_OPT_COMPRESS) ?
Option::err_NONE : Option::err_api_reject;
}
Option::Error
ConnectTimeoutOption::set(DBDriver* dbd)
{
return dbd->connected() ? Option::err_connected :
dbd->set_option(MYSQL_OPT_CONNECT_TIMEOUT, &arg_) ?
Option::err_NONE : Option::err_api_reject;
}
Option::Error
FoundRowsOption::set(DBDriver* dbd)
{
return dbd->connected() ? Option::err_connected :
dbd->set_option(CLIENT_FOUND_ROWS, arg_) ?
Option::err_NONE : Option::err_api_reject;
}
Option::Error
GuessConnectionOption::set(DBDriver* dbd)
{
#if (MYSQL_VERSION_ID >= 40101 && MYSQL_VERSION_ID <= 80003) || defined(MARIADB_BASE_VERSION)
return dbd->connected() ? Option::err_connected :
dbd->set_option(MYSQL_OPT_GUESS_CONNECTION) ?
Option::err_NONE : Option::err_api_reject;
#else
return Option::err_api_limit;
#endif
}
Option::Error
IgnoreSpaceOption::set(DBDriver* dbd)
{
return dbd->connected() ? Option::err_connected :
dbd->set_option(CLIENT_IGNORE_SPACE, arg_) ?
Option::err_NONE : Option::err_api_reject;
}
Option::Error
InitCommandOption::set(DBDriver* dbd)
{
return dbd->connected() ? Option::err_connected :
dbd->set_option(MYSQL_INIT_COMMAND, arg_.c_str()) ?
Option::err_NONE : Option::err_api_reject;
}
Option::Error
InteractiveOption::set(DBDriver* dbd)
{
return dbd->connected() ? Option::err_connected :
dbd->set_option(CLIENT_INTERACTIVE, arg_) ?
Option::err_NONE : Option::err_api_reject;
}
Option::Error
LocalFilesOption::set(DBDriver* dbd)
{
return dbd->connected() ? Option::err_connected :
dbd->set_option(CLIENT_LOCAL_FILES, arg_) ?
Option::err_NONE : Option::err_api_reject;
}
Option::Error
LocalInfileOption::set(DBDriver* dbd)
{
return dbd->connected() ? Option::err_connected :
dbd->set_option(MYSQL_OPT_LOCAL_INFILE, &arg_) ?
Option::err_NONE : Option::err_api_reject;
}
Option::Error
MultiResultsOption::set(DBDriver* dbd)
{
#if MYSQL_VERSION_ID >= 40101
if (dbd->connected()) {
return dbd->set_option(arg_ ? MYSQL_OPTION_MULTI_STATEMENTS_ON :
MYSQL_OPTION_MULTI_STATEMENTS_OFF) ?
Option::err_NONE : Option::err_api_reject;
}
else {
return dbd->set_option(CLIENT_MULTI_RESULTS, arg_) ?
Option::err_NONE : Option::err_api_reject;
}
#else
return Option::err_api_limit;
#endif
}
Option::Error
MultiStatementsOption::set(DBDriver* dbd)
{
#if MYSQL_VERSION_ID >= 40101
if (dbd->connected()) {
return dbd->set_option(arg_ ? MYSQL_OPTION_MULTI_STATEMENTS_ON :
MYSQL_OPTION_MULTI_STATEMENTS_OFF) ?
Option::err_NONE : Option::err_api_reject;
}
else {
return dbd->set_option(CLIENT_MULTI_STATEMENTS, arg_) ?
Option::err_NONE : Option::err_api_reject;
}
#else
return Option::err_api_limit;
#endif
}
Option::Error
NamedPipeOption::set(DBDriver* dbd)
{
return dbd->connected() ? Option::err_connected :
dbd->set_option(MYSQL_OPT_NAMED_PIPE) ?
Option::err_NONE : Option::err_api_reject;
}
Option::Error
NoSchemaOption::set(DBDriver* dbd)
{
return dbd->connected() ? Option::err_connected :
dbd->set_option(CLIENT_NO_SCHEMA, arg_) ?
Option::err_NONE : Option::err_api_reject;
}
#if MYSQL_VERSION_ID > 40000 // only in 4.0 +
Option::Error
ProtocolOption::set(DBDriver* dbd)
{
return dbd->connected() ? Option::err_connected :
dbd->set_option(MYSQL_OPT_PROTOCOL, &arg_) ?
Option::err_NONE : Option::err_api_reject;
}
#endif
Option::Error
ReadDefaultFileOption::set(DBDriver* dbd)
{
return dbd->connected() ? Option::err_connected :
dbd->set_option(MYSQL_READ_DEFAULT_FILE, arg_.c_str()) ?
Option::err_NONE : Option::err_api_reject;
}
Option::Error
ReadDefaultGroupOption::set(DBDriver* dbd)
{
return dbd->connected() ? Option::err_connected :
dbd->set_option(MYSQL_READ_DEFAULT_GROUP, arg_.c_str()) ?
Option::err_NONE : Option::err_api_reject;
}
Option::Error
ReadTimeoutOption::set(DBDriver* dbd)
{
#if MYSQL_VERSION_ID >= 40101
return dbd->connected() ? Option::err_connected :
dbd->set_option(MYSQL_OPT_READ_TIMEOUT, &arg_) ?
Option::err_NONE : Option::err_api_reject;
#else
return Option::err_api_limit;
#endif
}
Option::Error
ReconnectOption::set(DBDriver* dbd)
{
#if MYSQL_VERSION_ID >= 50106
// Option fixed in this version to work correctly whether set before
// connection comes up, or after
return dbd->set_option(MYSQL_OPT_RECONNECT, &arg_) ?
Option::err_NONE : Option::err_api_reject;
#elif MYSQL_VERSION_ID >= 50013
// Between the time the option was created in 5.0.13 and when it was
// fixed in 5.1.6, it only worked correctly if set after initial
// connection. So, don't accept it if disconnected, even though API
// does accept it; option gets reset when the connection comes up.
return dbd->connected() ?
dbd->set_option(MYSQL_OPT_RECONNECT, &arg_) ?
Option::err_NONE : Option::err_api_reject :
Option::err_disconnected;
#else
return Option::err_api_limit;
#endif
}
Option::Error
ReportDataTruncationOption::set(DBDriver* dbd)
{
#if MYSQL_VERSION_ID >= 50003
return dbd->connected() ? Option::err_connected :
dbd->set_option(MYSQL_REPORT_DATA_TRUNCATION, &arg_) ?
Option::err_NONE : Option::err_api_reject;
#else
return Option::err_api_limit;
#endif
}
Option::Error
SecureAuthOption::set(DBDriver* dbd)
{
#if (MYSQL_VERSION_ID >= 40101 && MYSQL_VERSION_ID <= 80002) || defined(MARIADB_BASE_VERSION)
return dbd->connected() ? Option::err_connected :
dbd->set_option(MYSQL_SECURE_AUTH, &arg_) ?
Option::err_NONE : Option::err_api_reject;
#else
return Option::err_api_limit;
#endif
}
Option::Error
SetCharsetDirOption::set(DBDriver* dbd)
{
return dbd->connected() ? Option::err_connected :
dbd->set_option(MYSQL_SET_CHARSET_DIR, arg_.c_str()) ?
Option::err_NONE : Option::err_api_reject;
}
Option::Error
SetCharsetNameOption::set(DBDriver* dbd)
{
return dbd->connected() ? Option::err_connected :
dbd->set_option(MYSQL_SET_CHARSET_NAME, arg_.c_str()) ?
Option::err_NONE : Option::err_api_reject;
}
Option::Error
SetClientIpOption::set(DBDriver* dbd)
{
#if (MYSQL_VERSION_ID >= 40101 && MYSQL_VERSION_ID <= 80003) || defined(MARIADB_BASE_VERSION)
return dbd->connected() ? Option::err_connected :
dbd->set_option(MYSQL_SET_CLIENT_IP, arg_.c_str()) ?
Option::err_NONE : Option::err_api_reject;
#else
return Option::err_api_limit;
#endif
}
Option::Error
SharedMemoryBaseNameOption::set(DBDriver* dbd)
{
#if MYSQL_VERSION_ID >= 40100
return dbd->connected() ? Option::err_connected :
dbd->set_option(MYSQL_SHARED_MEMORY_BASE_NAME, arg_.c_str()) ?
Option::err_NONE : Option::err_api_reject;
#else
return Option::err_api_limit;
#endif
}
Option::Error
SslOption::set(DBDriver* dbd)
{
#if defined(HAVE_MYSQL_SSL_SET)
return dbd->connected() ? Option::err_connected :
dbd->enable_ssl(
key_.size() ? key_.c_str() : 0,
cert_.size() ? cert_.c_str() : 0,
ca_.size() ? ca_.c_str() : 0,
capath_.size() ? capath_.c_str() : 0,
cipher_.size() ? cipher_.c_str() : 0) ?
Option::err_NONE : Option::err_api_reject;
#else
(void)dbd;
return Option::err_api_limit;
#endif
}
Option::Error
UseEmbeddedConnectionOption::set(DBDriver* dbd)
{
#if (MYSQL_VERSION_ID >= 40101 && MYSQL_VERSION_ID <= 80003) || defined(MARIADB_BASE_VERSION)
return dbd->connected() ? Option::err_connected :
dbd->set_option(MYSQL_OPT_USE_EMBEDDED_CONNECTION) ?
Option::err_NONE : Option::err_api_reject;
#else
return Option::err_api_limit;
#endif
}
Option::Error
UseRemoteConnectionOption::set(DBDriver* dbd)
{
#if (MYSQL_VERSION_ID >= 40101 && MYSQL_VERSION_ID <= 80003) || defined(MARIADB_BASE_VERSION)
return dbd->connected() ? Option::err_connected :
dbd->set_option(MYSQL_OPT_USE_REMOTE_CONNECTION) ?
Option::err_NONE : Option::err_api_reject;
#else
return Option::err_api_limit;
#endif
}
Option::Error
WriteTimeoutOption::set(DBDriver* dbd)
{
#if MYSQL_VERSION_ID >= 40101
return dbd->connected() ? Option::err_connected :
dbd->set_option(MYSQL_OPT_WRITE_TIMEOUT, &arg_) ?
Option::err_NONE : Option::err_api_reject;
#else
return Option::err_api_limit;
#endif
}
#endif // !defined(DOXYGEN_IGNORE)
} // end namespace mysqlpp
|