~stewart/drizzle/embedded-innodb-create-select-transaction-arrgh

« back to all changes in this revision

Viewing changes to sql/set_var.h

  • Committer: brian
  • Date: 2008-06-25 05:29:13 UTC
  • Revision ID: brian@localhost.localdomain-20080625052913-6upwo0jsrl4lnapl
clean slate

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
  sys_var(const char *name_arg, sys_after_update_func func= NULL,
 
75
          Binlog_status_enum binlog_status_arg= NOT_IN_BINLOG)
 
76
    :name(name_arg), after_update(func), no_support_one_shot(1),
 
77
    binlog_status(binlog_status_arg),
 
78
    m_allow_empty_value(TRUE)
 
79
  {}
 
80
  virtual ~sys_var() {}
 
81
  void chain_sys_var(sys_var_chain *chain_arg)
 
82
  {
 
83
    if (chain_arg->last)
 
84
      chain_arg->last->next= this;
 
85
    else
 
86
      chain_arg->first= this;
 
87
    chain_arg->last= this;
 
88
  }
 
89
  virtual bool check(THD *thd, set_var *var);
 
90
  bool check_enum(THD *thd, set_var *var, const TYPELIB *enum_names);
 
91
  bool check_set(THD *thd, set_var *var, TYPELIB *enum_names);
 
92
  bool is_written_to_binlog(enum_var_type type)
 
93
  {
 
94
    return (type == OPT_SESSION || type == OPT_DEFAULT) &&
 
95
      (binlog_status == SESSION_VARIABLE_IN_BINLOG);
 
96
  }
 
97
  virtual bool update(THD *thd, set_var *var)=0;
 
98
  virtual void set_default(THD *thd_arg, enum_var_type type) {}
 
99
  virtual SHOW_TYPE show_type() { return SHOW_UNDEF; }
 
100
  virtual uchar *value_ptr(THD *thd, enum_var_type type, LEX_STRING *base)
 
101
  { return 0; }
 
102
  virtual bool check_type(enum_var_type type)
 
103
  { return type != OPT_GLOBAL; }                /* Error if not GLOBAL */
 
104
  virtual bool check_update_type(Item_result type)
 
105
  { return type != INT_RESULT; }                /* Assume INT */
 
106
  virtual bool check_default(enum_var_type type)
 
107
  { return option_limits == 0; }
 
108
  Item *item(THD *thd, enum_var_type type, LEX_STRING *base);
 
109
  virtual bool is_struct() { return 0; }
 
110
  virtual bool is_readonly() const { return 0; }
 
111
  virtual sys_var_pluginvar *cast_pluginvar() { return 0; }
 
112
 
 
113
protected:
 
114
  void set_allow_empty_value(bool allow_empty_value)
 
115
  {
 
116
    m_allow_empty_value= allow_empty_value;
 
117
  }
 
118
 
 
119
private:
 
120
  const Binlog_status_enum binlog_status;
 
121
 
 
122
  bool m_allow_empty_value;
 
123
};
 
124
 
 
125
 
 
126
/*
 
127
  A base class for all variables that require its access to
 
128
  be guarded with a mutex.
 
129
*/
 
130
 
 
131
class sys_var_global: public sys_var
 
132
{
 
133
protected:
 
134
  pthread_mutex_t *guard;
 
135
public:
 
136
  sys_var_global(const char *name_arg, sys_after_update_func after_update_arg,
 
137
                 pthread_mutex_t *guard_arg)
 
138
    :sys_var(name_arg, after_update_arg), guard(guard_arg) {}
 
139
};
 
140
 
 
141
 
 
142
/*
 
143
  A global-only ulong variable that requires its access to be
 
144
  protected with a mutex.
 
145
*/
 
146
 
 
147
class sys_var_long_ptr_global: public sys_var_global
 
148
{
 
149
public:
 
150
  ulong *value;
 
151
  sys_var_long_ptr_global(sys_var_chain *chain, const char *name_arg,
 
152
                          ulong *value_ptr_arg,
 
153
                          pthread_mutex_t *guard_arg,
 
154
                          sys_after_update_func after_update_arg= NULL)
 
155
    :sys_var_global(name_arg, after_update_arg, guard_arg),
 
156
    value(value_ptr_arg)
 
157
  { chain_sys_var(chain); }
 
158
  bool check(THD *thd, set_var *var);
 
159
  bool update(THD *thd, set_var *var);
 
160
  void set_default(THD *thd, enum_var_type type);
 
161
  SHOW_TYPE show_type() { return SHOW_LONG; }
 
162
  uchar *value_ptr(THD *thd, enum_var_type type, LEX_STRING *base)
 
163
  { return (uchar*) value; }
 
164
};
 
165
 
 
166
 
 
167
/*
 
168
  A global ulong variable that is protected by LOCK_global_system_variables
 
169
*/
 
170
 
 
171
class sys_var_long_ptr :public sys_var_long_ptr_global
 
172
{
 
173
public:
 
174
  sys_var_long_ptr(sys_var_chain *chain, const char *name_arg, ulong *value_ptr,
 
175
                   sys_after_update_func after_update_arg= NULL);
 
176
};
 
177
 
 
178
 
 
179
class sys_var_ulonglong_ptr :public sys_var
 
180
{
 
181
public:
 
182
  ulonglong *value;
 
183
  sys_var_ulonglong_ptr(sys_var_chain *chain, const char *name_arg, ulonglong *value_ptr_arg)
 
184
    :sys_var(name_arg),value(value_ptr_arg)
 
185
  { chain_sys_var(chain); }
 
186
  sys_var_ulonglong_ptr(sys_var_chain *chain, const char *name_arg, ulonglong *value_ptr_arg,
 
187
                       sys_after_update_func func)
 
188
    :sys_var(name_arg,func), value(value_ptr_arg)
 
189
  { chain_sys_var(chain); }
 
190
  bool update(THD *thd, set_var *var);
 
191
  void set_default(THD *thd, enum_var_type type);
 
192
  SHOW_TYPE show_type() { return SHOW_LONGLONG; }
 
193
  uchar *value_ptr(THD *thd, enum_var_type type, LEX_STRING *base)
 
194
  { return (uchar*) value; }
 
195
};
 
196
 
 
197
 
 
198
class sys_var_bool_ptr :public sys_var
 
199
{
 
200
public:
 
201
  my_bool *value;
 
202
  sys_var_bool_ptr(sys_var_chain *chain, const char *name_arg, my_bool *value_arg)
 
203
    :sys_var(name_arg),value(value_arg)
 
204
  { chain_sys_var(chain); }
 
205
  bool check(THD *thd, set_var *var)
 
206
  {
 
207
    return check_enum(thd, var, &bool_typelib);
 
208
  }
 
209
  bool update(THD *thd, set_var *var);
 
210
  void set_default(THD *thd, enum_var_type type);
 
211
  SHOW_TYPE show_type() { return SHOW_MY_BOOL; }
 
212
  uchar *value_ptr(THD *thd, enum_var_type type, LEX_STRING *base)
 
213
  { return (uchar*) value; }
 
214
  bool check_update_type(Item_result type) { return 0; }
 
215
};
 
216
 
 
217
 
 
218
class sys_var_bool_ptr_readonly :public sys_var_bool_ptr
 
219
{
 
220
public:
 
221
  sys_var_bool_ptr_readonly(sys_var_chain *chain, const char *name_arg,
 
222
                            my_bool *value_arg)
 
223
    :sys_var_bool_ptr(chain, name_arg, value_arg)
 
224
  {}
 
225
  bool is_readonly() const { return 1; }
 
226
};
 
227
 
 
228
 
 
229
class sys_var_str :public sys_var
 
230
{
 
231
public:
 
232
  char *value;                                  // Pointer to allocated string
 
233
  uint value_length;
 
234
  sys_check_func check_func;
 
235
  sys_update_func update_func;
 
236
  sys_set_default_func set_default_func;
 
237
  sys_var_str(sys_var_chain *chain, const char *name_arg,
 
238
              sys_check_func check_func_arg,
 
239
              sys_update_func update_func_arg,
 
240
              sys_set_default_func set_default_func_arg,
 
241
              char *value_arg)
 
242
    :sys_var(name_arg), value(value_arg), check_func(check_func_arg),
 
243
    update_func(update_func_arg),set_default_func(set_default_func_arg)
 
244
  { chain_sys_var(chain); }
 
245
  bool check(THD *thd, set_var *var);
 
246
  bool update(THD *thd, set_var *var)
 
247
  {
 
248
    return (*update_func)(thd, var);
 
249
  }
 
250
  void set_default(THD *thd, enum_var_type type)
 
251
  {
 
252
    (*set_default_func)(thd, type);
 
253
  }
 
254
  SHOW_TYPE show_type() { return SHOW_CHAR; }
 
255
  uchar *value_ptr(THD *thd, enum_var_type type, LEX_STRING *base)
 
256
  { return (uchar*) value; }
 
257
  bool check_update_type(Item_result type)
 
258
  {
 
259
    return type != STRING_RESULT;               /* Only accept strings */
 
260
  }
 
261
  bool check_default(enum_var_type type) { return 0; }
 
262
};
 
263
 
 
264
 
 
265
class sys_var_const_str :public sys_var
 
266
{
 
267
public:
 
268
  char *value;                                  // Pointer to const value
 
269
  sys_var_const_str(sys_var_chain *chain, const char *name_arg,
 
270
                    const char *value_arg)
 
271
    :sys_var(name_arg), value((char*) value_arg)
 
272
  { chain_sys_var(chain); }
 
273
  bool check(THD *thd, set_var *var)
 
274
  {
 
275
    return 1;
 
276
  }
 
277
  bool update(THD *thd, set_var *var)
 
278
  {
 
279
    return 1;
 
280
  }
 
281
  SHOW_TYPE show_type() { return SHOW_CHAR; }
 
282
  uchar *value_ptr(THD *thd, enum_var_type type, LEX_STRING *base)
 
283
  {
 
284
    return (uchar*) value;
 
285
  }
 
286
  bool check_update_type(Item_result type)
 
287
  {
 
288
    return 1;
 
289
  }
 
290
  bool check_default(enum_var_type type) { return 1; }
 
291
  bool is_readonly() const { return 1; }
 
292
};
 
293
 
 
294
 
 
295
class sys_var_const_str_ptr :public sys_var
 
296
{
 
297
public:
 
298
  char **value;                                 // Pointer to const value
 
299
  sys_var_const_str_ptr(sys_var_chain *chain, const char *name_arg, char **value_arg)
 
300
    :sys_var(name_arg),value(value_arg)
 
301
  { chain_sys_var(chain); }
 
302
  bool check(THD *thd, set_var *var)
 
303
  {
 
304
    return 1;
 
305
  }
 
306
  bool update(THD *thd, set_var *var)
 
307
  {
 
308
    return 1;
 
309
  }
 
310
  SHOW_TYPE show_type() { return SHOW_CHAR; }
 
311
  uchar *value_ptr(THD *thd, enum_var_type type, LEX_STRING *base)
 
312
  {
 
313
    return (uchar*) *value;
 
314
  }
 
315
  bool check_update_type(Item_result type)
 
316
  {
 
317
    return 1;
 
318
  }
 
319
  bool check_default(enum_var_type type) { return 1; }
 
320
  bool is_readonly() const { return 1; }
 
321
};
 
322
 
 
323
 
 
324
class sys_var_enum :public sys_var
 
325
{
 
326
  uint *value;
 
327
  TYPELIB *enum_names;
 
328
public:
 
329
  sys_var_enum(sys_var_chain *chain, const char *name_arg, uint *value_arg,
 
330
               TYPELIB *typelib, sys_after_update_func func)
 
331
    :sys_var(name_arg,func), value(value_arg), enum_names(typelib)
 
332
  { chain_sys_var(chain); }
 
333
  bool check(THD *thd, set_var *var)
 
334
  {
 
335
    return check_enum(thd, var, enum_names);
 
336
  }
 
337
  bool update(THD *thd, set_var *var);
 
338
  SHOW_TYPE show_type() { return SHOW_CHAR; }
 
339
  uchar *value_ptr(THD *thd, enum_var_type type, LEX_STRING *base);
 
340
  bool check_update_type(Item_result type) { return 0; }
 
341
};
 
342
 
 
343
 
 
344
class sys_var_enum_const :public sys_var
 
345
{
 
346
  ulong SV::*offset;
 
347
  TYPELIB *enum_names;
 
348
public:
 
349
  sys_var_enum_const(sys_var_chain *chain, const char *name_arg, ulong SV::*offset_arg,
 
350
      TYPELIB *typelib, sys_after_update_func func)
 
351
    :sys_var(name_arg,func), offset(offset_arg), enum_names(typelib)
 
352
  { chain_sys_var(chain); }
 
353
  bool check(THD *thd, set_var *var) { return 1; }
 
354
  bool update(THD *thd, set_var *var) { return 1; }
 
355
  SHOW_TYPE show_type() { return SHOW_CHAR; }
 
356
  bool check_update_type(Item_result type) { return 1; }
 
357
  bool is_readonly() const { return 1; }
 
358
  uchar *value_ptr(THD *thd, enum_var_type type, LEX_STRING *base);
 
359
};
 
360
 
 
361
 
 
362
class sys_var_thd :public sys_var
 
363
{
 
364
public:
 
365
  sys_var_thd(const char *name_arg, 
 
366
              sys_after_update_func func= NULL,
 
367
              Binlog_status_enum binlog_status= NOT_IN_BINLOG)
 
368
    :sys_var(name_arg, func, binlog_status)
 
369
  {}
 
370
  bool check_type(enum_var_type type) { return 0; }
 
371
  bool check_default(enum_var_type type)
 
372
  {
 
373
    return type == OPT_GLOBAL && !option_limits;
 
374
  }
 
375
};
 
376
 
 
377
 
 
378
class sys_var_thd_ulong :public sys_var_thd
 
379
{
 
380
  sys_check_func check_func;
 
381
public:
 
382
  ulong SV::*offset;
 
383
  sys_var_thd_ulong(sys_var_chain *chain, const char *name_arg,
 
384
                    ulong SV::*offset_arg,
 
385
                    sys_check_func c_func= NULL,
 
386
                    sys_after_update_func au_func= NULL,
 
387
                    Binlog_status_enum binlog_status_arg= NOT_IN_BINLOG)
 
388
    :sys_var_thd(name_arg, au_func, binlog_status_arg), check_func(c_func),
 
389
    offset(offset_arg)
 
390
  { chain_sys_var(chain); }
 
391
  bool check(THD *thd, set_var *var);
 
392
  bool update(THD *thd, set_var *var);
 
393
  void set_default(THD *thd, enum_var_type type);
 
394
  SHOW_TYPE show_type() { return SHOW_LONG; }
 
395
  uchar *value_ptr(THD *thd, enum_var_type type, LEX_STRING *base);
 
396
};
 
397
 
 
398
 
 
399
class sys_var_thd_ha_rows :public sys_var_thd
 
400
{
 
401
public:
 
402
  ha_rows SV::*offset;
 
403
  sys_var_thd_ha_rows(sys_var_chain *chain, const char *name_arg, 
 
404
                      ha_rows SV::*offset_arg)
 
405
    :sys_var_thd(name_arg), offset(offset_arg)
 
406
  { chain_sys_var(chain); }
 
407
  sys_var_thd_ha_rows(sys_var_chain *chain, const char *name_arg, 
 
408
                      ha_rows SV::*offset_arg,
 
409
                      sys_after_update_func func)
 
410
    :sys_var_thd(name_arg,func), offset(offset_arg)
 
411
  { chain_sys_var(chain); }
 
412
  bool update(THD *thd, set_var *var);
 
413
  void set_default(THD *thd, enum_var_type type);
 
414
  SHOW_TYPE show_type() { return SHOW_HA_ROWS; }
 
415
  uchar *value_ptr(THD *thd, enum_var_type type, LEX_STRING *base);
 
416
};
 
417
 
 
418
 
 
419
class sys_var_thd_ulonglong :public sys_var_thd
 
420
{
 
421
public:
 
422
  ulonglong SV::*offset;
 
423
  bool only_global;
 
424
  sys_var_thd_ulonglong(sys_var_chain *chain, const char *name_arg, 
 
425
                        ulonglong SV::*offset_arg)
 
426
    :sys_var_thd(name_arg), offset(offset_arg)
 
427
  { chain_sys_var(chain); }
 
428
  sys_var_thd_ulonglong(sys_var_chain *chain, const char *name_arg, 
 
429
                        ulonglong SV::*offset_arg,
 
430
                        sys_after_update_func func, bool only_global_arg)
 
431
    :sys_var_thd(name_arg, func), offset(offset_arg),
 
432
    only_global(only_global_arg)
 
433
  { chain_sys_var(chain); }
 
434
  bool update(THD *thd, set_var *var);
 
435
  void set_default(THD *thd, enum_var_type type);
 
436
  SHOW_TYPE show_type() { return SHOW_LONGLONG; }
 
437
  uchar *value_ptr(THD *thd, enum_var_type type, LEX_STRING *base);
 
438
  bool check(THD *thd, set_var *var);
 
439
  bool check_default(enum_var_type type)
 
440
  {
 
441
    return type == OPT_GLOBAL && !option_limits;
 
442
  }
 
443
  bool check_type(enum_var_type type)
 
444
  {
 
445
    return (only_global && type != OPT_GLOBAL);
 
446
  }
 
447
};
 
448
 
 
449
 
 
450
class sys_var_thd_bool :public sys_var_thd
 
451
{
 
452
public:
 
453
  my_bool SV::*offset;
 
454
  sys_var_thd_bool(sys_var_chain *chain, const char *name_arg, my_bool SV::*offset_arg)
 
455
    :sys_var_thd(name_arg), offset(offset_arg)
 
456
  { chain_sys_var(chain); }
 
457
  sys_var_thd_bool(sys_var_chain *chain, const char *name_arg, my_bool SV::*offset_arg,
 
458
                   sys_after_update_func func)
 
459
    :sys_var_thd(name_arg,func), offset(offset_arg)
 
460
  { chain_sys_var(chain); }
 
461
  bool update(THD *thd, set_var *var);
 
462
  void set_default(THD *thd, enum_var_type type);
 
463
  SHOW_TYPE show_type() { return SHOW_MY_BOOL; }
 
464
  uchar *value_ptr(THD *thd, enum_var_type type, LEX_STRING *base);
 
465
  bool check(THD *thd, set_var *var)
 
466
  {
 
467
    return check_enum(thd, var, &bool_typelib);
 
468
  }
 
469
  bool check_update_type(Item_result type) { return 0; }
 
470
};
 
471
 
 
472
 
 
473
class sys_var_thd_enum :public sys_var_thd
 
474
{
 
475
protected:
 
476
  ulong SV::*offset;
 
477
  TYPELIB *enum_names;
 
478
  sys_check_func check_func;
 
479
public:
 
480
  sys_var_thd_enum(sys_var_chain *chain, const char *name_arg,
 
481
                   ulong SV::*offset_arg, TYPELIB *typelib,
 
482
                   sys_after_update_func func= NULL,
 
483
                   sys_check_func check= NULL)
 
484
    :sys_var_thd(name_arg, func), offset(offset_arg),
 
485
    enum_names(typelib), check_func(check)
 
486
  { chain_sys_var(chain); }
 
487
  bool check(THD *thd, set_var *var)
 
488
  {
 
489
    int ret= 0;
 
490
    if (check_func)
 
491
      ret= (*check_func)(thd, var);
 
492
    return ret ? ret : check_enum(thd, var, enum_names);
 
493
  }
 
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_CHAR; }
 
497
  uchar *value_ptr(THD *thd, enum_var_type type, LEX_STRING *base);
 
498
  bool check_update_type(Item_result type) { return 0; }
 
499
};
 
500
 
 
501
 
 
502
 
 
503
class sys_var_thd_optimizer_switch :public sys_var_thd_enum
 
504
{
 
505
public:
 
506
  sys_var_thd_optimizer_switch(sys_var_chain *chain, const char *name_arg, 
 
507
                               ulong SV::*offset_arg)
 
508
    :sys_var_thd_enum(chain, name_arg, offset_arg, &optimizer_switch_typelib)
 
509
  {}
 
510
  bool check(THD *thd, set_var *var)
 
511
  {
 
512
    return check_set(thd, var, enum_names);
 
513
  }
 
514
  void set_default(THD *thd, enum_var_type type);
 
515
  uchar *value_ptr(THD *thd, enum_var_type type, LEX_STRING *base);
 
516
  static bool symbolic_mode_representation(THD *thd, ulonglong sql_mode,
 
517
                                           LEX_STRING *rep);
 
518
};
 
519
 
 
520
 
 
521
class sys_var_thd_storage_engine :public sys_var_thd
 
522
{
 
523
protected:
 
524
  plugin_ref SV::*offset;
 
525
public:
 
526
  sys_var_thd_storage_engine(sys_var_chain *chain, const char *name_arg, 
 
527
                             plugin_ref SV::*offset_arg)
 
528
    :sys_var_thd(name_arg), offset(offset_arg)
 
529
  { chain_sys_var(chain); }
 
530
  bool check(THD *thd, set_var *var);
 
531
  SHOW_TYPE show_type() { return SHOW_CHAR; }
 
532
  bool check_update_type(Item_result type)
 
533
  {
 
534
    return type != STRING_RESULT;               /* Only accept strings */
 
535
  }
 
536
  void set_default(THD *thd, enum_var_type type);
 
537
  bool update(THD *thd, set_var *var);
 
538
  uchar *value_ptr(THD *thd, enum_var_type type, LEX_STRING *base);
 
539
};
 
540
 
 
541
class sys_var_thd_bit :public sys_var_thd
 
542
{
 
543
  sys_check_func check_func;
 
544
  sys_update_func update_func;
 
545
public:
 
546
  ulonglong bit_flag;
 
547
  bool reverse;
 
548
  sys_var_thd_bit(sys_var_chain *chain, const char *name_arg,
 
549
                  sys_check_func c_func, sys_update_func u_func,
 
550
                  ulonglong bit, bool reverse_arg=0,
 
551
                  Binlog_status_enum binlog_status_arg= NOT_IN_BINLOG)
 
552
    :sys_var_thd(name_arg, NULL, binlog_status_arg), check_func(c_func),
 
553
    update_func(u_func), bit_flag(bit), reverse(reverse_arg)
 
554
  { chain_sys_var(chain); }
 
555
  bool check(THD *thd, set_var *var);
 
556
  bool update(THD *thd, set_var *var);
 
557
  bool check_update_type(Item_result type) { return 0; }
 
558
  bool check_type(enum_var_type type) { return type == OPT_GLOBAL; }
 
559
  SHOW_TYPE show_type() { return SHOW_MY_BOOL; }
 
560
  uchar *value_ptr(THD *thd, enum_var_type type, LEX_STRING *base);
 
561
};
 
562
 
 
563
class sys_var_thd_dbug :public sys_var_thd
 
564
{
 
565
public:
 
566
  sys_var_thd_dbug(sys_var_chain *chain, const char *name_arg)
 
567
    :sys_var_thd(name_arg)
 
568
  { chain_sys_var(chain); }
 
569
  bool check_update_type(Item_result type) { return type != STRING_RESULT; }
 
570
  SHOW_TYPE show_type() { return SHOW_CHAR; }
 
571
  bool update(THD *thd, set_var *var);
 
572
  void set_default(THD *thd, enum_var_type type) { DBUG_POP(); }
 
573
  uchar *value_ptr(THD *thd, enum_var_type type, LEX_STRING *b);
 
574
};
 
575
 
 
576
 
 
577
 
 
578
/* some variables that require special handling */
 
579
 
 
580
class sys_var_timestamp :public sys_var
 
581
{
 
582
public:
 
583
  sys_var_timestamp(sys_var_chain *chain, const char *name_arg,
 
584
                    Binlog_status_enum binlog_status_arg= NOT_IN_BINLOG)
 
585
    :sys_var(name_arg, NULL, binlog_status_arg)
 
586
  { chain_sys_var(chain); }
 
587
  bool update(THD *thd, set_var *var);
 
588
  void set_default(THD *thd, enum_var_type type);
 
589
  bool check_type(enum_var_type type)    { return type == OPT_GLOBAL; }
 
590
  bool check_default(enum_var_type type) { return 0; }
 
591
  SHOW_TYPE show_type() { return SHOW_LONG; }
 
592
  uchar *value_ptr(THD *thd, enum_var_type type, LEX_STRING *base);
 
593
};
 
594
 
 
595
 
 
596
class sys_var_last_insert_id :public sys_var
 
597
{
 
598
public:
 
599
  sys_var_last_insert_id(sys_var_chain *chain, const char *name_arg,
 
600
                         Binlog_status_enum binlog_status_arg= NOT_IN_BINLOG)
 
601
    :sys_var(name_arg, NULL, binlog_status_arg)
 
602
  { chain_sys_var(chain); }
 
603
  bool update(THD *thd, set_var *var);
 
604
  bool check_type(enum_var_type type) { return type == OPT_GLOBAL; }
 
605
  SHOW_TYPE show_type() { return SHOW_LONGLONG; }
 
606
  uchar *value_ptr(THD *thd, enum_var_type type, LEX_STRING *base);
 
607
};
 
608
 
 
609
 
 
610
class sys_var_insert_id :public sys_var
 
611
{
 
612
public:
 
613
  sys_var_insert_id(sys_var_chain *chain, const char *name_arg)
 
614
    :sys_var(name_arg)
 
615
  { chain_sys_var(chain); }
 
616
  bool update(THD *thd, set_var *var);
 
617
  bool check_type(enum_var_type type) { return type == OPT_GLOBAL; }
 
618
  SHOW_TYPE show_type() { return SHOW_LONGLONG; }
 
619
  uchar *value_ptr(THD *thd, enum_var_type type, LEX_STRING *base);
 
620
};
 
621
 
 
622
 
 
623
class sys_var_rand_seed1 :public sys_var
 
624
{
 
625
public:
 
626
  sys_var_rand_seed1(sys_var_chain *chain, const char *name_arg,
 
627
                     Binlog_status_enum binlog_status_arg= NOT_IN_BINLOG)
 
628
    :sys_var(name_arg, NULL, binlog_status_arg)
 
629
  { chain_sys_var(chain); }
 
630
  bool update(THD *thd, set_var *var);
 
631
  bool check_type(enum_var_type type) { return type == OPT_GLOBAL; }
 
632
};
 
633
 
 
634
class sys_var_rand_seed2 :public sys_var
 
635
{
 
636
public:
 
637
  sys_var_rand_seed2(sys_var_chain *chain, const char *name_arg,
 
638
                     Binlog_status_enum binlog_status_arg= NOT_IN_BINLOG)
 
639
    :sys_var(name_arg, NULL, binlog_status_arg)
 
640
  { chain_sys_var(chain); }
 
641
  bool update(THD *thd, set_var *var);
 
642
  bool check_type(enum_var_type type) { return type == OPT_GLOBAL; }
 
643
};
 
644
 
 
645
 
 
646
class sys_var_collation :public sys_var_thd
 
647
{
 
648
public:
 
649
  sys_var_collation(const char *name_arg,
 
650
                    Binlog_status_enum binlog_status_arg= NOT_IN_BINLOG)
 
651
    :sys_var_thd(name_arg, NULL, binlog_status_arg)
 
652
  {
 
653
    no_support_one_shot= 0;
 
654
  }
 
655
  bool check(THD *thd, set_var *var);
 
656
  SHOW_TYPE show_type() { return SHOW_CHAR; }
 
657
  bool check_update_type(Item_result type)
 
658
  {
 
659
    return ((type != STRING_RESULT) && (type != INT_RESULT));
 
660
  }
 
661
  bool check_default(enum_var_type type) { return 0; }
 
662
  virtual void set_default(THD *thd, enum_var_type type)= 0;
 
663
};
 
664
 
 
665
class sys_var_character_set :public sys_var_thd
 
666
{
 
667
public:
 
668
  bool nullable;
 
669
  sys_var_character_set(const char *name_arg, bool is_nullable= 0,
 
670
                        Binlog_status_enum binlog_status_arg= NOT_IN_BINLOG)
 
671
    :sys_var_thd(name_arg, NULL, binlog_status_arg), nullable(is_nullable)
 
672
  {
 
673
    /*
 
674
      In fact only almost all variables derived from sys_var_character_set
 
675
      support ONE_SHOT; character_set_results doesn't. But that's good enough.
 
676
    */
 
677
    no_support_one_shot= 0;
 
678
  }
 
679
  bool check(THD *thd, set_var *var);
 
680
  SHOW_TYPE show_type() { return SHOW_CHAR; }
 
681
  bool check_update_type(Item_result type)
 
682
  {
 
683
    return ((type != STRING_RESULT) && (type != INT_RESULT));
 
684
  }
 
685
  bool check_default(enum_var_type type) { return 0; }
 
686
  bool update(THD *thd, set_var *var);
 
687
  uchar *value_ptr(THD *thd, enum_var_type type, LEX_STRING *base);
 
688
  virtual void set_default(THD *thd, enum_var_type type)= 0;
 
689
  virtual CHARSET_INFO **ci_ptr(THD *thd, enum_var_type type)= 0;
 
690
};
 
691
 
 
692
class sys_var_character_set_sv :public sys_var_character_set
 
693
{
 
694
  CHARSET_INFO *SV::*offset;
 
695
  CHARSET_INFO **global_default;
 
696
public:
 
697
  sys_var_character_set_sv(sys_var_chain *chain, const char *name_arg,
 
698
                           CHARSET_INFO *SV::*offset_arg,
 
699
                           CHARSET_INFO **global_default_arg,
 
700
                           bool is_nullable= 0,
 
701
                           Binlog_status_enum binlog_status_arg= NOT_IN_BINLOG)
 
702
    : sys_var_character_set(name_arg, is_nullable, binlog_status_arg),
 
703
    offset(offset_arg), global_default(global_default_arg)
 
704
  { chain_sys_var(chain); }
 
705
  void set_default(THD *thd, enum_var_type type);
 
706
  CHARSET_INFO **ci_ptr(THD *thd, enum_var_type type);
 
707
};
 
708
 
 
709
 
 
710
class sys_var_character_set_client: public sys_var_character_set_sv
 
711
{
 
712
public:
 
713
  sys_var_character_set_client(sys_var_chain *chain, const char *name_arg,
 
714
                               CHARSET_INFO *SV::*offset_arg,
 
715
                               CHARSET_INFO **global_default_arg,
 
716
                               Binlog_status_enum binlog_status_arg)
 
717
    : sys_var_character_set_sv(chain, name_arg, offset_arg, global_default_arg,
 
718
                               0, binlog_status_arg)
 
719
  { }
 
720
  bool check(THD *thd, set_var *var);
 
721
};
 
722
 
 
723
 
 
724
class sys_var_character_set_database :public sys_var_character_set
 
725
{
 
726
public:
 
727
  sys_var_character_set_database(sys_var_chain *chain, const char *name_arg,
 
728
                                 Binlog_status_enum binlog_status_arg=
 
729
                                   NOT_IN_BINLOG)
 
730
    : sys_var_character_set(name_arg, 0, binlog_status_arg)
 
731
  { chain_sys_var(chain); }
 
732
  void set_default(THD *thd, enum_var_type type);
 
733
  CHARSET_INFO **ci_ptr(THD *thd, enum_var_type type);
 
734
};
 
735
 
 
736
class sys_var_collation_sv :public sys_var_collation
 
737
{
 
738
  CHARSET_INFO *SV::*offset;
 
739
  CHARSET_INFO **global_default;
 
740
public:
 
741
  sys_var_collation_sv(sys_var_chain *chain, const char *name_arg,
 
742
                       CHARSET_INFO *SV::*offset_arg,
 
743
                       CHARSET_INFO **global_default_arg,
 
744
                       Binlog_status_enum binlog_status_arg= NOT_IN_BINLOG)
 
745
    :sys_var_collation(name_arg, binlog_status_arg),
 
746
    offset(offset_arg), global_default(global_default_arg)
 
747
  {
 
748
    chain_sys_var(chain);
 
749
  }
 
750
  bool update(THD *thd, set_var *var);
 
751
  void set_default(THD *thd, enum_var_type type);
 
752
  uchar *value_ptr(THD *thd, enum_var_type type, LEX_STRING *base);
 
753
};
 
754
 
 
755
 
 
756
class sys_var_key_cache_param :public sys_var
 
757
{
 
758
protected:
 
759
  size_t offset;
 
760
public:
 
761
  sys_var_key_cache_param(sys_var_chain *chain, const char *name_arg, 
 
762
                          size_t offset_arg)
 
763
    :sys_var(name_arg), offset(offset_arg)
 
764
  { chain_sys_var(chain); }
 
765
  uchar *value_ptr(THD *thd, enum_var_type type, LEX_STRING *base);
 
766
  bool check_default(enum_var_type type) { return 1; }
 
767
  bool is_struct() { return 1; }
 
768
};
 
769
 
 
770
 
 
771
class sys_var_key_buffer_size :public sys_var_key_cache_param
 
772
{
 
773
public:
 
774
  sys_var_key_buffer_size(sys_var_chain *chain, const char *name_arg)
 
775
    :sys_var_key_cache_param(chain, name_arg,
 
776
                             offsetof(KEY_CACHE, param_buff_size))
 
777
  {}
 
778
  bool update(THD *thd, set_var *var);
 
779
  SHOW_TYPE show_type() { return SHOW_LONGLONG; }
 
780
};
 
781
 
 
782
 
 
783
class sys_var_key_cache_long :public sys_var_key_cache_param
 
784
{
 
785
public:
 
786
  sys_var_key_cache_long(sys_var_chain *chain, const char *name_arg, size_t offset_arg)
 
787
    :sys_var_key_cache_param(chain, name_arg, offset_arg)
 
788
  {}
 
789
  bool update(THD *thd, set_var *var);
 
790
  SHOW_TYPE show_type() { return SHOW_LONG; }
 
791
};
 
792
 
 
793
 
 
794
class sys_var_thd_date_time_format :public sys_var_thd
 
795
{
 
796
  DATE_TIME_FORMAT *SV::*offset;
 
797
  timestamp_type date_time_type;
 
798
public:
 
799
  sys_var_thd_date_time_format(sys_var_chain *chain, const char *name_arg,
 
800
                               DATE_TIME_FORMAT *SV::*offset_arg,
 
801
                               timestamp_type date_time_type_arg)
 
802
    :sys_var_thd(name_arg), offset(offset_arg),
 
803
    date_time_type(date_time_type_arg)
 
804
  { chain_sys_var(chain); }
 
805
  SHOW_TYPE show_type() { return SHOW_CHAR; }
 
806
  bool check_update_type(Item_result type)
 
807
  {
 
808
    return type != STRING_RESULT;               /* Only accept strings */
 
809
  }
 
810
  bool check_default(enum_var_type type) { return 0; }
 
811
  bool check(THD *thd, set_var *var);
 
812
  bool update(THD *thd, set_var *var);
 
813
  void update2(THD *thd, enum_var_type type, DATE_TIME_FORMAT *new_value);
 
814
  uchar *value_ptr(THD *thd, enum_var_type type, LEX_STRING *base);
 
815
  void set_default(THD *thd, enum_var_type type);
 
816
};
 
817
 
 
818
 
 
819
class sys_var_log_state :public sys_var_bool_ptr
 
820
{
 
821
  uint log_type;
 
822
public:
 
823
  sys_var_log_state(sys_var_chain *chain, const char *name_arg, my_bool *value_arg, 
 
824
                    uint log_type_arg)
 
825
    :sys_var_bool_ptr(chain, name_arg, value_arg), log_type(log_type_arg) {}
 
826
  bool update(THD *thd, set_var *var);
 
827
  void set_default(THD *thd, enum_var_type type);
 
828
};
 
829
 
 
830
 
 
831
class sys_var_set :public sys_var
 
832
{
 
833
protected:
 
834
  ulong *value;
 
835
  TYPELIB *enum_names;
 
836
public:
 
837
  sys_var_set(sys_var_chain *chain, const char *name_arg, ulong *value_arg,
 
838
              TYPELIB *typelib, sys_after_update_func func)
 
839
    :sys_var(name_arg, func), value(value_arg), enum_names(typelib)
 
840
  { chain_sys_var(chain); }
 
841
  virtual bool check(THD *thd, set_var *var)
 
842
  {
 
843
    return check_set(thd, var, enum_names);
 
844
  }
 
845
  virtual void set_default(THD *thd, enum_var_type type)
 
846
  {  
 
847
    *value= 0;
 
848
  }
 
849
  bool update(THD *thd, set_var *var);
 
850
  uchar *value_ptr(THD *thd, enum_var_type type, LEX_STRING *base);
 
851
  bool check_update_type(Item_result type) { return 0; }
 
852
  SHOW_TYPE show_type() { return SHOW_CHAR; }
 
853
};
 
854
 
 
855
class sys_var_set_slave_mode :public sys_var_set
 
856
{
 
857
public:
 
858
  sys_var_set_slave_mode(sys_var_chain *chain, const char *name_arg,
 
859
                         ulong *value_arg,
 
860
                         TYPELIB *typelib, sys_after_update_func func) :
 
861
    sys_var_set(chain, name_arg, value_arg, typelib, func) {}
 
862
  void set_default(THD *thd, enum_var_type type);
 
863
  bool check(THD *thd, set_var *var);
 
864
  bool update(THD *thd, set_var *var);
 
865
};
 
866
 
 
867
class sys_var_log_output :public sys_var
 
868
{
 
869
  ulong *value;
 
870
  TYPELIB *enum_names;
 
871
public:
 
872
  sys_var_log_output(sys_var_chain *chain, const char *name_arg, ulong *value_arg,
 
873
                     TYPELIB *typelib, sys_after_update_func func)
 
874
    :sys_var(name_arg,func), value(value_arg), enum_names(typelib)
 
875
  {
 
876
    chain_sys_var(chain);
 
877
    set_allow_empty_value(FALSE);
 
878
  }
 
879
  virtual bool check(THD *thd, set_var *var)
 
880
  {
 
881
    return check_set(thd, var, enum_names);
 
882
  }
 
883
  bool update(THD *thd, set_var *var);
 
884
  uchar *value_ptr(THD *thd, enum_var_type type, LEX_STRING *base);
 
885
  bool check_update_type(Item_result type) { return 0; }
 
886
  void set_default(THD *thd, enum_var_type type);
 
887
  SHOW_TYPE show_type() { return SHOW_CHAR; }
 
888
};
 
889
 
 
890
 
 
891
/* Variable that you can only read from */
 
892
 
 
893
class sys_var_readonly: public sys_var
 
894
{
 
895
public:
 
896
  enum_var_type var_type;
 
897
  SHOW_TYPE show_type_value;
 
898
  sys_value_ptr_func value_ptr_func;
 
899
  sys_var_readonly(sys_var_chain *chain, const char *name_arg, enum_var_type type,
 
900
                   SHOW_TYPE show_type_arg,
 
901
                   sys_value_ptr_func value_ptr_func_arg)
 
902
    :sys_var(name_arg), var_type(type), 
 
903
       show_type_value(show_type_arg), value_ptr_func(value_ptr_func_arg)
 
904
  { chain_sys_var(chain); }
 
905
  bool update(THD *thd, set_var *var) { return 1; }
 
906
  bool check_default(enum_var_type type) { return 1; }
 
907
  bool check_type(enum_var_type type) { return type != var_type; }
 
908
  bool check_update_type(Item_result type) { return 1; }
 
909
  uchar *value_ptr(THD *thd, enum_var_type type, LEX_STRING *base)
 
910
  {
 
911
    return (*value_ptr_func)(thd);
 
912
  }
 
913
  SHOW_TYPE show_type() { return show_type_value; }
 
914
  bool is_readonly() const { return 1; }
 
915
};
 
916
 
 
917
 
 
918
class sys_var_have_option: public sys_var
 
919
{
 
920
protected:
 
921
  virtual SHOW_COMP_OPTION get_option() = 0;
 
922
public:
 
923
  sys_var_have_option(sys_var_chain *chain, const char *variable_name):
 
924
    sys_var(variable_name)
 
925
  { chain_sys_var(chain); }
 
926
  uchar *value_ptr(THD *thd, enum_var_type type, LEX_STRING *base)
 
927
  {
 
928
    return (uchar*) show_comp_option_name[get_option()];
 
929
  }
 
930
  bool update(THD *thd, set_var *var) { return 1; }
 
931
  bool check_default(enum_var_type type) { return 1; }
 
932
  bool check_type(enum_var_type type) { return type != OPT_GLOBAL; }
 
933
  bool check_update_type(Item_result type) { return 1; }
 
934
  SHOW_TYPE show_type() { return SHOW_CHAR; }
 
935
  bool is_readonly() const { return 1; }
 
936
};
 
937
 
 
938
 
 
939
class sys_var_have_variable: public sys_var_have_option
 
940
{
 
941
  SHOW_COMP_OPTION *have_variable;
 
942
 
 
943
public:
 
944
  sys_var_have_variable(sys_var_chain *chain, const char *variable_name,
 
945
                        SHOW_COMP_OPTION *have_variable_arg):
 
946
    sys_var_have_option(chain, variable_name),
 
947
    have_variable(have_variable_arg)
 
948
  { }
 
949
  SHOW_COMP_OPTION get_option() { return *have_variable; }
 
950
};
 
951
 
 
952
 
 
953
class sys_var_have_plugin: public sys_var_have_option
 
954
{
 
955
  const char *plugin_name_str;
 
956
  const uint plugin_name_len;
 
957
  const int plugin_type;
 
958
 
 
959
public:
 
960
  sys_var_have_plugin(sys_var_chain *chain, const char *variable_name,
 
961
                      const char *plugin_name_str_arg, uint plugin_name_len_arg, 
 
962
                      int plugin_type_arg):
 
963
    sys_var_have_option(chain, variable_name), 
 
964
    plugin_name_str(plugin_name_str_arg), plugin_name_len(plugin_name_len_arg),
 
965
    plugin_type(plugin_type_arg)
 
966
  { }
 
967
  /* the following method is declared in sql_plugin.cc */
 
968
  SHOW_COMP_OPTION get_option();
 
969
};
 
970
 
 
971
 
 
972
class sys_var_thd_time_zone :public sys_var_thd
 
973
{
 
974
public:
 
975
  sys_var_thd_time_zone(sys_var_chain *chain, const char *name_arg,
 
976
                        Binlog_status_enum binlog_status_arg= NOT_IN_BINLOG)
 
977
    :sys_var_thd(name_arg, NULL, binlog_status_arg)
 
978
  {
 
979
    no_support_one_shot= 0;
 
980
    chain_sys_var(chain);
 
981
  }
 
982
  bool check(THD *thd, set_var *var);
 
983
  SHOW_TYPE show_type() { return SHOW_CHAR; }
 
984
  bool check_update_type(Item_result type)
 
985
  {
 
986
    return type != STRING_RESULT;               /* Only accept strings */
 
987
  }
 
988
  bool check_default(enum_var_type type) { return 0; }
 
989
  bool update(THD *thd, set_var *var);
 
990
  uchar *value_ptr(THD *thd, enum_var_type type, LEX_STRING *base);
 
991
  virtual void set_default(THD *thd, enum_var_type type);
 
992
};
 
993
 
 
994
 
 
995
class sys_var_max_user_conn : public sys_var_thd
 
996
{
 
997
public:
 
998
  sys_var_max_user_conn(sys_var_chain *chain, const char *name_arg):
 
999
    sys_var_thd(name_arg)
 
1000
  { chain_sys_var(chain); }
 
1001
  bool check(THD *thd, set_var *var);
 
1002
  bool update(THD *thd, set_var *var);
 
1003
  bool check_default(enum_var_type type)
 
1004
  {
 
1005
    return type != OPT_GLOBAL || !option_limits;
 
1006
  }
 
1007
  void set_default(THD *thd, enum_var_type type);
 
1008
  SHOW_TYPE show_type() { return SHOW_INT; }
 
1009
  uchar *value_ptr(THD *thd, enum_var_type type, LEX_STRING *base);
 
1010
};
 
1011
 
 
1012
 
 
1013
class sys_var_microseconds :public sys_var_thd
 
1014
{
 
1015
  ulonglong SV::*offset;
 
1016
public:
 
1017
  sys_var_microseconds(sys_var_chain *chain, const char *name_arg,
 
1018
                       ulonglong SV::*offset_arg):
 
1019
    sys_var_thd(name_arg), offset(offset_arg)
 
1020
  { chain_sys_var(chain); }
 
1021
  bool check(THD *thd, set_var *var) {return 0;}
 
1022
  bool update(THD *thd, set_var *var);
 
1023
  void set_default(THD *thd, enum_var_type type);
 
1024
  SHOW_TYPE show_type() { return SHOW_DOUBLE; }
 
1025
  bool check_update_type(Item_result type)
 
1026
  {
 
1027
    return (type != INT_RESULT && type != REAL_RESULT && type != DECIMAL_RESULT);
 
1028
  }
 
1029
  uchar *value_ptr(THD *thd, enum_var_type type, LEX_STRING *base);
 
1030
};
 
1031
 
 
1032
 
 
1033
class sys_var_trust_routine_creators :public sys_var_bool_ptr
 
1034
{
 
1035
  /* We need a derived class only to have a warn_deprecated() */
 
1036
public:
 
1037
  sys_var_trust_routine_creators(sys_var_chain *chain,
 
1038
                                 const char *name_arg, my_bool *value_arg) :
 
1039
    sys_var_bool_ptr(chain, name_arg, value_arg) {};
 
1040
  void warn_deprecated(THD *thd);
 
1041
  void set_default(THD *thd, enum_var_type type);
 
1042
  bool update(THD *thd, set_var *var);
 
1043
};
 
1044
 
 
1045
/**
 
1046
  Handler for setting the system variable --read-only.
 
1047
*/
 
1048
 
 
1049
class sys_var_opt_readonly :public sys_var_bool_ptr
 
1050
{
 
1051
public:
 
1052
  sys_var_opt_readonly(sys_var_chain *chain, const char *name_arg, 
 
1053
                       my_bool *value_arg) :
 
1054
    sys_var_bool_ptr(chain, name_arg, value_arg) {};
 
1055
  ~sys_var_opt_readonly() {};
 
1056
  bool update(THD *thd, set_var *var);
 
1057
};
 
1058
 
 
1059
 
 
1060
class sys_var_thd_lc_time_names :public sys_var_thd
 
1061
{
 
1062
public:
 
1063
  sys_var_thd_lc_time_names(sys_var_chain *chain, const char *name_arg,
 
1064
                            Binlog_status_enum binlog_status_arg= NOT_IN_BINLOG)
 
1065
    : sys_var_thd(name_arg, NULL, binlog_status_arg)
 
1066
  {
 
1067
#if MYSQL_VERSION_ID < 50000
 
1068
    no_support_one_shot= 0;
 
1069
#endif
 
1070
    chain_sys_var(chain);
 
1071
  }
 
1072
  bool check(THD *thd, set_var *var);
 
1073
  SHOW_TYPE show_type() { return SHOW_CHAR; }
 
1074
  bool check_update_type(Item_result type)
 
1075
  {
 
1076
    return ((type != STRING_RESULT) && (type != INT_RESULT));
 
1077
  }
 
1078
  bool check_default(enum_var_type type) { return 0; }
 
1079
  bool update(THD *thd, set_var *var);
 
1080
  uchar *value_ptr(THD *thd, enum_var_type type, LEX_STRING *base);
 
1081
  virtual void set_default(THD *thd, enum_var_type type);
 
1082
};
 
1083
 
 
1084
 
 
1085
extern void fix_binlog_format_after_update(THD *thd, enum_var_type type);
 
1086
 
 
1087
class sys_var_thd_binlog_format :public sys_var_thd_enum
 
1088
{
 
1089
public:
 
1090
  sys_var_thd_binlog_format(sys_var_chain *chain, const char *name_arg, 
 
1091
                            ulong SV::*offset_arg)
 
1092
    :sys_var_thd_enum(chain, name_arg, offset_arg,
 
1093
                      &binlog_format_typelib,
 
1094
                      fix_binlog_format_after_update)
 
1095
  {};
 
1096
  bool is_readonly() const;
 
1097
};
 
1098
 
 
1099
/****************************************************************************
 
1100
  Classes for parsing of the SET command
 
1101
****************************************************************************/
 
1102
 
 
1103
class set_var_base :public Sql_alloc
 
1104
{
 
1105
public:
 
1106
  set_var_base() {}
 
1107
  virtual ~set_var_base() {}
 
1108
  virtual int check(THD *thd)=0;        /* To check privileges etc. */
 
1109
  virtual int update(THD *thd)=0;       /* To set the value */
 
1110
  /* light check for PS */
 
1111
  virtual bool no_support_one_shot() { return 1; }
 
1112
};
 
1113
 
 
1114
 
 
1115
/* MySQL internal variables, like query_cache_size */
 
1116
 
 
1117
class set_var :public set_var_base
 
1118
{
 
1119
public:
 
1120
  sys_var *var;
 
1121
  Item *value;
 
1122
  enum_var_type type;
 
1123
  union
 
1124
  {
 
1125
    CHARSET_INFO *charset;
 
1126
    ulong ulong_value;
 
1127
    ulonglong ulonglong_value;
 
1128
    plugin_ref plugin;
 
1129
    DATE_TIME_FORMAT *date_time_format;
 
1130
    Time_zone *time_zone;
 
1131
    MY_LOCALE *locale_value;
 
1132
  } save_result;
 
1133
  LEX_STRING base;                      /* for structs */
 
1134
 
 
1135
  set_var(enum_var_type type_arg, sys_var *var_arg,
 
1136
          const LEX_STRING *base_name_arg, Item *value_arg)
 
1137
    :var(var_arg), type(type_arg), base(*base_name_arg)
 
1138
  {
 
1139
    /*
 
1140
      If the set value is a field, change it to a string to allow things like
 
1141
      SET table_type=MYISAM;
 
1142
    */
 
1143
    if (value_arg && value_arg->type() == Item::FIELD_ITEM)
 
1144
    {
 
1145
      Item_field *item= (Item_field*) value_arg;
 
1146
      if (!(value=new Item_string(item->field_name, 
 
1147
                  (uint) strlen(item->field_name),
 
1148
                                  item->collation.collation)))
 
1149
        value=value_arg;                        /* Give error message later */
 
1150
    }
 
1151
    else
 
1152
      value=value_arg;
 
1153
  }
 
1154
  int check(THD *thd);
 
1155
  int update(THD *thd);
 
1156
  bool no_support_one_shot() { return var->no_support_one_shot; }
 
1157
};
 
1158
 
 
1159
 
 
1160
/* User variables like @my_own_variable */
 
1161
 
 
1162
class set_var_user: public set_var_base
 
1163
{
 
1164
  Item_func_set_user_var *user_var_item;
 
1165
public:
 
1166
  set_var_user(Item_func_set_user_var *item)
 
1167
    :user_var_item(item)
 
1168
  {}
 
1169
  int check(THD *thd);
 
1170
  int update(THD *thd);
 
1171
};
 
1172
 
 
1173
/* For SET NAMES and SET CHARACTER SET */
 
1174
 
 
1175
class set_var_collation_client: public set_var_base
 
1176
{
 
1177
  CHARSET_INFO *character_set_client;
 
1178
  CHARSET_INFO *character_set_results;
 
1179
  CHARSET_INFO *collation_connection;
 
1180
public:
 
1181
  set_var_collation_client(CHARSET_INFO *client_coll_arg,
 
1182
                           CHARSET_INFO *connection_coll_arg,
 
1183
                           CHARSET_INFO *result_coll_arg)
 
1184
    :character_set_client(client_coll_arg),
 
1185
     character_set_results(result_coll_arg),
 
1186
     collation_connection(connection_coll_arg)
 
1187
  {}
 
1188
  int check(THD *thd);
 
1189
  int update(THD *thd);
 
1190
};
 
1191
 
 
1192
 
 
1193
extern "C"
 
1194
{
 
1195
  typedef int (*process_key_cache_t) (const char *, KEY_CACHE *);
 
1196
}
 
1197
 
 
1198
/* Named lists (used for keycaches) */
 
1199
 
 
1200
class NAMED_LIST :public ilink
 
1201
{
 
1202
  const char *name;
 
1203
  uint name_length;
 
1204
public:
 
1205
  uchar* data;
 
1206
 
 
1207
  NAMED_LIST(I_List<NAMED_LIST> *links, const char *name_arg,
 
1208
             uint name_length_arg, uchar* data_arg)
 
1209
    :name_length(name_length_arg), data(data_arg)
 
1210
  {
 
1211
    name= my_strndup(name_arg, name_length, MYF(MY_WME));
 
1212
    links->push_back(this);
 
1213
  }
 
1214
  inline bool cmp(const char *name_cmp, uint length)
 
1215
  {
 
1216
    return length == name_length && !memcmp(name, name_cmp, length);
 
1217
  }
 
1218
  ~NAMED_LIST()
 
1219
  {
 
1220
    my_free((uchar*) name, MYF(0));
 
1221
  }
 
1222
  friend bool process_key_caches(process_key_cache_t func);
 
1223
  friend void delete_elements(I_List<NAMED_LIST> *list,
 
1224
                              void (*free_element)(const char*, uchar*));
 
1225
};
 
1226
 
 
1227
/* updated in sql_acl.cc */
 
1228
 
 
1229
extern sys_var_thd_bool sys_old_alter_table;
 
1230
extern sys_var_thd_bool sys_old_passwords;
 
1231
extern LEX_STRING default_key_cache_base;
 
1232
 
 
1233
/* For sql_yacc */
 
1234
struct sys_var_with_base
 
1235
{
 
1236
  sys_var *var;
 
1237
  LEX_STRING base_name;
 
1238
};
 
1239
 
 
1240
/*
 
1241
  Prototypes for helper functions
 
1242
*/
 
1243
 
 
1244
int set_var_init();
 
1245
void set_var_free();
 
1246
int mysql_append_static_vars(const SHOW_VAR *show_vars, uint count);
 
1247
SHOW_VAR* enumerate_sys_vars(THD *thd, bool sorted);
 
1248
int mysql_add_sys_var_chain(sys_var *chain, struct my_option *long_options);
 
1249
int mysql_del_sys_var_chain(sys_var *chain);
 
1250
sys_var *find_sys_var(THD *thd, const char *str, uint length=0);
 
1251
int sql_set_variables(THD *thd, List<set_var_base> *var_list);
 
1252
bool not_all_support_one_shot(List<set_var_base> *var_list);
 
1253
void fix_delay_key_write(THD *thd, enum_var_type type);
 
1254
void fix_slave_exec_mode(enum_var_type type);
 
1255
ulong fix_sql_mode(ulong sql_mode);
 
1256
extern sys_var_const_str sys_charset_system;
 
1257
extern sys_var_str sys_init_connect;
 
1258
extern sys_var_str sys_init_slave;
 
1259
extern sys_var_thd_time_zone sys_time_zone;
 
1260
extern sys_var_thd_bit sys_autocommit;
 
1261
CHARSET_INFO *get_old_charset_by_name(const char *old_name);
 
1262
uchar* find_named(I_List<NAMED_LIST> *list, const char *name, uint length,
 
1263
                NAMED_LIST **found);
 
1264
 
 
1265
extern sys_var_str sys_var_general_log_path, sys_var_slow_log_path;
 
1266
 
 
1267
/* key_cache functions */
 
1268
KEY_CACHE *get_key_cache(LEX_STRING *cache_name);
 
1269
KEY_CACHE *get_or_create_key_cache(const char *name, uint length);
 
1270
void free_key_cache(const char *name, KEY_CACHE *key_cache);
 
1271
bool process_key_caches(process_key_cache_t func);
 
1272
void delete_elements(I_List<NAMED_LIST> *list,
 
1273
                     void (*free_element)(const char*, uchar*));