~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/set_var.h

  • Committer: Stewart Smith
  • Date: 2008-11-21 16:06:07 UTC
  • mto: This revision was merged to the branch mainline in revision 593.
  • Revision ID: stewart@flamingspork.com-20081121160607-n6gdlt013spuo54r
remove mysql_frm_type
and fix engines to return correct value from delete_table when table doesn't exist.
(it should be ENOENT).

Also fix up some tests that manipulated frm files by hand. These tests are no longer valid and will need to be rewritten in the not too distant future.

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