~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to sql/set_var.h

MergedĀ fromĀ trunk.

Show diffs side-by-side

added added

removed removed

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