~drizzle-trunk/drizzle/development

390.1.2 by Monty Taylor
Fixed copyright headers in drizzled/
1
/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
 *  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
3
 *
4
 *  Copyright (C) 2008 Sun Microsystems
5
 *
6
 *  This program is free software; you can redistribute it and/or modify
7
 *  it under the terms of the GNU General Public License as published by
8
 *  the Free Software Foundation; version 2 of the License.
9
 *
10
 *  This program is distributed in the hope that it will be useful,
11
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 *  GNU General Public License for more details.
14
 *
15
 *  You should have received a copy of the GNU General Public License
16
 *  along with this program; if not, write to the Free Software
17
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
18
 */
1 by brian
clean slate
19
575.1.6 by Monty Taylor
Cleaned up some headers for PCH.
20
#ifndef DRIZZLED_ITEM_SET_H
21
#define DRIZZLED_ITEM_SET_H
22
584.1.15 by Monty Taylor
The mega-patch from hell. Renamed sql_class to session (since that's what it is) and removed it and field and table from common_includes.
23
#include <drizzled/functions/func.h>
24
#include <drizzled/functions/set_user_var.h>
25
1 by brian
clean slate
26
/* Classes to support the SET command */
27
28
29
/****************************************************************************
30
  Variables that are changable runtime are declared using the
31
  following classes
32
****************************************************************************/
33
34
class sys_var;
35
class set_var;
36
class sys_var_pluginvar; /* opaque */
584.1.15 by Monty Taylor
The mega-patch from hell. Renamed sql_class to session (since that's what it is) and removed it and field and table from common_includes.
37
class Time_zone;
1 by brian
clean slate
38
typedef struct system_variables SV;
39
typedef struct my_locale_st MY_LOCALE;
40
41
extern TYPELIB bool_typelib, delay_key_write_typelib, sql_mode_typelib,
617 by Brian Aker
ulong fixes
42
       optimizer_switch_typelib, slave_exec_mode_typelib;
1 by brian
clean slate
43
520.1.21 by Brian Aker
THD -> Session rename
44
typedef int (*sys_check_func)(Session *,  set_var *);
45
typedef bool (*sys_update_func)(Session *, set_var *);
46
typedef void (*sys_after_update_func)(Session *,enum_var_type);
47
typedef void (*sys_set_default_func)(Session *, enum_var_type);
520.1.22 by Brian Aker
Second pass of thd cleanup
48
typedef unsigned char *(*sys_value_ptr_func)(Session *session);
1 by brian
clean slate
49
50
struct sys_var_chain
51
{
52
  sys_var *first;
53
  sys_var *last;
54
};
55
56
class sys_var
57
{
58
public:
59
60
  /**
61
    Enumeration type to indicate for a system variable whether it will be written to the binlog or not.
62
  */
63
  enum Binlog_status_enum
64
  {  
65
    /* The variable value is not in the binlog. */
66
    NOT_IN_BINLOG,
67
    /* The value of the @@session variable is in the binlog. */
68
    SESSION_VARIABLE_IN_BINLOG
69
    /*
70
      Currently, no @@global variable is ever in the binlog, so we
71
      don't need an enumeration value for that.
72
    */
73
  };
74
75
  sys_var *next;
76
  struct my_option *option_limits;	/* Updated by by set_var_init() */
482 by Brian Aker
Remove uint.
77
  uint32_t name_length;			/* Updated by by set_var_init() */
1 by brian
clean slate
78
  const char *name;
79
80
  sys_after_update_func after_update;
81
  bool no_support_one_shot;
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
    binlog_status(binlog_status_arg),
51.1.46 by Jay Pipes
Removed/replaced DBUG symbols and standardized TRUE/FALSE
86
    m_allow_empty_value(true)
1 by brian
clean slate
87
  {}
88
  virtual ~sys_var() {}
89
  void chain_sys_var(sys_var_chain *chain_arg)
90
  {
91
    if (chain_arg->last)
92
      chain_arg->last->next= this;
93
    else
94
      chain_arg->first= this;
95
    chain_arg->last= this;
96
  }
520.1.22 by Brian Aker
Second pass of thd cleanup
97
  virtual bool check(Session *session, set_var *var);
98
  bool check_enum(Session *session, set_var *var, const TYPELIB *enum_names);
99
  bool check_set(Session *session, set_var *var, TYPELIB *enum_names);
100
  virtual bool update(Session *session, set_var *var)=0;
101
  virtual void set_default(Session *session_arg __attribute__((unused)),
212.1.3 by Monty Taylor
Renamed __attribute__((__unused__)) to __attribute__((unused)).
102
                           enum_var_type type __attribute__((unused)))
77.1.7 by Monty Taylor
Heap builds clean.
103
  {}
1 by brian
clean slate
104
  virtual SHOW_TYPE show_type() { return SHOW_UNDEF; }
520.1.22 by Brian Aker
Second pass of thd cleanup
105
  virtual unsigned char *value_ptr(Session *session __attribute__((unused)),
212.1.3 by Monty Taylor
Renamed __attribute__((__unused__)) to __attribute__((unused)).
106
                           enum_var_type type __attribute__((unused)),
107
                           LEX_STRING *base __attribute__((unused)))
1 by brian
clean slate
108
  { return 0; }
109
  virtual bool check_type(enum_var_type type)
110
  { return type != OPT_GLOBAL; }		/* Error if not GLOBAL */
111
  virtual bool check_update_type(Item_result type)
112
  { return type != INT_RESULT; }		/* Assume INT */
212.1.3 by Monty Taylor
Renamed __attribute__((__unused__)) to __attribute__((unused)).
113
  virtual bool check_default(enum_var_type type __attribute__((unused)))
1 by brian
clean slate
114
  { return option_limits == 0; }
520.1.22 by Brian Aker
Second pass of thd cleanup
115
  Item *item(Session *session, enum_var_type type, LEX_STRING *base);
1 by brian
clean slate
116
  virtual bool is_struct() { return 0; }
117
  virtual bool is_readonly() const { return 0; }
118
  virtual sys_var_pluginvar *cast_pluginvar() { return 0; }
119
120
protected:
121
  void set_allow_empty_value(bool allow_empty_value)
122
  {
123
    m_allow_empty_value= allow_empty_value;
124
  }
125
126
private:
127
  const Binlog_status_enum binlog_status;
128
129
  bool m_allow_empty_value;
130
};
131
132
133
/*
134
  A base class for all variables that require its access to
135
  be guarded with a mutex.
136
*/
137
138
class sys_var_global: public sys_var
139
{
140
protected:
141
  pthread_mutex_t *guard;
142
public:
143
  sys_var_global(const char *name_arg, sys_after_update_func after_update_arg,
144
                 pthread_mutex_t *guard_arg)
145
    :sys_var(name_arg, after_update_arg), guard(guard_arg) {}
146
};
147
148
149
/*
622 by Brian Aker
More ulong work.
150
  A global-only uint64_t variable that requires its access to be
1 by brian
clean slate
151
  protected with a mutex.
152
*/
153
154
class sys_var_long_ptr_global: public sys_var_global
155
{
622 by Brian Aker
More ulong work.
156
  uint64_t *value;
1 by brian
clean slate
157
public:
158
  sys_var_long_ptr_global(sys_var_chain *chain, const char *name_arg,
622 by Brian Aker
More ulong work.
159
                          uint64_t *value_ptr_arg,
1 by brian
clean slate
160
                          pthread_mutex_t *guard_arg,
161
                          sys_after_update_func after_update_arg= NULL)
162
    :sys_var_global(name_arg, after_update_arg, guard_arg),
163
    value(value_ptr_arg)
164
  { chain_sys_var(chain); }
520.1.22 by Brian Aker
Second pass of thd cleanup
165
  bool check(Session *session, set_var *var);
166
  bool update(Session *session, set_var *var);
167
  void set_default(Session *session, enum_var_type type);
1 by brian
clean slate
168
  SHOW_TYPE show_type() { return SHOW_LONG; }
520.1.22 by Brian Aker
Second pass of thd cleanup
169
  unsigned char *value_ptr(Session *session __attribute__((unused)),
212.1.3 by Monty Taylor
Renamed __attribute__((__unused__)) to __attribute__((unused)).
170
                   enum_var_type type __attribute__((unused)),
171
                   LEX_STRING *base __attribute__((unused)))
481 by Brian Aker
Remove all of uchar.
172
  { return (unsigned char*) value; }
1 by brian
clean slate
173
};
174
175
176
/*
622 by Brian Aker
More ulong work.
177
  A global uint64_t variable that is protected by LOCK_global_system_variables
1 by brian
clean slate
178
*/
179
180
class sys_var_long_ptr :public sys_var_long_ptr_global
181
{
182
public:
622 by Brian Aker
More ulong work.
183
  sys_var_long_ptr(sys_var_chain *chain, const char *name_arg, uint64_t *value_ptr,
1 by brian
clean slate
184
                   sys_after_update_func after_update_arg= NULL);
185
};
186
187
520.4.14 by Monty Taylor
Removed korr.h and tztime.h from common_includes. Also removed the HAVE_DTRACE block and stuck it in autoconf.
188
class sys_var_uint32_t_ptr :public sys_var
189
{
190
  uint32_t *value;
191
public:
192
  sys_var_uint32_t_ptr(sys_var_chain *chain, const char *name_arg,
193
                       uint32_t *value_ptr_arg)
194
    :sys_var(name_arg),value(value_ptr_arg)
195
  { chain_sys_var(chain); }
196
  sys_var_uint32_t_ptr(sys_var_chain *chain, const char *name_arg,
197
                       uint32_t *value_ptr_arg,
198
                       sys_after_update_func func)
199
    :sys_var(name_arg,func), value(value_ptr_arg)
200
  { chain_sys_var(chain); }
201
  bool update(Session *session, set_var *var);
202
  void set_default(Session *session, enum_var_type type);
203
  SHOW_TYPE show_type() { return SHOW_LONG; }
204
  unsigned char *value_ptr(Session *session __attribute__((unused)),
205
                   enum_var_type type __attribute__((unused)),
206
                   LEX_STRING *base __attribute__((unused)))
207
  { return (unsigned char*) value; }
208
};
209
210
151 by Brian Aker
Ulonglong to uint64_t
211
class sys_var_uint64_t_ptr :public sys_var
1 by brian
clean slate
212
{
151 by Brian Aker
Ulonglong to uint64_t
213
  uint64_t *value;
10 by Brian Aker
Start of var cleanup (really.... looking at this code the entire thing needs
214
public:
151 by Brian Aker
Ulonglong to uint64_t
215
  sys_var_uint64_t_ptr(sys_var_chain *chain, const char *name_arg, uint64_t *value_ptr_arg)
1 by brian
clean slate
216
    :sys_var(name_arg),value(value_ptr_arg)
217
  { chain_sys_var(chain); }
151 by Brian Aker
Ulonglong to uint64_t
218
  sys_var_uint64_t_ptr(sys_var_chain *chain, const char *name_arg, uint64_t *value_ptr_arg,
1 by brian
clean slate
219
		       sys_after_update_func func)
220
    :sys_var(name_arg,func), value(value_ptr_arg)
221
  { chain_sys_var(chain); }
520.1.22 by Brian Aker
Second pass of thd cleanup
222
  bool update(Session *session, set_var *var);
223
  void set_default(Session *session, enum_var_type type);
1 by brian
clean slate
224
  SHOW_TYPE show_type() { return SHOW_LONGLONG; }
520.1.22 by Brian Aker
Second pass of thd cleanup
225
  unsigned char *value_ptr(Session *session __attribute__((unused)),
212.1.3 by Monty Taylor
Renamed __attribute__((__unused__)) to __attribute__((unused)).
226
                   enum_var_type type __attribute__((unused)),
227
                   LEX_STRING *base __attribute__((unused)))
481 by Brian Aker
Remove all of uchar.
228
  { return (unsigned char*) value; }
1 by brian
clean slate
229
};
230
231
232
class sys_var_bool_ptr :public sys_var
233
{
234
public:
146 by Brian Aker
my_bool cleanup.
235
  bool *value;
147 by Brian Aker
More my_bool conversion. This time the set_var class.
236
  sys_var_bool_ptr(sys_var_chain *chain, const char *name_arg, bool *value_arg)
146 by Brian Aker
my_bool cleanup.
237
    :sys_var(name_arg),value(value_arg)
238
  { chain_sys_var(chain); }
520.1.22 by Brian Aker
Second pass of thd cleanup
239
  bool check(Session *session, set_var *var)
146 by Brian Aker
my_bool cleanup.
240
  {
520.1.22 by Brian Aker
Second pass of thd cleanup
241
    return check_enum(session, var, &bool_typelib);
146 by Brian Aker
my_bool cleanup.
242
  }
520.1.22 by Brian Aker
Second pass of thd cleanup
243
  bool update(Session *session, set_var *var);
244
  void set_default(Session *session, enum_var_type type);
146 by Brian Aker
my_bool cleanup.
245
  SHOW_TYPE show_type() { return SHOW_MY_BOOL; }
520.1.22 by Brian Aker
Second pass of thd cleanup
246
  unsigned char *value_ptr(Session *session __attribute__((unused)),
212.1.3 by Monty Taylor
Renamed __attribute__((__unused__)) to __attribute__((unused)).
247
                   enum_var_type type __attribute__((unused)),
248
                   LEX_STRING *base __attribute__((unused)))
481 by Brian Aker
Remove all of uchar.
249
  { return (unsigned char*) value; }
212.1.3 by Monty Taylor
Renamed __attribute__((__unused__)) to __attribute__((unused)).
250
  bool check_update_type(Item_result type __attribute__((unused)))
146 by Brian Aker
my_bool cleanup.
251
  { return 0; }
252
};
253
1 by brian
clean slate
254
class sys_var_bool_ptr_readonly :public sys_var_bool_ptr
255
{
256
public:
257
  sys_var_bool_ptr_readonly(sys_var_chain *chain, const char *name_arg,
147 by Brian Aker
More my_bool conversion. This time the set_var class.
258
                            bool *value_arg)
1 by brian
clean slate
259
    :sys_var_bool_ptr(chain, name_arg, value_arg)
260
  {}
261
  bool is_readonly() const { return 1; }
262
};
263
264
265
class sys_var_str :public sys_var
266
{
267
public:
268
  char *value;					// Pointer to allocated string
482 by Brian Aker
Remove uint.
269
  uint32_t value_length;
1 by brian
clean slate
270
  sys_check_func check_func;
271
  sys_update_func update_func;
272
  sys_set_default_func set_default_func;
273
  sys_var_str(sys_var_chain *chain, const char *name_arg,
274
	      sys_check_func check_func_arg,
275
	      sys_update_func update_func_arg,
276
	      sys_set_default_func set_default_func_arg,
277
              char *value_arg)
278
    :sys_var(name_arg), value(value_arg), check_func(check_func_arg),
279
    update_func(update_func_arg),set_default_func(set_default_func_arg)
280
  { chain_sys_var(chain); }
520.1.22 by Brian Aker
Second pass of thd cleanup
281
  bool check(Session *session, set_var *var);
282
  bool update(Session *session, set_var *var)
1 by brian
clean slate
283
  {
520.1.22 by Brian Aker
Second pass of thd cleanup
284
    return (*update_func)(session, var);
1 by brian
clean slate
285
  }
520.1.22 by Brian Aker
Second pass of thd cleanup
286
  void set_default(Session *session, enum_var_type type)
1 by brian
clean slate
287
  {
520.1.22 by Brian Aker
Second pass of thd cleanup
288
    (*set_default_func)(session, type);
1 by brian
clean slate
289
  }
290
  SHOW_TYPE show_type() { return SHOW_CHAR; }
520.1.22 by Brian Aker
Second pass of thd cleanup
291
  unsigned char *value_ptr(Session *session __attribute__((unused)),
212.1.3 by Monty Taylor
Renamed __attribute__((__unused__)) to __attribute__((unused)).
292
                   enum_var_type type __attribute__((unused)),
293
                   LEX_STRING *base __attribute__((unused)))
481 by Brian Aker
Remove all of uchar.
294
  { return (unsigned char*) value; }
1 by brian
clean slate
295
  bool check_update_type(Item_result type)
296
  {
297
    return type != STRING_RESULT;		/* Only accept strings */
298
  }
212.1.3 by Monty Taylor
Renamed __attribute__((__unused__)) to __attribute__((unused)).
299
  bool check_default(enum_var_type type __attribute__((unused)))
77.1.7 by Monty Taylor
Heap builds clean.
300
  { return 0; }
1 by brian
clean slate
301
};
302
303
304
class sys_var_const_str :public sys_var
305
{
306
  char *value;					// Pointer to const value
10 by Brian Aker
Start of var cleanup (really.... looking at this code the entire thing needs
307
public:
1 by brian
clean slate
308
  sys_var_const_str(sys_var_chain *chain, const char *name_arg,
309
                    const char *value_arg)
310
    :sys_var(name_arg), value((char*) value_arg)
311
  { chain_sys_var(chain); }
10 by Brian Aker
Start of var cleanup (really.... looking at this code the entire thing needs
312
  inline void set (char *new_value)
313
  {
314
    value= new_value;
315
  }
520.1.22 by Brian Aker
Second pass of thd cleanup
316
  bool check(Session *session __attribute__((unused)),
212.1.3 by Monty Taylor
Renamed __attribute__((__unused__)) to __attribute__((unused)).
317
             set_var *var __attribute__((unused)))
1 by brian
clean slate
318
  {
319
    return 1;
320
  }
520.1.22 by Brian Aker
Second pass of thd cleanup
321
  bool update(Session *session __attribute__((unused)),
212.1.3 by Monty Taylor
Renamed __attribute__((__unused__)) to __attribute__((unused)).
322
              set_var *var __attribute__((unused)))
1 by brian
clean slate
323
  {
324
    return 1;
325
  }
326
  SHOW_TYPE show_type() { return SHOW_CHAR; }
520.1.22 by Brian Aker
Second pass of thd cleanup
327
  unsigned char *value_ptr(Session *session __attribute__((unused)),
212.1.3 by Monty Taylor
Renamed __attribute__((__unused__)) to __attribute__((unused)).
328
                   enum_var_type type __attribute__((unused)),
329
                   LEX_STRING *base __attribute__((unused)))
1 by brian
clean slate
330
  {
481 by Brian Aker
Remove all of uchar.
331
    return (unsigned char*) value;
1 by brian
clean slate
332
  }
212.1.3 by Monty Taylor
Renamed __attribute__((__unused__)) to __attribute__((unused)).
333
  bool check_update_type(Item_result type __attribute__((unused)))
1 by brian
clean slate
334
  {
335
    return 1;
336
  }
212.1.3 by Monty Taylor
Renamed __attribute__((__unused__)) to __attribute__((unused)).
337
  bool check_default(enum_var_type type __attribute__((unused)))
77.1.7 by Monty Taylor
Heap builds clean.
338
  { return 1; }
1 by brian
clean slate
339
  bool is_readonly() const { return 1; }
340
};
341
342
343
class sys_var_const_str_ptr :public sys_var
344
{
345
  char **value;					// Pointer to const value
10 by Brian Aker
Start of var cleanup (really.... looking at this code the entire thing needs
346
public:
1 by brian
clean slate
347
  sys_var_const_str_ptr(sys_var_chain *chain, const char *name_arg, char **value_arg)
348
    :sys_var(name_arg),value(value_arg)
349
  { chain_sys_var(chain); }
520.1.22 by Brian Aker
Second pass of thd cleanup
350
  bool check(Session *session __attribute__((unused)),
212.1.3 by Monty Taylor
Renamed __attribute__((__unused__)) to __attribute__((unused)).
351
             set_var *var __attribute__((unused)))
1 by brian
clean slate
352
  {
353
    return 1;
354
  }
520.1.22 by Brian Aker
Second pass of thd cleanup
355
  bool update(Session *session __attribute__((unused)),
212.1.3 by Monty Taylor
Renamed __attribute__((__unused__)) to __attribute__((unused)).
356
              set_var *var __attribute__((unused)))
1 by brian
clean slate
357
  {
358
    return 1;
359
  }
360
  SHOW_TYPE show_type() { return SHOW_CHAR; }
520.1.22 by Brian Aker
Second pass of thd cleanup
361
  unsigned char *value_ptr(Session *session __attribute__((unused)),
212.1.3 by Monty Taylor
Renamed __attribute__((__unused__)) to __attribute__((unused)).
362
                   enum_var_type type __attribute__((unused)),
363
                   LEX_STRING *base __attribute__((unused)))
1 by brian
clean slate
364
  {
481 by Brian Aker
Remove all of uchar.
365
    return (unsigned char*) *value;
1 by brian
clean slate
366
  }
212.1.3 by Monty Taylor
Renamed __attribute__((__unused__)) to __attribute__((unused)).
367
  bool check_update_type(Item_result type __attribute__((unused)))
1 by brian
clean slate
368
  {
369
    return 1;
370
  }
212.1.3 by Monty Taylor
Renamed __attribute__((__unused__)) to __attribute__((unused)).
371
  bool check_default(enum_var_type type __attribute__((unused)))
77.1.7 by Monty Taylor
Heap builds clean.
372
  { return 1; }
373
  bool is_readonly(void) const { return 1; }
1 by brian
clean slate
374
};
375
376
377
class sys_var_enum :public sys_var
378
{
482 by Brian Aker
Remove uint.
379
  uint32_t *value;
1 by brian
clean slate
380
  TYPELIB *enum_names;
381
public:
482 by Brian Aker
Remove uint.
382
  sys_var_enum(sys_var_chain *chain, const char *name_arg, uint32_t *value_arg,
1 by brian
clean slate
383
	       TYPELIB *typelib, sys_after_update_func func)
384
    :sys_var(name_arg,func), value(value_arg), enum_names(typelib)
385
  { chain_sys_var(chain); }
520.1.22 by Brian Aker
Second pass of thd cleanup
386
  bool check(Session *session, set_var *var)
1 by brian
clean slate
387
  {
520.1.22 by Brian Aker
Second pass of thd cleanup
388
    return check_enum(session, var, enum_names);
1 by brian
clean slate
389
  }
520.1.22 by Brian Aker
Second pass of thd cleanup
390
  bool update(Session *session, set_var *var);
1 by brian
clean slate
391
  SHOW_TYPE show_type() { return SHOW_CHAR; }
520.1.22 by Brian Aker
Second pass of thd cleanup
392
  unsigned char *value_ptr(Session *session, enum_var_type type, LEX_STRING *base);
212.1.3 by Monty Taylor
Renamed __attribute__((__unused__)) to __attribute__((unused)).
393
  bool check_update_type(Item_result type __attribute__((unused)))
77.1.7 by Monty Taylor
Heap builds clean.
394
  { return 0; }
1 by brian
clean slate
395
};
396
397
398
class sys_var_enum_const :public sys_var
399
{
621 by Brian Aker
ulong fixes
400
  uint32_t SV::*offset;
1 by brian
clean slate
401
  TYPELIB *enum_names;
402
public:
621 by Brian Aker
ulong fixes
403
  sys_var_enum_const(sys_var_chain *chain, const char *name_arg, uint32_t SV::*offset_arg,
1 by brian
clean slate
404
      TYPELIB *typelib, sys_after_update_func func)
405
    :sys_var(name_arg,func), offset(offset_arg), enum_names(typelib)
406
  { chain_sys_var(chain); }
520.1.22 by Brian Aker
Second pass of thd cleanup
407
  bool check(Session *session __attribute__((unused)),
212.1.3 by Monty Taylor
Renamed __attribute__((__unused__)) to __attribute__((unused)).
408
             set_var *var __attribute__((unused)))
77.1.7 by Monty Taylor
Heap builds clean.
409
  { return 1; }
520.1.22 by Brian Aker
Second pass of thd cleanup
410
  bool update(Session *session __attribute__((unused)),
212.1.3 by Monty Taylor
Renamed __attribute__((__unused__)) to __attribute__((unused)).
411
              set_var *var __attribute__((unused)))
77.1.7 by Monty Taylor
Heap builds clean.
412
  { return 1; }
1 by brian
clean slate
413
  SHOW_TYPE show_type() { return SHOW_CHAR; }
212.1.3 by Monty Taylor
Renamed __attribute__((__unused__)) to __attribute__((unused)).
414
  bool check_update_type(Item_result type __attribute__((unused)))
77.1.7 by Monty Taylor
Heap builds clean.
415
  { return 1; }
1 by brian
clean slate
416
  bool is_readonly() const { return 1; }
520.1.22 by Brian Aker
Second pass of thd cleanup
417
  unsigned char *value_ptr(Session *session, enum_var_type type, LEX_STRING *base);
1 by brian
clean slate
418
};
419
420
520.1.22 by Brian Aker
Second pass of thd cleanup
421
class sys_var_session :public sys_var
1 by brian
clean slate
422
{
423
public:
520.1.22 by Brian Aker
Second pass of thd cleanup
424
  sys_var_session(const char *name_arg, 
1 by brian
clean slate
425
              sys_after_update_func func= NULL,
426
              Binlog_status_enum binlog_status= NOT_IN_BINLOG)
427
    :sys_var(name_arg, func, binlog_status)
428
  {}
212.1.3 by Monty Taylor
Renamed __attribute__((__unused__)) to __attribute__((unused)).
429
  bool check_type(enum_var_type type __attribute__((unused)))
77.1.7 by Monty Taylor
Heap builds clean.
430
  { return 0; }
1 by brian
clean slate
431
  bool check_default(enum_var_type type)
432
  {
433
    return type == OPT_GLOBAL && !option_limits;
434
  }
435
};
436
615 by Brian Aker
Added 32bit system variable support
437
class sys_var_session_uint32_t :public sys_var_session
438
{
439
  sys_check_func check_func;
440
public:
441
  uint32_t SV::*offset;
442
  sys_var_session_uint32_t(sys_var_chain *chain, const char *name_arg,
443
                           uint32_t SV::*offset_arg,
444
                           sys_check_func c_func= NULL,
445
                           sys_after_update_func au_func= NULL,
446
                           Binlog_status_enum binlog_status_arg= NOT_IN_BINLOG)
447
    :sys_var_session(name_arg, au_func, binlog_status_arg), check_func(c_func),
448
    offset(offset_arg)
449
  { chain_sys_var(chain); }
450
  bool check(Session *session, set_var *var);
451
  bool update(Session *session, set_var *var);
452
  void set_default(Session *session, enum_var_type type);
453
  SHOW_TYPE show_type() { return SHOW_LONG; }
454
  unsigned char *value_ptr(Session *session, enum_var_type type, LEX_STRING *base);
455
};
456
1 by brian
clean slate
457
520.1.22 by Brian Aker
Second pass of thd cleanup
458
class sys_var_session_ha_rows :public sys_var_session
1 by brian
clean slate
459
{
460
public:
461
  ha_rows SV::*offset;
520.1.22 by Brian Aker
Second pass of thd cleanup
462
  sys_var_session_ha_rows(sys_var_chain *chain, const char *name_arg, 
1 by brian
clean slate
463
                      ha_rows SV::*offset_arg)
520.1.22 by Brian Aker
Second pass of thd cleanup
464
    :sys_var_session(name_arg), offset(offset_arg)
1 by brian
clean slate
465
  { chain_sys_var(chain); }
520.1.22 by Brian Aker
Second pass of thd cleanup
466
  sys_var_session_ha_rows(sys_var_chain *chain, const char *name_arg, 
1 by brian
clean slate
467
                      ha_rows SV::*offset_arg,
468
		      sys_after_update_func func)
520.1.22 by Brian Aker
Second pass of thd cleanup
469
    :sys_var_session(name_arg,func), offset(offset_arg)
1 by brian
clean slate
470
  { chain_sys_var(chain); }
520.1.22 by Brian Aker
Second pass of thd cleanup
471
  bool update(Session *session, set_var *var);
472
  void set_default(Session *session, enum_var_type type);
1 by brian
clean slate
473
  SHOW_TYPE show_type() { return SHOW_HA_ROWS; }
520.1.22 by Brian Aker
Second pass of thd cleanup
474
  unsigned char *value_ptr(Session *session, enum_var_type type, LEX_STRING *base);
1 by brian
clean slate
475
};
476
477
520.1.22 by Brian Aker
Second pass of thd cleanup
478
class sys_var_session_uint64_t :public sys_var_session
1 by brian
clean slate
479
{
555 by Monty
Fixed 32-bit issues.
480
  sys_check_func check_func;
1 by brian
clean slate
481
public:
151 by Brian Aker
Ulonglong to uint64_t
482
  uint64_t SV::*offset;
1 by brian
clean slate
483
  bool only_global;
555 by Monty
Fixed 32-bit issues.
484
  sys_var_session_uint64_t(sys_var_chain *chain, const char *name_arg,
485
                           uint64_t SV::*offset_arg,
486
                           sys_after_update_func au_func= NULL,
487
                           sys_check_func c_func= NULL,
488
                           Binlog_status_enum binlog_status_arg= NOT_IN_BINLOG)
617 by Brian Aker
ulong fixes
489
    :sys_var_session(name_arg, au_func, binlog_status_arg),
490
    check_func(c_func),
491
    offset(offset_arg)
492
  { chain_sys_var(chain); }
493
  sys_var_session_uint64_t(sys_var_chain *chain, 
494
                           const char *name_arg, 
495
                           uint64_t SV::*offset_arg, 
496
                           sys_after_update_func func, 
497
                           bool only_global_arg,
498
                           sys_check_func cfunc= NULL)
555 by Monty
Fixed 32-bit issues.
499
    :sys_var_session(name_arg, func),
500
    check_func(cfunc),
501
    offset(offset_arg),
1 by brian
clean slate
502
    only_global(only_global_arg)
503
  { chain_sys_var(chain); }
520.1.22 by Brian Aker
Second pass of thd cleanup
504
  bool update(Session *session, set_var *var);
505
  void set_default(Session *session, enum_var_type type);
1 by brian
clean slate
506
  SHOW_TYPE show_type() { return SHOW_LONGLONG; }
520.1.22 by Brian Aker
Second pass of thd cleanup
507
  unsigned char *value_ptr(Session *session, enum_var_type type, LEX_STRING *base);
508
  bool check(Session *session, set_var *var);
1 by brian
clean slate
509
  bool check_default(enum_var_type type)
510
  {
511
    return type == OPT_GLOBAL && !option_limits;
512
  }
513
  bool check_type(enum_var_type type)
514
  {
515
    return (only_global && type != OPT_GLOBAL);
516
  }
517
};
518
519
520.1.22 by Brian Aker
Second pass of thd cleanup
520
class sys_var_session_bool :public sys_var_session
1 by brian
clean slate
521
{
522
public:
200 by Brian Aker
my_bool from handler and set_var
523
  bool SV::*offset;
520.1.22 by Brian Aker
Second pass of thd cleanup
524
  sys_var_session_bool(sys_var_chain *chain, const char *name_arg, bool SV::*offset_arg)
525
    :sys_var_session(name_arg), offset(offset_arg)
1 by brian
clean slate
526
  { chain_sys_var(chain); }
520.1.22 by Brian Aker
Second pass of thd cleanup
527
  sys_var_session_bool(sys_var_chain *chain, const char *name_arg, bool SV::*offset_arg,
1 by brian
clean slate
528
		   sys_after_update_func func)
520.1.22 by Brian Aker
Second pass of thd cleanup
529
    :sys_var_session(name_arg,func), offset(offset_arg)
1 by brian
clean slate
530
  { chain_sys_var(chain); }
520.1.22 by Brian Aker
Second pass of thd cleanup
531
  bool update(Session *session, set_var *var);
532
  void set_default(Session *session, enum_var_type type);
1 by brian
clean slate
533
  SHOW_TYPE show_type() { return SHOW_MY_BOOL; }
520.1.22 by Brian Aker
Second pass of thd cleanup
534
  unsigned char *value_ptr(Session *session, enum_var_type type, LEX_STRING *base);
535
  bool check(Session *session, set_var *var)
1 by brian
clean slate
536
  {
520.1.22 by Brian Aker
Second pass of thd cleanup
537
    return check_enum(session, var, &bool_typelib);
1 by brian
clean slate
538
  }
212.1.3 by Monty Taylor
Renamed __attribute__((__unused__)) to __attribute__((unused)).
539
  bool check_update_type(Item_result type __attribute__((unused)))
77.1.7 by Monty Taylor
Heap builds clean.
540
  { return 0; }
1 by brian
clean slate
541
};
542
543
520.1.22 by Brian Aker
Second pass of thd cleanup
544
class sys_var_session_enum :public sys_var_session
1 by brian
clean slate
545
{
546
protected:
617 by Brian Aker
ulong fixes
547
  uint32_t SV::*offset;
1 by brian
clean slate
548
  TYPELIB *enum_names;
549
  sys_check_func check_func;
550
public:
520.1.22 by Brian Aker
Second pass of thd cleanup
551
  sys_var_session_enum(sys_var_chain *chain, const char *name_arg,
617 by Brian Aker
ulong fixes
552
                   uint32_t SV::*offset_arg, TYPELIB *typelib,
1 by brian
clean slate
553
                   sys_after_update_func func= NULL,
554
                   sys_check_func check= NULL)
520.1.22 by Brian Aker
Second pass of thd cleanup
555
    :sys_var_session(name_arg, func), offset(offset_arg),
1 by brian
clean slate
556
    enum_names(typelib), check_func(check)
557
  { chain_sys_var(chain); }
520.1.22 by Brian Aker
Second pass of thd cleanup
558
  bool check(Session *session, set_var *var)
1 by brian
clean slate
559
  {
560
    int ret= 0;
561
    if (check_func)
520.1.22 by Brian Aker
Second pass of thd cleanup
562
      ret= (*check_func)(session, var);
563
    return ret ? ret : check_enum(session, var, enum_names);
1 by brian
clean slate
564
  }
520.1.22 by Brian Aker
Second pass of thd cleanup
565
  bool update(Session *session, set_var *var);
566
  void set_default(Session *session, enum_var_type type);
1 by brian
clean slate
567
  SHOW_TYPE show_type() { return SHOW_CHAR; }
520.1.22 by Brian Aker
Second pass of thd cleanup
568
  unsigned char *value_ptr(Session *session, enum_var_type type, LEX_STRING *base);
212.1.3 by Monty Taylor
Renamed __attribute__((__unused__)) to __attribute__((unused)).
569
  bool check_update_type(Item_result type __attribute__((unused)))
77.1.7 by Monty Taylor
Heap builds clean.
570
  { return 0; }
1 by brian
clean slate
571
};
572
573
574
520.1.22 by Brian Aker
Second pass of thd cleanup
575
class sys_var_session_optimizer_switch :public sys_var_session_enum
1 by brian
clean slate
576
{
577
public:
520.1.22 by Brian Aker
Second pass of thd cleanup
578
  sys_var_session_optimizer_switch(sys_var_chain *chain, const char *name_arg, 
617 by Brian Aker
ulong fixes
579
                                   uint32_t SV::*offset_arg)
520.1.22 by Brian Aker
Second pass of thd cleanup
580
    :sys_var_session_enum(chain, name_arg, offset_arg, &optimizer_switch_typelib)
1 by brian
clean slate
581
  {}
520.1.22 by Brian Aker
Second pass of thd cleanup
582
  bool check(Session *session, set_var *var)
1 by brian
clean slate
583
  {
520.1.22 by Brian Aker
Second pass of thd cleanup
584
    return check_set(session, var, enum_names);
1 by brian
clean slate
585
  }
520.1.22 by Brian Aker
Second pass of thd cleanup
586
  void set_default(Session *session, enum_var_type type);
587
  unsigned char *value_ptr(Session *session, enum_var_type type, LEX_STRING *base);
617 by Brian Aker
ulong fixes
588
  static bool symbolic_mode_representation(Session *session, uint32_t sql_mode,
1 by brian
clean slate
589
                                           LEX_STRING *rep);
590
};
591
592
520.1.22 by Brian Aker
Second pass of thd cleanup
593
class sys_var_session_storage_engine :public sys_var_session
1 by brian
clean slate
594
{
595
protected:
596
  plugin_ref SV::*offset;
597
public:
520.1.22 by Brian Aker
Second pass of thd cleanup
598
  sys_var_session_storage_engine(sys_var_chain *chain, const char *name_arg, 
1 by brian
clean slate
599
                             plugin_ref SV::*offset_arg)
520.1.22 by Brian Aker
Second pass of thd cleanup
600
    :sys_var_session(name_arg), offset(offset_arg)
1 by brian
clean slate
601
  { chain_sys_var(chain); }
520.1.22 by Brian Aker
Second pass of thd cleanup
602
  bool check(Session *session, set_var *var);
1 by brian
clean slate
603
  SHOW_TYPE show_type() { return SHOW_CHAR; }
604
  bool check_update_type(Item_result type)
605
  {
606
    return type != STRING_RESULT;		/* Only accept strings */
607
  }
520.1.22 by Brian Aker
Second pass of thd cleanup
608
  void set_default(Session *session, enum_var_type type);
609
  bool update(Session *session, set_var *var);
610
  unsigned char *value_ptr(Session *session, enum_var_type type, LEX_STRING *base);
1 by brian
clean slate
611
};
612
520.1.22 by Brian Aker
Second pass of thd cleanup
613
class sys_var_session_bit :public sys_var_session
1 by brian
clean slate
614
{
615
  sys_check_func check_func;
616
  sys_update_func update_func;
617
public:
151 by Brian Aker
Ulonglong to uint64_t
618
  uint64_t bit_flag;
1 by brian
clean slate
619
  bool reverse;
520.1.22 by Brian Aker
Second pass of thd cleanup
620
  sys_var_session_bit(sys_var_chain *chain, const char *name_arg,
1 by brian
clean slate
621
                  sys_check_func c_func, sys_update_func u_func,
151 by Brian Aker
Ulonglong to uint64_t
622
                  uint64_t bit, bool reverse_arg=0,
1 by brian
clean slate
623
                  Binlog_status_enum binlog_status_arg= NOT_IN_BINLOG)
520.1.22 by Brian Aker
Second pass of thd cleanup
624
    :sys_var_session(name_arg, NULL, binlog_status_arg), check_func(c_func),
1 by brian
clean slate
625
    update_func(u_func), bit_flag(bit), reverse(reverse_arg)
626
  { chain_sys_var(chain); }
520.1.22 by Brian Aker
Second pass of thd cleanup
627
  bool check(Session *session, set_var *var);
628
  bool update(Session *session, set_var *var);
212.1.3 by Monty Taylor
Renamed __attribute__((__unused__)) to __attribute__((unused)).
629
  bool check_update_type(Item_result type __attribute__((unused)))
77.1.7 by Monty Taylor
Heap builds clean.
630
  { return 0; }
1 by brian
clean slate
631
  bool check_type(enum_var_type type) { return type == OPT_GLOBAL; }
632
  SHOW_TYPE show_type() { return SHOW_MY_BOOL; }
520.1.22 by Brian Aker
Second pass of thd cleanup
633
  unsigned char *value_ptr(Session *session, enum_var_type type, LEX_STRING *base);
1 by brian
clean slate
634
};
635
636
/* some variables that require special handling */
637
638
class sys_var_timestamp :public sys_var
639
{
640
public:
641
  sys_var_timestamp(sys_var_chain *chain, const char *name_arg,
642
                    Binlog_status_enum binlog_status_arg= NOT_IN_BINLOG)
643
    :sys_var(name_arg, NULL, binlog_status_arg)
644
  { chain_sys_var(chain); }
520.1.22 by Brian Aker
Second pass of thd cleanup
645
  bool update(Session *session, set_var *var);
646
  void set_default(Session *session, enum_var_type type);
1 by brian
clean slate
647
  bool check_type(enum_var_type type)    { return type == OPT_GLOBAL; }
212.1.3 by Monty Taylor
Renamed __attribute__((__unused__)) to __attribute__((unused)).
648
  bool check_default(enum_var_type type __attribute__((unused)))
77.1.7 by Monty Taylor
Heap builds clean.
649
  { return 0; }
650
  SHOW_TYPE show_type(void) { return SHOW_LONG; }
520.1.22 by Brian Aker
Second pass of thd cleanup
651
  unsigned char *value_ptr(Session *session, enum_var_type type, LEX_STRING *base);
1 by brian
clean slate
652
};
653
654
655
class sys_var_last_insert_id :public sys_var
656
{
657
public:
658
  sys_var_last_insert_id(sys_var_chain *chain, const char *name_arg,
659
                         Binlog_status_enum binlog_status_arg= NOT_IN_BINLOG)
660
    :sys_var(name_arg, NULL, binlog_status_arg)
661
  { chain_sys_var(chain); }
520.1.22 by Brian Aker
Second pass of thd cleanup
662
  bool update(Session *session, set_var *var);
1 by brian
clean slate
663
  bool check_type(enum_var_type type) { return type == OPT_GLOBAL; }
664
  SHOW_TYPE show_type() { return SHOW_LONGLONG; }
520.1.22 by Brian Aker
Second pass of thd cleanup
665
  unsigned char *value_ptr(Session *session, enum_var_type type, LEX_STRING *base);
1 by brian
clean slate
666
};
667
668
669
class sys_var_insert_id :public sys_var
670
{
671
public:
672
  sys_var_insert_id(sys_var_chain *chain, const char *name_arg)
673
    :sys_var(name_arg)
674
  { chain_sys_var(chain); }
520.1.22 by Brian Aker
Second pass of thd cleanup
675
  bool update(Session *session, set_var *var);
1 by brian
clean slate
676
  bool check_type(enum_var_type type) { return type == OPT_GLOBAL; }
677
  SHOW_TYPE show_type() { return SHOW_LONGLONG; }
520.1.22 by Brian Aker
Second pass of thd cleanup
678
  unsigned char *value_ptr(Session *session, enum_var_type type, LEX_STRING *base);
1 by brian
clean slate
679
};
680
681
520.1.22 by Brian Aker
Second pass of thd cleanup
682
class sys_var_collation :public sys_var_session
1 by brian
clean slate
683
{
684
public:
685
  sys_var_collation(const char *name_arg,
686
                    Binlog_status_enum binlog_status_arg= NOT_IN_BINLOG)
520.1.22 by Brian Aker
Second pass of thd cleanup
687
    :sys_var_session(name_arg, NULL, binlog_status_arg)
1 by brian
clean slate
688
  {
689
    no_support_one_shot= 0;
690
  }
520.1.22 by Brian Aker
Second pass of thd cleanup
691
  bool check(Session *session, set_var *var);
1 by brian
clean slate
692
  SHOW_TYPE show_type() { return SHOW_CHAR; }
693
  bool check_update_type(Item_result type)
694
  {
695
    return ((type != STRING_RESULT) && (type != INT_RESULT));
696
  }
212.1.3 by Monty Taylor
Renamed __attribute__((__unused__)) to __attribute__((unused)).
697
  bool check_default(enum_var_type type __attribute__((unused))) { return 0; }
520.1.22 by Brian Aker
Second pass of thd cleanup
698
  virtual void set_default(Session *session, enum_var_type type)= 0;
1 by brian
clean slate
699
};
700
520.1.22 by Brian Aker
Second pass of thd cleanup
701
class sys_var_character_set :public sys_var_session
1 by brian
clean slate
702
{
703
public:
704
  bool nullable;
705
  sys_var_character_set(const char *name_arg, bool is_nullable= 0,
706
                        Binlog_status_enum binlog_status_arg= NOT_IN_BINLOG)
520.1.22 by Brian Aker
Second pass of thd cleanup
707
    :sys_var_session(name_arg, NULL, binlog_status_arg), nullable(is_nullable)
1 by brian
clean slate
708
  {
709
    /*
710
      In fact only almost all variables derived from sys_var_character_set
711
      support ONE_SHOT; character_set_results doesn't. But that's good enough.
712
    */
713
    no_support_one_shot= 0;
714
  }
520.1.22 by Brian Aker
Second pass of thd cleanup
715
  bool check(Session *session, set_var *var);
1 by brian
clean slate
716
  SHOW_TYPE show_type() { return SHOW_CHAR; }
717
  bool check_update_type(Item_result type)
718
  {
719
    return ((type != STRING_RESULT) && (type != INT_RESULT));
720
  }
212.1.3 by Monty Taylor
Renamed __attribute__((__unused__)) to __attribute__((unused)).
721
  bool check_default(enum_var_type type __attribute__((unused)))
77.1.7 by Monty Taylor
Heap builds clean.
722
  { return 0; }
520.1.22 by Brian Aker
Second pass of thd cleanup
723
  bool update(Session *session, set_var *var);
724
  unsigned char *value_ptr(Session *session, enum_var_type type, LEX_STRING *base);
725
  virtual void set_default(Session *session, enum_var_type type)= 0;
726
  virtual const CHARSET_INFO **ci_ptr(Session *session, enum_var_type type)= 0;
1 by brian
clean slate
727
};
728
729
class sys_var_collation_sv :public sys_var_collation
730
{
264.2.6 by Andrey Hristov
Constify the usage of CHARSET_INFO almost to the last place in the code.
731
  const CHARSET_INFO *SV::*offset;
732
  const CHARSET_INFO **global_default;
1 by brian
clean slate
733
public:
734
  sys_var_collation_sv(sys_var_chain *chain, const char *name_arg,
264.2.6 by Andrey Hristov
Constify the usage of CHARSET_INFO almost to the last place in the code.
735
		       const CHARSET_INFO *SV::*offset_arg,
736
                       const CHARSET_INFO **global_default_arg,
1 by brian
clean slate
737
                       Binlog_status_enum binlog_status_arg= NOT_IN_BINLOG)
738
    :sys_var_collation(name_arg, binlog_status_arg),
739
    offset(offset_arg), global_default(global_default_arg)
740
  {
741
    chain_sys_var(chain);
742
  }
520.1.22 by Brian Aker
Second pass of thd cleanup
743
  bool update(Session *session, set_var *var);
744
  void set_default(Session *session, enum_var_type type);
745
  unsigned char *value_ptr(Session *session, enum_var_type type, LEX_STRING *base);
1 by brian
clean slate
746
};
747
748
749
class sys_var_key_cache_param :public sys_var
750
{
751
protected:
752
  size_t offset;
753
public:
754
  sys_var_key_cache_param(sys_var_chain *chain, const char *name_arg, 
755
                          size_t offset_arg)
756
    :sys_var(name_arg), offset(offset_arg)
757
  { chain_sys_var(chain); }
520.1.22 by Brian Aker
Second pass of thd cleanup
758
  unsigned char *value_ptr(Session *session, enum_var_type type, LEX_STRING *base);
212.1.3 by Monty Taylor
Renamed __attribute__((__unused__)) to __attribute__((unused)).
759
  bool check_default(enum_var_type type __attribute__((unused)))
77.1.7 by Monty Taylor
Heap builds clean.
760
  { return 1; }
1 by brian
clean slate
761
  bool is_struct() { return 1; }
762
};
763
764
765
class sys_var_key_buffer_size :public sys_var_key_cache_param
766
{
767
public:
768
  sys_var_key_buffer_size(sys_var_chain *chain, const char *name_arg)
769
    :sys_var_key_cache_param(chain, name_arg,
770
                             offsetof(KEY_CACHE, param_buff_size))
771
  {}
520.1.22 by Brian Aker
Second pass of thd cleanup
772
  bool update(Session *session, set_var *var);
1 by brian
clean slate
773
  SHOW_TYPE show_type() { return SHOW_LONGLONG; }
774
};
775
776
777
class sys_var_key_cache_long :public sys_var_key_cache_param
778
{
779
public:
780
  sys_var_key_cache_long(sys_var_chain *chain, const char *name_arg, size_t offset_arg)
781
    :sys_var_key_cache_param(chain, name_arg, offset_arg)
782
  {}
520.1.22 by Brian Aker
Second pass of thd cleanup
783
  bool update(Session *session, set_var *var);
1 by brian
clean slate
784
  SHOW_TYPE show_type() { return SHOW_LONG; }
785
};
786
787
520.1.22 by Brian Aker
Second pass of thd cleanup
788
class sys_var_session_date_time_format :public sys_var_session
1 by brian
clean slate
789
{
790
  DATE_TIME_FORMAT *SV::*offset;
398.1.1 by Monty Taylor
Remove typedef enum enum_drizzle_timestamp_type timestamp_type;
791
  enum enum_drizzle_timestamp_type date_time_type;
1 by brian
clean slate
792
public:
520.1.22 by Brian Aker
Second pass of thd cleanup
793
  sys_var_session_date_time_format(sys_var_chain *chain, const char *name_arg,
1 by brian
clean slate
794
			       DATE_TIME_FORMAT *SV::*offset_arg,
398.1.1 by Monty Taylor
Remove typedef enum enum_drizzle_timestamp_type timestamp_type;
795
			       enum enum_drizzle_timestamp_type date_time_type_arg)
520.1.22 by Brian Aker
Second pass of thd cleanup
796
    :sys_var_session(name_arg), offset(offset_arg),
1 by brian
clean slate
797
    date_time_type(date_time_type_arg)
798
  { chain_sys_var(chain); }
799
  SHOW_TYPE show_type() { return SHOW_CHAR; }
800
  bool check_update_type(Item_result type)
801
  {
802
    return type != STRING_RESULT;		/* Only accept strings */
803
  }
212.1.3 by Monty Taylor
Renamed __attribute__((__unused__)) to __attribute__((unused)).
804
  bool check_default(enum_var_type type __attribute__((unused)))
77.1.7 by Monty Taylor
Heap builds clean.
805
  { return 0; }
520.1.22 by Brian Aker
Second pass of thd cleanup
806
  bool check(Session *session, set_var *var);
807
  bool update(Session *session, set_var *var);
808
  void update2(Session *session, enum_var_type type, DATE_TIME_FORMAT *new_value);
809
  unsigned char *value_ptr(Session *session, enum_var_type type, LEX_STRING *base);
810
  void set_default(Session *session, enum_var_type type);
1 by brian
clean slate
811
};
812
813
814
class sys_var_log_state :public sys_var_bool_ptr
815
{
482 by Brian Aker
Remove uint.
816
  uint32_t log_type;
1 by brian
clean slate
817
public:
147 by Brian Aker
More my_bool conversion. This time the set_var class.
818
  sys_var_log_state(sys_var_chain *chain, const char *name_arg, bool *value_arg, 
482 by Brian Aker
Remove uint.
819
                    uint32_t log_type_arg)
1 by brian
clean slate
820
    :sys_var_bool_ptr(chain, name_arg, value_arg), log_type(log_type_arg) {}
520.1.22 by Brian Aker
Second pass of thd cleanup
821
  bool update(Session *session, set_var *var);
822
  void set_default(Session *session, enum_var_type type);
1 by brian
clean slate
823
};
824
825
/* Variable that you can only read from */
826
827
class sys_var_readonly: public sys_var
828
{
829
public:
830
  enum_var_type var_type;
831
  SHOW_TYPE show_type_value;
832
  sys_value_ptr_func value_ptr_func;
833
  sys_var_readonly(sys_var_chain *chain, const char *name_arg, enum_var_type type,
834
		   SHOW_TYPE show_type_arg,
835
		   sys_value_ptr_func value_ptr_func_arg)
836
    :sys_var(name_arg), var_type(type), 
837
       show_type_value(show_type_arg), value_ptr_func(value_ptr_func_arg)
838
  { chain_sys_var(chain); }
520.1.22 by Brian Aker
Second pass of thd cleanup
839
  bool update(Session *session __attribute__((unused)),
212.1.3 by Monty Taylor
Renamed __attribute__((__unused__)) to __attribute__((unused)).
840
              set_var *var __attribute__((unused)))
77.1.7 by Monty Taylor
Heap builds clean.
841
  { return 1; }
212.1.3 by Monty Taylor
Renamed __attribute__((__unused__)) to __attribute__((unused)).
842
  bool check_default(enum_var_type type __attribute__((unused)))
77.1.7 by Monty Taylor
Heap builds clean.
843
  { return 1; }
1 by brian
clean slate
844
  bool check_type(enum_var_type type) { return type != var_type; }
212.1.3 by Monty Taylor
Renamed __attribute__((__unused__)) to __attribute__((unused)).
845
  bool check_update_type(Item_result type __attribute__((unused)))
77.1.7 by Monty Taylor
Heap builds clean.
846
  { return 1; }
520.1.22 by Brian Aker
Second pass of thd cleanup
847
  unsigned char *value_ptr(Session *session, enum_var_type type __attribute__((unused)),
212.1.3 by Monty Taylor
Renamed __attribute__((__unused__)) to __attribute__((unused)).
848
                   LEX_STRING *base __attribute__((unused)))
1 by brian
clean slate
849
  {
520.1.22 by Brian Aker
Second pass of thd cleanup
850
    return (*value_ptr_func)(session);
1 by brian
clean slate
851
  }
77.1.7 by Monty Taylor
Heap builds clean.
852
  SHOW_TYPE show_type(void) { return show_type_value; }
853
  bool is_readonly(void) const { return 1; }
1 by brian
clean slate
854
};
855
856
857
class sys_var_have_option: public sys_var
858
{
859
protected:
860
  virtual SHOW_COMP_OPTION get_option() = 0;
861
public:
862
  sys_var_have_option(sys_var_chain *chain, const char *variable_name):
863
    sys_var(variable_name)
864
  { chain_sys_var(chain); }
520.1.22 by Brian Aker
Second pass of thd cleanup
865
  unsigned char *value_ptr(Session *session __attribute__((unused)),
212.1.3 by Monty Taylor
Renamed __attribute__((__unused__)) to __attribute__((unused)).
866
                   enum_var_type type __attribute__((unused)),
867
                   LEX_STRING *base __attribute__((unused)))
1 by brian
clean slate
868
  {
481 by Brian Aker
Remove all of uchar.
869
    return (unsigned char*) show_comp_option_name[get_option()];
1 by brian
clean slate
870
  }
520.1.22 by Brian Aker
Second pass of thd cleanup
871
  bool update(Session *session __attribute__((unused)),
212.1.3 by Monty Taylor
Renamed __attribute__((__unused__)) to __attribute__((unused)).
872
              set_var *var __attribute__((unused))) { return 1; }
873
  bool check_default(enum_var_type type __attribute__((unused)))
77.1.7 by Monty Taylor
Heap builds clean.
874
  { return 1; }
1 by brian
clean slate
875
  bool check_type(enum_var_type type) { return type != OPT_GLOBAL; }
212.1.3 by Monty Taylor
Renamed __attribute__((__unused__)) to __attribute__((unused)).
876
  bool check_update_type(Item_result type __attribute__((unused)))
77.1.7 by Monty Taylor
Heap builds clean.
877
  { return 1; }
1 by brian
clean slate
878
  SHOW_TYPE show_type() { return SHOW_CHAR; }
879
  bool is_readonly() const { return 1; }
880
};
881
882
883
class sys_var_have_variable: public sys_var_have_option
884
{
885
  SHOW_COMP_OPTION *have_variable;
886
887
public:
888
  sys_var_have_variable(sys_var_chain *chain, const char *variable_name,
889
                        SHOW_COMP_OPTION *have_variable_arg):
890
    sys_var_have_option(chain, variable_name),
891
    have_variable(have_variable_arg)
892
  { }
893
  SHOW_COMP_OPTION get_option() { return *have_variable; }
894
};
895
896
897
class sys_var_have_plugin: public sys_var_have_option
898
{
899
  const char *plugin_name_str;
482 by Brian Aker
Remove uint.
900
  const uint32_t plugin_name_len;
1 by brian
clean slate
901
  const int plugin_type;
902
903
public:
904
  sys_var_have_plugin(sys_var_chain *chain, const char *variable_name,
482 by Brian Aker
Remove uint.
905
                      const char *plugin_name_str_arg, uint32_t plugin_name_len_arg, 
1 by brian
clean slate
906
                      int plugin_type_arg):
907
    sys_var_have_option(chain, variable_name), 
908
    plugin_name_str(plugin_name_str_arg), plugin_name_len(plugin_name_len_arg),
909
    plugin_type(plugin_type_arg)
910
  { }
911
  /* the following method is declared in sql_plugin.cc */
912
  SHOW_COMP_OPTION get_option();
913
};
914
915
520.1.22 by Brian Aker
Second pass of thd cleanup
916
class sys_var_session_time_zone :public sys_var_session
1 by brian
clean slate
917
{
918
public:
520.1.22 by Brian Aker
Second pass of thd cleanup
919
  sys_var_session_time_zone(sys_var_chain *chain, const char *name_arg,
1 by brian
clean slate
920
                        Binlog_status_enum binlog_status_arg= NOT_IN_BINLOG)
520.1.22 by Brian Aker
Second pass of thd cleanup
921
    :sys_var_session(name_arg, NULL, binlog_status_arg)
1 by brian
clean slate
922
  {
923
    no_support_one_shot= 0;
924
    chain_sys_var(chain);
925
  }
520.1.22 by Brian Aker
Second pass of thd cleanup
926
  bool check(Session *session, set_var *var);
1 by brian
clean slate
927
  SHOW_TYPE show_type() { return SHOW_CHAR; }
928
  bool check_update_type(Item_result type)
929
  {
930
    return type != STRING_RESULT;		/* Only accept strings */
931
  }
212.1.3 by Monty Taylor
Renamed __attribute__((__unused__)) to __attribute__((unused)).
932
  bool check_default(enum_var_type type __attribute__((unused)))
77.1.7 by Monty Taylor
Heap builds clean.
933
  { return 0; }
520.1.22 by Brian Aker
Second pass of thd cleanup
934
  bool update(Session *session, set_var *var);
935
  unsigned char *value_ptr(Session *session, enum_var_type type, LEX_STRING *base);
936
  virtual void set_default(Session *session, enum_var_type type);
1 by brian
clean slate
937
};
938
939
520.1.22 by Brian Aker
Second pass of thd cleanup
940
class sys_var_microseconds :public sys_var_session
1 by brian
clean slate
941
{
151 by Brian Aker
Ulonglong to uint64_t
942
  uint64_t SV::*offset;
1 by brian
clean slate
943
public:
944
  sys_var_microseconds(sys_var_chain *chain, const char *name_arg,
151 by Brian Aker
Ulonglong to uint64_t
945
                       uint64_t SV::*offset_arg):
520.1.22 by Brian Aker
Second pass of thd cleanup
946
    sys_var_session(name_arg), offset(offset_arg)
1 by brian
clean slate
947
  { chain_sys_var(chain); }
520.1.22 by Brian Aker
Second pass of thd cleanup
948
  bool check(Session *session __attribute__((unused)),
212.1.3 by Monty Taylor
Renamed __attribute__((__unused__)) to __attribute__((unused)).
949
             set_var *var __attribute__((unused))) {return 0;}
520.1.22 by Brian Aker
Second pass of thd cleanup
950
  bool update(Session *session, set_var *var);
951
  void set_default(Session *session, enum_var_type type);
1 by brian
clean slate
952
  SHOW_TYPE show_type() { return SHOW_DOUBLE; }
953
  bool check_update_type(Item_result type)
954
  {
955
    return (type != INT_RESULT && type != REAL_RESULT && type != DECIMAL_RESULT);
956
  }
520.1.22 by Brian Aker
Second pass of thd cleanup
957
  unsigned char *value_ptr(Session *session, enum_var_type type, LEX_STRING *base);
1 by brian
clean slate
958
};
959
960
/**
961
  Handler for setting the system variable --read-only.
962
*/
963
964
class sys_var_opt_readonly :public sys_var_bool_ptr
965
{
966
public:
967
  sys_var_opt_readonly(sys_var_chain *chain, const char *name_arg, 
147 by Brian Aker
More my_bool conversion. This time the set_var class.
968
                       bool *value_arg) :
1 by brian
clean slate
969
    sys_var_bool_ptr(chain, name_arg, value_arg) {};
970
  ~sys_var_opt_readonly() {};
520.1.22 by Brian Aker
Second pass of thd cleanup
971
  bool update(Session *session, set_var *var);
1 by brian
clean slate
972
};
973
974
520.1.22 by Brian Aker
Second pass of thd cleanup
975
class sys_var_session_lc_time_names :public sys_var_session
1 by brian
clean slate
976
{
977
public:
520.1.22 by Brian Aker
Second pass of thd cleanup
978
  sys_var_session_lc_time_names(sys_var_chain *chain, const char *name_arg,
1 by brian
clean slate
979
                            Binlog_status_enum binlog_status_arg= NOT_IN_BINLOG)
520.1.22 by Brian Aker
Second pass of thd cleanup
980
    : sys_var_session(name_arg, NULL, binlog_status_arg)
1 by brian
clean slate
981
  {
982
    chain_sys_var(chain);
983
  }
520.1.22 by Brian Aker
Second pass of thd cleanup
984
  bool check(Session *session, set_var *var);
1 by brian
clean slate
985
  SHOW_TYPE show_type() { return SHOW_CHAR; }
986
  bool check_update_type(Item_result type)
987
  {
988
    return ((type != STRING_RESULT) && (type != INT_RESULT));
989
  }
212.1.3 by Monty Taylor
Renamed __attribute__((__unused__)) to __attribute__((unused)).
990
  bool check_default(enum_var_type type __attribute__((unused)))
77.1.7 by Monty Taylor
Heap builds clean.
991
  { return 0; }
520.1.22 by Brian Aker
Second pass of thd cleanup
992
  bool update(Session *session, set_var *var);
993
  unsigned char *value_ptr(Session *session, enum_var_type type, LEX_STRING *base);
994
  virtual void set_default(Session *session, enum_var_type type);
1 by brian
clean slate
995
};
996
997
998
/****************************************************************************
999
  Classes for parsing of the SET command
1000
****************************************************************************/
1001
1002
class set_var_base :public Sql_alloc
1003
{
1004
public:
1005
  set_var_base() {}
1006
  virtual ~set_var_base() {}
520.1.22 by Brian Aker
Second pass of thd cleanup
1007
  virtual int check(Session *session)=0;	/* To check privileges etc. */
1008
  virtual int update(Session *session)=0;	/* To set the value */
1 by brian
clean slate
1009
  /* light check for PS */
1010
  virtual bool no_support_one_shot() { return 1; }
1011
};
1012
1013
141 by Brian Aker
Code cleanup. Mainly dead stuff :)
1014
/* MySQL internal variables */
1 by brian
clean slate
1015
1016
class set_var :public set_var_base
1017
{
1018
public:
1019
  sys_var *var;
1020
  Item *value;
1021
  enum_var_type type;
1022
  union
1023
  {
264.2.6 by Andrey Hristov
Constify the usage of CHARSET_INFO almost to the last place in the code.
1024
    const CHARSET_INFO *charset;
520.4.14 by Monty Taylor
Removed korr.h and tztime.h from common_includes. Also removed the HAVE_DTRACE block and stuck it in autoconf.
1025
    uint32_t uint32_t_value;
151 by Brian Aker
Ulonglong to uint64_t
1026
    uint64_t uint64_t_value;
1 by brian
clean slate
1027
    plugin_ref plugin;
1028
    DATE_TIME_FORMAT *date_time_format;
1029
    Time_zone *time_zone;
1030
    MY_LOCALE *locale_value;
1031
  } save_result;
1032
  LEX_STRING base;			/* for structs */
1033
1034
  set_var(enum_var_type type_arg, sys_var *var_arg,
1035
          const LEX_STRING *base_name_arg, Item *value_arg)
1036
    :var(var_arg), type(type_arg), base(*base_name_arg)
1037
  {
1038
    /*
1039
      If the set value is a field, change it to a string to allow things like
1040
      SET table_type=MYISAM;
1041
    */
1042
    if (value_arg && value_arg->type() == Item::FIELD_ITEM)
1043
    {
1044
      Item_field *item= (Item_field*) value_arg;
1045
      if (!(value=new Item_string(item->field_name, 
1046
                  (uint) strlen(item->field_name),
1047
				  item->collation.collation)))
1048
	value=value_arg;			/* Give error message later */
1049
    }
1050
    else
1051
      value=value_arg;
1052
  }
520.1.22 by Brian Aker
Second pass of thd cleanup
1053
  int check(Session *session);
1054
  int update(Session *session);
1 by brian
clean slate
1055
  bool no_support_one_shot() { return var->no_support_one_shot; }
1056
};
1057
1058
1059
/* User variables like @my_own_variable */
1060
1061
class set_var_user: public set_var_base
1062
{
1063
  Item_func_set_user_var *user_var_item;
1064
public:
1065
  set_var_user(Item_func_set_user_var *item)
1066
    :user_var_item(item)
1067
  {}
520.1.22 by Brian Aker
Second pass of thd cleanup
1068
  int check(Session *session);
1069
  int update(Session *session);
1 by brian
clean slate
1070
};
1071
1072
/* For SET NAMES and SET CHARACTER SET */
1073
1074
class set_var_collation_client: public set_var_base
1075
{
264.2.6 by Andrey Hristov
Constify the usage of CHARSET_INFO almost to the last place in the code.
1076
  const CHARSET_INFO *character_set_client;
1077
  const CHARSET_INFO *character_set_results;
1078
  const CHARSET_INFO *collation_connection;
1 by brian
clean slate
1079
public:
264.2.6 by Andrey Hristov
Constify the usage of CHARSET_INFO almost to the last place in the code.
1080
  set_var_collation_client(const CHARSET_INFO * const client_coll_arg,
1081
  			   const CHARSET_INFO * const connection_coll_arg,
1082
  			   const CHARSET_INFO * const result_coll_arg)
1 by brian
clean slate
1083
    :character_set_client(client_coll_arg),
1084
     character_set_results(result_coll_arg),
1085
     collation_connection(connection_coll_arg)
1086
  {}
520.1.22 by Brian Aker
Second pass of thd cleanup
1087
  int check(Session *session);
1088
  int update(Session *session);
1 by brian
clean slate
1089
};
1090
1091
1092
extern "C"
1093
{
1094
  typedef int (*process_key_cache_t) (const char *, KEY_CACHE *);
1095
}
1096
1097
/* Named lists (used for keycaches) */
1098
1099
class NAMED_LIST :public ilink
1100
{
1101
  const char *name;
482 by Brian Aker
Remove uint.
1102
  uint32_t name_length;
1 by brian
clean slate
1103
public:
481 by Brian Aker
Remove all of uchar.
1104
  unsigned char* data;
1 by brian
clean slate
1105
1106
  NAMED_LIST(I_List<NAMED_LIST> *links, const char *name_arg,
482 by Brian Aker
Remove uint.
1107
	     uint32_t name_length_arg, unsigned char* data_arg)
1 by brian
clean slate
1108
    :name_length(name_length_arg), data(data_arg)
1109
  {
1110
    name= my_strndup(name_arg, name_length, MYF(MY_WME));
1111
    links->push_back(this);
1112
  }
482 by Brian Aker
Remove uint.
1113
  inline bool cmp(const char *name_cmp, uint32_t length)
1 by brian
clean slate
1114
  {
1115
    return length == name_length && !memcmp(name, name_cmp, length);
1116
  }
1117
  ~NAMED_LIST()
1118
  {
481 by Brian Aker
Remove all of uchar.
1119
    free((unsigned char*) name);
1 by brian
clean slate
1120
  }
1121
  friend bool process_key_caches(process_key_cache_t func);
1122
  friend void delete_elements(I_List<NAMED_LIST> *list,
481 by Brian Aker
Remove all of uchar.
1123
			      void (*free_element)(const char*, unsigned char*));
1 by brian
clean slate
1124
};
1125
1126
/* updated in sql_acl.cc */
1127
520.1.22 by Brian Aker
Second pass of thd cleanup
1128
extern sys_var_session_bool sys_old_alter_table;
1 by brian
clean slate
1129
extern LEX_STRING default_key_cache_base;
1130
1131
/* For sql_yacc */
1132
struct sys_var_with_base
1133
{
1134
  sys_var *var;
1135
  LEX_STRING base_name;
1136
};
1137
1138
/*
1139
  Prototypes for helper functions
1140
*/
1141
1142
int set_var_init();
1143
void set_var_free();
482 by Brian Aker
Remove uint.
1144
int mysql_append_static_vars(const SHOW_VAR *show_vars, uint32_t count);
520.1.22 by Brian Aker
Second pass of thd cleanup
1145
SHOW_VAR* enumerate_sys_vars(Session *session, bool sorted);
1 by brian
clean slate
1146
int mysql_add_sys_var_chain(sys_var *chain, struct my_option *long_options);
1147
int mysql_del_sys_var_chain(sys_var *chain);
520.1.22 by Brian Aker
Second pass of thd cleanup
1148
sys_var *find_sys_var(Session *session, const char *str, uint32_t length=0);
1149
int sql_set_variables(Session *session, List<set_var_base> *var_list);
1 by brian
clean slate
1150
bool not_all_support_one_shot(List<set_var_base> *var_list);
520.1.22 by Brian Aker
Second pass of thd cleanup
1151
void fix_delay_key_write(Session *session, enum_var_type type);
1 by brian
clean slate
1152
void fix_slave_exec_mode(enum_var_type type);
1153
extern sys_var_str sys_init_connect;
1154
extern sys_var_str sys_init_slave;
520.1.22 by Brian Aker
Second pass of thd cleanup
1155
extern sys_var_session_time_zone sys_time_zone;
1156
extern sys_var_session_bit sys_autocommit;
264.2.6 by Andrey Hristov
Constify the usage of CHARSET_INFO almost to the last place in the code.
1157
const CHARSET_INFO *get_old_charset_by_name(const char *old_name);
482 by Brian Aker
Remove uint.
1158
unsigned char* find_named(I_List<NAMED_LIST> *list, const char *name, uint32_t length,
1 by brian
clean slate
1159
		NAMED_LIST **found);
1160
1161
extern sys_var_str sys_var_general_log_path, sys_var_slow_log_path;
1162
1163
/* key_cache functions */
1164
KEY_CACHE *get_key_cache(LEX_STRING *cache_name);
482 by Brian Aker
Remove uint.
1165
KEY_CACHE *get_or_create_key_cache(const char *name, uint32_t length);
1 by brian
clean slate
1166
void free_key_cache(const char *name, KEY_CACHE *key_cache);
1167
bool process_key_caches(process_key_cache_t func);
1168
void delete_elements(I_List<NAMED_LIST> *list,
481 by Brian Aker
Remove all of uchar.
1169
		     void (*free_element)(const char*, unsigned char*));
575.1.6 by Monty Taylor
Cleaned up some headers for PCH.
1170
1171
#endif /* DRIZZLED_ITEM_SET_H */