1
/* Copyright (C) 2002-2006 MySQL AB
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.
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.
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 */
16
/* Classes to support the SET command */
18
#ifdef USE_PRAGMA_INTERFACE
19
#pragma interface /* gcc class implementation */
22
/****************************************************************************
23
Variables that are changable runtime are declared using the
25
****************************************************************************/
29
class sys_var_pluginvar; /* opaque */
30
typedef struct system_variables SV;
31
typedef struct my_locale_st MY_LOCALE;
33
extern TYPELIB bool_typelib, delay_key_write_typelib, sql_mode_typelib,
34
optimizer_switch_typelib, slave_exec_mode_typelib;
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);
53
Enumeration type to indicate for a system variable whether it will be written to the binlog or not.
55
enum Binlog_status_enum
57
/* The variable value is not in the binlog. */
59
/* The value of the @@session variable is in the binlog. */
60
SESSION_VARIABLE_IN_BINLOG
62
Currently, no @@global variable is ever in the binlog, so we
63
don't need an enumeration value for that.
68
struct my_option *option_limits; /* Updated by by set_var_init() */
69
uint name_length; /* Updated by by set_var_init() */
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)
81
void chain_sys_var(sys_var_chain *chain_arg)
84
chain_arg->last->next= this;
86
chain_arg->first= this;
87
chain_arg->last= this;
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)
94
return (type == OPT_SESSION || type == OPT_DEFAULT) &&
95
(binlog_status == SESSION_VARIABLE_IN_BINLOG);
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)
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; }
114
void set_allow_empty_value(bool allow_empty_value)
116
m_allow_empty_value= allow_empty_value;
120
const Binlog_status_enum binlog_status;
122
bool m_allow_empty_value;
127
A base class for all variables that require its access to
128
be guarded with a mutex.
131
class sys_var_global: public sys_var
134
pthread_mutex_t *guard;
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) {}
143
A global-only ulong variable that requires its access to be
144
protected with a mutex.
147
class sys_var_long_ptr_global: public sys_var_global
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),
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; }
168
A global ulong variable that is protected by LOCK_global_system_variables
171
class sys_var_long_ptr :public sys_var_long_ptr_global
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);
179
class sys_var_ulonglong_ptr :public sys_var
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; }
198
class sys_var_bool_ptr :public sys_var
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)
207
return check_enum(thd, var, &bool_typelib);
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; }
218
class sys_var_bool_ptr_readonly :public sys_var_bool_ptr
221
sys_var_bool_ptr_readonly(sys_var_chain *chain, const char *name_arg,
223
:sys_var_bool_ptr(chain, name_arg, value_arg)
225
bool is_readonly() const { return 1; }
229
class sys_var_str :public sys_var
232
char *value; // Pointer to allocated string
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,
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)
248
return (*update_func)(thd, var);
250
void set_default(THD *thd, enum_var_type type)
252
(*set_default_func)(thd, type);
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)
259
return type != STRING_RESULT; /* Only accept strings */
261
bool check_default(enum_var_type type) { return 0; }
265
class sys_var_const_str :public sys_var
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)
277
bool update(THD *thd, set_var *var)
281
SHOW_TYPE show_type() { return SHOW_CHAR; }
282
uchar *value_ptr(THD *thd, enum_var_type type, LEX_STRING *base)
284
return (uchar*) value;
286
bool check_update_type(Item_result type)
290
bool check_default(enum_var_type type) { return 1; }
291
bool is_readonly() const { return 1; }
295
class sys_var_const_str_ptr :public sys_var
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)
306
bool update(THD *thd, set_var *var)
310
SHOW_TYPE show_type() { return SHOW_CHAR; }
311
uchar *value_ptr(THD *thd, enum_var_type type, LEX_STRING *base)
313
return (uchar*) *value;
315
bool check_update_type(Item_result type)
319
bool check_default(enum_var_type type) { return 1; }
320
bool is_readonly() const { return 1; }
324
class sys_var_enum :public sys_var
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)
335
return check_enum(thd, var, enum_names);
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; }
344
class sys_var_enum_const :public sys_var
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);
362
class sys_var_thd :public sys_var
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)
370
bool check_type(enum_var_type type) { return 0; }
371
bool check_default(enum_var_type type)
373
return type == OPT_GLOBAL && !option_limits;
378
class sys_var_thd_ulong :public sys_var_thd
380
sys_check_func check_func;
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),
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);
399
class sys_var_thd_ha_rows :public sys_var_thd
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);
419
class sys_var_thd_ulonglong :public sys_var_thd
422
ulonglong SV::*offset;
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)
441
return type == OPT_GLOBAL && !option_limits;
443
bool check_type(enum_var_type type)
445
return (only_global && type != OPT_GLOBAL);
450
class sys_var_thd_bool :public sys_var_thd
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)
467
return check_enum(thd, var, &bool_typelib);
469
bool check_update_type(Item_result type) { return 0; }
473
class sys_var_thd_enum :public sys_var_thd
478
sys_check_func check_func;
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)
491
ret= (*check_func)(thd, var);
492
return ret ? ret : check_enum(thd, var, enum_names);
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; }
503
class sys_var_thd_optimizer_switch :public sys_var_thd_enum
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)
510
bool check(THD *thd, set_var *var)
512
return check_set(thd, var, enum_names);
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,
521
class sys_var_thd_storage_engine :public sys_var_thd
524
plugin_ref SV::*offset;
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)
534
return type != STRING_RESULT; /* Only accept strings */
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);
541
class sys_var_thd_bit :public sys_var_thd
543
sys_check_func check_func;
544
sys_update_func update_func;
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);
563
class sys_var_thd_dbug :public sys_var_thd
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);
578
/* some variables that require special handling */
580
class sys_var_timestamp :public sys_var
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);
596
class sys_var_last_insert_id :public sys_var
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);
610
class sys_var_insert_id :public sys_var
613
sys_var_insert_id(sys_var_chain *chain, const char *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);
623
class sys_var_rand_seed1 :public sys_var
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; }
634
class sys_var_rand_seed2 :public sys_var
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; }
646
class sys_var_collation :public sys_var_thd
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)
653
no_support_one_shot= 0;
655
bool check(THD *thd, set_var *var);
656
SHOW_TYPE show_type() { return SHOW_CHAR; }
657
bool check_update_type(Item_result type)
659
return ((type != STRING_RESULT) && (type != INT_RESULT));
661
bool check_default(enum_var_type type) { return 0; }
662
virtual void set_default(THD *thd, enum_var_type type)= 0;
665
class sys_var_character_set :public sys_var_thd
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)
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.
677
no_support_one_shot= 0;
679
bool check(THD *thd, set_var *var);
680
SHOW_TYPE show_type() { return SHOW_CHAR; }
681
bool check_update_type(Item_result type)
683
return ((type != STRING_RESULT) && (type != INT_RESULT));
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;
692
class sys_var_character_set_sv :public sys_var_character_set
694
CHARSET_INFO *SV::*offset;
695
CHARSET_INFO **global_default;
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,
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);
710
class sys_var_character_set_client: public sys_var_character_set_sv
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)
720
bool check(THD *thd, set_var *var);
724
class sys_var_character_set_database :public sys_var_character_set
727
sys_var_character_set_database(sys_var_chain *chain, const char *name_arg,
728
Binlog_status_enum binlog_status_arg=
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);
736
class sys_var_collation_sv :public sys_var_collation
738
CHARSET_INFO *SV::*offset;
739
CHARSET_INFO **global_default;
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)
748
chain_sys_var(chain);
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);
756
class sys_var_key_cache_param :public sys_var
761
sys_var_key_cache_param(sys_var_chain *chain, const char *name_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; }
771
class sys_var_key_buffer_size :public sys_var_key_cache_param
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))
778
bool update(THD *thd, set_var *var);
779
SHOW_TYPE show_type() { return SHOW_LONGLONG; }
783
class sys_var_key_cache_long :public sys_var_key_cache_param
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)
789
bool update(THD *thd, set_var *var);
790
SHOW_TYPE show_type() { return SHOW_LONG; }
794
class sys_var_thd_date_time_format :public sys_var_thd
796
DATE_TIME_FORMAT *SV::*offset;
797
timestamp_type date_time_type;
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)
808
return type != STRING_RESULT; /* Only accept strings */
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);
819
class sys_var_log_state :public sys_var_bool_ptr
823
sys_var_log_state(sys_var_chain *chain, const char *name_arg, my_bool *value_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);
831
class sys_var_set :public sys_var
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)
843
return check_set(thd, var, enum_names);
845
virtual void set_default(THD *thd, enum_var_type type)
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; }
855
class sys_var_set_slave_mode :public sys_var_set
858
sys_var_set_slave_mode(sys_var_chain *chain, const char *name_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);
867
class sys_var_log_output :public sys_var
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)
876
chain_sys_var(chain);
877
set_allow_empty_value(FALSE);
879
virtual bool check(THD *thd, set_var *var)
881
return check_set(thd, var, enum_names);
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; }
891
/* Variable that you can only read from */
893
class sys_var_readonly: public sys_var
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)
911
return (*value_ptr_func)(thd);
913
SHOW_TYPE show_type() { return show_type_value; }
914
bool is_readonly() const { return 1; }
918
class sys_var_have_option: public sys_var
921
virtual SHOW_COMP_OPTION get_option() = 0;
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)
928
return (uchar*) show_comp_option_name[get_option()];
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; }
939
class sys_var_have_variable: public sys_var_have_option
941
SHOW_COMP_OPTION *have_variable;
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)
949
SHOW_COMP_OPTION get_option() { return *have_variable; }
953
class sys_var_have_plugin: public sys_var_have_option
955
const char *plugin_name_str;
956
const uint plugin_name_len;
957
const int plugin_type;
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)
967
/* the following method is declared in sql_plugin.cc */
968
SHOW_COMP_OPTION get_option();
972
class sys_var_thd_time_zone :public sys_var_thd
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)
979
no_support_one_shot= 0;
980
chain_sys_var(chain);
982
bool check(THD *thd, set_var *var);
983
SHOW_TYPE show_type() { return SHOW_CHAR; }
984
bool check_update_type(Item_result type)
986
return type != STRING_RESULT; /* Only accept strings */
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);
995
class sys_var_max_user_conn : public sys_var_thd
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)
1005
return type != OPT_GLOBAL || !option_limits;
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);
1013
class sys_var_microseconds :public sys_var_thd
1015
ulonglong SV::*offset;
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)
1027
return (type != INT_RESULT && type != REAL_RESULT && type != DECIMAL_RESULT);
1029
uchar *value_ptr(THD *thd, enum_var_type type, LEX_STRING *base);
1033
class sys_var_trust_routine_creators :public sys_var_bool_ptr
1035
/* We need a derived class only to have a warn_deprecated() */
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);
1046
Handler for setting the system variable --read-only.
1049
class sys_var_opt_readonly :public sys_var_bool_ptr
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);
1060
class sys_var_thd_lc_time_names :public sys_var_thd
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)
1067
#if MYSQL_VERSION_ID < 50000
1068
no_support_one_shot= 0;
1070
chain_sys_var(chain);
1072
bool check(THD *thd, set_var *var);
1073
SHOW_TYPE show_type() { return SHOW_CHAR; }
1074
bool check_update_type(Item_result type)
1076
return ((type != STRING_RESULT) && (type != INT_RESULT));
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);
1085
extern void fix_binlog_format_after_update(THD *thd, enum_var_type type);
1087
class sys_var_thd_binlog_format :public sys_var_thd_enum
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)
1096
bool is_readonly() const;
1099
/****************************************************************************
1100
Classes for parsing of the SET command
1101
****************************************************************************/
1103
class set_var_base :public Sql_alloc
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; }
1115
/* MySQL internal variables, like query_cache_size */
1117
class set_var :public set_var_base
1125
CHARSET_INFO *charset;
1127
ulonglong ulonglong_value;
1129
DATE_TIME_FORMAT *date_time_format;
1130
Time_zone *time_zone;
1131
MY_LOCALE *locale_value;
1133
LEX_STRING base; /* for structs */
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)
1140
If the set value is a field, change it to a string to allow things like
1141
SET table_type=MYISAM;
1143
if (value_arg && value_arg->type() == Item::FIELD_ITEM)
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 */
1154
int check(THD *thd);
1155
int update(THD *thd);
1156
bool no_support_one_shot() { return var->no_support_one_shot; }
1160
/* User variables like @my_own_variable */
1162
class set_var_user: public set_var_base
1164
Item_func_set_user_var *user_var_item;
1166
set_var_user(Item_func_set_user_var *item)
1167
:user_var_item(item)
1169
int check(THD *thd);
1170
int update(THD *thd);
1173
/* For SET NAMES and SET CHARACTER SET */
1175
class set_var_collation_client: public set_var_base
1177
CHARSET_INFO *character_set_client;
1178
CHARSET_INFO *character_set_results;
1179
CHARSET_INFO *collation_connection;
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)
1188
int check(THD *thd);
1189
int update(THD *thd);
1195
typedef int (*process_key_cache_t) (const char *, KEY_CACHE *);
1198
/* Named lists (used for keycaches) */
1200
class NAMED_LIST :public ilink
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)
1211
name= my_strndup(name_arg, name_length, MYF(MY_WME));
1212
links->push_back(this);
1214
inline bool cmp(const char *name_cmp, uint length)
1216
return length == name_length && !memcmp(name, name_cmp, length);
1220
my_free((uchar*) name, MYF(0));
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*));
1227
/* updated in sql_acl.cc */
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;
1234
struct sys_var_with_base
1237
LEX_STRING base_name;
1241
Prototypes for helper functions
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);
1265
extern sys_var_str sys_var_general_log_path, sys_var_slow_log_path;
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*));