~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/set_var.h

  • Committer: Brian Aker
  • Date: 2010-05-27 01:25:56 UTC
  • mfrom: (1567.1.4 new-staging)
  • Revision ID: brian@gaz-20100527012556-5zgkirkl7swbigd6
Merge of Brian, Paul. PBXT compile issue, and test framework cleanup. 

Show diffs side-by-side

added added

removed removed

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