~ubuntu-branches/ubuntu/precise/mysql-5.1/precise

« back to all changes in this revision

Viewing changes to sql/set_var.h

  • Committer: Bazaar Package Importer
  • Author(s): Norbert Tretkowski
  • Date: 2010-03-17 14:56:02 UTC
  • Revision ID: james.westby@ubuntu.com-20100317145602-x7e30l1b2sb5s6w6
Tags: upstream-5.1.45
ImportĀ upstreamĀ versionĀ 5.1.45

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* Copyright (C) 2002-2006 MySQL AB
 
2
 
 
3
   This program is free software; you can redistribute it and/or modify
 
4
   it under the terms of the GNU General Public License as published by
 
5
   the Free Software Foundation; version 2 of the License.
 
6
 
 
7
   This program is distributed in the hope that it will be useful,
 
8
   but WITHOUT ANY WARRANTY; without even the implied warranty of
 
9
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
10
   GNU General Public License for more details.
 
11
 
 
12
   You should have received a copy of the GNU General Public License
 
13
   along with this program; if not, write to the Free Software
 
14
   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */
 
15
 
 
16
/* Classes to support the SET command */
 
17
 
 
18
#ifdef USE_PRAGMA_INTERFACE
 
19
#pragma interface                       /* gcc class implementation */
 
20
#endif
 
21
 
 
22
/****************************************************************************
 
23
  Variables that are changable runtime are declared using the
 
24
  following classes
 
25
****************************************************************************/
 
26
 
 
27
class sys_var;
 
28
class set_var;
 
29
class sys_var_pluginvar; /* opaque */
 
30
typedef struct system_variables SV;
 
31
typedef struct my_locale_st MY_LOCALE;
 
32
 
 
33
extern TYPELIB bool_typelib, delay_key_write_typelib, sql_mode_typelib,
 
34
  optimizer_switch_typelib, slave_exec_mode_typelib;
 
35
 
 
36
typedef int (*sys_check_func)(THD *,  set_var *);
 
37
typedef bool (*sys_update_func)(THD *, set_var *);
 
38
typedef void (*sys_after_update_func)(THD *,enum_var_type);
 
39
typedef void (*sys_set_default_func)(THD *, enum_var_type);
 
40
typedef uchar *(*sys_value_ptr_func)(THD *thd);
 
41
 
 
42
struct sys_var_chain
 
43
{
 
44
  sys_var *first;
 
45
  sys_var *last;
 
46
};
 
47
 
 
48
class sys_var
 
49
{
 
50
public:
 
51
 
 
52
  /**
 
53
    Enumeration type to indicate for a system variable whether it will be written to the binlog or not.
 
54
  */
 
55
  enum Binlog_status_enum
 
56
  {  
 
57
    /* The variable value is not in the binlog. */
 
58
    NOT_IN_BINLOG,
 
59
    /* The value of the @@session variable is in the binlog. */
 
60
    SESSION_VARIABLE_IN_BINLOG
 
61
    /*
 
62
      Currently, no @@global variable is ever in the binlog, so we
 
63
      don't need an enumeration value for that.
 
64
    */
 
65
  };
 
66
 
 
67
  sys_var *next;
 
68
  struct my_option *option_limits;      /* Updated by by set_var_init() */
 
69
  uint name_length;                     /* Updated by by set_var_init() */
 
70
  const char *name;
 
71
 
 
72
  sys_after_update_func after_update;
 
73
  bool no_support_one_shot;
 
74
  /*
 
75
    true if the value is in character_set_filesystem, 
 
76
    false otherwise.
 
77
    Note that we can't use a pointer to the charset as the system var is 
 
78
    instantiated in global scope and the charset pointers are initialized
 
79
    later.
 
80
  */  
 
81
  bool is_os_charset;
 
82
  sys_var(const char *name_arg, sys_after_update_func func= NULL,
 
83
          Binlog_status_enum binlog_status_arg= NOT_IN_BINLOG)
 
84
    :name(name_arg), after_update(func), no_support_one_shot(1),
 
85
    is_os_charset (FALSE),
 
86
    binlog_status(binlog_status_arg),
 
87
    m_allow_empty_value(TRUE)
 
88
  {}
 
89
  virtual ~sys_var() {}
 
90
  void chain_sys_var(sys_var_chain *chain_arg)
 
91
  {
 
92
    if (chain_arg->last)
 
93
      chain_arg->last->next= this;
 
94
    else
 
95
      chain_arg->first= this;
 
96
    chain_arg->last= this;
 
97
  }
 
98
  virtual bool check(THD *thd, set_var *var);
 
99
  bool check_enum(THD *thd, set_var *var, const TYPELIB *enum_names);
 
100
  bool check_set(THD *thd, set_var *var, TYPELIB *enum_names);
 
101
  bool is_written_to_binlog(enum_var_type type)
 
102
  {
 
103
    return (type == OPT_SESSION || type == OPT_DEFAULT) &&
 
104
      (binlog_status == SESSION_VARIABLE_IN_BINLOG);
 
105
  }
 
106
  virtual bool update(THD *thd, set_var *var)=0;
 
107
  virtual void set_default(THD *thd_arg, enum_var_type type) {}
 
108
  virtual SHOW_TYPE show_type() { return SHOW_UNDEF; }
 
109
  virtual uchar *value_ptr(THD *thd, enum_var_type type, LEX_STRING *base)
 
110
  { return 0; }
 
111
  virtual bool check_type(enum_var_type type)
 
112
  { return type != OPT_GLOBAL; }                /* Error if not GLOBAL */
 
113
  virtual bool check_update_type(Item_result type)
 
114
  { return type != INT_RESULT; }                /* Assume INT */
 
115
  virtual bool check_default(enum_var_type type)
 
116
  { return option_limits == 0; }
 
117
  virtual bool is_struct() { return 0; }
 
118
  virtual bool is_readonly() const { return 0; }
 
119
  CHARSET_INFO *charset(THD *thd);
 
120
  virtual sys_var_pluginvar *cast_pluginvar() { return 0; }
 
121
 
 
122
protected:
 
123
  void set_allow_empty_value(bool allow_empty_value)
 
124
  {
 
125
    m_allow_empty_value= allow_empty_value;
 
126
  }
 
127
 
 
128
private:
 
129
  const Binlog_status_enum binlog_status;
 
130
 
 
131
  bool m_allow_empty_value;
 
132
};
 
133
 
 
134
 
 
135
/*
 
136
  A base class for all variables that require its access to
 
137
  be guarded with a mutex.
 
138
*/
 
139
 
 
140
class sys_var_global: public sys_var
 
141
{
 
142
protected:
 
143
  pthread_mutex_t *guard;
 
144
public:
 
145
  sys_var_global(const char *name_arg, sys_after_update_func after_update_arg,
 
146
                 pthread_mutex_t *guard_arg)
 
147
    :sys_var(name_arg, after_update_arg), guard(guard_arg) {}
 
148
};
 
149
 
 
150
 
 
151
/*
 
152
  A global-only ulong variable that requires its access to be
 
153
  protected with a mutex.
 
154
*/
 
155
 
 
156
class sys_var_long_ptr_global: public sys_var_global
 
157
{
 
158
public:
 
159
  ulong *value;
 
160
  sys_var_long_ptr_global(sys_var_chain *chain, const char *name_arg,
 
161
                          ulong *value_ptr_arg,
 
162
                          pthread_mutex_t *guard_arg,
 
163
                          sys_after_update_func after_update_arg= NULL)
 
164
    :sys_var_global(name_arg, after_update_arg, guard_arg),
 
165
    value(value_ptr_arg)
 
166
  { chain_sys_var(chain); }
 
167
  bool check(THD *thd, set_var *var);
 
168
  bool update(THD *thd, set_var *var);
 
169
  void set_default(THD *thd, enum_var_type type);
 
170
  SHOW_TYPE show_type() { return SHOW_LONG; }
 
171
  uchar *value_ptr(THD *thd, enum_var_type type, LEX_STRING *base)
 
172
  { return (uchar*) value; }
 
173
};
 
174
 
 
175
 
 
176
/*
 
177
  A global ulong variable that is protected by LOCK_global_system_variables
 
178
*/
 
179
 
 
180
class sys_var_long_ptr :public sys_var_long_ptr_global
 
181
{
 
182
public:
 
183
  sys_var_long_ptr(sys_var_chain *chain, const char *name_arg, ulong *value_ptr,
 
184
                   sys_after_update_func after_update_arg= NULL);
 
185
};
 
186
 
 
187
 
 
188
class sys_var_ulonglong_ptr :public sys_var
 
189
{
 
190
public:
 
191
  ulonglong *value;
 
192
  sys_var_ulonglong_ptr(sys_var_chain *chain, const char *name_arg, ulonglong *value_ptr_arg)
 
193
    :sys_var(name_arg),value(value_ptr_arg)
 
194
  { chain_sys_var(chain); }
 
195
  sys_var_ulonglong_ptr(sys_var_chain *chain, const char *name_arg, ulonglong *value_ptr_arg,
 
196
                       sys_after_update_func func)
 
197
    :sys_var(name_arg,func), value(value_ptr_arg)
 
198
  { chain_sys_var(chain); }
 
199
  bool update(THD *thd, set_var *var);
 
200
  void set_default(THD *thd, enum_var_type type);
 
201
  SHOW_TYPE show_type() { return SHOW_LONGLONG; }
 
202
  uchar *value_ptr(THD *thd, enum_var_type type, LEX_STRING *base)
 
203
  { return (uchar*) value; }
 
204
};
 
205
 
 
206
 
 
207
class sys_var_bool_ptr :public sys_var
 
208
{
 
209
public:
 
210
  my_bool *value;
 
211
  sys_var_bool_ptr(sys_var_chain *chain, const char *name_arg, my_bool *value_arg)
 
212
    :sys_var(name_arg),value(value_arg)
 
213
  { chain_sys_var(chain); }
 
214
  bool check(THD *thd, set_var *var)
 
215
  {
 
216
    return check_enum(thd, var, &bool_typelib);
 
217
  }
 
218
  bool update(THD *thd, set_var *var);
 
219
  void set_default(THD *thd, enum_var_type type);
 
220
  SHOW_TYPE show_type() { return SHOW_MY_BOOL; }
 
221
  uchar *value_ptr(THD *thd, enum_var_type type, LEX_STRING *base)
 
222
  { return (uchar*) value; }
 
223
  bool check_update_type(Item_result type) { return 0; }
 
224
};
 
225
 
 
226
 
 
227
class sys_var_bool_ptr_readonly :public sys_var_bool_ptr
 
228
{
 
229
public:
 
230
  sys_var_bool_ptr_readonly(sys_var_chain *chain, const char *name_arg,
 
231
                            my_bool *value_arg)
 
232
    :sys_var_bool_ptr(chain, name_arg, value_arg)
 
233
  {}
 
234
  bool is_readonly() const { return 1; }
 
235
};
 
236
 
 
237
 
 
238
class sys_var_str :public sys_var
 
239
{
 
240
public:
 
241
  char *value;                                  // Pointer to allocated string
 
242
  uint value_length;
 
243
  sys_check_func check_func;
 
244
  sys_update_func update_func;
 
245
  sys_set_default_func set_default_func;
 
246
  sys_var_str(sys_var_chain *chain, const char *name_arg,
 
247
              sys_check_func check_func_arg,
 
248
              sys_update_func update_func_arg,
 
249
              sys_set_default_func set_default_func_arg,
 
250
              char *value_arg)
 
251
    :sys_var(name_arg), value(value_arg), check_func(check_func_arg),
 
252
    update_func(update_func_arg),set_default_func(set_default_func_arg)
 
253
  { chain_sys_var(chain); }
 
254
  bool check(THD *thd, set_var *var);
 
255
  bool update(THD *thd, set_var *var)
 
256
  {
 
257
    return (*update_func)(thd, var);
 
258
  }
 
259
  void set_default(THD *thd, enum_var_type type)
 
260
  {
 
261
    (*set_default_func)(thd, type);
 
262
  }
 
263
  SHOW_TYPE show_type() { return SHOW_CHAR; }
 
264
  uchar *value_ptr(THD *thd, enum_var_type type, LEX_STRING *base)
 
265
  { return (uchar*) value; }
 
266
  bool check_update_type(Item_result type)
 
267
  {
 
268
    return type != STRING_RESULT;               /* Only accept strings */
 
269
  }
 
270
  bool check_default(enum_var_type type) { return 0; }
 
271
};
 
272
 
 
273
 
 
274
class sys_var_const_str :public sys_var
 
275
{
 
276
public:
 
277
  char *value;                                  // Pointer to const value
 
278
  sys_var_const_str(sys_var_chain *chain, const char *name_arg,
 
279
                    const char *value_arg)
 
280
    :sys_var(name_arg), value((char*) value_arg)
 
281
  { chain_sys_var(chain); }
 
282
  bool check(THD *thd, set_var *var)
 
283
  {
 
284
    return 1;
 
285
  }
 
286
  bool update(THD *thd, set_var *var)
 
287
  {
 
288
    return 1;
 
289
  }
 
290
  SHOW_TYPE show_type() { return SHOW_CHAR; }
 
291
  uchar *value_ptr(THD *thd, enum_var_type type, LEX_STRING *base)
 
292
  {
 
293
    return (uchar*) value;
 
294
  }
 
295
  bool check_update_type(Item_result type)
 
296
  {
 
297
    return 1;
 
298
  }
 
299
  bool check_default(enum_var_type type) { return 1; }
 
300
  bool is_readonly() const { return 1; }
 
301
};
 
302
 
 
303
 
 
304
class sys_var_const_os_str: public sys_var_const_str
 
305
{
 
306
public:
 
307
  sys_var_const_os_str(sys_var_chain *chain, const char *name_arg, 
 
308
                       const char *value_arg)
 
309
    :sys_var_const_str(chain, name_arg, value_arg)
 
310
  { 
 
311
    is_os_charset= TRUE; 
 
312
  }
 
313
};
 
314
 
 
315
 
 
316
class sys_var_const_str_ptr :public sys_var
 
317
{
 
318
public:
 
319
  char **value;                                 // Pointer to const value
 
320
  sys_var_const_str_ptr(sys_var_chain *chain, const char *name_arg, char **value_arg)
 
321
    :sys_var(name_arg),value(value_arg)
 
322
  { chain_sys_var(chain); }
 
323
  bool check(THD *thd, set_var *var)
 
324
  {
 
325
    return 1;
 
326
  }
 
327
  bool update(THD *thd, set_var *var)
 
328
  {
 
329
    return 1;
 
330
  }
 
331
  SHOW_TYPE show_type() { return SHOW_CHAR; }
 
332
  uchar *value_ptr(THD *thd, enum_var_type type, LEX_STRING *base)
 
333
  {
 
334
    return (uchar*) *value;
 
335
  }
 
336
  bool check_update_type(Item_result type)
 
337
  {
 
338
    return 1;
 
339
  }
 
340
  bool check_default(enum_var_type type) { return 1; }
 
341
  bool is_readonly() const { return 1; }
 
342
};
 
343
 
 
344
 
 
345
class sys_var_const_os_str_ptr :public sys_var_const_str_ptr
 
346
{
 
347
public:
 
348
  sys_var_const_os_str_ptr(sys_var_chain *chain, const char *name_arg, 
 
349
                           char **value_arg)
 
350
    :sys_var_const_str_ptr(chain, name_arg, value_arg)
 
351
  {
 
352
    is_os_charset= TRUE; 
 
353
  }
 
354
};
 
355
 
 
356
 
 
357
class sys_var_enum :public sys_var
 
358
{
 
359
  uint *value;
 
360
  TYPELIB *enum_names;
 
361
public:
 
362
  sys_var_enum(sys_var_chain *chain, const char *name_arg, uint *value_arg,
 
363
               TYPELIB *typelib, sys_after_update_func func)
 
364
    :sys_var(name_arg,func), value(value_arg), enum_names(typelib)
 
365
  { chain_sys_var(chain); }
 
366
  bool check(THD *thd, set_var *var)
 
367
  {
 
368
    return check_enum(thd, var, enum_names);
 
369
  }
 
370
  bool update(THD *thd, set_var *var);
 
371
  SHOW_TYPE show_type() { return SHOW_CHAR; }
 
372
  uchar *value_ptr(THD *thd, enum_var_type type, LEX_STRING *base);
 
373
  bool check_update_type(Item_result type) { return 0; }
 
374
};
 
375
 
 
376
 
 
377
class sys_var_enum_const :public sys_var
 
378
{
 
379
  ulong SV::*offset;
 
380
  TYPELIB *enum_names;
 
381
public:
 
382
  sys_var_enum_const(sys_var_chain *chain, const char *name_arg, ulong SV::*offset_arg,
 
383
      TYPELIB *typelib, sys_after_update_func func)
 
384
    :sys_var(name_arg,func), offset(offset_arg), enum_names(typelib)
 
385
  { chain_sys_var(chain); }
 
386
  bool check(THD *thd, set_var *var) { return 1; }
 
387
  bool update(THD *thd, set_var *var) { return 1; }
 
388
  SHOW_TYPE show_type() { return SHOW_CHAR; }
 
389
  bool check_update_type(Item_result type) { return 1; }
 
390
  bool is_readonly() const { return 1; }
 
391
  uchar *value_ptr(THD *thd, enum_var_type type, LEX_STRING *base);
 
392
};
 
393
 
 
394
 
 
395
class sys_var_thd :public sys_var
 
396
{
 
397
public:
 
398
  sys_var_thd(const char *name_arg, 
 
399
              sys_after_update_func func= NULL,
 
400
              Binlog_status_enum binlog_status= NOT_IN_BINLOG)
 
401
    :sys_var(name_arg, func, binlog_status)
 
402
  {}
 
403
  bool check_type(enum_var_type type) { return 0; }
 
404
  bool check_default(enum_var_type type)
 
405
  {
 
406
    return type == OPT_GLOBAL && !option_limits;
 
407
  }
 
408
};
 
409
 
 
410
 
 
411
class sys_var_thd_ulong :public sys_var_thd
 
412
{
 
413
  sys_check_func check_func;
 
414
public:
 
415
  ulong SV::*offset;
 
416
  sys_var_thd_ulong(sys_var_chain *chain, const char *name_arg,
 
417
                    ulong SV::*offset_arg,
 
418
                    sys_check_func c_func= NULL,
 
419
                    sys_after_update_func au_func= NULL,
 
420
                    Binlog_status_enum binlog_status_arg= NOT_IN_BINLOG)
 
421
    :sys_var_thd(name_arg, au_func, binlog_status_arg), check_func(c_func),
 
422
    offset(offset_arg)
 
423
  { chain_sys_var(chain); }
 
424
  bool check(THD *thd, set_var *var);
 
425
  bool update(THD *thd, set_var *var);
 
426
  void set_default(THD *thd, enum_var_type type);
 
427
  SHOW_TYPE show_type() { return SHOW_LONG; }
 
428
  uchar *value_ptr(THD *thd, enum_var_type type, LEX_STRING *base);
 
429
};
 
430
 
 
431
 
 
432
class sys_var_thd_ha_rows :public sys_var_thd
 
433
{
 
434
public:
 
435
  ha_rows SV::*offset;
 
436
  sys_var_thd_ha_rows(sys_var_chain *chain, const char *name_arg, 
 
437
                      ha_rows SV::*offset_arg)
 
438
    :sys_var_thd(name_arg), offset(offset_arg)
 
439
  { chain_sys_var(chain); }
 
440
  sys_var_thd_ha_rows(sys_var_chain *chain, const char *name_arg, 
 
441
                      ha_rows SV::*offset_arg,
 
442
                      sys_after_update_func func)
 
443
    :sys_var_thd(name_arg,func), offset(offset_arg)
 
444
  { chain_sys_var(chain); }
 
445
  bool update(THD *thd, set_var *var);
 
446
  void set_default(THD *thd, enum_var_type type);
 
447
  SHOW_TYPE show_type() { return SHOW_HA_ROWS; }
 
448
  uchar *value_ptr(THD *thd, enum_var_type type, LEX_STRING *base);
 
449
};
 
450
 
 
451
 
 
452
class sys_var_thd_ulonglong :public sys_var_thd
 
453
{
 
454
public:
 
455
  ulonglong SV::*offset;
 
456
  bool only_global;
 
457
  sys_var_thd_ulonglong(sys_var_chain *chain, const char *name_arg, 
 
458
                        ulonglong SV::*offset_arg)
 
459
    :sys_var_thd(name_arg), offset(offset_arg)
 
460
  { chain_sys_var(chain); }
 
461
  sys_var_thd_ulonglong(sys_var_chain *chain, const char *name_arg, 
 
462
                        ulonglong SV::*offset_arg,
 
463
                        sys_after_update_func func, bool only_global_arg)
 
464
    :sys_var_thd(name_arg, func), offset(offset_arg),
 
465
    only_global(only_global_arg)
 
466
  { chain_sys_var(chain); }
 
467
  bool update(THD *thd, set_var *var);
 
468
  void set_default(THD *thd, enum_var_type type);
 
469
  SHOW_TYPE show_type() { return SHOW_LONGLONG; }
 
470
  uchar *value_ptr(THD *thd, enum_var_type type, LEX_STRING *base);
 
471
  bool check(THD *thd, set_var *var);
 
472
  bool check_default(enum_var_type type)
 
473
  {
 
474
    return type == OPT_GLOBAL && !option_limits;
 
475
  }
 
476
  bool check_type(enum_var_type type)
 
477
  {
 
478
    return (only_global && type != OPT_GLOBAL);
 
479
  }
 
480
};
 
481
 
 
482
 
 
483
class sys_var_thd_bool :public sys_var_thd
 
484
{
 
485
public:
 
486
  my_bool SV::*offset;
 
487
  sys_var_thd_bool(sys_var_chain *chain, const char *name_arg, my_bool SV::*offset_arg)
 
488
    :sys_var_thd(name_arg), offset(offset_arg)
 
489
  { chain_sys_var(chain); }
 
490
  sys_var_thd_bool(sys_var_chain *chain, const char *name_arg, my_bool SV::*offset_arg,
 
491
                   sys_after_update_func func)
 
492
    :sys_var_thd(name_arg,func), offset(offset_arg)
 
493
  { chain_sys_var(chain); }
 
494
  bool update(THD *thd, set_var *var);
 
495
  void set_default(THD *thd, enum_var_type type);
 
496
  SHOW_TYPE show_type() { return SHOW_MY_BOOL; }
 
497
  uchar *value_ptr(THD *thd, enum_var_type type, LEX_STRING *base);
 
498
  bool check(THD *thd, set_var *var)
 
499
  {
 
500
    return check_enum(thd, var, &bool_typelib);
 
501
  }
 
502
  bool check_update_type(Item_result type) { return 0; }
 
503
};
 
504
 
 
505
 
 
506
class sys_var_thd_enum :public sys_var_thd
 
507
{
 
508
protected:
 
509
  ulong SV::*offset;
 
510
  TYPELIB *enum_names;
 
511
  sys_check_func check_func;
 
512
public:
 
513
  sys_var_thd_enum(sys_var_chain *chain, const char *name_arg,
 
514
                   ulong SV::*offset_arg, TYPELIB *typelib,
 
515
                   sys_after_update_func func= NULL,
 
516
                   sys_check_func check= NULL)
 
517
    :sys_var_thd(name_arg, func), offset(offset_arg),
 
518
    enum_names(typelib), check_func(check)
 
519
  { chain_sys_var(chain); }
 
520
  bool check(THD *thd, set_var *var)
 
521
  {
 
522
    int ret= 0;
 
523
    if (check_func)
 
524
      ret= (*check_func)(thd, var);
 
525
    return ret ? ret : check_enum(thd, var, enum_names);
 
526
  }
 
527
  bool update(THD *thd, set_var *var);
 
528
  void set_default(THD *thd, enum_var_type type);
 
529
  SHOW_TYPE show_type() { return SHOW_CHAR; }
 
530
  uchar *value_ptr(THD *thd, enum_var_type type, LEX_STRING *base);
 
531
  bool check_update_type(Item_result type) { return 0; }
 
532
};
 
533
 
 
534
 
 
535
class sys_var_thd_optimizer_switch :public sys_var_thd_enum
 
536
{
 
537
public:
 
538
  sys_var_thd_optimizer_switch(sys_var_chain *chain, const char *name_arg, 
 
539
                               ulong SV::*offset_arg)
 
540
    :sys_var_thd_enum(chain, name_arg, offset_arg, &optimizer_switch_typelib)
 
541
  {}
 
542
  bool check(THD *thd, set_var *var);
 
543
  void set_default(THD *thd, enum_var_type type);
 
544
  uchar *value_ptr(THD *thd, enum_var_type type, LEX_STRING *base);
 
545
  static bool symbolic_mode_representation(THD *thd, ulonglong sql_mode,
 
546
                                           LEX_STRING *rep);
 
547
};
 
548
 
 
549
extern void fix_sql_mode_var(THD *thd, enum_var_type type);
 
550
 
 
551
class sys_var_thd_sql_mode :public sys_var_thd_enum
 
552
{
 
553
public:
 
554
  sys_var_thd_sql_mode(sys_var_chain *chain, const char *name_arg, 
 
555
                       ulong SV::*offset_arg)
 
556
    :sys_var_thd_enum(chain, name_arg, offset_arg, &sql_mode_typelib,
 
557
                      fix_sql_mode_var)
 
558
  {}
 
559
  bool check(THD *thd, set_var *var)
 
560
  {
 
561
    return check_set(thd, var, enum_names);
 
562
  }
 
563
  void set_default(THD *thd, enum_var_type type);
 
564
  uchar *value_ptr(THD *thd, enum_var_type type, LEX_STRING *base);
 
565
  static bool symbolic_mode_representation(THD *thd, ulonglong sql_mode,
 
566
                                           LEX_STRING *rep);
 
567
};
 
568
 
 
569
 
 
570
class sys_var_thd_storage_engine :public sys_var_thd
 
571
{
 
572
protected:
 
573
  plugin_ref SV::*offset;
 
574
public:
 
575
  sys_var_thd_storage_engine(sys_var_chain *chain, const char *name_arg, 
 
576
                             plugin_ref SV::*offset_arg)
 
577
    :sys_var_thd(name_arg), offset(offset_arg)
 
578
  { chain_sys_var(chain); }
 
579
  bool check(THD *thd, set_var *var);
 
580
  SHOW_TYPE show_type() { return SHOW_CHAR; }
 
581
  bool check_update_type(Item_result type)
 
582
  {
 
583
    return type != STRING_RESULT;               /* Only accept strings */
 
584
  }
 
585
  void set_default(THD *thd, enum_var_type type);
 
586
  bool update(THD *thd, set_var *var);
 
587
  uchar *value_ptr(THD *thd, enum_var_type type, LEX_STRING *base);
 
588
};
 
589
 
 
590
class sys_var_thd_table_type :public sys_var_thd_storage_engine
 
591
{
 
592
public:
 
593
  sys_var_thd_table_type(sys_var_chain *chain, const char *name_arg, 
 
594
                         plugin_ref SV::*offset_arg)
 
595
    :sys_var_thd_storage_engine(chain, name_arg, offset_arg)
 
596
  {}
 
597
  void warn_deprecated(THD *thd);
 
598
  void set_default(THD *thd, enum_var_type type);
 
599
  bool update(THD *thd, set_var *var);
 
600
};
 
601
 
 
602
class sys_var_thd_bit :public sys_var_thd
 
603
{
 
604
  sys_check_func check_func;
 
605
  sys_update_func update_func;
 
606
public:
 
607
  ulonglong bit_flag;
 
608
  bool reverse;
 
609
  sys_var_thd_bit(sys_var_chain *chain, const char *name_arg,
 
610
                  sys_check_func c_func, sys_update_func u_func,
 
611
                  ulonglong bit, bool reverse_arg=0,
 
612
                  Binlog_status_enum binlog_status_arg= NOT_IN_BINLOG)
 
613
    :sys_var_thd(name_arg, NULL, binlog_status_arg), check_func(c_func),
 
614
    update_func(u_func), bit_flag(bit), reverse(reverse_arg)
 
615
  { chain_sys_var(chain); }
 
616
  bool check(THD *thd, set_var *var);
 
617
  bool update(THD *thd, set_var *var);
 
618
  bool check_update_type(Item_result type) { return 0; }
 
619
  bool check_type(enum_var_type type) { return type == OPT_GLOBAL; }
 
620
  SHOW_TYPE show_type() { return SHOW_MY_BOOL; }
 
621
  uchar *value_ptr(THD *thd, enum_var_type type, LEX_STRING *base);
 
622
};
 
623
 
 
624
#ifndef DBUG_OFF
 
625
class sys_var_thd_dbug :public sys_var_thd
 
626
{
 
627
public:
 
628
  sys_var_thd_dbug(sys_var_chain *chain, const char *name_arg)
 
629
    :sys_var_thd(name_arg)
 
630
  { chain_sys_var(chain); }
 
631
  bool check_update_type(Item_result type) { return type != STRING_RESULT; }
 
632
  bool check(THD *thd, set_var *var);
 
633
  SHOW_TYPE show_type() { return SHOW_CHAR; }
 
634
  bool update(THD *thd, set_var *var);
 
635
  void set_default(THD *thd, enum_var_type type) { DBUG_POP(); }
 
636
  uchar *value_ptr(THD *thd, enum_var_type type, LEX_STRING *b);
 
637
};
 
638
#endif /* DBUG_OFF */
 
639
 
 
640
#if defined(ENABLED_DEBUG_SYNC)
 
641
/* Debug Sync Facility. Implemented in debug_sync.cc. */
 
642
class sys_var_debug_sync :public sys_var_thd
 
643
{
 
644
public:
 
645
  sys_var_debug_sync(sys_var_chain *chain, const char *name_arg)
 
646
    :sys_var_thd(name_arg)
 
647
  { chain_sys_var(chain); }
 
648
  bool check(THD *thd, set_var *var);
 
649
  bool update(THD *thd, set_var *var);
 
650
  SHOW_TYPE show_type() { return SHOW_CHAR; }
 
651
  bool check_update_type(Item_result type) { return type != STRING_RESULT; }
 
652
  uchar *value_ptr(THD *thd, enum_var_type type, LEX_STRING *base);
 
653
};
 
654
#endif /* defined(ENABLED_DEBUG_SYNC) */
 
655
 
 
656
/* some variables that require special handling */
 
657
 
 
658
class sys_var_timestamp :public sys_var
 
659
{
 
660
public:
 
661
  sys_var_timestamp(sys_var_chain *chain, const char *name_arg,
 
662
                    Binlog_status_enum binlog_status_arg= NOT_IN_BINLOG)
 
663
    :sys_var(name_arg, NULL, binlog_status_arg)
 
664
  { chain_sys_var(chain); }
 
665
  bool update(THD *thd, set_var *var);
 
666
  void set_default(THD *thd, enum_var_type type);
 
667
  bool check_type(enum_var_type type)    { return type == OPT_GLOBAL; }
 
668
  bool check_default(enum_var_type type) { return 0; }
 
669
  SHOW_TYPE show_type() { return SHOW_LONG; }
 
670
  uchar *value_ptr(THD *thd, enum_var_type type, LEX_STRING *base);
 
671
};
 
672
 
 
673
 
 
674
class sys_var_last_insert_id :public sys_var
 
675
{
 
676
public:
 
677
  sys_var_last_insert_id(sys_var_chain *chain, const char *name_arg,
 
678
                         Binlog_status_enum binlog_status_arg= NOT_IN_BINLOG)
 
679
    :sys_var(name_arg, NULL, binlog_status_arg)
 
680
  { chain_sys_var(chain); }
 
681
  bool update(THD *thd, set_var *var);
 
682
  bool check_type(enum_var_type type) { return type == OPT_GLOBAL; }
 
683
  SHOW_TYPE show_type() { return SHOW_LONGLONG; }
 
684
  uchar *value_ptr(THD *thd, enum_var_type type, LEX_STRING *base);
 
685
};
 
686
 
 
687
 
 
688
class sys_var_insert_id :public sys_var
 
689
{
 
690
public:
 
691
  sys_var_insert_id(sys_var_chain *chain, const char *name_arg)
 
692
    :sys_var(name_arg)
 
693
  { chain_sys_var(chain); }
 
694
  bool update(THD *thd, set_var *var);
 
695
  bool check_type(enum_var_type type) { return type == OPT_GLOBAL; }
 
696
  SHOW_TYPE show_type() { return SHOW_LONGLONG; }
 
697
  uchar *value_ptr(THD *thd, enum_var_type type, LEX_STRING *base);
 
698
};
 
699
 
 
700
 
 
701
class sys_var_rand_seed1 :public sys_var
 
702
{
 
703
public:
 
704
  sys_var_rand_seed1(sys_var_chain *chain, const char *name_arg,
 
705
                     Binlog_status_enum binlog_status_arg= NOT_IN_BINLOG)
 
706
    :sys_var(name_arg, NULL, binlog_status_arg)
 
707
  { chain_sys_var(chain); }
 
708
  bool update(THD *thd, set_var *var);
 
709
  bool check_type(enum_var_type type) { return type == OPT_GLOBAL; }
 
710
};
 
711
 
 
712
class sys_var_rand_seed2 :public sys_var
 
713
{
 
714
public:
 
715
  sys_var_rand_seed2(sys_var_chain *chain, const char *name_arg,
 
716
                     Binlog_status_enum binlog_status_arg= NOT_IN_BINLOG)
 
717
    :sys_var(name_arg, NULL, binlog_status_arg)
 
718
  { chain_sys_var(chain); }
 
719
  bool update(THD *thd, set_var *var);
 
720
  bool check_type(enum_var_type type) { return type == OPT_GLOBAL; }
 
721
};
 
722
 
 
723
 
 
724
class sys_var_collation :public sys_var_thd
 
725
{
 
726
public:
 
727
  sys_var_collation(const char *name_arg,
 
728
                    Binlog_status_enum binlog_status_arg= NOT_IN_BINLOG)
 
729
    :sys_var_thd(name_arg, NULL, binlog_status_arg)
 
730
  {
 
731
    no_support_one_shot= 0;
 
732
  }
 
733
  bool check(THD *thd, set_var *var);
 
734
  SHOW_TYPE show_type() { return SHOW_CHAR; }
 
735
  bool check_update_type(Item_result type)
 
736
  {
 
737
    return ((type != STRING_RESULT) && (type != INT_RESULT));
 
738
  }
 
739
  bool check_default(enum_var_type type) { return 0; }
 
740
  virtual void set_default(THD *thd, enum_var_type type)= 0;
 
741
};
 
742
 
 
743
class sys_var_character_set :public sys_var_thd
 
744
{
 
745
public:
 
746
  bool nullable;
 
747
  sys_var_character_set(const char *name_arg, bool is_nullable= 0,
 
748
                        Binlog_status_enum binlog_status_arg= NOT_IN_BINLOG)
 
749
    :sys_var_thd(name_arg, NULL, binlog_status_arg), nullable(is_nullable)
 
750
  {
 
751
    /*
 
752
      In fact only almost all variables derived from sys_var_character_set
 
753
      support ONE_SHOT; character_set_results doesn't. But that's good enough.
 
754
    */
 
755
    no_support_one_shot= 0;
 
756
  }
 
757
  bool check(THD *thd, set_var *var);
 
758
  SHOW_TYPE show_type() { return SHOW_CHAR; }
 
759
  bool check_update_type(Item_result type)
 
760
  {
 
761
    return ((type != STRING_RESULT) && (type != INT_RESULT));
 
762
  }
 
763
  bool check_default(enum_var_type type) { return 0; }
 
764
  bool update(THD *thd, set_var *var);
 
765
  uchar *value_ptr(THD *thd, enum_var_type type, LEX_STRING *base);
 
766
  virtual void set_default(THD *thd, enum_var_type type)= 0;
 
767
  virtual CHARSET_INFO **ci_ptr(THD *thd, enum_var_type type)= 0;
 
768
};
 
769
 
 
770
class sys_var_character_set_sv :public sys_var_character_set
 
771
{
 
772
  CHARSET_INFO *SV::*offset;
 
773
  CHARSET_INFO **global_default;
 
774
public:
 
775
  sys_var_character_set_sv(sys_var_chain *chain, const char *name_arg,
 
776
                           CHARSET_INFO *SV::*offset_arg,
 
777
                           CHARSET_INFO **global_default_arg,
 
778
                           bool is_nullable= 0,
 
779
                           Binlog_status_enum binlog_status_arg= NOT_IN_BINLOG)
 
780
    : sys_var_character_set(name_arg, is_nullable, binlog_status_arg),
 
781
    offset(offset_arg), global_default(global_default_arg)
 
782
  { chain_sys_var(chain); }
 
783
  void set_default(THD *thd, enum_var_type type);
 
784
  CHARSET_INFO **ci_ptr(THD *thd, enum_var_type type);
 
785
};
 
786
 
 
787
 
 
788
class sys_var_character_set_client: public sys_var_character_set_sv
 
789
{
 
790
public:
 
791
  sys_var_character_set_client(sys_var_chain *chain, const char *name_arg,
 
792
                               CHARSET_INFO *SV::*offset_arg,
 
793
                               CHARSET_INFO **global_default_arg,
 
794
                               Binlog_status_enum binlog_status_arg)
 
795
    : sys_var_character_set_sv(chain, name_arg, offset_arg, global_default_arg,
 
796
                               0, binlog_status_arg)
 
797
  { }
 
798
  bool check(THD *thd, set_var *var);
 
799
};
 
800
 
 
801
 
 
802
class sys_var_character_set_database :public sys_var_character_set
 
803
{
 
804
public:
 
805
  sys_var_character_set_database(sys_var_chain *chain, const char *name_arg,
 
806
                                 Binlog_status_enum binlog_status_arg=
 
807
                                   NOT_IN_BINLOG)
 
808
    : sys_var_character_set(name_arg, 0, binlog_status_arg)
 
809
  { chain_sys_var(chain); }
 
810
  void set_default(THD *thd, enum_var_type type);
 
811
  CHARSET_INFO **ci_ptr(THD *thd, enum_var_type type);
 
812
};
 
813
 
 
814
class sys_var_collation_sv :public sys_var_collation
 
815
{
 
816
  CHARSET_INFO *SV::*offset;
 
817
  CHARSET_INFO **global_default;
 
818
public:
 
819
  sys_var_collation_sv(sys_var_chain *chain, const char *name_arg,
 
820
                       CHARSET_INFO *SV::*offset_arg,
 
821
                       CHARSET_INFO **global_default_arg,
 
822
                       Binlog_status_enum binlog_status_arg= NOT_IN_BINLOG)
 
823
    :sys_var_collation(name_arg, binlog_status_arg),
 
824
    offset(offset_arg), global_default(global_default_arg)
 
825
  {
 
826
    chain_sys_var(chain);
 
827
  }
 
828
  bool update(THD *thd, set_var *var);
 
829
  void set_default(THD *thd, enum_var_type type);
 
830
  uchar *value_ptr(THD *thd, enum_var_type type, LEX_STRING *base);
 
831
};
 
832
 
 
833
 
 
834
class sys_var_key_cache_param :public sys_var
 
835
{
 
836
protected:
 
837
  size_t offset;
 
838
public:
 
839
  sys_var_key_cache_param(sys_var_chain *chain, const char *name_arg, 
 
840
                          size_t offset_arg)
 
841
    :sys_var(name_arg), offset(offset_arg)
 
842
  { chain_sys_var(chain); }
 
843
  uchar *value_ptr(THD *thd, enum_var_type type, LEX_STRING *base);
 
844
  bool check_default(enum_var_type type) { return 1; }
 
845
  bool is_struct() { return 1; }
 
846
};
 
847
 
 
848
 
 
849
class sys_var_key_buffer_size :public sys_var_key_cache_param
 
850
{
 
851
public:
 
852
  sys_var_key_buffer_size(sys_var_chain *chain, const char *name_arg)
 
853
    :sys_var_key_cache_param(chain, name_arg,
 
854
                             offsetof(KEY_CACHE, param_buff_size))
 
855
  {}
 
856
  bool update(THD *thd, set_var *var);
 
857
  SHOW_TYPE show_type() { return SHOW_LONGLONG; }
 
858
};
 
859
 
 
860
 
 
861
class sys_var_key_cache_long :public sys_var_key_cache_param
 
862
{
 
863
public:
 
864
  sys_var_key_cache_long(sys_var_chain *chain, const char *name_arg, size_t offset_arg)
 
865
    :sys_var_key_cache_param(chain, name_arg, offset_arg)
 
866
  {}
 
867
  bool update(THD *thd, set_var *var);
 
868
  SHOW_TYPE show_type() { return SHOW_LONG; }
 
869
};
 
870
 
 
871
 
 
872
class sys_var_thd_date_time_format :public sys_var_thd
 
873
{
 
874
  DATE_TIME_FORMAT *SV::*offset;
 
875
  timestamp_type date_time_type;
 
876
public:
 
877
  sys_var_thd_date_time_format(sys_var_chain *chain, const char *name_arg,
 
878
                               DATE_TIME_FORMAT *SV::*offset_arg,
 
879
                               timestamp_type date_time_type_arg)
 
880
    :sys_var_thd(name_arg), offset(offset_arg),
 
881
    date_time_type(date_time_type_arg)
 
882
  { chain_sys_var(chain); }
 
883
  SHOW_TYPE show_type() { return SHOW_CHAR; }
 
884
  bool check_update_type(Item_result type)
 
885
  {
 
886
    return type != STRING_RESULT;               /* Only accept strings */
 
887
  }
 
888
  bool check_default(enum_var_type type) { return 0; }
 
889
  bool check(THD *thd, set_var *var);
 
890
  bool update(THD *thd, set_var *var);
 
891
  void update2(THD *thd, enum_var_type type, DATE_TIME_FORMAT *new_value);
 
892
  uchar *value_ptr(THD *thd, enum_var_type type, LEX_STRING *base);
 
893
  void set_default(THD *thd, enum_var_type type);
 
894
};
 
895
 
 
896
 
 
897
class sys_var_log_state :public sys_var_bool_ptr
 
898
{
 
899
  uint log_type;
 
900
public:
 
901
  sys_var_log_state(sys_var_chain *chain, const char *name_arg, my_bool *value_arg, 
 
902
                    uint log_type_arg)
 
903
    :sys_var_bool_ptr(chain, name_arg, value_arg), log_type(log_type_arg) {}
 
904
  bool update(THD *thd, set_var *var);
 
905
  void set_default(THD *thd, enum_var_type type);
 
906
};
 
907
 
 
908
 
 
909
class sys_var_set :public sys_var
 
910
{
 
911
protected:
 
912
  ulong *value;
 
913
  TYPELIB *enum_names;
 
914
public:
 
915
  sys_var_set(sys_var_chain *chain, const char *name_arg, ulong *value_arg,
 
916
              TYPELIB *typelib, sys_after_update_func func)
 
917
    :sys_var(name_arg, func), value(value_arg), enum_names(typelib)
 
918
  { chain_sys_var(chain); }
 
919
  virtual bool check(THD *thd, set_var *var)
 
920
  {
 
921
    return check_set(thd, var, enum_names);
 
922
  }
 
923
  virtual void set_default(THD *thd, enum_var_type type)
 
924
  {  
 
925
    *value= 0;
 
926
  }
 
927
  bool update(THD *thd, set_var *var);
 
928
  uchar *value_ptr(THD *thd, enum_var_type type, LEX_STRING *base);
 
929
  bool check_update_type(Item_result type) { return 0; }
 
930
  SHOW_TYPE show_type() { return SHOW_CHAR; }
 
931
};
 
932
 
 
933
class sys_var_set_slave_mode :public sys_var_set
 
934
{
 
935
public:
 
936
  sys_var_set_slave_mode(sys_var_chain *chain, const char *name_arg,
 
937
                         ulong *value_arg,
 
938
                         TYPELIB *typelib, sys_after_update_func func) :
 
939
    sys_var_set(chain, name_arg, value_arg, typelib, func) {}
 
940
  void set_default(THD *thd, enum_var_type type);
 
941
  bool check(THD *thd, set_var *var);
 
942
  bool update(THD *thd, set_var *var);
 
943
};
 
944
 
 
945
class sys_var_log_output :public sys_var
 
946
{
 
947
  ulong *value;
 
948
  TYPELIB *enum_names;
 
949
public:
 
950
  sys_var_log_output(sys_var_chain *chain, const char *name_arg, ulong *value_arg,
 
951
                     TYPELIB *typelib, sys_after_update_func func)
 
952
    :sys_var(name_arg,func), value(value_arg), enum_names(typelib)
 
953
  {
 
954
    chain_sys_var(chain);
 
955
    set_allow_empty_value(FALSE);
 
956
  }
 
957
  virtual bool check(THD *thd, set_var *var)
 
958
  {
 
959
    return check_set(thd, var, enum_names);
 
960
  }
 
961
  bool update(THD *thd, set_var *var);
 
962
  uchar *value_ptr(THD *thd, enum_var_type type, LEX_STRING *base);
 
963
  bool check_update_type(Item_result type) { return 0; }
 
964
  void set_default(THD *thd, enum_var_type type);
 
965
  SHOW_TYPE show_type() { return SHOW_CHAR; }
 
966
};
 
967
 
 
968
 
 
969
/* Variable that you can only read from */
 
970
 
 
971
class sys_var_readonly: public sys_var
 
972
{
 
973
public:
 
974
  enum_var_type var_type;
 
975
  SHOW_TYPE show_type_value;
 
976
  sys_value_ptr_func value_ptr_func;
 
977
  sys_var_readonly(sys_var_chain *chain, const char *name_arg, enum_var_type type,
 
978
                   SHOW_TYPE show_type_arg,
 
979
                   sys_value_ptr_func value_ptr_func_arg)
 
980
    :sys_var(name_arg), var_type(type), 
 
981
       show_type_value(show_type_arg), value_ptr_func(value_ptr_func_arg)
 
982
  { chain_sys_var(chain); }
 
983
  bool update(THD *thd, set_var *var) { return 1; }
 
984
  bool check_default(enum_var_type type) { return 1; }
 
985
  bool check_type(enum_var_type type) { return type != var_type; }
 
986
  bool check_update_type(Item_result type) { return 1; }
 
987
  uchar *value_ptr(THD *thd, enum_var_type type, LEX_STRING *base)
 
988
  {
 
989
    return (*value_ptr_func)(thd);
 
990
  }
 
991
  SHOW_TYPE show_type() { return show_type_value; }
 
992
  bool is_readonly() const { return 1; }
 
993
};
 
994
 
 
995
 
 
996
class sys_var_readonly_os: public sys_var_readonly
 
997
{
 
998
public:
 
999
  sys_var_readonly_os(sys_var_chain *chain, const char *name_arg, enum_var_type type,
 
1000
                   SHOW_TYPE show_type_arg,
 
1001
                   sys_value_ptr_func value_ptr_func_arg)
 
1002
    :sys_var_readonly(chain, name_arg, type, show_type_arg, value_ptr_func_arg)
 
1003
  {
 
1004
    is_os_charset= TRUE;
 
1005
  }
 
1006
};
 
1007
 
 
1008
 
 
1009
/**
 
1010
  Global-only, read-only variable. E.g. command line option.
 
1011
*/
 
1012
 
 
1013
class sys_var_const: public sys_var
 
1014
{
 
1015
public:
 
1016
  enum_var_type var_type;
 
1017
  SHOW_TYPE show_type_value;
 
1018
  uchar *ptr;
 
1019
  sys_var_const(sys_var_chain *chain, const char *name_arg, enum_var_type type,
 
1020
                SHOW_TYPE show_type_arg, uchar *ptr_arg)
 
1021
    :sys_var(name_arg), var_type(type),
 
1022
    show_type_value(show_type_arg), ptr(ptr_arg)
 
1023
  { chain_sys_var(chain); }
 
1024
  bool update(THD *thd, set_var *var) { return 1; }
 
1025
  bool check_default(enum_var_type type) { return 1; }
 
1026
  bool check_type(enum_var_type type) { return type != var_type; }
 
1027
  bool check_update_type(Item_result type) { return 1; }
 
1028
  uchar *value_ptr(THD *thd, enum_var_type type, LEX_STRING *base)
 
1029
  {
 
1030
    return ptr;
 
1031
  }
 
1032
  SHOW_TYPE show_type() { return show_type_value; }
 
1033
  bool is_readonly() const { return 1; }
 
1034
};
 
1035
 
 
1036
 
 
1037
class sys_var_const_os: public sys_var_const
 
1038
{
 
1039
public:
 
1040
  enum_var_type var_type;
 
1041
  SHOW_TYPE show_type_value;
 
1042
  uchar *ptr;
 
1043
  sys_var_const_os(sys_var_chain *chain, const char *name_arg, 
 
1044
                   enum_var_type type,
 
1045
                SHOW_TYPE show_type_arg, uchar *ptr_arg)
 
1046
    :sys_var_const(chain, name_arg, type, show_type_arg, ptr_arg)
 
1047
  {
 
1048
    is_os_charset= TRUE;
 
1049
  }
 
1050
};
 
1051
 
 
1052
 
 
1053
class sys_var_have_option: public sys_var
 
1054
{
 
1055
protected:
 
1056
  virtual SHOW_COMP_OPTION get_option() = 0;
 
1057
public:
 
1058
  sys_var_have_option(sys_var_chain *chain, const char *variable_name):
 
1059
    sys_var(variable_name)
 
1060
  { chain_sys_var(chain); }
 
1061
  uchar *value_ptr(THD *thd, enum_var_type type, LEX_STRING *base)
 
1062
  {
 
1063
    return (uchar*) show_comp_option_name[get_option()];
 
1064
  }
 
1065
  bool update(THD *thd, set_var *var) { return 1; }
 
1066
  bool check_default(enum_var_type type) { return 1; }
 
1067
  bool check_type(enum_var_type type) { return type != OPT_GLOBAL; }
 
1068
  bool check_update_type(Item_result type) { return 1; }
 
1069
  SHOW_TYPE show_type() { return SHOW_CHAR; }
 
1070
  bool is_readonly() const { return 1; }
 
1071
};
 
1072
 
 
1073
 
 
1074
class sys_var_have_variable: public sys_var_have_option
 
1075
{
 
1076
  SHOW_COMP_OPTION *have_variable;
 
1077
 
 
1078
public:
 
1079
  sys_var_have_variable(sys_var_chain *chain, const char *variable_name,
 
1080
                        SHOW_COMP_OPTION *have_variable_arg):
 
1081
    sys_var_have_option(chain, variable_name),
 
1082
    have_variable(have_variable_arg)
 
1083
  { }
 
1084
  SHOW_COMP_OPTION get_option() { return *have_variable; }
 
1085
};
 
1086
 
 
1087
 
 
1088
class sys_var_have_plugin: public sys_var_have_option
 
1089
{
 
1090
  const char *plugin_name_str;
 
1091
  const uint plugin_name_len;
 
1092
  const int plugin_type;
 
1093
 
 
1094
public:
 
1095
  sys_var_have_plugin(sys_var_chain *chain, const char *variable_name,
 
1096
                      const char *plugin_name_str_arg, uint plugin_name_len_arg, 
 
1097
                      int plugin_type_arg):
 
1098
    sys_var_have_option(chain, variable_name), 
 
1099
    plugin_name_str(plugin_name_str_arg), plugin_name_len(plugin_name_len_arg),
 
1100
    plugin_type(plugin_type_arg)
 
1101
  { }
 
1102
  /* the following method is declared in sql_plugin.cc */
 
1103
  SHOW_COMP_OPTION get_option();
 
1104
};
 
1105
 
 
1106
 
 
1107
class sys_var_thd_time_zone :public sys_var_thd
 
1108
{
 
1109
public:
 
1110
  sys_var_thd_time_zone(sys_var_chain *chain, const char *name_arg,
 
1111
                        Binlog_status_enum binlog_status_arg= NOT_IN_BINLOG)
 
1112
    :sys_var_thd(name_arg, NULL, binlog_status_arg)
 
1113
  {
 
1114
    no_support_one_shot= 0;
 
1115
    chain_sys_var(chain);
 
1116
  }
 
1117
  bool check(THD *thd, set_var *var);
 
1118
  SHOW_TYPE show_type() { return SHOW_CHAR; }
 
1119
  bool check_update_type(Item_result type)
 
1120
  {
 
1121
    return type != STRING_RESULT;               /* Only accept strings */
 
1122
  }
 
1123
  bool check_default(enum_var_type type) { return 0; }
 
1124
  bool update(THD *thd, set_var *var);
 
1125
  uchar *value_ptr(THD *thd, enum_var_type type, LEX_STRING *base);
 
1126
  virtual void set_default(THD *thd, enum_var_type type);
 
1127
};
 
1128
 
 
1129
 
 
1130
class sys_var_max_user_conn : public sys_var_thd
 
1131
{
 
1132
public:
 
1133
  sys_var_max_user_conn(sys_var_chain *chain, const char *name_arg):
 
1134
    sys_var_thd(name_arg)
 
1135
  { chain_sys_var(chain); }
 
1136
  bool check(THD *thd, set_var *var);
 
1137
  bool update(THD *thd, set_var *var);
 
1138
  bool check_default(enum_var_type type)
 
1139
  {
 
1140
    return type != OPT_GLOBAL || !option_limits;
 
1141
  }
 
1142
  void set_default(THD *thd, enum_var_type type);
 
1143
  SHOW_TYPE show_type() { return SHOW_INT; }
 
1144
  uchar *value_ptr(THD *thd, enum_var_type type, LEX_STRING *base);
 
1145
};
 
1146
 
 
1147
 
 
1148
/**
 
1149
 * @brief This is a specialization of sys_var_thd_ulong that implements a 
 
1150
   read-only session variable. The class overrides check() and check_default() 
 
1151
   to achieve the read-only property for the session part of the variable.
 
1152
 */
 
1153
class sys_var_thd_ulong_session_readonly : public sys_var_thd_ulong
 
1154
{
 
1155
public:
 
1156
  sys_var_thd_ulong_session_readonly(sys_var_chain *chain_arg, 
 
1157
                                     const char *name_arg, ulong SV::*offset_arg, 
 
1158
                                     sys_check_func c_func= NULL,
 
1159
                                     sys_after_update_func au_func= NULL, 
 
1160
                                     Binlog_status_enum bl_status_arg= NOT_IN_BINLOG):
 
1161
    sys_var_thd_ulong(chain_arg, name_arg, offset_arg, c_func, au_func, bl_status_arg)
 
1162
  { }
 
1163
  bool check(THD *thd, set_var *var);
 
1164
  bool check_default(enum_var_type type)
 
1165
  {
 
1166
    return type != OPT_GLOBAL || !option_limits;
 
1167
  }
 
1168
};
 
1169
 
 
1170
 
 
1171
class sys_var_microseconds :public sys_var_thd
 
1172
{
 
1173
  ulonglong SV::*offset;
 
1174
public:
 
1175
  sys_var_microseconds(sys_var_chain *chain, const char *name_arg,
 
1176
                       ulonglong SV::*offset_arg):
 
1177
    sys_var_thd(name_arg), offset(offset_arg)
 
1178
  { chain_sys_var(chain); }
 
1179
  bool check(THD *thd, set_var *var) {return 0;}
 
1180
  bool update(THD *thd, set_var *var);
 
1181
  void set_default(THD *thd, enum_var_type type);
 
1182
  SHOW_TYPE show_type() { return SHOW_DOUBLE; }
 
1183
  bool check_update_type(Item_result type)
 
1184
  {
 
1185
    return (type != INT_RESULT && type != REAL_RESULT && type != DECIMAL_RESULT);
 
1186
  }
 
1187
  uchar *value_ptr(THD *thd, enum_var_type type, LEX_STRING *base);
 
1188
};
 
1189
 
 
1190
 
 
1191
class sys_var_trust_routine_creators :public sys_var_bool_ptr
 
1192
{
 
1193
  /* We need a derived class only to have a warn_deprecated() */
 
1194
public:
 
1195
  sys_var_trust_routine_creators(sys_var_chain *chain,
 
1196
                                 const char *name_arg, my_bool *value_arg) :
 
1197
    sys_var_bool_ptr(chain, name_arg, value_arg) {};
 
1198
  void warn_deprecated(THD *thd);
 
1199
  void set_default(THD *thd, enum_var_type type);
 
1200
  bool update(THD *thd, set_var *var);
 
1201
};
 
1202
 
 
1203
 
 
1204
/**
 
1205
  Handler for setting the system variable --read-only.
 
1206
*/
 
1207
 
 
1208
class sys_var_opt_readonly :public sys_var_bool_ptr
 
1209
{
 
1210
public:
 
1211
  sys_var_opt_readonly(sys_var_chain *chain, const char *name_arg, 
 
1212
                       my_bool *value_arg) :
 
1213
    sys_var_bool_ptr(chain, name_arg, value_arg) {};
 
1214
  ~sys_var_opt_readonly() {};
 
1215
  bool update(THD *thd, set_var *var);
 
1216
};
 
1217
 
 
1218
 
 
1219
class sys_var_thd_lc_time_names :public sys_var_thd
 
1220
{
 
1221
public:
 
1222
  sys_var_thd_lc_time_names(sys_var_chain *chain, const char *name_arg,
 
1223
                            Binlog_status_enum binlog_status_arg= NOT_IN_BINLOG)
 
1224
    : sys_var_thd(name_arg, NULL, binlog_status_arg)
 
1225
  {
 
1226
#if MYSQL_VERSION_ID < 50000
 
1227
    no_support_one_shot= 0;
 
1228
#endif
 
1229
    chain_sys_var(chain);
 
1230
  }
 
1231
  bool check(THD *thd, set_var *var);
 
1232
  SHOW_TYPE show_type() { return SHOW_CHAR; }
 
1233
  bool check_update_type(Item_result type)
 
1234
  {
 
1235
    return ((type != STRING_RESULT) && (type != INT_RESULT));
 
1236
  }
 
1237
  bool check_default(enum_var_type type) { return 0; }
 
1238
  bool update(THD *thd, set_var *var);
 
1239
  uchar *value_ptr(THD *thd, enum_var_type type, LEX_STRING *base);
 
1240
  virtual void set_default(THD *thd, enum_var_type type);
 
1241
};
 
1242
 
 
1243
#ifdef HAVE_EVENT_SCHEDULER
 
1244
class sys_var_event_scheduler :public sys_var_long_ptr
 
1245
{
 
1246
  /* We need a derived class only to have a warn_deprecated() */
 
1247
public:
 
1248
  sys_var_event_scheduler(sys_var_chain *chain, const char *name_arg) :
 
1249
    sys_var_long_ptr(chain, name_arg, NULL, NULL) {};
 
1250
  bool update(THD *thd, set_var *var);
 
1251
  uchar *value_ptr(THD *thd, enum_var_type type, LEX_STRING *base);
 
1252
  SHOW_TYPE show_type() { return SHOW_CHAR; }
 
1253
  bool check(THD *thd, set_var *var);
 
1254
  bool check_update_type(Item_result type)
 
1255
  {
 
1256
    return type != STRING_RESULT && type != INT_RESULT;
 
1257
  }
 
1258
};
 
1259
#endif
 
1260
 
 
1261
extern void fix_binlog_format_after_update(THD *thd, enum_var_type type);
 
1262
 
 
1263
class sys_var_thd_binlog_format :public sys_var_thd_enum
 
1264
{
 
1265
public:
 
1266
  sys_var_thd_binlog_format(sys_var_chain *chain, const char *name_arg, 
 
1267
                            ulong SV::*offset_arg)
 
1268
    :sys_var_thd_enum(chain, name_arg, offset_arg,
 
1269
                      &binlog_format_typelib,
 
1270
                      fix_binlog_format_after_update)
 
1271
  {};
 
1272
  bool check(THD *thd, set_var *var);
 
1273
  bool is_readonly() const;
 
1274
};
 
1275
 
 
1276
/****************************************************************************
 
1277
  Classes for parsing of the SET command
 
1278
****************************************************************************/
 
1279
 
 
1280
class set_var_base :public Sql_alloc
 
1281
{
 
1282
public:
 
1283
  set_var_base() {}
 
1284
  virtual ~set_var_base() {}
 
1285
  virtual int check(THD *thd)=0;        /* To check privileges etc. */
 
1286
  virtual int update(THD *thd)=0;       /* To set the value */
 
1287
  /* light check for PS */
 
1288
  virtual int light_check(THD *thd) { return check(thd); }
 
1289
  virtual bool no_support_one_shot() { return 1; }
 
1290
};
 
1291
 
 
1292
 
 
1293
/* MySQL internal variables, like query_cache_size */
 
1294
 
 
1295
class set_var :public set_var_base
 
1296
{
 
1297
public:
 
1298
  sys_var *var;
 
1299
  Item *value;
 
1300
  enum_var_type type;
 
1301
  union
 
1302
  {
 
1303
    CHARSET_INFO *charset;
 
1304
    ulong ulong_value;
 
1305
    ulonglong ulonglong_value;
 
1306
    plugin_ref plugin;
 
1307
    DATE_TIME_FORMAT *date_time_format;
 
1308
    Time_zone *time_zone;
 
1309
    MY_LOCALE *locale_value;
 
1310
  } save_result;
 
1311
  LEX_STRING base;                      /* for structs */
 
1312
 
 
1313
  set_var(enum_var_type type_arg, sys_var *var_arg,
 
1314
          const LEX_STRING *base_name_arg, Item *value_arg)
 
1315
    :var(var_arg), type(type_arg), base(*base_name_arg)
 
1316
  {
 
1317
    /*
 
1318
      If the set value is a field, change it to a string to allow things like
 
1319
      SET table_type=MYISAM;
 
1320
    */
 
1321
    if (value_arg && value_arg->type() == Item::FIELD_ITEM)
 
1322
    {
 
1323
      Item_field *item= (Item_field*) value_arg;
 
1324
      if (!(value=new Item_string(item->field_name, 
 
1325
                  (uint) strlen(item->field_name),
 
1326
                                  item->collation.collation)))
 
1327
        value=value_arg;                        /* Give error message later */
 
1328
    }
 
1329
    else
 
1330
      value=value_arg;
 
1331
  }
 
1332
  int check(THD *thd);
 
1333
  int update(THD *thd);
 
1334
  int light_check(THD *thd);
 
1335
  bool no_support_one_shot() { return var->no_support_one_shot; }
 
1336
};
 
1337
 
 
1338
 
 
1339
/* User variables like @my_own_variable */
 
1340
 
 
1341
class set_var_user: public set_var_base
 
1342
{
 
1343
  Item_func_set_user_var *user_var_item;
 
1344
public:
 
1345
  set_var_user(Item_func_set_user_var *item)
 
1346
    :user_var_item(item)
 
1347
  {}
 
1348
  int check(THD *thd);
 
1349
  int update(THD *thd);
 
1350
  int light_check(THD *thd);
 
1351
};
 
1352
 
 
1353
/* For SET PASSWORD */
 
1354
 
 
1355
class set_var_password: public set_var_base
 
1356
{
 
1357
  LEX_USER *user;
 
1358
  char *password;
 
1359
public:
 
1360
  set_var_password(LEX_USER *user_arg,char *password_arg)
 
1361
    :user(user_arg), password(password_arg)
 
1362
  {}
 
1363
  int check(THD *thd);
 
1364
  int update(THD *thd);
 
1365
};
 
1366
 
 
1367
 
 
1368
/* For SET NAMES and SET CHARACTER SET */
 
1369
 
 
1370
class set_var_collation_client: public set_var_base
 
1371
{
 
1372
  CHARSET_INFO *character_set_client;
 
1373
  CHARSET_INFO *character_set_results;
 
1374
  CHARSET_INFO *collation_connection;
 
1375
public:
 
1376
  set_var_collation_client(CHARSET_INFO *client_coll_arg,
 
1377
                           CHARSET_INFO *connection_coll_arg,
 
1378
                           CHARSET_INFO *result_coll_arg)
 
1379
    :character_set_client(client_coll_arg),
 
1380
     character_set_results(result_coll_arg),
 
1381
     collation_connection(connection_coll_arg)
 
1382
  {}
 
1383
  int check(THD *thd);
 
1384
  int update(THD *thd);
 
1385
};
 
1386
 
 
1387
 
 
1388
extern "C"
 
1389
{
 
1390
  typedef int (*process_key_cache_t) (const char *, KEY_CACHE *);
 
1391
}
 
1392
 
 
1393
/* Named lists (used for keycaches) */
 
1394
 
 
1395
class NAMED_LIST :public ilink
 
1396
{
 
1397
  const char *name;
 
1398
  uint name_length;
 
1399
public:
 
1400
  uchar* data;
 
1401
 
 
1402
  NAMED_LIST(I_List<NAMED_LIST> *links, const char *name_arg,
 
1403
             uint name_length_arg, uchar* data_arg)
 
1404
    :name_length(name_length_arg), data(data_arg)
 
1405
  {
 
1406
    name= my_strndup(name_arg, name_length, MYF(MY_WME));
 
1407
    links->push_back(this);
 
1408
  }
 
1409
  inline bool cmp(const char *name_cmp, uint length)
 
1410
  {
 
1411
    return length == name_length && !memcmp(name, name_cmp, length);
 
1412
  }
 
1413
  ~NAMED_LIST()
 
1414
  {
 
1415
    my_free((uchar*) name, MYF(0));
 
1416
  }
 
1417
  friend bool process_key_caches(process_key_cache_t func);
 
1418
  friend void delete_elements(I_List<NAMED_LIST> *list,
 
1419
                              void (*free_element)(const char*, uchar*));
 
1420
};
 
1421
 
 
1422
/* updated in sql_acl.cc */
 
1423
 
 
1424
extern sys_var_thd_bool sys_old_alter_table;
 
1425
extern sys_var_thd_bool sys_old_passwords;
 
1426
extern LEX_STRING default_key_cache_base;
 
1427
 
 
1428
/* For sql_yacc */
 
1429
struct sys_var_with_base
 
1430
{
 
1431
  sys_var *var;
 
1432
  LEX_STRING base_name;
 
1433
};
 
1434
 
 
1435
/*
 
1436
  Prototypes for helper functions
 
1437
*/
 
1438
 
 
1439
int set_var_init();
 
1440
void set_var_free();
 
1441
SHOW_VAR* enumerate_sys_vars(THD *thd, bool sorted);
 
1442
int mysql_add_sys_var_chain(sys_var *chain, struct my_option *long_options);
 
1443
int mysql_del_sys_var_chain(sys_var *chain);
 
1444
sys_var *find_sys_var(THD *thd, const char *str, uint length=0);
 
1445
int sql_set_variables(THD *thd, List<set_var_base> *var_list);
 
1446
bool not_all_support_one_shot(List<set_var_base> *var_list);
 
1447
void fix_delay_key_write(THD *thd, enum_var_type type);
 
1448
void fix_slave_exec_mode(enum_var_type type);
 
1449
ulong fix_sql_mode(ulong sql_mode);
 
1450
extern sys_var_const_str sys_charset_system;
 
1451
extern sys_var_str sys_init_connect;
 
1452
extern sys_var_str sys_init_slave;
 
1453
extern sys_var_thd_time_zone sys_time_zone;
 
1454
extern sys_var_thd_bit sys_autocommit;
 
1455
CHARSET_INFO *get_old_charset_by_name(const char *old_name);
 
1456
uchar* find_named(I_List<NAMED_LIST> *list, const char *name, uint length,
 
1457
                NAMED_LIST **found);
 
1458
 
 
1459
extern sys_var_str sys_var_general_log_path, sys_var_slow_log_path;
 
1460
 
 
1461
/* key_cache functions */
 
1462
KEY_CACHE *get_key_cache(LEX_STRING *cache_name);
 
1463
KEY_CACHE *get_or_create_key_cache(const char *name, uint length);
 
1464
void free_key_cache(const char *name, KEY_CACHE *key_cache);
 
1465
bool process_key_caches(process_key_cache_t func);
 
1466
void delete_elements(I_List<NAMED_LIST> *list,
 
1467
                     void (*free_element)(const char*, uchar*));