~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/set_var.h

Merge of Jay

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_ITEM_SET_H
 
21
#define DRIZZLED_ITEM_SET_H
 
22
 
 
23
#include <drizzled/function/func.h>
 
24
#include <drizzled/function/set_user_var.h>
 
25
#include <drizzled/item/string.h>
 
26
 
 
27
#include <string>
15
28
 
16
29
/* Classes to support the SET command */
17
30
 
18
 
#ifdef USE_PRAGMA_INTERFACE
19
 
#pragma interface                       /* gcc class implementation */
20
 
#endif
21
31
 
22
32
/****************************************************************************
23
33
  Variables that are changable runtime are declared using the
27
37
class sys_var;
28
38
class set_var;
29
39
class sys_var_pluginvar; /* opaque */
 
40
class Time_zone;
30
41
typedef struct system_variables SV;
31
42
typedef struct my_locale_st MY_LOCALE;
32
43
 
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);
 
44
extern TYPELIB bool_typelib;
 
45
extern TYPELIB optimizer_switch_typelib;
 
46
 
 
47
typedef int (*sys_check_func)(Session *,  set_var *);
 
48
typedef bool (*sys_update_func)(Session *, set_var *);
 
49
typedef void (*sys_after_update_func)(Session *,enum_var_type);
 
50
typedef void (*sys_set_default_func)(Session *, enum_var_type);
 
51
typedef unsigned char *(*sys_value_ptr_func)(Session *session);
 
52
 
 
53
static const std::vector<std::string> empty_aliases;
41
54
 
42
55
struct sys_var_chain
43
56
{
45
58
  sys_var *last;
46
59
};
47
60
 
 
61
/**
 
62
 * A class which represents a variable, either global or 
 
63
 * session-local.
 
64
 */
48
65
class sys_var
49
66
{
50
 
public:
51
 
 
52
 
  /**
53
 
    Enumeration type to indicate for a system variable whether it will be written to the binlog or not.
54
 
  */
55
 
  enum Binlog_status_enum
56
 
  {  
57
 
    /* The variable value is not in the binlog. */
58
 
    NOT_IN_BINLOG,
59
 
    /* The value of the @@session variable is in the binlog. */
60
 
    SESSION_VARIABLE_IN_BINLOG
61
 
    /*
62
 
      Currently, no @@global variable is ever in the binlog, so we
63
 
      don't need an enumeration value for that.
64
 
    */
65
 
  };
66
 
 
 
67
protected:
 
68
  const std::string name; /**< The name of the variable */
 
69
  sys_after_update_func after_update; /**< Function pointer triggered after the variable's value is updated */
 
70
  struct my_option *option_limits; /**< Updated by by set_var_init() */
 
71
  bool m_allow_empty_value; /**< Does variable allow an empty value? */
67
72
  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),
 
73
public:
 
74
  sys_var(const std::string name_arg, sys_after_update_func func= NULL)
 
75
    :
 
76
    name(name_arg),
 
77
    after_update(func),
78
78
    m_allow_empty_value(true)
79
79
  {}
80
80
  virtual ~sys_var() {}
86
86
      chain_arg->first= this;
87
87
    chain_arg->last= this;
88
88
  }
89
 
  virtual bool check(THD *thd, set_var *var);
90
 
  bool check_enum(THD *thd, set_var *var, const TYPELIB *enum_names);
91
 
  bool check_set(THD *thd, set_var *var, TYPELIB *enum_names);
92
 
  bool is_written_to_binlog(enum_var_type type)
93
 
  {
94
 
    return (type == OPT_SESSION || type == OPT_DEFAULT) &&
95
 
      (binlog_status == SESSION_VARIABLE_IN_BINLOG);
96
 
  }
97
 
  virtual bool update(THD *thd, set_var *var)=0;
98
 
  virtual void set_default(THD *thd_arg __attribute__((unused)),
99
 
                           enum_var_type type __attribute__((unused)))
 
89
 
 
90
  /** 
 
91
   * Returns the name of the variable.
 
92
   *
 
93
   * @note 
 
94
   *
 
95
   * So that we can exist in a Registry. We really need to formalize that 
 
96
   */
 
97
  inline const std::string &getName() const
 
98
  {
 
99
    return name;
 
100
  }
 
101
  /**
 
102
   * Returns a vector of strings representing aliases
 
103
   * for this variable's name.
 
104
   */
 
105
  const std::vector<std::string>& getAliases() const
 
106
  {
 
107
    return empty_aliases;
 
108
  }
 
109
  /**
 
110
   * Returns a pointer to the next sys_var, or NULL if none.
 
111
   */
 
112
  inline sys_var *getNext() const
 
113
  {
 
114
    return next;
 
115
  }
 
116
  /**
 
117
   * Sets the pointer to the next sys_var.
 
118
   *
 
119
   * @param Pointer to the next sys_var, or NULL if you set the tail...
 
120
   */
 
121
  inline void setNext(sys_var *in_next)
 
122
  {
 
123
    next= in_next;
 
124
  }
 
125
  /**
 
126
   * Returns a pointer to the variable's option limits
 
127
   */
 
128
  inline struct my_option *getOptionLimits() const
 
129
  {
 
130
    return option_limits;
 
131
  }
 
132
  /**
 
133
   * Sets the pointer to the variable's option limits
 
134
   *
 
135
   * @param Pointer to the option limits my_option variable
 
136
   */
 
137
  inline void setOptionLimits(struct my_option *in_option_limits)
 
138
  {
 
139
    option_limits= in_option_limits;
 
140
  }
 
141
  /** 
 
142
   * Returns the function pointer for after update trigger, or NULL if none.
 
143
   */
 
144
  inline sys_after_update_func getAfterUpdateTrigger() const
 
145
  {
 
146
    return after_update;
 
147
  }
 
148
  virtual bool check(Session *session, set_var *var);
 
149
  bool check_enum(Session *session, set_var *var, const TYPELIB *enum_names);
 
150
  bool check_set(Session *session, set_var *var, TYPELIB *enum_names);
 
151
  virtual bool update(Session *session, set_var *var)=0;
 
152
  virtual void set_default(Session *, enum_var_type)
100
153
  {}
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; }
 
154
  virtual SHOW_TYPE show_type()
 
155
  {
 
156
    return SHOW_UNDEF;
 
157
  }
 
158
  virtual unsigned char *value_ptr(Session *, enum_var_type, const LEX_STRING *)
 
159
  {
 
160
    return 0;
 
161
  }
106
162
  virtual bool check_type(enum_var_type type)
107
 
  { return type != OPT_GLOBAL; }                /* Error if not GLOBAL */
 
163
  {
 
164
    return type != OPT_GLOBAL;
 
165
  }             /* Error if not GLOBAL */
108
166
  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;
 
167
  {
 
168
    return type != INT_RESULT;
 
169
  }             /* Assume INT */
 
170
  virtual bool check_default(enum_var_type)
 
171
  {
 
172
    return option_limits == 0;
 
173
  }
 
174
  Item *item(Session *session, enum_var_type type, const LEX_STRING *base);
 
175
  virtual bool is_readonly() const
 
176
  {
 
177
    return 0;
 
178
  }
 
179
  virtual sys_var_pluginvar *cast_pluginvar()
 
180
  {
 
181
    return 0;
 
182
  }
127
183
};
128
184
 
129
 
 
130
 
/*
131
 
  A base class for all variables that require its access to
132
 
  be guarded with a mutex.
133
 
*/
134
 
 
 
185
/**
 
186
 * A base class for all variables that require its access to
 
187
 * be guarded with a mutex.
 
188
 */
135
189
class sys_var_global: public sys_var
136
190
{
137
191
protected:
138
192
  pthread_mutex_t *guard;
139
193
public:
140
 
  sys_var_global(const char *name_arg, sys_after_update_func after_update_arg,
 
194
  sys_var_global(const char *name_arg,
 
195
                 sys_after_update_func after_update_arg,
141
196
                 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);
 
197
    :
 
198
      sys_var(name_arg, after_update_arg), 
 
199
      guard(guard_arg) 
 
200
  {}
 
201
};
 
202
 
 
203
class sys_var_uint32_t_ptr :public sys_var
 
204
{
 
205
  uint32_t *value;
 
206
public:
 
207
  sys_var_uint32_t_ptr(sys_var_chain *chain, const char *name_arg,
 
208
                       uint32_t *value_ptr_arg)
 
209
    :sys_var(name_arg),value(value_ptr_arg)
 
210
  { chain_sys_var(chain); }
 
211
  sys_var_uint32_t_ptr(sys_var_chain *chain, const char *name_arg,
 
212
                       uint32_t *value_ptr_arg,
 
213
                       sys_after_update_func func)
 
214
    :sys_var(name_arg,func), value(value_ptr_arg)
 
215
  { chain_sys_var(chain); }
 
216
  bool check(Session *session, set_var *var);
 
217
  bool update(Session *session, set_var *var);
 
218
  void set_default(Session *session, enum_var_type type);
 
219
  SHOW_TYPE show_type() { return SHOW_INT; }
 
220
  unsigned char *value_ptr(Session *, enum_var_type, const LEX_STRING *)
 
221
  { return (unsigned char*) value; }
182
222
};
183
223
 
184
224
 
193
233
                       sys_after_update_func func)
194
234
    :sys_var(name_arg,func), value(value_ptr_arg)
195
235
  { chain_sys_var(chain); }
196
 
  bool update(THD *thd, set_var *var);
197
 
  void set_default(THD *thd, enum_var_type type);
 
236
  bool update(Session *session, set_var *var);
 
237
  void set_default(Session *session, enum_var_type type);
198
238
  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; }
 
239
  unsigned char *value_ptr(Session *, enum_var_type,
 
240
                           const LEX_STRING *)
 
241
  { return (unsigned char*) value; }
203
242
};
204
243
 
 
244
class sys_var_size_t_ptr :public sys_var
 
245
{
 
246
  size_t *value;
 
247
public:
 
248
  sys_var_size_t_ptr(sys_var_chain *chain, const char *name_arg, size_t *value_ptr_arg)
 
249
    :sys_var(name_arg),value(value_ptr_arg)
 
250
  { chain_sys_var(chain); }
 
251
  sys_var_size_t_ptr(sys_var_chain *chain, const char *name_arg, size_t *value_ptr_arg,
 
252
                     sys_after_update_func func)
 
253
    :sys_var(name_arg,func), value(value_ptr_arg)
 
254
  { chain_sys_var(chain); }
 
255
  bool update(Session *session, set_var *var);
 
256
  void set_default(Session *session, enum_var_type type);
 
257
  SHOW_TYPE show_type() { return SHOW_SIZE; }
 
258
  unsigned char *value_ptr(Session *, enum_var_type, const LEX_STRING *)
 
259
  { return (unsigned char*) value; }
 
260
};
205
261
 
206
262
class sys_var_bool_ptr :public sys_var
207
263
{
210
266
  sys_var_bool_ptr(sys_var_chain *chain, const char *name_arg, bool *value_arg)
211
267
    :sys_var(name_arg),value(value_arg)
212
268
  { chain_sys_var(chain); }
213
 
  bool check(THD *thd, set_var *var)
 
269
  bool check(Session *session, set_var *var)
214
270
  {
215
 
    return check_enum(thd, var, &bool_typelib);
 
271
    return check_enum(session, var, &bool_typelib);
216
272
  }
217
 
  bool update(THD *thd, set_var *var);
218
 
  void set_default(THD *thd, enum_var_type type);
 
273
  bool update(Session *session, set_var *var);
 
274
  void set_default(Session *session, enum_var_type type);
219
275
  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)))
 
276
  unsigned char *value_ptr(Session *, enum_var_type, const LEX_STRING *)
 
277
  { return (unsigned char*) value; }
 
278
  bool check_update_type(Item_result)
225
279
  { return 0; }
226
280
};
227
281
 
240
294
{
241
295
public:
242
296
  char *value;                                  // Pointer to allocated string
243
 
  uint value_length;
 
297
  uint32_t value_length;
244
298
  sys_check_func check_func;
245
299
  sys_update_func update_func;
246
300
  sys_set_default_func set_default_func;
252
306
    :sys_var(name_arg), value(value_arg), check_func(check_func_arg),
253
307
    update_func(update_func_arg),set_default_func(set_default_func_arg)
254
308
  { chain_sys_var(chain); }
255
 
  bool check(THD *thd, set_var *var);
256
 
  bool update(THD *thd, set_var *var)
 
309
  bool check(Session *session, set_var *var);
 
310
  bool update(Session *session, set_var *var)
257
311
  {
258
 
    return (*update_func)(thd, var);
 
312
    return (*update_func)(session, var);
259
313
  }
260
 
  void set_default(THD *thd, enum_var_type type)
 
314
  void set_default(Session *session, enum_var_type type)
261
315
  {
262
 
    (*set_default_func)(thd, type);
 
316
    (*set_default_func)(session, type);
263
317
  }
264
318
  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; }
 
319
  unsigned char *value_ptr(Session *, enum_var_type, const LEX_STRING *)
 
320
  { return (unsigned char*) value; }
269
321
  bool check_update_type(Item_result type)
270
322
  {
271
323
    return type != STRING_RESULT;               /* Only accept strings */
272
324
  }
273
 
  bool check_default(enum_var_type type __attribute__((unused)))
 
325
  bool check_default(enum_var_type)
274
326
  { return 0; }
275
327
};
276
328
 
287
339
  {
288
340
    value= new_value;
289
341
  }
290
 
  bool check(THD *thd __attribute__((unused)),
291
 
             set_var *var __attribute__((unused)))
 
342
  bool check(Session *, set_var *)
292
343
  {
293
344
    return 1;
294
345
  }
295
 
  bool update(THD *thd __attribute__((unused)),
296
 
              set_var *var __attribute__((unused)))
 
346
  bool update(Session *, set_var *)
297
347
  {
298
348
    return 1;
299
349
  }
300
350
  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)))
 
351
  unsigned char *value_ptr(Session *, enum_var_type, const LEX_STRING *)
304
352
  {
305
 
    return (uchar*) value;
 
353
    return (unsigned char*) value;
306
354
  }
307
 
  bool check_update_type(Item_result type __attribute__((unused)))
 
355
  bool check_update_type(Item_result)
308
356
  {
309
357
    return 1;
310
358
  }
311
 
  bool check_default(enum_var_type type __attribute__((unused)))
 
359
  bool check_default(enum_var_type)
312
360
  { return 1; }
313
361
  bool is_readonly() const { return 1; }
314
362
};
321
369
  sys_var_const_str_ptr(sys_var_chain *chain, const char *name_arg, char **value_arg)
322
370
    :sys_var(name_arg),value(value_arg)
323
371
  { chain_sys_var(chain); }
324
 
  bool check(THD *thd __attribute__((unused)),
325
 
             set_var *var __attribute__((unused)))
 
372
  bool check(Session *, set_var *)
326
373
  {
327
374
    return 1;
328
375
  }
329
 
  bool update(THD *thd __attribute__((unused)),
330
 
              set_var *var __attribute__((unused)))
 
376
  bool update(Session *, set_var *)
331
377
  {
332
378
    return 1;
333
379
  }
334
380
  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)))
 
381
  unsigned char *value_ptr(Session *, enum_var_type, const LEX_STRING *)
338
382
  {
339
 
    return (uchar*) *value;
 
383
    return (unsigned char*) *value;
340
384
  }
341
 
  bool check_update_type(Item_result type __attribute__((unused)))
 
385
  bool check_update_type(Item_result)
342
386
  {
343
387
    return 1;
344
388
  }
345
 
  bool check_default(enum_var_type type __attribute__((unused)))
 
389
  bool check_default(enum_var_type)
346
390
  { return 1; }
347
391
  bool is_readonly(void) const { return 1; }
348
392
};
350
394
 
351
395
class sys_var_enum :public sys_var
352
396
{
353
 
  uint *value;
 
397
  uint32_t *value;
354
398
  TYPELIB *enum_names;
355
399
public:
356
 
  sys_var_enum(sys_var_chain *chain, const char *name_arg, uint *value_arg,
 
400
  sys_var_enum(sys_var_chain *chain, const char *name_arg, uint32_t *value_arg,
357
401
               TYPELIB *typelib, sys_after_update_func func)
358
402
    :sys_var(name_arg,func), value(value_arg), enum_names(typelib)
359
403
  { chain_sys_var(chain); }
360
 
  bool check(THD *thd, set_var *var)
 
404
  bool check(Session *session, set_var *var)
361
405
  {
362
 
    return check_enum(thd, var, enum_names);
 
406
    return check_enum(session, var, enum_names);
363
407
  }
364
 
  bool update(THD *thd, set_var *var);
 
408
  bool update(Session *session, set_var *var);
365
409
  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)))
 
410
  unsigned char *value_ptr(Session *session, enum_var_type type,
 
411
                           const LEX_STRING *base);
 
412
  bool check_update_type(Item_result)
368
413
  { return 0; }
369
414
};
370
415
 
371
416
 
372
417
class sys_var_enum_const :public sys_var
373
418
{
374
 
  ulong SV::*offset;
 
419
  uint32_t SV::*offset;
375
420
  TYPELIB *enum_names;
376
421
public:
377
 
  sys_var_enum_const(sys_var_chain *chain, const char *name_arg, ulong SV::*offset_arg,
 
422
  sys_var_enum_const(sys_var_chain *chain, const char *name_arg, uint32_t SV::*offset_arg,
378
423
      TYPELIB *typelib, sys_after_update_func func)
379
424
    :sys_var(name_arg,func), offset(offset_arg), enum_names(typelib)
380
425
  { chain_sys_var(chain); }
381
 
  bool check(THD *thd __attribute__((unused)),
382
 
             set_var *var __attribute__((unused)))
 
426
  bool check(Session *, set_var *)
383
427
  { return 1; }
384
 
  bool update(THD *thd __attribute__((unused)),
385
 
              set_var *var __attribute__((unused)))
 
428
  bool update(Session *, set_var *)
386
429
  { return 1; }
387
430
  SHOW_TYPE show_type() { return SHOW_CHAR; }
388
 
  bool check_update_type(Item_result type __attribute__((unused)))
 
431
  bool check_update_type(Item_result)
389
432
  { return 1; }
390
433
  bool is_readonly() const { return 1; }
391
 
  uchar *value_ptr(THD *thd, enum_var_type type, LEX_STRING *base);
 
434
  unsigned char *value_ptr(Session *session, enum_var_type type,
 
435
                           const LEX_STRING *base);
392
436
};
393
437
 
394
438
 
395
 
class sys_var_thd :public sys_var
 
439
class sys_var_session :public sys_var
396
440
{
397
441
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)
 
442
  sys_var_session(const char *name_arg,
 
443
              sys_after_update_func func= NULL)
 
444
    :sys_var(name_arg, func)
402
445
  {}
403
 
  bool check_type(enum_var_type type __attribute__((unused)))
 
446
  bool check_type(enum_var_type)
404
447
  { return 0; }
405
448
  bool check_default(enum_var_type type)
406
449
  {
408
451
  }
409
452
};
410
453
 
411
 
 
412
 
class sys_var_thd_ulong :public sys_var_thd
 
454
class sys_var_session_uint32_t :public sys_var_session
413
455
{
414
456
  sys_check_func check_func;
415
457
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),
 
458
  uint32_t SV::*offset;
 
459
  sys_var_session_uint32_t(sys_var_chain *chain, const char *name_arg,
 
460
                           uint32_t SV::*offset_arg,
 
461
                           sys_check_func c_func= NULL,
 
462
                           sys_after_update_func au_func= NULL)
 
463
    :sys_var_session(name_arg, au_func), check_func(c_func),
423
464
    offset(offset_arg)
424
465
  { 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);
 
466
  bool check(Session *session, set_var *var);
 
467
  bool update(Session *session, set_var *var);
 
468
  void set_default(Session *session, enum_var_type type);
 
469
  SHOW_TYPE show_type() { return SHOW_INT; }
 
470
  unsigned char *value_ptr(Session *session, enum_var_type type,
 
471
                           const LEX_STRING *base);
430
472
};
431
473
 
432
474
 
433
 
class sys_var_thd_ha_rows :public sys_var_thd
 
475
class sys_var_session_ha_rows :public sys_var_session
434
476
{
435
477
public:
436
478
  ha_rows SV::*offset;
437
 
  sys_var_thd_ha_rows(sys_var_chain *chain, const char *name_arg, 
 
479
  sys_var_session_ha_rows(sys_var_chain *chain, const char *name_arg,
438
480
                      ha_rows SV::*offset_arg)
439
 
    :sys_var_thd(name_arg), offset(offset_arg)
 
481
    :sys_var_session(name_arg), offset(offset_arg)
440
482
  { chain_sys_var(chain); }
441
 
  sys_var_thd_ha_rows(sys_var_chain *chain, const char *name_arg, 
 
483
  sys_var_session_ha_rows(sys_var_chain *chain, const char *name_arg,
442
484
                      ha_rows SV::*offset_arg,
443
485
                      sys_after_update_func func)
444
 
    :sys_var_thd(name_arg,func), offset(offset_arg)
 
486
    :sys_var_session(name_arg,func), offset(offset_arg)
445
487
  { chain_sys_var(chain); }
446
 
  bool update(THD *thd, set_var *var);
447
 
  void set_default(THD *thd, enum_var_type type);
 
488
  bool update(Session *session, set_var *var);
 
489
  void set_default(Session *session, enum_var_type type);
448
490
  SHOW_TYPE show_type() { return SHOW_HA_ROWS; }
449
 
  uchar *value_ptr(THD *thd, enum_var_type type, LEX_STRING *base);
 
491
  unsigned char *value_ptr(Session *session, enum_var_type type,
 
492
                           const LEX_STRING *base);
450
493
};
451
494
 
452
495
 
453
 
class sys_var_thd_uint64_t :public sys_var_thd
 
496
class sys_var_session_uint64_t :public sys_var_session
454
497
{
 
498
  sys_check_func check_func;
455
499
public:
456
500
  uint64_t SV::*offset;
457
501
  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)
 
502
  sys_var_session_uint64_t(sys_var_chain *chain, 
 
503
                           const char *name_arg,
 
504
                           uint64_t SV::*offset_arg,
 
505
                           sys_after_update_func au_func= NULL,
 
506
                           sys_check_func c_func= NULL)
 
507
    :sys_var_session(name_arg, au_func),
 
508
    check_func(c_func),
 
509
    offset(offset_arg)
461
510
  { 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),
 
511
  sys_var_session_uint64_t(sys_var_chain *chain,
 
512
                           const char *name_arg,
 
513
                           uint64_t SV::*offset_arg,
 
514
                           sys_after_update_func func,
 
515
                           bool only_global_arg,
 
516
                           sys_check_func cfunc= NULL)
 
517
    :sys_var_session(name_arg, func),
 
518
    check_func(cfunc),
 
519
    offset(offset_arg),
466
520
    only_global(only_global_arg)
467
521
  { chain_sys_var(chain); }
468
 
  bool update(THD *thd, set_var *var);
469
 
  void set_default(THD *thd, enum_var_type type);
 
522
  bool update(Session *session, set_var *var);
 
523
  void set_default(Session *session, enum_var_type type);
470
524
  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
 
525
  unsigned char *value_ptr(Session *session, enum_var_type type,
 
526
                           const LEX_STRING *base);
 
527
  bool check(Session *session, set_var *var);
 
528
  bool check_default(enum_var_type type)
 
529
  {
 
530
    return type == OPT_GLOBAL && !option_limits;
 
531
  }
 
532
  bool check_type(enum_var_type type)
 
533
  {
 
534
    return (only_global && type != OPT_GLOBAL);
 
535
  }
 
536
};
 
537
 
 
538
class sys_var_session_size_t :public sys_var_session
 
539
{
 
540
  sys_check_func check_func;
 
541
public:
 
542
  size_t SV::*offset;
 
543
  bool only_global;
 
544
  sys_var_session_size_t(sys_var_chain *chain, const char *name_arg,
 
545
                         size_t SV::*offset_arg,
 
546
                         sys_after_update_func au_func= NULL,
 
547
                         sys_check_func c_func= NULL)
 
548
    :sys_var_session(name_arg, au_func),
 
549
     check_func(c_func),
 
550
     offset(offset_arg)
 
551
  { chain_sys_var(chain); }
 
552
  sys_var_session_size_t(sys_var_chain *chain,
 
553
                         const char *name_arg,
 
554
                         size_t SV::*offset_arg,
 
555
                         sys_after_update_func func,
 
556
                         bool only_global_arg,
 
557
                         sys_check_func cfunc= NULL)
 
558
    :sys_var_session(name_arg, func),
 
559
     check_func(cfunc),
 
560
     offset(offset_arg),
 
561
     only_global(only_global_arg)
 
562
  { chain_sys_var(chain); }
 
563
  bool update(Session *session, set_var *var);
 
564
  void set_default(Session *session, enum_var_type type);
 
565
  SHOW_TYPE show_type() { return SHOW_SIZE; }
 
566
  unsigned char *value_ptr(Session *session, enum_var_type type,
 
567
                           const LEX_STRING *base);
 
568
  bool check(Session *session, set_var *var);
 
569
  bool check_default(enum_var_type type)
 
570
  {
 
571
    return type == OPT_GLOBAL && !option_limits;
 
572
  }
 
573
  bool check_type(enum_var_type type)
 
574
  {
 
575
    return (only_global && type != OPT_GLOBAL);
 
576
  }
 
577
};
 
578
 
 
579
 
 
580
class sys_var_session_bool :public sys_var_session
485
581
{
486
582
public:
487
583
  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)
 
584
  sys_var_session_bool(sys_var_chain *chain, const char *name_arg, bool SV::*offset_arg)
 
585
    :sys_var_session(name_arg), offset(offset_arg)
490
586
  { chain_sys_var(chain); }
491
 
  sys_var_thd_bool(sys_var_chain *chain, const char *name_arg, bool SV::*offset_arg,
 
587
  sys_var_session_bool(sys_var_chain *chain, const char *name_arg, bool SV::*offset_arg,
492
588
                   sys_after_update_func func)
493
 
    :sys_var_thd(name_arg,func), offset(offset_arg)
 
589
    :sys_var_session(name_arg,func), offset(offset_arg)
494
590
  { chain_sys_var(chain); }
495
 
  bool update(THD *thd, set_var *var);
496
 
  void set_default(THD *thd, enum_var_type type);
 
591
  bool update(Session *session, set_var *var);
 
592
  void set_default(Session *session, enum_var_type type);
497
593
  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)
 
594
  unsigned char *value_ptr(Session *session, enum_var_type type,
 
595
                           const LEX_STRING *base);
 
596
  bool check(Session *session, set_var *var)
500
597
  {
501
 
    return check_enum(thd, var, &bool_typelib);
 
598
    return check_enum(session, var, &bool_typelib);
502
599
  }
503
 
  bool check_update_type(Item_result type __attribute__((unused)))
 
600
  bool check_update_type(Item_result)
504
601
  { return 0; }
505
602
};
506
603
 
507
604
 
508
 
class sys_var_thd_enum :public sys_var_thd
 
605
class sys_var_session_enum :public sys_var_session
509
606
{
510
607
protected:
511
 
  ulong SV::*offset;
 
608
  uint32_t SV::*offset;
512
609
  TYPELIB *enum_names;
513
610
  sys_check_func check_func;
514
611
public:
515
 
  sys_var_thd_enum(sys_var_chain *chain, const char *name_arg,
516
 
                   ulong SV::*offset_arg, TYPELIB *typelib,
 
612
  sys_var_session_enum(sys_var_chain *chain, const char *name_arg,
 
613
                   uint32_t SV::*offset_arg, TYPELIB *typelib,
517
614
                   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)
 
615
                   sys_check_func check_f= NULL)
 
616
    :sys_var_session(name_arg, func), offset(offset_arg),
 
617
    enum_names(typelib), check_func(check_f)
521
618
  { chain_sys_var(chain); }
522
 
  bool check(THD *thd, set_var *var)
 
619
  bool check(Session *session, set_var *var)
523
620
  {
524
621
    int ret= 0;
525
622
    if (check_func)
526
 
      ret= (*check_func)(thd, var);
527
 
    return ret ? ret : check_enum(thd, var, enum_names);
 
623
      ret= (*check_func)(session, var);
 
624
    return ret ? ret : check_enum(session, var, enum_names);
528
625
  }
529
 
  bool update(THD *thd, set_var *var);
530
 
  void set_default(THD *thd, enum_var_type type);
 
626
  bool update(Session *session, set_var *var);
 
627
  void set_default(Session *session, enum_var_type type);
531
628
  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)))
 
629
  unsigned char *value_ptr(Session *session, enum_var_type type,
 
630
                           const LEX_STRING *base);
 
631
  bool check_update_type(Item_result)
534
632
  { return 0; }
535
633
};
536
634
 
537
635
 
538
636
 
539
 
class sys_var_thd_optimizer_switch :public sys_var_thd_enum
 
637
class sys_var_session_optimizer_switch :public sys_var_session_enum
540
638
{
541
639
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)
 
640
  sys_var_session_optimizer_switch(sys_var_chain *chain, const char *name_arg,
 
641
                                   uint32_t SV::*offset_arg)
 
642
    :sys_var_session_enum(chain, name_arg, offset_arg, &optimizer_switch_typelib)
545
643
  {}
546
 
  bool check(THD *thd, set_var *var)
 
644
  bool check(Session *session, set_var *var)
547
645
  {
548
 
    return check_set(thd, var, enum_names);
 
646
    return check_set(session, var, enum_names);
549
647
  }
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,
 
648
  void set_default(Session *session, enum_var_type type);
 
649
  unsigned char *value_ptr(Session *session, enum_var_type type,
 
650
                           const LEX_STRING *base);
 
651
  static bool symbolic_mode_representation(Session *session, uint32_t sql_mode,
553
652
                                           LEX_STRING *rep);
554
653
};
555
654
 
556
655
 
557
 
class sys_var_thd_storage_engine :public sys_var_thd
 
656
class sys_var_session_storage_engine :public sys_var_session
558
657
{
559
658
protected:
560
 
  plugin_ref SV::*offset;
 
659
  StorageEngine *SV::*offset;
561
660
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)
 
661
  sys_var_session_storage_engine(sys_var_chain *chain, const char *name_arg,
 
662
                                 StorageEngine *SV::*offset_arg)
 
663
    :sys_var_session(name_arg), offset(offset_arg)
565
664
  { chain_sys_var(chain); }
566
 
  bool check(THD *thd, set_var *var);
 
665
  bool check(Session *session, set_var *var);
567
666
  SHOW_TYPE show_type() { return SHOW_CHAR; }
568
667
  bool check_update_type(Item_result type)
569
668
  {
570
669
    return type != STRING_RESULT;               /* Only accept strings */
571
670
  }
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);
 
671
  void set_default(Session *session, enum_var_type type);
 
672
  bool update(Session *session, set_var *var);
 
673
  unsigned char *value_ptr(Session *session, enum_var_type type,
 
674
                           const LEX_STRING *base);
575
675
};
576
676
 
577
 
class sys_var_thd_bit :public sys_var_thd
 
677
class sys_var_session_bit :public sys_var_session
578
678
{
579
679
  sys_check_func check_func;
580
680
  sys_update_func update_func;
581
681
public:
582
682
  uint64_t bit_flag;
583
683
  bool reverse;
584
 
  sys_var_thd_bit(sys_var_chain *chain, const char *name_arg,
 
684
  sys_var_session_bit(sys_var_chain *chain, const char *name_arg,
585
685
                  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),
 
686
                  uint64_t bit, bool reverse_arg=0)
 
687
    :sys_var_session(name_arg, NULL), check_func(c_func),
589
688
    update_func(u_func), bit_flag(bit), reverse(reverse_arg)
590
689
  { 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)))
 
690
  bool check(Session *session, set_var *var);
 
691
  bool update(Session *session, set_var *var);
 
692
  bool check_update_type(Item_result)
594
693
  { return 0; }
595
694
  bool check_type(enum_var_type type) { return type == OPT_GLOBAL; }
596
695
  SHOW_TYPE show_type() { return SHOW_MY_BOOL; }
597
 
  uchar *value_ptr(THD *thd, enum_var_type type, LEX_STRING *base);
 
696
  unsigned char *value_ptr(Session *session, enum_var_type type,
 
697
                           const LEX_STRING *base);
598
698
};
599
699
 
600
700
/* some variables that require special handling */
602
702
class sys_var_timestamp :public sys_var
603
703
{
604
704
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)
 
705
  sys_var_timestamp(sys_var_chain *chain, const char *name_arg)
 
706
    :sys_var(name_arg, NULL)
608
707
  { chain_sys_var(chain); }
609
 
  bool update(THD *thd, set_var *var);
610
 
  void set_default(THD *thd, enum_var_type type);
 
708
  bool update(Session *session, set_var *var);
 
709
  void set_default(Session *session, enum_var_type type);
611
710
  bool check_type(enum_var_type type)    { return type == OPT_GLOBAL; }
612
 
  bool check_default(enum_var_type type __attribute__((unused)))
 
711
  bool check_default(enum_var_type)
613
712
  { return 0; }
614
713
  SHOW_TYPE show_type(void) { return SHOW_LONG; }
615
 
  uchar *value_ptr(THD *thd, enum_var_type type, LEX_STRING *base);
 
714
  unsigned char *value_ptr(Session *session, enum_var_type type,
 
715
                           const LEX_STRING *base);
616
716
};
617
717
 
618
718
 
619
719
class sys_var_last_insert_id :public sys_var
620
720
{
621
721
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)
 
722
  sys_var_last_insert_id(sys_var_chain *chain, const char *name_arg)
 
723
    :sys_var(name_arg, NULL)
 
724
  { chain_sys_var(chain); }
 
725
  bool update(Session *session, set_var *var);
 
726
  bool check_type(enum_var_type type) { return type == OPT_GLOBAL; }
 
727
  SHOW_TYPE show_type() { return SHOW_LONGLONG; }
 
728
  unsigned char *value_ptr(Session *session, enum_var_type type,
 
729
                           const LEX_STRING *base);
 
730
};
 
731
 
 
732
 
 
733
class sys_var_collation :public sys_var_session
 
734
{
 
735
public:
 
736
  sys_var_collation(const char *name_arg)
 
737
    :sys_var_session(name_arg, NULL)
743
738
  { }
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);
 
739
  bool check(Session *session, set_var *var);
 
740
  SHOW_TYPE show_type() { return SHOW_CHAR; }
 
741
  bool check_update_type(Item_result type)
 
742
  {
 
743
    return ((type != STRING_RESULT) && (type != INT_RESULT));
 
744
  }
 
745
  bool check_default(enum_var_type) { return 0; }
 
746
  virtual void set_default(Session *session, enum_var_type type)= 0;
758
747
};
759
748
 
760
749
class sys_var_collation_sv :public sys_var_collation
763
752
  const CHARSET_INFO **global_default;
764
753
public:
765
754
  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),
 
755
                       const CHARSET_INFO *SV::*offset_arg,
 
756
                       const CHARSET_INFO **global_default_arg)
 
757
    :sys_var_collation(name_arg),
770
758
    offset(offset_arg), global_default(global_default_arg)
771
759
  {
772
760
    chain_sys_var(chain);
773
761
  }
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);
 
762
  bool update(Session *session, set_var *var);
 
763
  void set_default(Session *session, enum_var_type type);
 
764
  unsigned char *value_ptr(Session *session, enum_var_type type,
 
765
                           const LEX_STRING *base);
777
766
};
778
767
 
779
768
 
782
771
protected:
783
772
  size_t offset;
784
773
public:
785
 
  sys_var_key_cache_param(sys_var_chain *chain, const char *name_arg, 
 
774
  sys_var_key_cache_param(sys_var_chain *chain, const char *name_arg,
786
775
                          size_t offset_arg)
787
776
    :sys_var(name_arg), offset(offset_arg)
788
777
  { 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)))
 
778
  unsigned char *value_ptr(Session *session, enum_var_type type,
 
779
                           const LEX_STRING *base);
 
780
  bool check_default(enum_var_type)
791
781
  { return 1; }
792
 
  bool is_struct() { return 1; }
793
782
};
794
783
 
795
784
 
800
789
    :sys_var_key_cache_param(chain, name_arg,
801
790
                             offsetof(KEY_CACHE, param_buff_size))
802
791
  {}
803
 
  bool update(THD *thd, set_var *var);
 
792
  bool update(Session *session, set_var *var);
804
793
  SHOW_TYPE show_type() { return SHOW_LONGLONG; }
805
794
};
806
795
 
807
796
 
808
 
class sys_var_key_cache_long :public sys_var_key_cache_param
 
797
class sys_var_key_cache_uint32_t :public sys_var_key_cache_param
809
798
{
810
799
public:
811
 
  sys_var_key_cache_long(sys_var_chain *chain, const char *name_arg, size_t offset_arg)
 
800
  sys_var_key_cache_uint32_t(sys_var_chain *chain, const char *name_arg, size_t offset_arg)
812
801
    :sys_var_key_cache_param(chain, name_arg, offset_arg)
813
802
  {}
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
 
 
 
803
  bool update(Session *session, set_var *var);
 
804
  SHOW_TYPE show_type() { return SHOW_INT; }
 
805
};
919
806
 
920
807
/* Variable that you can only read from */
921
808
 
928
815
  sys_var_readonly(sys_var_chain *chain, const char *name_arg, enum_var_type type,
929
816
                   SHOW_TYPE show_type_arg,
930
817
                   sys_value_ptr_func value_ptr_func_arg)
931
 
    :sys_var(name_arg), var_type(type), 
 
818
    :sys_var(name_arg), var_type(type),
932
819
       show_type_value(show_type_arg), value_ptr_func(value_ptr_func_arg)
933
820
  { chain_sys_var(chain); }
934
 
  bool update(THD *thd __attribute__((unused)),
935
 
              set_var *var __attribute__((unused)))
 
821
  bool update(Session *, set_var *)
936
822
  { return 1; }
937
 
  bool check_default(enum_var_type type __attribute__((unused)))
 
823
  bool check_default(enum_var_type)
938
824
  { return 1; }
939
825
  bool check_type(enum_var_type type) { return type != var_type; }
940
 
  bool check_update_type(Item_result type __attribute__((unused)))
 
826
  bool check_update_type(Item_result)
941
827
  { return 1; }
942
 
  uchar *value_ptr(THD *thd, enum_var_type type __attribute__((unused)),
943
 
                   LEX_STRING *base __attribute__((unused)))
 
828
  unsigned char *value_ptr(Session *session, enum_var_type,
 
829
                           const LEX_STRING *)
944
830
  {
945
 
    return (*value_ptr_func)(thd);
 
831
    return (*value_ptr_func)(session);
946
832
  }
947
833
  SHOW_TYPE show_type(void) { return show_type_value; }
948
834
  bool is_readonly(void) const { return 1; }
957
843
  sys_var_have_option(sys_var_chain *chain, const char *variable_name):
958
844
    sys_var(variable_name)
959
845
  { 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)))
 
846
  unsigned char *value_ptr(Session *, enum_var_type,
 
847
                           const LEX_STRING *)
963
848
  {
964
 
    return (uchar*) show_comp_option_name[get_option()];
 
849
    return (unsigned char*) show_comp_option_name[get_option()];
965
850
  }
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)))
 
851
  bool update(Session *, set_var *) { return 1; }
 
852
  bool check_default(enum_var_type)
969
853
  { return 1; }
970
854
  bool check_type(enum_var_type type) { return type != OPT_GLOBAL; }
971
 
  bool check_update_type(Item_result type __attribute__((unused)))
 
855
  bool check_update_type(Item_result)
972
856
  { return 1; }
973
857
  SHOW_TYPE show_type() { return SHOW_CHAR; }
974
858
  bool is_readonly() const { return 1; }
992
876
class sys_var_have_plugin: public sys_var_have_option
993
877
{
994
878
  const char *plugin_name_str;
995
 
  const uint plugin_name_len;
 
879
  const uint32_t plugin_name_len;
996
880
  const int plugin_type;
997
881
 
998
882
public:
999
883
  sys_var_have_plugin(sys_var_chain *chain, const char *variable_name,
1000
 
                      const char *plugin_name_str_arg, uint plugin_name_len_arg, 
 
884
                      const char *plugin_name_str_arg, uint32_t plugin_name_len_arg,
1001
885
                      int plugin_type_arg):
1002
 
    sys_var_have_option(chain, variable_name), 
 
886
    sys_var_have_option(chain, variable_name),
1003
887
    plugin_name_str(plugin_name_str_arg), plugin_name_len(plugin_name_len_arg),
1004
888
    plugin_type(plugin_type_arg)
1005
889
  { }
1008
892
};
1009
893
 
1010
894
 
1011
 
class sys_var_thd_time_zone :public sys_var_thd
 
895
class sys_var_session_time_zone :public sys_var_session
1012
896
{
1013
897
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)
 
898
  sys_var_session_time_zone(sys_var_chain *chain, const char *name_arg)
 
899
    :sys_var_session(name_arg, NULL)
1017
900
  {
1018
 
    no_support_one_shot= 0;
1019
901
    chain_sys_var(chain);
1020
902
  }
1021
 
  bool check(THD *thd, set_var *var);
 
903
  bool check(Session *session, set_var *var);
1022
904
  SHOW_TYPE show_type() { return SHOW_CHAR; }
1023
905
  bool check_update_type(Item_result type)
1024
906
  {
1025
907
    return type != STRING_RESULT;               /* Only accept strings */
1026
908
  }
1027
 
  bool check_default(enum_var_type type __attribute__((unused)))
 
909
  bool check_default(enum_var_type)
1028
910
  { 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
 
911
  bool update(Session *session, set_var *var);
 
912
  unsigned char *value_ptr(Session *session, enum_var_type type,
 
913
                           const LEX_STRING *base);
 
914
  virtual void set_default(Session *session, enum_var_type type);
 
915
};
 
916
 
 
917
 
 
918
class sys_var_microseconds :public sys_var_session
1054
919
{
1055
920
  uint64_t SV::*offset;
1056
921
public:
1057
922
  sys_var_microseconds(sys_var_chain *chain, const char *name_arg,
1058
923
                       uint64_t SV::*offset_arg):
1059
 
    sys_var_thd(name_arg), offset(offset_arg)
 
924
    sys_var_session(name_arg), offset(offset_arg)
1060
925
  { 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);
 
926
  bool check(Session *, set_var *) {return 0;}
 
927
  bool update(Session *session, set_var *var);
 
928
  void set_default(Session *session, enum_var_type type);
1065
929
  SHOW_TYPE show_type() { return SHOW_DOUBLE; }
1066
930
  bool check_update_type(Item_result type)
1067
931
  {
1068
932
    return (type != INT_RESULT && type != REAL_RESULT && type != DECIMAL_RESULT);
1069
933
  }
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)
 
934
};
 
935
 
 
936
class sys_var_session_lc_time_names :public sys_var_session
 
937
{
 
938
public:
 
939
  sys_var_session_lc_time_names(sys_var_chain *chain, const char *name_arg)
 
940
    : sys_var_session(name_arg, NULL)
1094
941
  {
1095
 
#if DRIZZLE_VERSION_ID < 50000
1096
 
    no_support_one_shot= 0;
1097
 
#endif
1098
942
    chain_sys_var(chain);
1099
943
  }
1100
 
  bool check(THD *thd, set_var *var);
 
944
  bool check(Session *session, set_var *var);
1101
945
  SHOW_TYPE show_type() { return SHOW_CHAR; }
1102
946
  bool check_update_type(Item_result type)
1103
947
  {
1104
948
    return ((type != STRING_RESULT) && (type != INT_RESULT));
1105
949
  }
1106
 
  bool check_default(enum_var_type type __attribute__((unused)))
 
950
  bool check_default(enum_var_type)
1107
951
  { 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
 
};
 
952
  bool update(Session *session, set_var *var);
 
953
  unsigned char *value_ptr(Session *session, enum_var_type type,
 
954
                           const LEX_STRING *base);
 
955
  virtual void set_default(Session *session, enum_var_type type);
 
956
};
 
957
 
1127
958
 
1128
959
/****************************************************************************
1129
960
  Classes for parsing of the SET command
1134
965
public:
1135
966
  set_var_base() {}
1136
967
  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 */
 
968
  virtual int check(Session *session)=0;        /* To check privileges etc. */
 
969
  virtual int update(Session *session)=0;       /* To set the value */
1139
970
  /* light check for PS */
1140
 
  virtual bool no_support_one_shot() { return 1; }
1141
971
};
1142
972
 
1143
 
 
1144
973
/* MySQL internal variables */
1145
 
 
1146
974
class set_var :public set_var_base
1147
975
{
1148
976
public:
1152
980
  union
1153
981
  {
1154
982
    const CHARSET_INFO *charset;
1155
 
    ulong ulong_value;
 
983
    uint32_t uint32_t_value;
1156
984
    uint64_t uint64_t_value;
1157
 
    plugin_ref plugin;
1158
 
    DATE_TIME_FORMAT *date_time_format;
 
985
    size_t size_t_value;
 
986
    StorageEngine *storage_engine;
1159
987
    Time_zone *time_zone;
1160
988
    MY_LOCALE *locale_value;
1161
989
  } save_result;
1172
1000
    if (value_arg && value_arg->type() == Item::FIELD_ITEM)
1173
1001
    {
1174
1002
      Item_field *item= (Item_field*) value_arg;
1175
 
      if (!(value=new Item_string(item->field_name, 
1176
 
                  (uint) strlen(item->field_name),
 
1003
      if (!(value=new Item_string(item->field_name,
 
1004
                  (uint32_t) strlen(item->field_name),
1177
1005
                                  item->collation.collation)))
1178
1006
        value=value_arg;                        /* Give error message later */
1179
1007
    }
1180
1008
    else
1181
1009
      value=value_arg;
1182
1010
  }
1183
 
  int check(THD *thd);
1184
 
  int update(THD *thd);
1185
 
  bool no_support_one_shot() { return var->no_support_one_shot; }
 
1011
  int check(Session *session);
 
1012
  int update(Session *session);
1186
1013
};
1187
1014
 
1188
1015
 
1195
1022
  set_var_user(Item_func_set_user_var *item)
1196
1023
    :user_var_item(item)
1197
1024
  {}
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;
 
1025
  int check(Session *session);
 
1026
  int update(Session *session);
 
1027
};
 
1028
 
1260
1029
 
1261
1030
/* For sql_yacc */
1262
1031
struct sys_var_with_base
1271
1040
 
1272
1041
int set_var_init();
1273
1042
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);
 
1043
int mysql_append_static_vars(const SHOW_VAR *show_vars, uint32_t count);
 
1044
SHOW_VAR* enumerate_sys_vars(Session *session, bool sorted);
 
1045
void drizzle_add_plugin_sysvar(sys_var_pluginvar *var);
 
1046
void drizzle_del_plugin_sysvar();
1276
1047
int mysql_add_sys_var_chain(sys_var *chain, struct my_option *long_options);
1277
1048
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);
 
1049
sys_var *find_sys_var(Session *session, const char *str, uint32_t length=0);
 
1050
int sql_set_variables(Session *session, List<set_var_base> *var_list);
1280
1051
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;
 
1052
extern sys_var_session_time_zone sys_time_zone;
 
1053
extern sys_var_session_bit sys_autocommit;
1288
1054
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
1055
 
1292
1056
extern sys_var_str sys_var_general_log_path, sys_var_slow_log_path;
1293
1057
 
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*));
 
1058
#endif /* DRIZZLED_ITEM_SET_H */