~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/set_var.h

  • Committer: Brian Aker
  • Date: 2008-10-06 06:47:29 UTC
  • Revision ID: brian@tangent.org-20081006064729-2i9mhjkzyvow9xsm
RemoveĀ uint.

Show diffs side-by-side

added added

removed removed

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