File: options.h

package info (click to toggle)
mysql%2B%2B 3.0.9-1
  • links: PTS
  • area: main
  • in suites: squeeze
  • size: 11,228 kB
  • ctags: 9,647
  • sloc: cpp: 33,154; sh: 3,098; perl: 778; makefile: 700
file content (496 lines) | stat: -rw-r--r-- 11,690 bytes parent folder | download
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
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
/// \file options.h
/// \brief Declares the Option class hierarchy, used to implement
/// connection options in Connection and DBDriver classes.
///
/// This is tied closely enough to DBDriver that there's a pure-OO
/// argument that it should be declared as protected or private members
/// within DBDriver.  We do it outside DBDriver because there's so much
/// of it.  It'd overwhelm everything else that's going on in that class
/// totally out of proprortion to the importance of options.

/***********************************************************************
 Copyright (c) 2007 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
***********************************************************************/

#if !defined(MYSQLPP_OPTIONS_H)
#define MYSQLPP_OPTIONS_H

#include "common.h"

#include <deque>
#include <string>


namespace mysqlpp {

#if !defined(DOXYGEN_IGNORE)
class DBDriver;
#endif


////////////////////////////////////////////////////////////////////////
// Classes

/// \brief Define abstract interface for all *Option subclasses.
///
/// This is the base class for the mid-level interface classes that take
/// arguments, plus the direct base for options that take no arguments.
class MYSQLPP_EXPORT Option
{
public:
	/// \brief Types of option setting errors we can diagnose
	enum Error {
		err_NONE,		///< option was set successfully
		err_api_limit,	///< option not supported by underlying C API
		err_api_reject,	///< underlying C API returned error when setting option
		err_connected	///< can't set the given option while connected
	};
	
	virtual ~Option() { }					///< Destroy object
	virtual Error set(DBDriver* dbd) = 0;	///< Apply option
};


/// \brief Define abstract interface for all *Options that take a
/// lone scalar as an argument.
template <typename T>
class MYSQLPP_EXPORT DataOption : public Option
{
public:
	typedef T ArgType;						///< Alias for template param

protected:
	DataOption(const T& arg) : arg_(arg) { }///< Construct object
	T arg_;									///< The argument value
};

typedef DataOption<unsigned> IntegerOption;		///< Option w/ int argument
typedef DataOption<bool> BooleanOption;			///< Option w/ bool argument
typedef DataOption<std::string> StringOption;	///< Option w/ string argument


/// \brief Enable data compression on the connection
class MYSQLPP_EXPORT CompressOption : public Option
{
#if !defined(DOXYGEN_IGNORE)
public:
	CompressOption() : Option() { }

private:
	Error set(DBDriver* dbd);
#endif
};


/// \brief Change Connection::connect() default timeout
class MYSQLPP_EXPORT ConnectTimeoutOption : public IntegerOption
{
#if !defined(DOXYGEN_IGNORE)
public:
	ConnectTimeoutOption(ArgType arg) : IntegerOption(arg) { }

private:
	Error set(DBDriver* dbd);
#endif
};


/// \brief Make Query::affected_rows() return number of matched rows
///
/// Default is to return number of \b changed rows.
class MYSQLPP_EXPORT FoundRowsOption : public BooleanOption
{
#if !defined(DOXYGEN_IGNORE)
public:
	FoundRowsOption(ArgType arg) : BooleanOption(arg) { }

private:
	Error set(DBDriver* dbd);
#endif
};


/// \brief Allow C API to guess what kind of connection to use
///
/// This is the default.  The option exists to override
/// UseEmbeddedConnectionOption and UseEmbeddedConnectionOption.
class MYSQLPP_EXPORT GuessConnectionOption : public Option
{
#if !defined(DOXYGEN_IGNORE)
public:
	GuessConnectionOption() : Option() { }

private:
	Error set(DBDriver* dbd);
#endif
};


/// \brief Allow spaces after function names in queries
class MYSQLPP_EXPORT IgnoreSpaceOption : public BooleanOption
{
#if !defined(DOXYGEN_IGNORE)
public:
	IgnoreSpaceOption(ArgType arg) : BooleanOption(arg) { }

private:
	Error set(DBDriver* dbd);
#endif
};


/// \brief Give SQL executed on connect
class MYSQLPP_EXPORT InitCommandOption : public StringOption
{
#if !defined(DOXYGEN_IGNORE)
public:
	InitCommandOption(ArgType arg) : StringOption(arg) { }

private:
	Error set(DBDriver* dbd);
#endif
};


/// \brief Assert that this is an interactive program
///
/// Affects connection timeouts.
class MYSQLPP_EXPORT InteractiveOption : public BooleanOption
{
#if !defined(DOXYGEN_IGNORE)
public:
	InteractiveOption(ArgType arg) : BooleanOption(arg) { }

private:
	Error set(DBDriver* dbd);
#endif
};


/// \brief Enable LOAD DATA LOCAL statement
class MYSQLPP_EXPORT LocalFilesOption : public BooleanOption
{
#if !defined(DOXYGEN_IGNORE)
public:
	LocalFilesOption(ArgType arg) : BooleanOption(arg) { }

private:
	Error set(DBDriver* dbd);
#endif
};


/// \brief Enable LOAD LOCAL INFILE statement
class MYSQLPP_EXPORT LocalInfileOption : public IntegerOption
{
#if !defined(DOXYGEN_IGNORE)
public:
	LocalInfileOption(ArgType arg) : IntegerOption(arg) { }

private:
	Error set(DBDriver* dbd);
#endif
};


/// \brief Enable multiple result sets in a reply
class MYSQLPP_EXPORT MultiResultsOption : public BooleanOption
{
#if !defined(DOXYGEN_IGNORE)
public:
	MultiResultsOption(ArgType arg) : BooleanOption(arg) { }

private:
	Error set(DBDriver* dbd);
#endif
};


/// \brief Enable multiple queries in a request to the server
class MYSQLPP_EXPORT MultiStatementsOption : public BooleanOption
{
#if !defined(DOXYGEN_IGNORE)
public:
	MultiStatementsOption(ArgType arg) : BooleanOption(arg) { }

private:
	Error set(DBDriver* dbd);
#endif
};


/// \brief Suggest use of named pipes
class MYSQLPP_EXPORT NamedPipeOption : public Option
{
#if !defined(DOXYGEN_IGNORE)
public:
	NamedPipeOption() : Option() { }

private:
	Error set(DBDriver* dbd);
#endif
};


/// \brief Disable db.tbl.col syntax in queries
class MYSQLPP_EXPORT NoSchemaOption : public BooleanOption
{
#if !defined(DOXYGEN_IGNORE)
public:
	NoSchemaOption(ArgType arg) : BooleanOption(arg) { }

private:
	Error set(DBDriver* dbd);
#endif
};


#if MYSQL_VERSION_ID > 40000		// only in 4.0 +
/// \brief Set type of protocol to use
class MYSQLPP_EXPORT ProtocolOption : public IntegerOption
{
#if !defined(DOXYGEN_IGNORE)
public:
	ProtocolOption(ArgType arg) : IntegerOption(arg) { }

private:
	Error set(DBDriver* dbd);
#endif
};
#endif


/// \brief Override use of my.cnf
class MYSQLPP_EXPORT ReadDefaultFileOption : public StringOption
{
#if !defined(DOXYGEN_IGNORE)
public:
	ReadDefaultFileOption(ArgType arg) : StringOption(arg) { }

private:
	Error set(DBDriver* dbd);
#endif
};


/// \brief Override use of my.cnf
class MYSQLPP_EXPORT ReadDefaultGroupOption : public StringOption
{
#if !defined(DOXYGEN_IGNORE)
public:
	ReadDefaultGroupOption(ArgType arg) : StringOption(arg) { }

private:
	Error set(DBDriver* dbd);
#endif
};


/// \brief Set timeout for IPC data reads
class MYSQLPP_EXPORT ReadTimeoutOption : public IntegerOption
{
#if !defined(DOXYGEN_IGNORE)
public:
	ReadTimeoutOption(ArgType arg) : IntegerOption(arg) { }

private:
	Error set(DBDriver* dbd);
#endif
};


/// \brief Enable automatic reconnection to server
class MYSQLPP_EXPORT ReconnectOption : public BooleanOption
{
#if !defined(DOXYGEN_IGNORE)
public:
	ReconnectOption(ArgType arg) : BooleanOption(arg) { }

private:
	Error set(DBDriver* dbd);
#endif
};


/// \brief Set reporting of data truncation errors
class MYSQLPP_EXPORT ReportDataTruncationOption : public BooleanOption
{
#if !defined(DOXYGEN_IGNORE)
public:
	ReportDataTruncationOption(ArgType arg) : BooleanOption(arg) { }

private:
	Error set(DBDriver* dbd);
#endif
};


/// \brief Enforce use of secure authentication, refusing connection if
/// not available
class MYSQLPP_EXPORT SecureAuthOption : public BooleanOption
{
#if !defined(DOXYGEN_IGNORE)
public:
	SecureAuthOption(ArgType arg) : BooleanOption(arg) { }

private:
	Error set(DBDriver* dbd);
#endif
};


/// \brief Give path to charset definition files
class MYSQLPP_EXPORT SetCharsetDirOption : public StringOption
{
#if !defined(DOXYGEN_IGNORE)
public:
	SetCharsetDirOption(ArgType arg) : StringOption(arg) { }

private:
	Error set(DBDriver* dbd);
#endif
};


/// \brief Give name of default charset
class MYSQLPP_EXPORT SetCharsetNameOption : public StringOption
{
#if !defined(DOXYGEN_IGNORE)
public:
	SetCharsetNameOption(ArgType arg) : StringOption(arg) { }

private:
	Error set(DBDriver* dbd);
#endif
};


/// \brief Fake client IP address when connecting to embedded server
class MYSQLPP_EXPORT SetClientIpOption : public StringOption
{
#if !defined(DOXYGEN_IGNORE)
public:
	SetClientIpOption(ArgType arg) : StringOption(arg) { }

private:
	Error set(DBDriver* dbd);
#endif
};


/// \brief Set name of shmem segment for IPC
class MYSQLPP_EXPORT SharedMemoryBaseNameOption : public StringOption
{
#if !defined(DOXYGEN_IGNORE)
public:
	SharedMemoryBaseNameOption(ArgType arg) : StringOption(arg) { }

private:
	Error set(DBDriver* dbd);
#endif
};


/// \brief Specialized option for handling SSL parameters.
class MYSQLPP_EXPORT SslOption : public Option
{
public:
	/// \brief Create a set of SSL connection option parameters
	///
	/// \param key the pathname to the key file
	/// \param cert the pathname to the certificate file
	/// \param ca the pathname to the certificate authority file
	/// \param capath directory that contains trusted SSL CA
	///        certificates in pem format.
	/// \param cipher list of allowable ciphers to use
	///
	/// This option replaces \c Connection::enable_ssl() from MySQL++
	/// version 2.  Now you can set this connection option just like any
	/// other.
	SslOption(const char* key = 0, const char* cert = 0,
			const char* ca = 0, const char* capath = 0,
			const char* cipher = 0)
	{
		if (key)	key_.assign(key);
		if (cert)	cert_.assign(cert);
		if (ca)		ca_.assign(ca);
		if (capath)	capath_.assign(capath);
		if (cipher)	cipher_.assign(cipher);
	}

private:
	std::string key_, cert_, ca_, capath_, cipher_;
	Error set(DBDriver* dbd);
};


/// \brief Connect to embedded  server in preference to remote server
class MYSQLPP_EXPORT UseEmbeddedConnectionOption : public Option
{
#if !defined(DOXYGEN_IGNORE)
public:
	UseEmbeddedConnectionOption() : Option() { }

private:
	Error set(DBDriver* dbd);
#endif
};


/// \brief Connect to remote server in preference to embedded server
class MYSQLPP_EXPORT UseRemoteConnectionOption : public Option
{
#if !defined(DOXYGEN_IGNORE)
public:
	UseRemoteConnectionOption() : Option() { }

private:
	Error set(DBDriver* dbd);
#endif
};


/// \brief Set timeout for IPC data reads
class MYSQLPP_EXPORT WriteTimeoutOption : public IntegerOption
{
#if !defined(DOXYGEN_IGNORE)
public:
	WriteTimeoutOption(ArgType arg) : IntegerOption(arg) { }

private:
	Error set(DBDriver* dbd);
#endif
};


////////////////////////////////////////////////////////////////////////
// Typedefs

/// \brief The data type of the list of connection options
typedef std::deque<Option*> OptionList;

/// \brief Primary iterator type into List
typedef OptionList::const_iterator OptionListIt;

} // end namespace mysqlpp

#endif // !defined(MYSQLPP_OPTIONS_H)