~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/set_var.h

  • Committer: Monty Taylor
  • Date: 2009-03-24 17:44:41 UTC
  • mto: (960.5.2 mordred)
  • mto: This revision was merged to the branch mainline in revision 964.
  • Revision ID: mordred@inaugust.com-20090324174441-nmsq0gwjlgf7f0mt
Changed handlerton to StorageEngine.

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_ITEM_SET_H
 
21
#define DRIZZLED_ITEM_SET_H
 
22
 
 
23
#include <drizzled/function/func.h>
 
24
#include <drizzled/function/set_user_var.h>
 
25
#include <drizzled/item/string.h>
 
26
 
 
27
#include <string>
 
28
 
20
29
/* Classes to support the SET command */
21
30
 
22
 
#ifdef USE_PRAGMA_INTERFACE
23
 
#pragma interface                       /* gcc class implementation */
24
 
#endif
25
31
 
26
32
/****************************************************************************
27
33
  Variables that are changable runtime are declared using the
31
37
class sys_var;
32
38
class set_var;
33
39
class sys_var_pluginvar; /* opaque */
 
40
class Time_zone;
34
41
typedef struct system_variables SV;
35
42
typedef struct my_locale_st MY_LOCALE;
36
43
 
37
44
extern TYPELIB bool_typelib, delay_key_write_typelib, sql_mode_typelib,
38
 
  optimizer_switch_typelib, slave_exec_mode_typelib;
 
45
       optimizer_switch_typelib, slave_exec_mode_typelib;
39
46
 
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);
 
47
typedef int (*sys_check_func)(Session *,  set_var *);
 
48
typedef bool (*sys_update_func)(Session *, set_var *);
 
49
typedef void (*sys_after_update_func)(Session *,enum_var_type);
 
50
typedef void (*sys_set_default_func)(Session *, enum_var_type);
 
51
typedef unsigned char *(*sys_value_ptr_func)(Session *session);
45
52
 
46
53
struct sys_var_chain
47
54
{
57
64
    Enumeration type to indicate for a system variable whether it will be written to the binlog or not.
58
65
  */
59
66
  enum Binlog_status_enum
60
 
  {  
 
67
  {
61
68
    /* The variable value is not in the binlog. */
62
69
    NOT_IN_BINLOG,
63
70
    /* The value of the @@session variable is in the binlog. */
74
81
  const char *name;
75
82
 
76
83
  sys_after_update_func after_update;
77
 
  bool no_support_one_shot;
78
84
  sys_var(const char *name_arg, sys_after_update_func func= NULL,
79
85
          Binlog_status_enum binlog_status_arg= NOT_IN_BINLOG)
80
 
    :name(name_arg), after_update(func), no_support_one_shot(1),
 
86
    :name(name_arg), after_update(func),
81
87
    binlog_status(binlog_status_arg),
82
88
    m_allow_empty_value(true)
83
89
  {}
90
96
      chain_arg->first= this;
91
97
    chain_arg->last= this;
92
98
  }
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)))
 
99
  virtual bool check(Session *session, set_var *var);
 
100
  bool check_enum(Session *session, set_var *var, const TYPELIB *enum_names);
 
101
  bool check_set(Session *session, set_var *var, TYPELIB *enum_names);
 
102
  virtual bool update(Session *session, set_var *var)=0;
 
103
  virtual void set_default(Session *, enum_var_type)
104
104
  {}
105
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)))
 
106
  virtual unsigned char *value_ptr(Session *, enum_var_type, const LEX_STRING *)
109
107
  { return 0; }
110
108
  virtual bool check_type(enum_var_type type)
111
109
  { return type != OPT_GLOBAL; }                /* Error if not GLOBAL */
112
110
  virtual bool check_update_type(Item_result type)
113
111
  { return type != INT_RESULT; }                /* Assume INT */
114
 
  virtual bool check_default(enum_var_type type __attribute__((unused)))
 
112
  virtual bool check_default(enum_var_type)
115
113
  { return option_limits == 0; }
116
 
  Item *item(THD *thd, enum_var_type type, LEX_STRING *base);
 
114
  Item *item(Session *session, enum_var_type type, const LEX_STRING *base);
117
115
  virtual bool is_struct() { return 0; }
118
116
  virtual bool is_readonly() const { return 0; }
119
117
  virtual sys_var_pluginvar *cast_pluginvar() { return 0; }
147
145
};
148
146
 
149
147
 
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
 
148
class sys_var_uint32_t_ptr :public sys_var
156
149
{
157
 
  ulong *value;
 
150
  uint32_t *value;
158
151
public:
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)))
 
152
  sys_var_uint32_t_ptr(sys_var_chain *chain, const char *name_arg,
 
153
                       uint32_t *value_ptr_arg)
 
154
    :sys_var(name_arg),value(value_ptr_arg)
 
155
  { chain_sys_var(chain); }
 
156
  sys_var_uint32_t_ptr(sys_var_chain *chain, const char *name_arg,
 
157
                       uint32_t *value_ptr_arg,
 
158
                       sys_after_update_func func)
 
159
    :sys_var(name_arg,func), value(value_ptr_arg)
 
160
  { chain_sys_var(chain); }
 
161
  bool check(Session *session, set_var *var);
 
162
  bool update(Session *session, set_var *var);
 
163
  void set_default(Session *session, enum_var_type type);
 
164
  SHOW_TYPE show_type() { return SHOW_INT; }
 
165
  unsigned char *value_ptr(Session *, enum_var_type, const LEX_STRING *)
173
166
  { return (unsigned char*) value; }
174
167
};
175
168
 
176
169
 
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
 
 
189
170
class sys_var_uint64_t_ptr :public sys_var
190
171
{
191
172
  uint64_t *value;
197
178
                       sys_after_update_func func)
198
179
    :sys_var(name_arg,func), value(value_ptr_arg)
199
180
  { chain_sys_var(chain); }
200
 
  bool update(THD *thd, set_var *var);
201
 
  void set_default(THD *thd, enum_var_type type);
 
181
  bool update(Session *session, set_var *var);
 
182
  void set_default(Session *session, enum_var_type type);
202
183
  SHOW_TYPE show_type() { return SHOW_LONGLONG; }
203
 
  unsigned char *value_ptr(THD *thd __attribute__((unused)),
204
 
                   enum_var_type type __attribute__((unused)),
205
 
                   LEX_STRING *base __attribute__((unused)))
 
184
  unsigned char *value_ptr(Session *, enum_var_type,
 
185
                           const LEX_STRING *)
206
186
  { return (unsigned char*) value; }
207
187
};
208
188
 
 
189
class sys_var_size_t_ptr :public sys_var
 
190
{
 
191
  size_t *value;
 
192
public:
 
193
  sys_var_size_t_ptr(sys_var_chain *chain, const char *name_arg, size_t *value_ptr_arg)
 
194
    :sys_var(name_arg),value(value_ptr_arg)
 
195
  { chain_sys_var(chain); }
 
196
  sys_var_size_t_ptr(sys_var_chain *chain, const char *name_arg, size_t *value_ptr_arg,
 
197
                     sys_after_update_func func)
 
198
    :sys_var(name_arg,func), value(value_ptr_arg)
 
199
  { chain_sys_var(chain); }
 
200
  bool update(Session *session, set_var *var);
 
201
  void set_default(Session *session, enum_var_type type);
 
202
  SHOW_TYPE show_type() { return SHOW_SIZE; }
 
203
  unsigned char *value_ptr(Session *, enum_var_type, const LEX_STRING *)
 
204
  { return (unsigned char*) value; }
 
205
};
209
206
 
210
207
class sys_var_bool_ptr :public sys_var
211
208
{
214
211
  sys_var_bool_ptr(sys_var_chain *chain, const char *name_arg, bool *value_arg)
215
212
    :sys_var(name_arg),value(value_arg)
216
213
  { chain_sys_var(chain); }
217
 
  bool check(THD *thd, set_var *var)
 
214
  bool check(Session *session, set_var *var)
218
215
  {
219
 
    return check_enum(thd, var, &bool_typelib);
 
216
    return check_enum(session, var, &bool_typelib);
220
217
  }
221
 
  bool update(THD *thd, set_var *var);
222
 
  void set_default(THD *thd, enum_var_type type);
 
218
  bool update(Session *session, set_var *var);
 
219
  void set_default(Session *session, enum_var_type type);
223
220
  SHOW_TYPE show_type() { return SHOW_MY_BOOL; }
224
 
  unsigned char *value_ptr(THD *thd __attribute__((unused)),
225
 
                   enum_var_type type __attribute__((unused)),
226
 
                   LEX_STRING *base __attribute__((unused)))
 
221
  unsigned char *value_ptr(Session *, enum_var_type, const LEX_STRING *)
227
222
  { return (unsigned char*) value; }
228
 
  bool check_update_type(Item_result type __attribute__((unused)))
 
223
  bool check_update_type(Item_result)
229
224
  { return 0; }
230
225
};
231
226
 
256
251
    :sys_var(name_arg), value(value_arg), check_func(check_func_arg),
257
252
    update_func(update_func_arg),set_default_func(set_default_func_arg)
258
253
  { chain_sys_var(chain); }
259
 
  bool check(THD *thd, set_var *var);
260
 
  bool update(THD *thd, set_var *var)
 
254
  bool check(Session *session, set_var *var);
 
255
  bool update(Session *session, set_var *var)
261
256
  {
262
 
    return (*update_func)(thd, var);
 
257
    return (*update_func)(session, var);
263
258
  }
264
 
  void set_default(THD *thd, enum_var_type type)
 
259
  void set_default(Session *session, enum_var_type type)
265
260
  {
266
 
    (*set_default_func)(thd, type);
 
261
    (*set_default_func)(session, type);
267
262
  }
268
263
  SHOW_TYPE show_type() { return SHOW_CHAR; }
269
 
  unsigned char *value_ptr(THD *thd __attribute__((unused)),
270
 
                   enum_var_type type __attribute__((unused)),
271
 
                   LEX_STRING *base __attribute__((unused)))
 
264
  unsigned char *value_ptr(Session *, enum_var_type, const LEX_STRING *)
272
265
  { return (unsigned char*) value; }
273
266
  bool check_update_type(Item_result type)
274
267
  {
275
268
    return type != STRING_RESULT;               /* Only accept strings */
276
269
  }
277
 
  bool check_default(enum_var_type type __attribute__((unused)))
 
270
  bool check_default(enum_var_type)
278
271
  { return 0; }
279
272
};
280
273
 
291
284
  {
292
285
    value= new_value;
293
286
  }
294
 
  bool check(THD *thd __attribute__((unused)),
295
 
             set_var *var __attribute__((unused)))
 
287
  bool check(Session *, set_var *)
296
288
  {
297
289
    return 1;
298
290
  }
299
 
  bool update(THD *thd __attribute__((unused)),
300
 
              set_var *var __attribute__((unused)))
 
291
  bool update(Session *, set_var *)
301
292
  {
302
293
    return 1;
303
294
  }
304
295
  SHOW_TYPE show_type() { return SHOW_CHAR; }
305
 
  unsigned char *value_ptr(THD *thd __attribute__((unused)),
306
 
                   enum_var_type type __attribute__((unused)),
307
 
                   LEX_STRING *base __attribute__((unused)))
 
296
  unsigned char *value_ptr(Session *, enum_var_type, const LEX_STRING *)
308
297
  {
309
298
    return (unsigned char*) value;
310
299
  }
311
 
  bool check_update_type(Item_result type __attribute__((unused)))
 
300
  bool check_update_type(Item_result)
312
301
  {
313
302
    return 1;
314
303
  }
315
 
  bool check_default(enum_var_type type __attribute__((unused)))
 
304
  bool check_default(enum_var_type)
316
305
  { return 1; }
317
306
  bool is_readonly() const { return 1; }
318
307
};
325
314
  sys_var_const_str_ptr(sys_var_chain *chain, const char *name_arg, char **value_arg)
326
315
    :sys_var(name_arg),value(value_arg)
327
316
  { chain_sys_var(chain); }
328
 
  bool check(THD *thd __attribute__((unused)),
329
 
             set_var *var __attribute__((unused)))
 
317
  bool check(Session *, set_var *)
330
318
  {
331
319
    return 1;
332
320
  }
333
 
  bool update(THD *thd __attribute__((unused)),
334
 
              set_var *var __attribute__((unused)))
 
321
  bool update(Session *, set_var *)
335
322
  {
336
323
    return 1;
337
324
  }
338
325
  SHOW_TYPE show_type() { return SHOW_CHAR; }
339
 
  unsigned char *value_ptr(THD *thd __attribute__((unused)),
340
 
                   enum_var_type type __attribute__((unused)),
341
 
                   LEX_STRING *base __attribute__((unused)))
 
326
  unsigned char *value_ptr(Session *, enum_var_type, const LEX_STRING *)
342
327
  {
343
328
    return (unsigned char*) *value;
344
329
  }
345
 
  bool check_update_type(Item_result type __attribute__((unused)))
 
330
  bool check_update_type(Item_result)
346
331
  {
347
332
    return 1;
348
333
  }
349
 
  bool check_default(enum_var_type type __attribute__((unused)))
 
334
  bool check_default(enum_var_type)
350
335
  { return 1; }
351
336
  bool is_readonly(void) const { return 1; }
352
337
};
361
346
               TYPELIB *typelib, sys_after_update_func func)
362
347
    :sys_var(name_arg,func), value(value_arg), enum_names(typelib)
363
348
  { chain_sys_var(chain); }
364
 
  bool check(THD *thd, set_var *var)
 
349
  bool check(Session *session, set_var *var)
365
350
  {
366
 
    return check_enum(thd, var, enum_names);
 
351
    return check_enum(session, var, enum_names);
367
352
  }
368
 
  bool update(THD *thd, set_var *var);
 
353
  bool update(Session *session, set_var *var);
369
354
  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)))
 
355
  unsigned char *value_ptr(Session *session, enum_var_type type,
 
356
                           const LEX_STRING *base);
 
357
  bool check_update_type(Item_result)
372
358
  { return 0; }
373
359
};
374
360
 
375
361
 
376
362
class sys_var_enum_const :public sys_var
377
363
{
378
 
  ulong SV::*offset;
 
364
  uint32_t SV::*offset;
379
365
  TYPELIB *enum_names;
380
366
public:
381
 
  sys_var_enum_const(sys_var_chain *chain, const char *name_arg, ulong SV::*offset_arg,
 
367
  sys_var_enum_const(sys_var_chain *chain, const char *name_arg, uint32_t SV::*offset_arg,
382
368
      TYPELIB *typelib, sys_after_update_func func)
383
369
    :sys_var(name_arg,func), offset(offset_arg), enum_names(typelib)
384
370
  { chain_sys_var(chain); }
385
 
  bool check(THD *thd __attribute__((unused)),
386
 
             set_var *var __attribute__((unused)))
 
371
  bool check(Session *, set_var *)
387
372
  { return 1; }
388
 
  bool update(THD *thd __attribute__((unused)),
389
 
              set_var *var __attribute__((unused)))
 
373
  bool update(Session *, set_var *)
390
374
  { return 1; }
391
375
  SHOW_TYPE show_type() { return SHOW_CHAR; }
392
 
  bool check_update_type(Item_result type __attribute__((unused)))
 
376
  bool check_update_type(Item_result)
393
377
  { return 1; }
394
378
  bool is_readonly() const { return 1; }
395
 
  unsigned char *value_ptr(THD *thd, enum_var_type type, LEX_STRING *base);
 
379
  unsigned char *value_ptr(Session *session, enum_var_type type,
 
380
                           const LEX_STRING *base);
396
381
};
397
382
 
398
383
 
399
 
class sys_var_thd :public sys_var
 
384
class sys_var_session :public sys_var
400
385
{
401
386
public:
402
 
  sys_var_thd(const char *name_arg, 
 
387
  sys_var_session(const char *name_arg,
403
388
              sys_after_update_func func= NULL,
404
 
              Binlog_status_enum binlog_status= NOT_IN_BINLOG)
405
 
    :sys_var(name_arg, func, binlog_status)
 
389
              Binlog_status_enum bl_status= NOT_IN_BINLOG)
 
390
    :sys_var(name_arg, func, bl_status)
406
391
  {}
407
 
  bool check_type(enum_var_type type __attribute__((unused)))
 
392
  bool check_type(enum_var_type)
408
393
  { return 0; }
409
394
  bool check_default(enum_var_type type)
410
395
  {
412
397
  }
413
398
};
414
399
 
415
 
 
416
 
class sys_var_thd_ulong :public sys_var_thd
 
400
class sys_var_session_uint32_t :public sys_var_session
417
401
{
418
402
  sys_check_func check_func;
419
403
public:
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),
 
404
  uint32_t SV::*offset;
 
405
  sys_var_session_uint32_t(sys_var_chain *chain, const char *name_arg,
 
406
                           uint32_t SV::*offset_arg,
 
407
                           sys_check_func c_func= NULL,
 
408
                           sys_after_update_func au_func= NULL,
 
409
                           Binlog_status_enum binlog_status_arg= NOT_IN_BINLOG)
 
410
    :sys_var_session(name_arg, au_func, binlog_status_arg), check_func(c_func),
427
411
    offset(offset_arg)
428
412
  { chain_sys_var(chain); }
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);
 
413
  bool check(Session *session, set_var *var);
 
414
  bool update(Session *session, set_var *var);
 
415
  void set_default(Session *session, enum_var_type type);
 
416
  SHOW_TYPE show_type() { return SHOW_INT; }
 
417
  unsigned char *value_ptr(Session *session, enum_var_type type,
 
418
                           const LEX_STRING *base);
434
419
};
435
420
 
436
421
 
437
 
class sys_var_thd_ha_rows :public sys_var_thd
 
422
class sys_var_session_ha_rows :public sys_var_session
438
423
{
439
424
public:
440
425
  ha_rows SV::*offset;
441
 
  sys_var_thd_ha_rows(sys_var_chain *chain, const char *name_arg, 
 
426
  sys_var_session_ha_rows(sys_var_chain *chain, const char *name_arg,
442
427
                      ha_rows SV::*offset_arg)
443
 
    :sys_var_thd(name_arg), offset(offset_arg)
 
428
    :sys_var_session(name_arg), offset(offset_arg)
444
429
  { chain_sys_var(chain); }
445
 
  sys_var_thd_ha_rows(sys_var_chain *chain, const char *name_arg, 
 
430
  sys_var_session_ha_rows(sys_var_chain *chain, const char *name_arg,
446
431
                      ha_rows SV::*offset_arg,
447
432
                      sys_after_update_func func)
448
 
    :sys_var_thd(name_arg,func), offset(offset_arg)
 
433
    :sys_var_session(name_arg,func), offset(offset_arg)
449
434
  { chain_sys_var(chain); }
450
 
  bool update(THD *thd, set_var *var);
451
 
  void set_default(THD *thd, enum_var_type type);
 
435
  bool update(Session *session, set_var *var);
 
436
  void set_default(Session *session, enum_var_type type);
452
437
  SHOW_TYPE show_type() { return SHOW_HA_ROWS; }
453
 
  unsigned char *value_ptr(THD *thd, enum_var_type type, LEX_STRING *base);
 
438
  unsigned char *value_ptr(Session *session, enum_var_type type,
 
439
                           const LEX_STRING *base);
454
440
};
455
441
 
456
442
 
457
 
class sys_var_thd_uint64_t :public sys_var_thd
 
443
class sys_var_session_uint64_t :public sys_var_session
458
444
{
 
445
  sys_check_func check_func;
459
446
public:
460
447
  uint64_t SV::*offset;
461
448
  bool only_global;
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)
 
449
  sys_var_session_uint64_t(sys_var_chain *chain, const char *name_arg,
 
450
                           uint64_t SV::*offset_arg,
 
451
                           sys_after_update_func au_func= NULL,
 
452
                           sys_check_func c_func= NULL,
 
453
                           Binlog_status_enum binlog_status_arg= NOT_IN_BINLOG)
 
454
    :sys_var_session(name_arg, au_func, binlog_status_arg),
 
455
    check_func(c_func),
 
456
    offset(offset_arg)
465
457
  { chain_sys_var(chain); }
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),
 
458
  sys_var_session_uint64_t(sys_var_chain *chain,
 
459
                           const char *name_arg,
 
460
                           uint64_t SV::*offset_arg,
 
461
                           sys_after_update_func func,
 
462
                           bool only_global_arg,
 
463
                           sys_check_func cfunc= NULL)
 
464
    :sys_var_session(name_arg, func),
 
465
    check_func(cfunc),
 
466
    offset(offset_arg),
470
467
    only_global(only_global_arg)
471
468
  { chain_sys_var(chain); }
472
 
  bool update(THD *thd, set_var *var);
473
 
  void set_default(THD *thd, enum_var_type type);
 
469
  bool update(Session *session, set_var *var);
 
470
  void set_default(Session *session, enum_var_type type);
474
471
  SHOW_TYPE show_type() { return SHOW_LONGLONG; }
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
 
472
  unsigned char *value_ptr(Session *session, enum_var_type type,
 
473
                           const LEX_STRING *base);
 
474
  bool check(Session *session, set_var *var);
 
475
  bool check_default(enum_var_type type)
 
476
  {
 
477
    return type == OPT_GLOBAL && !option_limits;
 
478
  }
 
479
  bool check_type(enum_var_type type)
 
480
  {
 
481
    return (only_global && type != OPT_GLOBAL);
 
482
  }
 
483
};
 
484
 
 
485
class sys_var_session_size_t :public sys_var_session
 
486
{
 
487
  sys_check_func check_func;
 
488
public:
 
489
  size_t SV::*offset;
 
490
  bool only_global;
 
491
  sys_var_session_size_t(sys_var_chain *chain, const char *name_arg,
 
492
                         size_t SV::*offset_arg,
 
493
                         sys_after_update_func au_func= NULL,
 
494
                         sys_check_func c_func= NULL,
 
495
                         Binlog_status_enum binlog_status_arg= NOT_IN_BINLOG)
 
496
    :sys_var_session(name_arg, au_func, binlog_status_arg),
 
497
     check_func(c_func),
 
498
     offset(offset_arg)
 
499
  { chain_sys_var(chain); }
 
500
  sys_var_session_size_t(sys_var_chain *chain,
 
501
                         const char *name_arg,
 
502
                         size_t SV::*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),
 
509
     only_global(only_global_arg)
 
510
  { chain_sys_var(chain); }
 
511
  bool update(Session *session, set_var *var);
 
512
  void set_default(Session *session, enum_var_type type);
 
513
  SHOW_TYPE show_type() { return SHOW_SIZE; }
 
514
  unsigned char *value_ptr(Session *session, enum_var_type type,
 
515
                           const LEX_STRING *base);
 
516
  bool check(Session *session, set_var *var);
 
517
  bool check_default(enum_var_type type)
 
518
  {
 
519
    return type == OPT_GLOBAL && !option_limits;
 
520
  }
 
521
  bool check_type(enum_var_type type)
 
522
  {
 
523
    return (only_global && type != OPT_GLOBAL);
 
524
  }
 
525
};
 
526
 
 
527
 
 
528
class sys_var_session_bool :public sys_var_session
489
529
{
490
530
public:
491
531
  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)
 
532
  sys_var_session_bool(sys_var_chain *chain, const char *name_arg, bool SV::*offset_arg)
 
533
    :sys_var_session(name_arg), offset(offset_arg)
494
534
  { chain_sys_var(chain); }
495
 
  sys_var_thd_bool(sys_var_chain *chain, const char *name_arg, bool SV::*offset_arg,
 
535
  sys_var_session_bool(sys_var_chain *chain, const char *name_arg, bool SV::*offset_arg,
496
536
                   sys_after_update_func func)
497
 
    :sys_var_thd(name_arg,func), offset(offset_arg)
 
537
    :sys_var_session(name_arg,func), offset(offset_arg)
498
538
  { chain_sys_var(chain); }
499
 
  bool update(THD *thd, set_var *var);
500
 
  void set_default(THD *thd, enum_var_type type);
 
539
  bool update(Session *session, set_var *var);
 
540
  void set_default(Session *session, enum_var_type type);
501
541
  SHOW_TYPE show_type() { return SHOW_MY_BOOL; }
502
 
  unsigned char *value_ptr(THD *thd, enum_var_type type, LEX_STRING *base);
503
 
  bool check(THD *thd, set_var *var)
 
542
  unsigned char *value_ptr(Session *session, enum_var_type type,
 
543
                           const LEX_STRING *base);
 
544
  bool check(Session *session, set_var *var)
504
545
  {
505
 
    return check_enum(thd, var, &bool_typelib);
 
546
    return check_enum(session, var, &bool_typelib);
506
547
  }
507
 
  bool check_update_type(Item_result type __attribute__((unused)))
 
548
  bool check_update_type(Item_result)
508
549
  { return 0; }
509
550
};
510
551
 
511
552
 
512
 
class sys_var_thd_enum :public sys_var_thd
 
553
class sys_var_session_enum :public sys_var_session
513
554
{
514
555
protected:
515
 
  ulong SV::*offset;
 
556
  uint32_t SV::*offset;
516
557
  TYPELIB *enum_names;
517
558
  sys_check_func check_func;
518
559
public:
519
 
  sys_var_thd_enum(sys_var_chain *chain, const char *name_arg,
520
 
                   ulong SV::*offset_arg, TYPELIB *typelib,
 
560
  sys_var_session_enum(sys_var_chain *chain, const char *name_arg,
 
561
                   uint32_t SV::*offset_arg, TYPELIB *typelib,
521
562
                   sys_after_update_func func= NULL,
522
 
                   sys_check_func check= NULL)
523
 
    :sys_var_thd(name_arg, func), offset(offset_arg),
524
 
    enum_names(typelib), check_func(check)
 
563
                   sys_check_func check_f= NULL)
 
564
    :sys_var_session(name_arg, func), offset(offset_arg),
 
565
    enum_names(typelib), check_func(check_f)
525
566
  { chain_sys_var(chain); }
526
 
  bool check(THD *thd, set_var *var)
 
567
  bool check(Session *session, set_var *var)
527
568
  {
528
569
    int ret= 0;
529
570
    if (check_func)
530
 
      ret= (*check_func)(thd, var);
531
 
    return ret ? ret : check_enum(thd, var, enum_names);
 
571
      ret= (*check_func)(session, var);
 
572
    return ret ? ret : check_enum(session, var, enum_names);
532
573
  }
533
 
  bool update(THD *thd, set_var *var);
534
 
  void set_default(THD *thd, enum_var_type type);
 
574
  bool update(Session *session, set_var *var);
 
575
  void set_default(Session *session, enum_var_type type);
535
576
  SHOW_TYPE show_type() { return SHOW_CHAR; }
536
 
  unsigned char *value_ptr(THD *thd, enum_var_type type, LEX_STRING *base);
537
 
  bool check_update_type(Item_result type __attribute__((unused)))
 
577
  unsigned char *value_ptr(Session *session, enum_var_type type,
 
578
                           const LEX_STRING *base);
 
579
  bool check_update_type(Item_result)
538
580
  { return 0; }
539
581
};
540
582
 
541
583
 
542
584
 
543
 
class sys_var_thd_optimizer_switch :public sys_var_thd_enum
 
585
class sys_var_session_optimizer_switch :public sys_var_session_enum
544
586
{
545
587
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)
 
588
  sys_var_session_optimizer_switch(sys_var_chain *chain, const char *name_arg,
 
589
                                   uint32_t SV::*offset_arg)
 
590
    :sys_var_session_enum(chain, name_arg, offset_arg, &optimizer_switch_typelib)
549
591
  {}
550
 
  bool check(THD *thd, set_var *var)
 
592
  bool check(Session *session, set_var *var)
551
593
  {
552
 
    return check_set(thd, var, enum_names);
 
594
    return check_set(session, var, enum_names);
553
595
  }
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,
 
596
  void set_default(Session *session, enum_var_type type);
 
597
  unsigned char *value_ptr(Session *session, enum_var_type type,
 
598
                           const LEX_STRING *base);
 
599
  static bool symbolic_mode_representation(Session *session, uint32_t sql_mode,
557
600
                                           LEX_STRING *rep);
558
601
};
559
602
 
560
603
 
561
 
class sys_var_thd_storage_engine :public sys_var_thd
 
604
class sys_var_session_storage_engine :public sys_var_session
562
605
{
563
606
protected:
564
607
  plugin_ref SV::*offset;
565
608
public:
566
 
  sys_var_thd_storage_engine(sys_var_chain *chain, const char *name_arg, 
 
609
  sys_var_session_storage_engine(sys_var_chain *chain, const char *name_arg,
567
610
                             plugin_ref SV::*offset_arg)
568
 
    :sys_var_thd(name_arg), offset(offset_arg)
 
611
    :sys_var_session(name_arg), offset(offset_arg)
569
612
  { chain_sys_var(chain); }
570
 
  bool check(THD *thd, set_var *var);
 
613
  bool check(Session *session, set_var *var);
571
614
  SHOW_TYPE show_type() { return SHOW_CHAR; }
572
615
  bool check_update_type(Item_result type)
573
616
  {
574
617
    return type != STRING_RESULT;               /* Only accept strings */
575
618
  }
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);
 
619
  void set_default(Session *session, enum_var_type type);
 
620
  bool update(Session *session, set_var *var);
 
621
  unsigned char *value_ptr(Session *session, enum_var_type type,
 
622
                           const LEX_STRING *base);
579
623
};
580
624
 
581
 
class sys_var_thd_bit :public sys_var_thd
 
625
class sys_var_session_bit :public sys_var_session
582
626
{
583
627
  sys_check_func check_func;
584
628
  sys_update_func update_func;
585
629
public:
586
630
  uint64_t bit_flag;
587
631
  bool reverse;
588
 
  sys_var_thd_bit(sys_var_chain *chain, const char *name_arg,
 
632
  sys_var_session_bit(sys_var_chain *chain, const char *name_arg,
589
633
                  sys_check_func c_func, sys_update_func u_func,
590
634
                  uint64_t bit, bool reverse_arg=0,
591
635
                  Binlog_status_enum binlog_status_arg= NOT_IN_BINLOG)
592
 
    :sys_var_thd(name_arg, NULL, binlog_status_arg), check_func(c_func),
 
636
    :sys_var_session(name_arg, NULL, binlog_status_arg), check_func(c_func),
593
637
    update_func(u_func), bit_flag(bit), reverse(reverse_arg)
594
638
  { chain_sys_var(chain); }
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)))
 
639
  bool check(Session *session, set_var *var);
 
640
  bool update(Session *session, set_var *var);
 
641
  bool check_update_type(Item_result)
598
642
  { return 0; }
599
643
  bool check_type(enum_var_type type) { return type == OPT_GLOBAL; }
600
644
  SHOW_TYPE show_type() { return SHOW_MY_BOOL; }
601
 
  unsigned char *value_ptr(THD *thd, enum_var_type type, LEX_STRING *base);
 
645
  unsigned char *value_ptr(Session *session, enum_var_type type,
 
646
                           const LEX_STRING *base);
602
647
};
603
648
 
604
649
/* some variables that require special handling */
610
655
                    Binlog_status_enum binlog_status_arg= NOT_IN_BINLOG)
611
656
    :sys_var(name_arg, NULL, binlog_status_arg)
612
657
  { chain_sys_var(chain); }
613
 
  bool update(THD *thd, set_var *var);
614
 
  void set_default(THD *thd, enum_var_type type);
 
658
  bool update(Session *session, set_var *var);
 
659
  void set_default(Session *session, enum_var_type type);
615
660
  bool check_type(enum_var_type type)    { return type == OPT_GLOBAL; }
616
 
  bool check_default(enum_var_type type __attribute__((unused)))
 
661
  bool check_default(enum_var_type)
617
662
  { return 0; }
618
663
  SHOW_TYPE show_type(void) { return SHOW_LONG; }
619
 
  unsigned char *value_ptr(THD *thd, enum_var_type type, LEX_STRING *base);
 
664
  unsigned char *value_ptr(Session *session, enum_var_type type,
 
665
                           const LEX_STRING *base);
620
666
};
621
667
 
622
668
 
627
673
                         Binlog_status_enum binlog_status_arg= NOT_IN_BINLOG)
628
674
    :sys_var(name_arg, NULL, binlog_status_arg)
629
675
  { 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
 
676
  bool update(Session *session, set_var *var);
 
677
  bool check_type(enum_var_type type) { return type == OPT_GLOBAL; }
 
678
  SHOW_TYPE show_type() { return SHOW_LONGLONG; }
 
679
  unsigned char *value_ptr(Session *session, enum_var_type type,
 
680
                           const LEX_STRING *base);
 
681
};
 
682
 
 
683
 
 
684
class sys_var_collation :public sys_var_session
674
685
{
675
686
public:
676
687
  sys_var_collation(const char *name_arg,
677
688
                    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)
 
689
    :sys_var_session(name_arg, NULL, binlog_status_arg)
747
690
  { }
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);
 
691
  bool check(Session *session, set_var *var);
 
692
  SHOW_TYPE show_type() { return SHOW_CHAR; }
 
693
  bool check_update_type(Item_result type)
 
694
  {
 
695
    return ((type != STRING_RESULT) && (type != INT_RESULT));
 
696
  }
 
697
  bool check_default(enum_var_type) { return 0; }
 
698
  virtual void set_default(Session *session, enum_var_type type)= 0;
762
699
};
763
700
 
764
701
class sys_var_collation_sv :public sys_var_collation
775
712
  {
776
713
    chain_sys_var(chain);
777
714
  }
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);
 
715
  bool update(Session *session, set_var *var);
 
716
  void set_default(Session *session, enum_var_type type);
 
717
  unsigned char *value_ptr(Session *session, enum_var_type type,
 
718
                           const LEX_STRING *base);
781
719
};
782
720
 
783
721
 
786
724
protected:
787
725
  size_t offset;
788
726
public:
789
 
  sys_var_key_cache_param(sys_var_chain *chain, const char *name_arg, 
 
727
  sys_var_key_cache_param(sys_var_chain *chain, const char *name_arg,
790
728
                          size_t offset_arg)
791
729
    :sys_var(name_arg), offset(offset_arg)
792
730
  { 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)))
 
731
  unsigned char *value_ptr(Session *session, enum_var_type type,
 
732
                           const LEX_STRING *base);
 
733
  bool check_default(enum_var_type)
795
734
  { return 1; }
796
735
  bool is_struct() { return 1; }
797
736
};
804
743
    :sys_var_key_cache_param(chain, name_arg,
805
744
                             offsetof(KEY_CACHE, param_buff_size))
806
745
  {}
807
 
  bool update(THD *thd, set_var *var);
 
746
  bool update(Session *session, set_var *var);
808
747
  SHOW_TYPE show_type() { return SHOW_LONGLONG; }
809
748
};
810
749
 
811
750
 
812
 
class sys_var_key_cache_long :public sys_var_key_cache_param
 
751
class sys_var_key_cache_uint32_t :public sys_var_key_cache_param
813
752
{
814
753
public:
815
 
  sys_var_key_cache_long(sys_var_chain *chain, const char *name_arg, size_t offset_arg)
 
754
  sys_var_key_cache_uint32_t(sys_var_chain *chain, const char *name_arg, size_t offset_arg)
816
755
    :sys_var_key_cache_param(chain, name_arg, offset_arg)
817
756
  {}
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
 
 
 
757
  bool update(Session *session, set_var *var);
 
758
  SHOW_TYPE show_type() { return SHOW_INT; }
 
759
};
923
760
 
924
761
/* Variable that you can only read from */
925
762
 
932
769
  sys_var_readonly(sys_var_chain *chain, const char *name_arg, enum_var_type type,
933
770
                   SHOW_TYPE show_type_arg,
934
771
                   sys_value_ptr_func value_ptr_func_arg)
935
 
    :sys_var(name_arg), var_type(type), 
 
772
    :sys_var(name_arg), var_type(type),
936
773
       show_type_value(show_type_arg), value_ptr_func(value_ptr_func_arg)
937
774
  { chain_sys_var(chain); }
938
 
  bool update(THD *thd __attribute__((unused)),
939
 
              set_var *var __attribute__((unused)))
 
775
  bool update(Session *, set_var *)
940
776
  { return 1; }
941
 
  bool check_default(enum_var_type type __attribute__((unused)))
 
777
  bool check_default(enum_var_type)
942
778
  { return 1; }
943
779
  bool check_type(enum_var_type type) { return type != var_type; }
944
 
  bool check_update_type(Item_result type __attribute__((unused)))
 
780
  bool check_update_type(Item_result)
945
781
  { return 1; }
946
 
  unsigned char *value_ptr(THD *thd, enum_var_type type __attribute__((unused)),
947
 
                   LEX_STRING *base __attribute__((unused)))
 
782
  unsigned char *value_ptr(Session *session, enum_var_type,
 
783
                           const LEX_STRING *)
948
784
  {
949
 
    return (*value_ptr_func)(thd);
 
785
    return (*value_ptr_func)(session);
950
786
  }
951
787
  SHOW_TYPE show_type(void) { return show_type_value; }
952
788
  bool is_readonly(void) const { return 1; }
961
797
  sys_var_have_option(sys_var_chain *chain, const char *variable_name):
962
798
    sys_var(variable_name)
963
799
  { 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)))
 
800
  unsigned char *value_ptr(Session *, enum_var_type,
 
801
                           const LEX_STRING *)
967
802
  {
968
803
    return (unsigned char*) show_comp_option_name[get_option()];
969
804
  }
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)))
 
805
  bool update(Session *, set_var *) { return 1; }
 
806
  bool check_default(enum_var_type)
973
807
  { return 1; }
974
808
  bool check_type(enum_var_type type) { return type != OPT_GLOBAL; }
975
 
  bool check_update_type(Item_result type __attribute__((unused)))
 
809
  bool check_update_type(Item_result)
976
810
  { return 1; }
977
811
  SHOW_TYPE show_type() { return SHOW_CHAR; }
978
812
  bool is_readonly() const { return 1; }
1001
835
 
1002
836
public:
1003
837
  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, 
 
838
                      const char *plugin_name_str_arg, uint32_t plugin_name_len_arg,
1005
839
                      int plugin_type_arg):
1006
 
    sys_var_have_option(chain, variable_name), 
 
840
    sys_var_have_option(chain, variable_name),
1007
841
    plugin_name_str(plugin_name_str_arg), plugin_name_len(plugin_name_len_arg),
1008
842
    plugin_type(plugin_type_arg)
1009
843
  { }
1012
846
};
1013
847
 
1014
848
 
1015
 
class sys_var_thd_time_zone :public sys_var_thd
 
849
class sys_var_session_time_zone :public sys_var_session
1016
850
{
1017
851
public:
1018
 
  sys_var_thd_time_zone(sys_var_chain *chain, const char *name_arg,
 
852
  sys_var_session_time_zone(sys_var_chain *chain, const char *name_arg,
1019
853
                        Binlog_status_enum binlog_status_arg= NOT_IN_BINLOG)
1020
 
    :sys_var_thd(name_arg, NULL, binlog_status_arg)
 
854
    :sys_var_session(name_arg, NULL, binlog_status_arg)
1021
855
  {
1022
 
    no_support_one_shot= 0;
1023
856
    chain_sys_var(chain);
1024
857
  }
1025
 
  bool check(THD *thd, set_var *var);
 
858
  bool check(Session *session, set_var *var);
1026
859
  SHOW_TYPE show_type() { return SHOW_CHAR; }
1027
860
  bool check_update_type(Item_result type)
1028
861
  {
1029
862
    return type != STRING_RESULT;               /* Only accept strings */
1030
863
  }
1031
 
  bool check_default(enum_var_type type __attribute__((unused)))
 
864
  bool check_default(enum_var_type)
1032
865
  { return 0; }
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
 
866
  bool update(Session *session, set_var *var);
 
867
  unsigned char *value_ptr(Session *session, enum_var_type type,
 
868
                           const LEX_STRING *base);
 
869
  virtual void set_default(Session *session, enum_var_type type);
 
870
};
 
871
 
 
872
 
 
873
class sys_var_microseconds :public sys_var_session
1058
874
{
1059
875
  uint64_t SV::*offset;
1060
876
public:
1061
877
  sys_var_microseconds(sys_var_chain *chain, const char *name_arg,
1062
878
                       uint64_t SV::*offset_arg):
1063
 
    sys_var_thd(name_arg), offset(offset_arg)
 
879
    sys_var_session(name_arg), offset(offset_arg)
1064
880
  { chain_sys_var(chain); }
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);
 
881
  bool check(Session *, set_var *) {return 0;}
 
882
  bool update(Session *session, set_var *var);
 
883
  void set_default(Session *session, enum_var_type type);
1069
884
  SHOW_TYPE show_type() { return SHOW_DOUBLE; }
1070
885
  bool check_update_type(Item_result type)
1071
886
  {
1072
887
    return (type != INT_RESULT && type != REAL_RESULT && type != DECIMAL_RESULT);
1073
888
  }
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,
 
889
  unsigned char *value_ptr(Session *session, enum_var_type type,
 
890
                           const LEX_STRING *base);
 
891
};
 
892
 
 
893
class sys_var_session_lc_time_names :public sys_var_session
 
894
{
 
895
public:
 
896
  sys_var_session_lc_time_names(sys_var_chain *chain, const char *name_arg,
1096
897
                            Binlog_status_enum binlog_status_arg= NOT_IN_BINLOG)
1097
 
    : sys_var_thd(name_arg, NULL, binlog_status_arg)
 
898
    : sys_var_session(name_arg, NULL, binlog_status_arg)
1098
899
  {
1099
 
#if DRIZZLE_VERSION_ID < 50000
1100
 
    no_support_one_shot= 0;
1101
 
#endif
1102
900
    chain_sys_var(chain);
1103
901
  }
1104
 
  bool check(THD *thd, set_var *var);
 
902
  bool check(Session *session, set_var *var);
1105
903
  SHOW_TYPE show_type() { return SHOW_CHAR; }
1106
904
  bool check_update_type(Item_result type)
1107
905
  {
1108
906
    return ((type != STRING_RESULT) && (type != INT_RESULT));
1109
907
  }
1110
 
  bool check_default(enum_var_type type __attribute__((unused)))
 
908
  bool check_default(enum_var_type)
1111
909
  { return 0; }
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
 
};
 
910
  bool update(Session *session, set_var *var);
 
911
  unsigned char *value_ptr(Session *session, enum_var_type type,
 
912
                           const LEX_STRING *base);
 
913
  virtual void set_default(Session *session, enum_var_type type);
 
914
};
 
915
 
1131
916
 
1132
917
/****************************************************************************
1133
918
  Classes for parsing of the SET command
1138
923
public:
1139
924
  set_var_base() {}
1140
925
  virtual ~set_var_base() {}
1141
 
  virtual int check(THD *thd)=0;        /* To check privileges etc. */
1142
 
  virtual int update(THD *thd)=0;       /* To set the value */
 
926
  virtual int check(Session *session)=0;        /* To check privileges etc. */
 
927
  virtual int update(Session *session)=0;       /* To set the value */
1143
928
  /* light check for PS */
1144
 
  virtual bool no_support_one_shot() { return 1; }
1145
929
};
1146
930
 
1147
931
 
1156
940
  union
1157
941
  {
1158
942
    const CHARSET_INFO *charset;
1159
 
    ulong ulong_value;
 
943
    uint32_t uint32_t_value;
1160
944
    uint64_t uint64_t_value;
 
945
    size_t size_t_value;
1161
946
    plugin_ref plugin;
1162
 
    DATE_TIME_FORMAT *date_time_format;
1163
947
    Time_zone *time_zone;
1164
948
    MY_LOCALE *locale_value;
1165
949
  } save_result;
1176
960
    if (value_arg && value_arg->type() == Item::FIELD_ITEM)
1177
961
    {
1178
962
      Item_field *item= (Item_field*) value_arg;
1179
 
      if (!(value=new Item_string(item->field_name, 
1180
 
                  (uint) strlen(item->field_name),
 
963
      if (!(value=new Item_string(item->field_name,
 
964
                  (uint32_t) strlen(item->field_name),
1181
965
                                  item->collation.collation)))
1182
966
        value=value_arg;                        /* Give error message later */
1183
967
    }
1184
968
    else
1185
969
      value=value_arg;
1186
970
  }
1187
 
  int check(THD *thd);
1188
 
  int update(THD *thd);
1189
 
  bool no_support_one_shot() { return var->no_support_one_shot; }
 
971
  int check(Session *session);
 
972
  int update(Session *session);
1190
973
};
1191
974
 
1192
975
 
1199
982
  set_var_user(Item_func_set_user_var *item)
1200
983
    :user_var_item(item)
1201
984
  {}
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);
 
985
  int check(Session *session);
 
986
  int update(Session *session);
1223
987
};
1224
988
 
1225
989
 
1232
996
 
1233
997
class NAMED_LIST :public ilink
1234
998
{
1235
 
  const char *name;
1236
 
  uint32_t name_length;
 
999
  std::string name;
1237
1000
public:
1238
1001
  unsigned char* data;
1239
1002
 
1240
1003
  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
 
  }
 
1004
                   uint32_t name_length_arg, unsigned char* data_arg);
 
1005
  bool cmp(const char *name_cmp, uint32_t length);
1255
1006
  friend bool process_key_caches(process_key_cache_t func);
1256
1007
  friend void delete_elements(I_List<NAMED_LIST> *list,
1257
 
                              void (*free_element)(const char*, unsigned char*));
 
1008
                              void (*free_element)(const char*,
 
1009
                                                   unsigned char*));
1258
1010
};
1259
1011
 
1260
1012
/* updated in sql_acl.cc */
1261
1013
 
1262
 
extern sys_var_thd_bool sys_old_alter_table;
 
1014
extern sys_var_session_bool sys_old_alter_table;
1263
1015
extern LEX_STRING default_key_cache_base;
1264
1016
 
1265
1017
/* For sql_yacc */
1276
1028
int set_var_init();
1277
1029
void set_var_free();
1278
1030
int mysql_append_static_vars(const SHOW_VAR *show_vars, uint32_t count);
1279
 
SHOW_VAR* enumerate_sys_vars(THD *thd, bool sorted);
 
1031
SHOW_VAR* enumerate_sys_vars(Session *session, bool sorted);
1280
1032
int mysql_add_sys_var_chain(sys_var *chain, struct my_option *long_options);
1281
1033
int mysql_del_sys_var_chain(sys_var *chain);
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);
 
1034
sys_var *find_sys_var(Session *session, const char *str, uint32_t length=0);
 
1035
int sql_set_variables(Session *session, List<set_var_base> *var_list);
1284
1036
bool not_all_support_one_shot(List<set_var_base> *var_list);
1285
 
void fix_delay_key_write(THD *thd, enum_var_type type);
 
1037
void fix_delay_key_write(Session *session, enum_var_type type);
1286
1038
void fix_slave_exec_mode(enum_var_type type);
1287
 
extern sys_var_const_str sys_charset_system;
1288
1039
extern sys_var_str sys_init_connect;
1289
1040
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;
 
1041
extern sys_var_session_time_zone sys_time_zone;
 
1042
extern sys_var_session_bit sys_autocommit;
1292
1043
const CHARSET_INFO *get_old_charset_by_name(const char *old_name);
1293
1044
unsigned char* find_named(I_List<NAMED_LIST> *list, const char *name, uint32_t length,
1294
1045
                NAMED_LIST **found);
1296
1047
extern sys_var_str sys_var_general_log_path, sys_var_slow_log_path;
1297
1048
 
1298
1049
/* key_cache functions */
1299
 
KEY_CACHE *get_key_cache(LEX_STRING *cache_name);
 
1050
KEY_CACHE *get_key_cache(const LEX_STRING *cache_name);
1300
1051
KEY_CACHE *get_or_create_key_cache(const char *name, uint32_t length);
1301
1052
void free_key_cache(const char *name, KEY_CACHE *key_cache);
1302
1053
bool process_key_caches(process_key_cache_t func);
1303
1054
void delete_elements(I_List<NAMED_LIST> *list,
1304
1055
                     void (*free_element)(const char*, unsigned char*));
 
1056
 
 
1057
#endif /* DRIZZLED_ITEM_SET_H */