~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/set_var.h

  • Committer: Brian Aker
  • Date: 2008-07-28 18:01:38 UTC
  • Revision ID: brian@tangent.org-20080728180138-q2pxlq0qiapvqsdn
Remove YEAR field type

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
 
 *  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
3
 
 *
4
 
 *  Copyright (C) 2008 Sun Microsystems
5
 
 *
6
 
 *  This program is free software; you can redistribute it and/or modify
7
 
 *  it under the terms of the GNU General Public License as published by
8
 
 *  the Free Software Foundation; version 2 of the License.
9
 
 *
10
 
 *  This program is distributed in the hope that it will be useful,
11
 
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 
 *  GNU General Public License for more details.
14
 
 *
15
 
 *  You should have received a copy of the GNU General Public License
16
 
 *  along with this program; if not, write to the Free Software
17
 
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
18
 
 */
19
 
 
20
 
#ifndef DRIZZLED_SET_VAR_H
21
 
#define DRIZZLED_SET_VAR_H
22
 
 
23
 
#include <string>
24
 
 
25
 
#include "drizzled/function/func.h"
26
 
#include "drizzled/function/set_user_var.h"
27
 
#include "drizzled/item/string.h"
28
 
#include "drizzled/item/field.h"
29
 
 
30
 
 
31
 
/* Classes to support the SET command */
32
 
 
33
 
 
34
 
/****************************************************************************
35
 
  Variables that are changable runtime are declared using the
36
 
  following classes
37
 
****************************************************************************/
38
 
 
39
 
class sys_var;
40
 
class set_var;
41
 
class sys_var_pluginvar; /* opaque */
42
 
class Time_zone;
43
 
typedef struct system_variables SV;
44
 
typedef struct my_locale_st MY_LOCALE;
45
 
 
46
 
extern TYPELIB bool_typelib;
47
 
extern TYPELIB optimizer_switch_typelib;
48
 
 
49
 
typedef int (*sys_check_func)(Session *,  set_var *);
50
 
typedef bool (*sys_update_func)(Session *, set_var *);
51
 
typedef void (*sys_after_update_func)(Session *,enum_var_type);
52
 
typedef void (*sys_set_default_func)(Session *, enum_var_type);
53
 
typedef unsigned char *(*sys_value_ptr_func)(Session *session);
54
 
 
55
 
static const std::vector<std::string> empty_aliases;
56
 
extern struct system_variables max_system_variables;
57
 
extern size_t table_def_size;
58
 
 
59
 
extern char *drizzle_tmpdir;
60
 
extern const char *first_keyword;
61
 
extern const char *in_left_expr_name;
62
 
extern const char *in_additional_cond;
63
 
extern const char *in_having_cond;
64
 
extern char language[FN_REFLEN];
65
 
extern char glob_hostname[FN_REFLEN];
66
 
extern char drizzle_home[FN_REFLEN];
67
 
extern char pidfile_name[FN_REFLEN];
68
 
extern char system_time_zone[30];
69
 
extern char *opt_tc_log_file;
70
 
extern uint64_t session_startup_options;
71
 
extern uint32_t global_thread_id;
72
 
extern uint64_t aborted_threads;
73
 
extern uint64_t aborted_connects;
74
 
extern uint64_t table_cache_size;
75
 
extern uint64_t max_connect_errors;
76
 
extern uint32_t back_log;
77
 
extern uint32_t ha_open_options;
78
 
extern char *drizzled_bind_host;
79
 
extern uint32_t dropping_tables;
80
 
extern bool opt_endinfo;
81
 
extern bool locked_in_memory;
82
 
extern uint32_t volatile thread_running;
83
 
extern uint32_t volatile global_read_lock;
84
 
extern bool opt_readonly;
85
 
extern char* opt_secure_file_priv;
86
 
extern char *default_tz_name;
87
 
 
88
 
struct sys_var_chain
89
 
{
90
 
  sys_var *first;
91
 
  sys_var *last;
92
 
};
93
 
 
94
 
/**
95
 
 * A class which represents a variable, either global or 
96
 
 * session-local.
97
 
 */
98
 
class sys_var
99
 
{
100
 
protected:
101
 
  const std::string name; /**< The name of the variable */
102
 
  sys_after_update_func after_update; /**< Function pointer triggered after the variable's value is updated */
103
 
  struct my_option *option_limits; /**< Updated by by set_var_init() */
104
 
  bool m_allow_empty_value; /**< Does variable allow an empty value? */
105
 
  sys_var *next;
106
 
public:
107
 
  sys_var(const std::string name_arg, sys_after_update_func func= NULL)
108
 
    :
109
 
    name(name_arg),
110
 
    after_update(func),
111
 
    m_allow_empty_value(true)
112
 
  {}
113
 
  virtual ~sys_var() {}
114
 
  void chain_sys_var(sys_var_chain *chain_arg)
115
 
  {
116
 
    if (chain_arg->last)
117
 
      chain_arg->last->next= this;
118
 
    else
119
 
      chain_arg->first= this;
120
 
    chain_arg->last= this;
121
 
  }
122
 
 
123
 
  /** 
124
 
   * Returns the name of the variable.
125
 
   *
126
 
   * @note 
127
 
   *
128
 
   * So that we can exist in a Registry. We really need to formalize that 
129
 
   */
130
 
  inline const std::string &getName() const
131
 
  {
132
 
    return name;
133
 
  }
134
 
  /**
135
 
   * Returns a vector of strings representing aliases
136
 
   * for this variable's name.
137
 
   */
138
 
  const std::vector<std::string>& getAliases() const
139
 
  {
140
 
    return empty_aliases;
141
 
  }
142
 
  /**
143
 
   * Returns a pointer to the next sys_var, or NULL if none.
144
 
   */
145
 
  inline sys_var *getNext() const
146
 
  {
147
 
    return next;
148
 
  }
149
 
  /**
150
 
   * Sets the pointer to the next sys_var.
151
 
   *
152
 
   * @param Pointer to the next sys_var, or NULL if you set the tail...
153
 
   */
154
 
  inline void setNext(sys_var *in_next)
155
 
  {
156
 
    next= in_next;
157
 
  }
158
 
  /**
159
 
   * Returns a pointer to the variable's option limits
160
 
   */
161
 
  inline struct my_option *getOptionLimits() const
162
 
  {
163
 
    return option_limits;
164
 
  }
165
 
  /**
166
 
   * Sets the pointer to the variable's option limits
167
 
   *
168
 
   * @param Pointer to the option limits my_option variable
169
 
   */
170
 
  inline void setOptionLimits(struct my_option *in_option_limits)
171
 
  {
172
 
    option_limits= in_option_limits;
173
 
  }
174
 
  /** 
175
 
   * Returns the function pointer for after update trigger, or NULL if none.
176
 
   */
177
 
  inline sys_after_update_func getAfterUpdateTrigger() const
178
 
  {
179
 
    return after_update;
180
 
  }
181
 
  virtual bool check(Session *session, set_var *var);
182
 
  bool check_enum(Session *session, set_var *var, const TYPELIB *enum_names);
183
 
  bool check_set(Session *session, set_var *var, TYPELIB *enum_names);
184
 
  virtual bool update(Session *session, set_var *var)=0;
185
 
  virtual void set_default(Session *, enum_var_type)
186
 
  {}
187
 
  virtual SHOW_TYPE show_type()
188
 
  {
189
 
    return SHOW_UNDEF;
190
 
  }
191
 
  virtual unsigned char *value_ptr(Session *, enum_var_type, const LEX_STRING *)
192
 
  {
193
 
    return 0;
194
 
  }
195
 
  virtual bool check_type(enum_var_type type)
196
 
  {
197
 
    return type != OPT_GLOBAL;
198
 
  }             /* Error if not GLOBAL */
199
 
  virtual bool check_update_type(Item_result type)
200
 
  {
201
 
    return type != INT_RESULT;
202
 
  }             /* Assume INT */
203
 
  virtual bool check_default(enum_var_type)
204
 
  {
205
 
    return option_limits == 0;
206
 
  }
207
 
  Item *item(Session *session, enum_var_type type, const LEX_STRING *base);
208
 
  virtual bool is_readonly() const
209
 
  {
210
 
    return 0;
211
 
  }
212
 
  virtual sys_var_pluginvar *cast_pluginvar()
213
 
  {
214
 
    return 0;
215
 
  }
216
 
};
217
 
 
218
 
/**
219
 
 * A base class for all variables that require its access to
220
 
 * be guarded with a mutex.
221
 
 */
222
 
class sys_var_global: public sys_var
223
 
{
224
 
protected:
225
 
  pthread_mutex_t *guard;
226
 
public:
227
 
  sys_var_global(const char *name_arg,
228
 
                 sys_after_update_func after_update_arg,
229
 
                 pthread_mutex_t *guard_arg)
230
 
    :
231
 
      sys_var(name_arg, after_update_arg), 
232
 
      guard(guard_arg) 
233
 
  {}
234
 
};
235
 
 
236
 
class sys_var_uint32_t_ptr :public sys_var
237
 
{
238
 
  uint32_t *value;
239
 
public:
240
 
  sys_var_uint32_t_ptr(sys_var_chain *chain, const char *name_arg,
241
 
                       uint32_t *value_ptr_arg)
242
 
    :sys_var(name_arg),value(value_ptr_arg)
243
 
  { chain_sys_var(chain); }
244
 
  sys_var_uint32_t_ptr(sys_var_chain *chain, const char *name_arg,
245
 
                       uint32_t *value_ptr_arg,
246
 
                       sys_after_update_func func)
247
 
    :sys_var(name_arg,func), value(value_ptr_arg)
248
 
  { chain_sys_var(chain); }
249
 
  bool check(Session *session, set_var *var);
250
 
  bool update(Session *session, set_var *var);
251
 
  void set_default(Session *session, enum_var_type type);
252
 
  SHOW_TYPE show_type() { return SHOW_INT; }
253
 
  unsigned char *value_ptr(Session *, enum_var_type, const LEX_STRING *)
254
 
  { return (unsigned char*) value; }
255
 
};
256
 
 
257
 
 
258
 
class sys_var_uint64_t_ptr :public sys_var
259
 
{
260
 
  uint64_t *value;
261
 
public:
262
 
  sys_var_uint64_t_ptr(sys_var_chain *chain, const char *name_arg, uint64_t *value_ptr_arg)
263
 
    :sys_var(name_arg),value(value_ptr_arg)
264
 
  { chain_sys_var(chain); }
265
 
  sys_var_uint64_t_ptr(sys_var_chain *chain, const char *name_arg, uint64_t *value_ptr_arg,
266
 
                       sys_after_update_func func)
267
 
    :sys_var(name_arg,func), value(value_ptr_arg)
268
 
  { chain_sys_var(chain); }
269
 
  bool update(Session *session, set_var *var);
270
 
  void set_default(Session *session, enum_var_type type);
271
 
  SHOW_TYPE show_type() { return SHOW_LONGLONG; }
272
 
  unsigned char *value_ptr(Session *, enum_var_type,
273
 
                           const LEX_STRING *)
274
 
  { return (unsigned char*) value; }
275
 
};
276
 
 
277
 
class sys_var_size_t_ptr :public sys_var
278
 
{
279
 
  size_t *value;
280
 
public:
281
 
  sys_var_size_t_ptr(sys_var_chain *chain, const char *name_arg, size_t *value_ptr_arg)
282
 
    :sys_var(name_arg),value(value_ptr_arg)
283
 
  { chain_sys_var(chain); }
284
 
  sys_var_size_t_ptr(sys_var_chain *chain, const char *name_arg, size_t *value_ptr_arg,
285
 
                     sys_after_update_func func)
286
 
    :sys_var(name_arg,func), value(value_ptr_arg)
287
 
  { chain_sys_var(chain); }
288
 
  bool update(Session *session, set_var *var);
289
 
  void set_default(Session *session, enum_var_type type);
290
 
  SHOW_TYPE show_type() { return SHOW_SIZE; }
291
 
  unsigned char *value_ptr(Session *, enum_var_type, const LEX_STRING *)
292
 
  { return (unsigned char*) value; }
293
 
};
294
 
 
295
 
class sys_var_bool_ptr :public sys_var
296
 
{
297
 
public:
298
 
  bool *value;
299
 
  sys_var_bool_ptr(sys_var_chain *chain, const char *name_arg, bool *value_arg)
300
 
    :sys_var(name_arg),value(value_arg)
301
 
  { chain_sys_var(chain); }
302
 
  bool check(Session *session, set_var *var)
303
 
  {
304
 
    return check_enum(session, var, &bool_typelib);
305
 
  }
306
 
  bool update(Session *session, set_var *var);
307
 
  void set_default(Session *session, enum_var_type type);
308
 
  SHOW_TYPE show_type() { return SHOW_MY_BOOL; }
309
 
  unsigned char *value_ptr(Session *, enum_var_type, const LEX_STRING *)
310
 
  { return (unsigned char*) value; }
311
 
  bool check_update_type(Item_result)
312
 
  { return 0; }
313
 
};
314
 
 
315
 
class sys_var_bool_ptr_readonly :public sys_var_bool_ptr
316
 
{
317
 
public:
318
 
  sys_var_bool_ptr_readonly(sys_var_chain *chain, const char *name_arg,
319
 
                            bool *value_arg)
320
 
    :sys_var_bool_ptr(chain, name_arg, value_arg)
321
 
  {}
322
 
  bool is_readonly() const { return 1; }
323
 
};
324
 
 
325
 
 
326
 
class sys_var_str :public sys_var
327
 
{
328
 
public:
329
 
  char *value;                                  // Pointer to allocated string
330
 
  uint32_t value_length;
331
 
  sys_check_func check_func;
332
 
  sys_update_func update_func;
333
 
  sys_set_default_func set_default_func;
334
 
  sys_var_str(sys_var_chain *chain, const char *name_arg,
335
 
              sys_check_func check_func_arg,
336
 
              sys_update_func update_func_arg,
337
 
              sys_set_default_func set_default_func_arg,
338
 
              char *value_arg)
339
 
    :sys_var(name_arg), value(value_arg), check_func(check_func_arg),
340
 
    update_func(update_func_arg),set_default_func(set_default_func_arg)
341
 
  { chain_sys_var(chain); }
342
 
  bool check(Session *session, set_var *var);
343
 
  bool update(Session *session, set_var *var)
344
 
  {
345
 
    return (*update_func)(session, var);
346
 
  }
347
 
  void set_default(Session *session, enum_var_type type)
348
 
  {
349
 
    (*set_default_func)(session, type);
350
 
  }
351
 
  SHOW_TYPE show_type() { return SHOW_CHAR; }
352
 
  unsigned char *value_ptr(Session *, enum_var_type, const LEX_STRING *)
353
 
  { return (unsigned char*) value; }
354
 
  bool check_update_type(Item_result type)
355
 
  {
356
 
    return type != STRING_RESULT;               /* Only accept strings */
357
 
  }
358
 
  bool check_default(enum_var_type)
359
 
  { return 0; }
360
 
};
361
 
 
362
 
 
363
 
class sys_var_const_str :public sys_var
364
 
{
365
 
  char *value;                                  // Pointer to const value
366
 
public:
367
 
  sys_var_const_str(sys_var_chain *chain, const char *name_arg,
368
 
                    const char *value_arg)
369
 
    :sys_var(name_arg), value((char*) value_arg)
370
 
  { chain_sys_var(chain); }
371
 
  inline void set (char *new_value)
372
 
  {
373
 
    value= new_value;
374
 
  }
375
 
  bool check(Session *, set_var *)
376
 
  {
377
 
    return 1;
378
 
  }
379
 
  bool update(Session *, set_var *)
380
 
  {
381
 
    return 1;
382
 
  }
383
 
  SHOW_TYPE show_type() { return SHOW_CHAR; }
384
 
  unsigned char *value_ptr(Session *, enum_var_type, const LEX_STRING *)
385
 
  {
386
 
    return (unsigned char*) value;
387
 
  }
388
 
  bool check_update_type(Item_result)
389
 
  {
390
 
    return 1;
391
 
  }
392
 
  bool check_default(enum_var_type)
393
 
  { return 1; }
394
 
  bool is_readonly() const { return 1; }
395
 
};
396
 
 
397
 
 
398
 
class sys_var_const_str_ptr :public sys_var
399
 
{
400
 
  char **value;                                 // Pointer to const value
401
 
public:
402
 
  sys_var_const_str_ptr(sys_var_chain *chain, const char *name_arg, char **value_arg)
403
 
    :sys_var(name_arg),value(value_arg)
404
 
  { chain_sys_var(chain); }
405
 
  bool check(Session *, set_var *)
406
 
  {
407
 
    return 1;
408
 
  }
409
 
  bool update(Session *, set_var *)
410
 
  {
411
 
    return 1;
412
 
  }
413
 
  SHOW_TYPE show_type() { return SHOW_CHAR; }
414
 
  unsigned char *value_ptr(Session *, enum_var_type, const LEX_STRING *)
415
 
  {
416
 
    return (unsigned char*) *value;
417
 
  }
418
 
  bool check_update_type(Item_result)
419
 
  {
420
 
    return 1;
421
 
  }
422
 
  bool check_default(enum_var_type)
423
 
  { return 1; }
424
 
  bool is_readonly(void) const { return 1; }
425
 
};
426
 
 
427
 
 
428
 
class sys_var_enum :public sys_var
429
 
{
430
 
  uint32_t *value;
431
 
  TYPELIB *enum_names;
432
 
public:
433
 
  sys_var_enum(sys_var_chain *chain, const char *name_arg, uint32_t *value_arg,
434
 
               TYPELIB *typelib, sys_after_update_func func)
435
 
    :sys_var(name_arg,func), value(value_arg), enum_names(typelib)
436
 
  { chain_sys_var(chain); }
437
 
  bool check(Session *session, set_var *var)
438
 
  {
439
 
    return check_enum(session, var, enum_names);
440
 
  }
441
 
  bool update(Session *session, set_var *var);
442
 
  SHOW_TYPE show_type() { return SHOW_CHAR; }
443
 
  unsigned char *value_ptr(Session *session, enum_var_type type,
444
 
                           const LEX_STRING *base);
445
 
  bool check_update_type(Item_result)
446
 
  { return 0; }
447
 
};
448
 
 
449
 
 
450
 
class sys_var_enum_const :public sys_var
451
 
{
452
 
  uint32_t SV::*offset;
453
 
  TYPELIB *enum_names;
454
 
public:
455
 
  sys_var_enum_const(sys_var_chain *chain, const char *name_arg, uint32_t SV::*offset_arg,
456
 
      TYPELIB *typelib, sys_after_update_func func)
457
 
    :sys_var(name_arg,func), offset(offset_arg), enum_names(typelib)
458
 
  { chain_sys_var(chain); }
459
 
  bool check(Session *, set_var *)
460
 
  { return 1; }
461
 
  bool update(Session *, set_var *)
462
 
  { return 1; }
463
 
  SHOW_TYPE show_type() { return SHOW_CHAR; }
464
 
  bool check_update_type(Item_result)
465
 
  { return 1; }
466
 
  bool is_readonly() const { return 1; }
467
 
  unsigned char *value_ptr(Session *session, enum_var_type type,
468
 
                           const LEX_STRING *base);
469
 
};
470
 
 
471
 
 
472
 
class sys_var_session :public sys_var
473
 
{
474
 
public:
475
 
  sys_var_session(const char *name_arg,
476
 
              sys_after_update_func func= NULL)
477
 
    :sys_var(name_arg, func)
478
 
  {}
479
 
  bool check_type(enum_var_type)
480
 
  { return 0; }
481
 
  bool check_default(enum_var_type type)
482
 
  {
483
 
    return type == OPT_GLOBAL && !option_limits;
484
 
  }
485
 
};
486
 
 
487
 
class sys_var_session_uint32_t :public sys_var_session
488
 
{
489
 
  sys_check_func check_func;
490
 
public:
491
 
  uint32_t SV::*offset;
492
 
  sys_var_session_uint32_t(sys_var_chain *chain, const char *name_arg,
493
 
                           uint32_t SV::*offset_arg,
494
 
                           sys_check_func c_func= NULL,
495
 
                           sys_after_update_func au_func= NULL)
496
 
    :sys_var_session(name_arg, au_func), check_func(c_func),
497
 
    offset(offset_arg)
498
 
  { chain_sys_var(chain); }
499
 
  bool check(Session *session, set_var *var);
500
 
  bool update(Session *session, set_var *var);
501
 
  void set_default(Session *session, enum_var_type type);
502
 
  SHOW_TYPE show_type() { return SHOW_INT; }
503
 
  unsigned char *value_ptr(Session *session, enum_var_type type,
504
 
                           const LEX_STRING *base);
505
 
};
506
 
 
507
 
 
508
 
class sys_var_session_ha_rows :public sys_var_session
509
 
{
510
 
public:
511
 
  ha_rows SV::*offset;
512
 
  sys_var_session_ha_rows(sys_var_chain *chain, const char *name_arg,
513
 
                      ha_rows SV::*offset_arg)
514
 
    :sys_var_session(name_arg), offset(offset_arg)
515
 
  { chain_sys_var(chain); }
516
 
  sys_var_session_ha_rows(sys_var_chain *chain, const char *name_arg,
517
 
                      ha_rows SV::*offset_arg,
518
 
                      sys_after_update_func func)
519
 
    :sys_var_session(name_arg,func), offset(offset_arg)
520
 
  { chain_sys_var(chain); }
521
 
  bool update(Session *session, set_var *var);
522
 
  void set_default(Session *session, enum_var_type type);
523
 
  SHOW_TYPE show_type() { return SHOW_HA_ROWS; }
524
 
  unsigned char *value_ptr(Session *session, enum_var_type type,
525
 
                           const LEX_STRING *base);
526
 
};
527
 
 
528
 
 
529
 
class sys_var_session_uint64_t :public sys_var_session
530
 
{
531
 
  sys_check_func check_func;
532
 
public:
533
 
  uint64_t SV::*offset;
534
 
  bool only_global;
535
 
  sys_var_session_uint64_t(sys_var_chain *chain, 
536
 
                           const char *name_arg,
537
 
                           uint64_t SV::*offset_arg,
538
 
                           sys_after_update_func au_func= NULL,
539
 
                           sys_check_func c_func= NULL)
540
 
    :sys_var_session(name_arg, au_func),
541
 
    check_func(c_func),
542
 
    offset(offset_arg)
543
 
  { chain_sys_var(chain); }
544
 
  sys_var_session_uint64_t(sys_var_chain *chain,
545
 
                           const char *name_arg,
546
 
                           uint64_t SV::*offset_arg,
547
 
                           sys_after_update_func func,
548
 
                           bool only_global_arg,
549
 
                           sys_check_func cfunc= NULL)
550
 
    :sys_var_session(name_arg, func),
551
 
    check_func(cfunc),
552
 
    offset(offset_arg),
553
 
    only_global(only_global_arg)
554
 
  { chain_sys_var(chain); }
555
 
  bool update(Session *session, set_var *var);
556
 
  void set_default(Session *session, enum_var_type type);
557
 
  SHOW_TYPE show_type() { return SHOW_LONGLONG; }
558
 
  unsigned char *value_ptr(Session *session, enum_var_type type,
559
 
                           const LEX_STRING *base);
560
 
  bool check(Session *session, set_var *var);
561
 
  bool check_default(enum_var_type type)
562
 
  {
563
 
    return type == OPT_GLOBAL && !option_limits;
564
 
  }
565
 
  bool check_type(enum_var_type type)
566
 
  {
567
 
    return (only_global && type != OPT_GLOBAL);
568
 
  }
569
 
};
570
 
 
571
 
class sys_var_session_size_t :public sys_var_session
572
 
{
573
 
  sys_check_func check_func;
574
 
public:
575
 
  size_t SV::*offset;
576
 
  bool only_global;
577
 
  sys_var_session_size_t(sys_var_chain *chain, const char *name_arg,
578
 
                         size_t SV::*offset_arg,
579
 
                         sys_after_update_func au_func= NULL,
580
 
                         sys_check_func c_func= NULL)
581
 
    :sys_var_session(name_arg, au_func),
582
 
     check_func(c_func),
583
 
     offset(offset_arg)
584
 
  { chain_sys_var(chain); }
585
 
  sys_var_session_size_t(sys_var_chain *chain,
586
 
                         const char *name_arg,
587
 
                         size_t SV::*offset_arg,
588
 
                         sys_after_update_func func,
589
 
                         bool only_global_arg,
590
 
                         sys_check_func cfunc= NULL)
591
 
    :sys_var_session(name_arg, func),
592
 
     check_func(cfunc),
593
 
     offset(offset_arg),
594
 
     only_global(only_global_arg)
595
 
  { chain_sys_var(chain); }
596
 
  bool update(Session *session, set_var *var);
597
 
  void set_default(Session *session, enum_var_type type);
598
 
  SHOW_TYPE show_type() { return SHOW_SIZE; }
599
 
  unsigned char *value_ptr(Session *session, enum_var_type type,
600
 
                           const LEX_STRING *base);
601
 
  bool check(Session *session, set_var *var);
602
 
  bool check_default(enum_var_type type)
603
 
  {
604
 
    return type == OPT_GLOBAL && !option_limits;
605
 
  }
606
 
  bool check_type(enum_var_type type)
607
 
  {
608
 
    return (only_global && type != OPT_GLOBAL);
609
 
  }
610
 
};
611
 
 
612
 
 
613
 
class sys_var_session_bool :public sys_var_session
614
 
{
615
 
public:
616
 
  bool SV::*offset;
617
 
  sys_var_session_bool(sys_var_chain *chain, const char *name_arg, bool SV::*offset_arg)
618
 
    :sys_var_session(name_arg), offset(offset_arg)
619
 
  { chain_sys_var(chain); }
620
 
  sys_var_session_bool(sys_var_chain *chain, const char *name_arg, bool SV::*offset_arg,
621
 
                   sys_after_update_func func)
622
 
    :sys_var_session(name_arg,func), offset(offset_arg)
623
 
  { chain_sys_var(chain); }
624
 
  bool update(Session *session, set_var *var);
625
 
  void set_default(Session *session, enum_var_type type);
626
 
  SHOW_TYPE show_type() { return SHOW_MY_BOOL; }
627
 
  unsigned char *value_ptr(Session *session, enum_var_type type,
628
 
                           const LEX_STRING *base);
629
 
  bool check(Session *session, set_var *var)
630
 
  {
631
 
    return check_enum(session, var, &bool_typelib);
632
 
  }
633
 
  bool check_update_type(Item_result)
634
 
  { return 0; }
635
 
};
636
 
 
637
 
 
638
 
class sys_var_session_enum :public sys_var_session
639
 
{
640
 
protected:
641
 
  uint32_t SV::*offset;
642
 
  TYPELIB *enum_names;
643
 
  sys_check_func check_func;
644
 
public:
645
 
  sys_var_session_enum(sys_var_chain *chain, const char *name_arg,
646
 
                   uint32_t SV::*offset_arg, TYPELIB *typelib,
647
 
                   sys_after_update_func func= NULL,
648
 
                   sys_check_func check_f= NULL)
649
 
    :sys_var_session(name_arg, func), offset(offset_arg),
650
 
    enum_names(typelib), check_func(check_f)
651
 
  { chain_sys_var(chain); }
652
 
  bool check(Session *session, set_var *var)
653
 
  {
654
 
    int ret= 0;
655
 
    if (check_func)
656
 
      ret= (*check_func)(session, var);
657
 
    return ret ? ret : check_enum(session, var, enum_names);
658
 
  }
659
 
  bool update(Session *session, set_var *var);
660
 
  void set_default(Session *session, enum_var_type type);
661
 
  SHOW_TYPE show_type() { return SHOW_CHAR; }
662
 
  unsigned char *value_ptr(Session *session, enum_var_type type,
663
 
                           const LEX_STRING *base);
664
 
  bool check_update_type(Item_result)
665
 
  { return 0; }
666
 
};
667
 
 
668
 
 
669
 
 
670
 
class sys_var_session_optimizer_switch :public sys_var_session_enum
671
 
{
672
 
public:
673
 
  sys_var_session_optimizer_switch(sys_var_chain *chain, const char *name_arg,
674
 
                                   uint32_t SV::*offset_arg)
675
 
    :sys_var_session_enum(chain, name_arg, offset_arg, &optimizer_switch_typelib)
676
 
  {}
677
 
  bool check(Session *session, set_var *var)
678
 
  {
679
 
    return check_set(session, var, enum_names);
680
 
  }
681
 
  void set_default(Session *session, enum_var_type type);
682
 
  unsigned char *value_ptr(Session *session, enum_var_type type,
683
 
                           const LEX_STRING *base);
684
 
  static bool symbolic_mode_representation(Session *session, uint32_t sql_mode,
685
 
                                           LEX_STRING *rep);
686
 
};
687
 
 
688
 
 
689
 
class sys_var_session_storage_engine :public sys_var_session
690
 
{
691
 
protected:
692
 
  drizzled::plugin::StorageEngine *SV::*offset;
693
 
public:
694
 
  sys_var_session_storage_engine(sys_var_chain *chain, const char *name_arg,
695
 
                                 drizzled::plugin::StorageEngine *SV::*offset_arg)
696
 
    :sys_var_session(name_arg), offset(offset_arg)
697
 
  { chain_sys_var(chain); }
698
 
  bool check(Session *session, set_var *var);
699
 
  SHOW_TYPE show_type() { return SHOW_CHAR; }
700
 
  bool check_update_type(Item_result type)
701
 
  {
702
 
    return type != STRING_RESULT;               /* Only accept strings */
703
 
  }
704
 
  void set_default(Session *session, enum_var_type type);
705
 
  bool update(Session *session, set_var *var);
706
 
  unsigned char *value_ptr(Session *session, enum_var_type type,
707
 
                           const LEX_STRING *base);
708
 
};
709
 
 
710
 
class sys_var_session_bit :public sys_var_session
711
 
{
712
 
  sys_check_func check_func;
713
 
  sys_update_func update_func;
714
 
public:
715
 
  uint64_t bit_flag;
716
 
  bool reverse;
717
 
  sys_var_session_bit(sys_var_chain *chain, const char *name_arg,
718
 
                  sys_check_func c_func, sys_update_func u_func,
719
 
                  uint64_t bit, bool reverse_arg=0)
720
 
    :sys_var_session(name_arg, NULL), check_func(c_func),
721
 
    update_func(u_func), bit_flag(bit), reverse(reverse_arg)
722
 
  { chain_sys_var(chain); }
723
 
  bool check(Session *session, set_var *var);
724
 
  bool update(Session *session, set_var *var);
725
 
  bool check_update_type(Item_result)
726
 
  { return 0; }
727
 
  bool check_type(enum_var_type type) { return type == OPT_GLOBAL; }
728
 
  SHOW_TYPE show_type() { return SHOW_MY_BOOL; }
729
 
  unsigned char *value_ptr(Session *session, enum_var_type type,
730
 
                           const LEX_STRING *base);
731
 
};
732
 
 
733
 
/* some variables that require special handling */
734
 
 
735
 
class sys_var_timestamp :public sys_var
736
 
{
737
 
public:
738
 
  sys_var_timestamp(sys_var_chain *chain, const char *name_arg)
739
 
    :sys_var(name_arg, NULL)
740
 
  { chain_sys_var(chain); }
741
 
  bool update(Session *session, set_var *var);
742
 
  void set_default(Session *session, enum_var_type type);
743
 
  bool check_type(enum_var_type type)    { return type == OPT_GLOBAL; }
744
 
  bool check_default(enum_var_type)
745
 
  { return 0; }
746
 
  SHOW_TYPE show_type(void) { return SHOW_LONG; }
747
 
  unsigned char *value_ptr(Session *session, enum_var_type type,
748
 
                           const LEX_STRING *base);
749
 
};
750
 
 
751
 
 
752
 
class sys_var_last_insert_id :public sys_var
753
 
{
754
 
public:
755
 
  sys_var_last_insert_id(sys_var_chain *chain, const char *name_arg)
756
 
    :sys_var(name_arg, NULL)
757
 
  { chain_sys_var(chain); }
758
 
  bool update(Session *session, set_var *var);
759
 
  bool check_type(enum_var_type type) { return type == OPT_GLOBAL; }
760
 
  SHOW_TYPE show_type() { return SHOW_LONGLONG; }
761
 
  unsigned char *value_ptr(Session *session, enum_var_type type,
762
 
                           const LEX_STRING *base);
763
 
};
764
 
 
765
 
 
766
 
class sys_var_collation :public sys_var_session
767
 
{
768
 
public:
769
 
  sys_var_collation(const char *name_arg)
770
 
    :sys_var_session(name_arg, NULL)
771
 
  { }
772
 
  bool check(Session *session, set_var *var);
773
 
  SHOW_TYPE show_type() { return SHOW_CHAR; }
774
 
  bool check_update_type(Item_result type)
775
 
  {
776
 
    return ((type != STRING_RESULT) && (type != INT_RESULT));
777
 
  }
778
 
  bool check_default(enum_var_type) { return 0; }
779
 
  virtual void set_default(Session *session, enum_var_type type)= 0;
780
 
};
781
 
 
782
 
class sys_var_collation_sv :public sys_var_collation
783
 
{
784
 
  const CHARSET_INFO *SV::*offset;
785
 
  const CHARSET_INFO **global_default;
786
 
public:
787
 
  sys_var_collation_sv(sys_var_chain *chain, const char *name_arg,
788
 
                       const CHARSET_INFO *SV::*offset_arg,
789
 
                       const CHARSET_INFO **global_default_arg)
790
 
    :sys_var_collation(name_arg),
791
 
    offset(offset_arg), global_default(global_default_arg)
792
 
  {
793
 
    chain_sys_var(chain);
794
 
  }
795
 
  bool update(Session *session, set_var *var);
796
 
  void set_default(Session *session, enum_var_type type);
797
 
  unsigned char *value_ptr(Session *session, enum_var_type type,
798
 
                           const LEX_STRING *base);
799
 
};
800
 
 
801
 
 
802
 
class sys_var_key_cache_param :public sys_var
803
 
{
804
 
protected:
805
 
  size_t offset;
806
 
public:
807
 
  sys_var_key_cache_param(sys_var_chain *chain, const char *name_arg,
808
 
                          size_t offset_arg)
809
 
    :sys_var(name_arg), offset(offset_arg)
810
 
  { chain_sys_var(chain); }
811
 
  unsigned char *value_ptr(Session *session, enum_var_type type,
812
 
                           const LEX_STRING *base);
813
 
  bool check_default(enum_var_type)
814
 
  { return 1; }
815
 
};
816
 
 
817
 
 
818
 
class sys_var_key_buffer_size :public sys_var_key_cache_param
819
 
{
820
 
public:
821
 
  sys_var_key_buffer_size(sys_var_chain *chain, const char *name_arg);
822
 
  bool update(Session *session, set_var *var);
823
 
  SHOW_TYPE show_type() { return SHOW_LONGLONG; }
824
 
};
825
 
 
826
 
 
827
 
class sys_var_key_cache_uint32_t :public sys_var_key_cache_param
828
 
{
829
 
public:
830
 
  sys_var_key_cache_uint32_t(sys_var_chain *chain, const char *name_arg, size_t offset_arg)
831
 
    :sys_var_key_cache_param(chain, name_arg, offset_arg)
832
 
  {}
833
 
  bool update(Session *session, set_var *var);
834
 
  SHOW_TYPE show_type() { return SHOW_INT; }
835
 
};
836
 
 
837
 
/* Variable that you can only read from */
838
 
 
839
 
class sys_var_readonly: public sys_var
840
 
{
841
 
public:
842
 
  enum_var_type var_type;
843
 
  SHOW_TYPE show_type_value;
844
 
  sys_value_ptr_func value_ptr_func;
845
 
  sys_var_readonly(sys_var_chain *chain, const char *name_arg, enum_var_type type,
846
 
                   SHOW_TYPE show_type_arg,
847
 
                   sys_value_ptr_func value_ptr_func_arg)
848
 
    :sys_var(name_arg), var_type(type),
849
 
       show_type_value(show_type_arg), value_ptr_func(value_ptr_func_arg)
850
 
  { chain_sys_var(chain); }
851
 
  bool update(Session *, set_var *)
852
 
  { return 1; }
853
 
  bool check_default(enum_var_type)
854
 
  { return 1; }
855
 
  bool check_type(enum_var_type type) { return type != var_type; }
856
 
  bool check_update_type(Item_result)
857
 
  { return 1; }
858
 
  unsigned char *value_ptr(Session *session, enum_var_type,
859
 
                           const LEX_STRING *)
860
 
  {
861
 
    return (*value_ptr_func)(session);
862
 
  }
863
 
  SHOW_TYPE show_type(void) { return show_type_value; }
864
 
  bool is_readonly(void) const { return 1; }
865
 
};
866
 
 
867
 
 
868
 
class sys_var_have_option: public sys_var
869
 
{
870
 
protected:
871
 
  virtual SHOW_COMP_OPTION get_option() = 0;
872
 
public:
873
 
  sys_var_have_option(sys_var_chain *chain, const char *variable_name):
874
 
    sys_var(variable_name)
875
 
  { chain_sys_var(chain); }
876
 
  unsigned char *value_ptr(Session *, enum_var_type,
877
 
                           const LEX_STRING *)
878
 
  {
879
 
    return (unsigned char*) show_comp_option_name[get_option()];
880
 
  }
881
 
  bool update(Session *, set_var *) { return 1; }
882
 
  bool check_default(enum_var_type)
883
 
  { return 1; }
884
 
  bool check_type(enum_var_type type) { return type != OPT_GLOBAL; }
885
 
  bool check_update_type(Item_result)
886
 
  { return 1; }
887
 
  SHOW_TYPE show_type() { return SHOW_CHAR; }
888
 
  bool is_readonly() const { return 1; }
889
 
};
890
 
 
891
 
 
892
 
class sys_var_have_variable: public sys_var_have_option
893
 
{
894
 
  SHOW_COMP_OPTION *have_variable;
895
 
 
896
 
public:
897
 
  sys_var_have_variable(sys_var_chain *chain, const char *variable_name,
898
 
                        SHOW_COMP_OPTION *have_variable_arg):
899
 
    sys_var_have_option(chain, variable_name),
900
 
    have_variable(have_variable_arg)
901
 
  { }
902
 
  SHOW_COMP_OPTION get_option() { return *have_variable; }
903
 
};
904
 
 
905
 
 
906
 
class sys_var_have_plugin: public sys_var_have_option
907
 
{
908
 
  const char *plugin_name_str;
909
 
  const uint32_t plugin_name_len;
910
 
  const int plugin_type;
911
 
 
912
 
public:
913
 
  sys_var_have_plugin(sys_var_chain *chain, const char *variable_name,
914
 
                      const char *plugin_name_str_arg, uint32_t plugin_name_len_arg,
915
 
                      int plugin_type_arg):
916
 
    sys_var_have_option(chain, variable_name),
917
 
    plugin_name_str(plugin_name_str_arg), plugin_name_len(plugin_name_len_arg),
918
 
    plugin_type(plugin_type_arg)
919
 
  { }
920
 
  /* the following method is declared in sql_plugin.cc */
921
 
  SHOW_COMP_OPTION get_option();
922
 
};
923
 
 
924
 
 
925
 
class sys_var_session_time_zone :public sys_var_session
926
 
{
927
 
public:
928
 
  sys_var_session_time_zone(sys_var_chain *chain, const char *name_arg)
929
 
    :sys_var_session(name_arg, NULL)
930
 
  {
931
 
    chain_sys_var(chain);
932
 
  }
933
 
  bool check(Session *session, set_var *var);
934
 
  SHOW_TYPE show_type() { return SHOW_CHAR; }
935
 
  bool check_update_type(Item_result type)
936
 
  {
937
 
    return type != STRING_RESULT;               /* Only accept strings */
938
 
  }
939
 
  bool check_default(enum_var_type)
940
 
  { return 0; }
941
 
  bool update(Session *session, set_var *var);
942
 
  unsigned char *value_ptr(Session *session, enum_var_type type,
943
 
                           const LEX_STRING *base);
944
 
  virtual void set_default(Session *session, enum_var_type type);
945
 
};
946
 
 
947
 
 
948
 
class sys_var_microseconds :public sys_var_session
949
 
{
950
 
  uint64_t SV::*offset;
951
 
public:
952
 
  sys_var_microseconds(sys_var_chain *chain, const char *name_arg,
953
 
                       uint64_t SV::*offset_arg):
954
 
    sys_var_session(name_arg), offset(offset_arg)
955
 
  { chain_sys_var(chain); }
956
 
  bool check(Session *, set_var *) {return 0;}
957
 
  bool update(Session *session, set_var *var);
958
 
  void set_default(Session *session, enum_var_type type);
959
 
  SHOW_TYPE show_type() { return SHOW_DOUBLE; }
960
 
  bool check_update_type(Item_result type)
961
 
  {
962
 
    return (type != INT_RESULT && type != REAL_RESULT && type != DECIMAL_RESULT);
963
 
  }
964
 
};
965
 
 
966
 
class sys_var_session_lc_time_names :public sys_var_session
967
 
{
968
 
public:
969
 
  sys_var_session_lc_time_names(sys_var_chain *chain, const char *name_arg)
970
 
    : sys_var_session(name_arg, NULL)
971
 
  {
972
 
    chain_sys_var(chain);
973
 
  }
974
 
  bool check(Session *session, set_var *var);
975
 
  SHOW_TYPE show_type() { return SHOW_CHAR; }
976
 
  bool check_update_type(Item_result type)
977
 
  {
978
 
    return ((type != STRING_RESULT) && (type != INT_RESULT));
979
 
  }
980
 
  bool check_default(enum_var_type)
981
 
  { return 0; }
982
 
  bool update(Session *session, set_var *var);
983
 
  unsigned char *value_ptr(Session *session, enum_var_type type,
984
 
                           const LEX_STRING *base);
985
 
  virtual void set_default(Session *session, enum_var_type type);
986
 
};
987
 
 
988
 
 
989
 
/****************************************************************************
990
 
  Classes for parsing of the SET command
991
 
****************************************************************************/
992
 
 
993
 
class set_var_base :public drizzled::memory::SqlAlloc
994
 
{
995
 
public:
996
 
  set_var_base() {}
997
 
  virtual ~set_var_base() {}
998
 
  virtual int check(Session *session)=0;        /* To check privileges etc. */
999
 
  virtual int update(Session *session)=0;       /* To set the value */
1000
 
  /* light check for PS */
1001
 
};
1002
 
 
1003
 
/* MySQL internal variables */
1004
 
class set_var :public set_var_base
1005
 
{
1006
 
public:
1007
 
  sys_var *var;
1008
 
  Item *value;
1009
 
  enum_var_type type;
1010
 
  union
1011
 
  {
1012
 
    const CHARSET_INFO *charset;
1013
 
    uint32_t uint32_t_value;
1014
 
    uint64_t uint64_t_value;
1015
 
    size_t size_t_value;
1016
 
    drizzled::plugin::StorageEngine *storage_engine;
1017
 
    Time_zone *time_zone;
1018
 
    MY_LOCALE *locale_value;
1019
 
  } save_result;
1020
 
  LEX_STRING base;                      /* for structs */
1021
 
 
1022
 
  set_var(enum_var_type type_arg, sys_var *var_arg,
1023
 
          const LEX_STRING *base_name_arg, Item *value_arg)
1024
 
    :var(var_arg), type(type_arg), base(*base_name_arg)
1025
 
  {
1026
 
    /*
1027
 
      If the set value is a field, change it to a string to allow things like
1028
 
      SET table_type=MYISAM;
1029
 
    */
1030
 
    if (value_arg && value_arg->type() == Item::FIELD_ITEM)
1031
 
    {
1032
 
      Item_field *item= (Item_field*) value_arg;
1033
 
      if (!(value=new Item_string(item->field_name,
1034
 
                  (uint32_t) strlen(item->field_name),
1035
 
                                  item->collation.collation)))
1036
 
        value=value_arg;                        /* Give error message later */
1037
 
    }
1038
 
    else
1039
 
      value=value_arg;
1040
 
  }
1041
 
  int check(Session *session);
1042
 
  int update(Session *session);
1043
 
};
1044
 
 
1045
 
 
1046
 
/* User variables like @my_own_variable */
1047
 
 
1048
 
class set_var_user: public set_var_base
1049
 
{
1050
 
  Item_func_set_user_var *user_var_item;
1051
 
public:
1052
 
  set_var_user(Item_func_set_user_var *item)
1053
 
    :user_var_item(item)
1054
 
  {}
1055
 
  int check(Session *session);
1056
 
  int update(Session *session);
1057
 
};
1058
 
 
1059
 
 
1060
 
/* For sql_yacc */
1061
 
struct sys_var_with_base
1062
 
{
1063
 
  sys_var *var;
1064
 
  LEX_STRING base_name;
1065
 
};
1066
 
 
1067
 
/*
1068
 
  Prototypes for helper functions
1069
 
*/
1070
 
 
1071
 
int set_var_init();
1072
 
void set_var_free();
1073
 
int mysql_append_static_vars(const SHOW_VAR *show_vars, uint32_t count);
1074
 
SHOW_VAR* enumerate_sys_vars(Session *session, bool sorted);
1075
 
void drizzle_add_plugin_sysvar(sys_var_pluginvar *var);
1076
 
void drizzle_del_plugin_sysvar();
1077
 
int mysql_add_sys_var_chain(sys_var *chain, struct my_option *long_options);
1078
 
int mysql_del_sys_var_chain(sys_var *chain);
1079
 
sys_var *find_sys_var(Session *session, const char *str, uint32_t length=0);
1080
 
int sql_set_variables(Session *session, List<set_var_base> *var_list);
1081
 
bool not_all_support_one_shot(List<set_var_base> *var_list);
1082
 
extern sys_var_session_time_zone sys_time_zone;
1083
 
extern sys_var_session_bit sys_autocommit;
1084
 
const CHARSET_INFO *get_old_charset_by_name(const char *old_name);
1085
 
 
1086
 
extern sys_var_str sys_var_general_log_path, sys_var_slow_log_path;
1087
 
 
1088
 
#endif /* DRIZZLED_SET_VAR_H */