~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/set_var.h

  • Committer: Brian Aker
  • Date: 2010-10-22 07:16:38 UTC
  • mfrom: (1863.1.11 template-sys-var)
  • Revision ID: brian@tangent.org-20101022071638-pk02309d027gs6zf
Merge Monty

Show diffs side-by-side

added added

removed removed

Lines of Context:
27
27
#include "drizzled/function/set_user_var.h"
28
28
#include "drizzled/item/string.h"
29
29
#include "drizzled/item/field.h"
 
30
#include "drizzled/constrained_value.h"
30
31
 
31
32
namespace drizzled
32
33
{
74
75
extern uint32_t global_thread_id;
75
76
extern uint64_t table_cache_size;
76
77
extern uint64_t max_connect_errors;
77
 
extern uint32_t back_log;
 
78
extern back_log_constraints back_log;
78
79
extern uint32_t ha_open_options;
79
80
extern char *drizzled_bind_host;
80
81
extern uint32_t dropping_tables;
89
90
 
90
91
void init_sys_var();
91
92
 
 
93
/****************************************************************************
 
94
  Classes for parsing of the SET command
 
95
****************************************************************************/
 
96
 
 
97
class set_var_base :public memory::SqlAlloc
 
98
{
 
99
public:
 
100
  set_var_base() {}
 
101
  virtual ~set_var_base() {}
 
102
  virtual int check(Session *session)=0;        /* To check privileges etc. */
 
103
  virtual int update(Session *session)=0;       /* To set the value */
 
104
  /* light check for PS */
 
105
};
 
106
 
 
107
/* MySQL internal variables */
 
108
class set_var :public set_var_base
 
109
{
 
110
public:
 
111
  sys_var *var;
 
112
  Item *value;
 
113
  sql_var_t type;
 
114
  union
 
115
  {
 
116
    const CHARSET_INFO *charset;
 
117
    uint32_t uint32_t_value;
 
118
    uint64_t uint64_t_value;
 
119
    size_t size_t_value;
 
120
    plugin::StorageEngine *storage_engine;
 
121
    Time_zone *time_zone;
 
122
    MY_LOCALE *locale_value;
 
123
  } save_result;
 
124
  LEX_STRING base;                      /* for structs */
 
125
 
 
126
  set_var(sql_var_t type_arg, sys_var *var_arg,
 
127
          const LEX_STRING *base_name_arg, Item *value_arg)
 
128
    :var(var_arg), type(type_arg), base(*base_name_arg)
 
129
  {
 
130
    /*
 
131
      If the set value is a field, change it to a string to allow things like
 
132
      SET table_type=MYISAM;
 
133
    */
 
134
    if (value_arg && value_arg->type() == Item::FIELD_ITEM)
 
135
    {
 
136
      Item_field *item= (Item_field*) value_arg;
 
137
      if (!(value=new Item_string(item->field_name,
 
138
                  (uint32_t) strlen(item->field_name),
 
139
                                  item->collation.collation)))
 
140
        value=value_arg;                        /* Give error message later */
 
141
    }
 
142
    else
 
143
      value=value_arg;
 
144
  }
 
145
  int check(Session *session);
 
146
  int update(Session *session);
 
147
};
 
148
 
 
149
 
92
150
/**
93
151
 * A class which represents a variable, either global or 
94
152
 * session-local.
372
430
  bool is_readonly() const { return true; }
373
431
};
374
432
 
 
433
template<class T>
 
434
class sys_var_constrained_value :
 
435
  public sys_var
 
436
{
 
437
  constrained_value<T> &value;
 
438
  T basic_value;
 
439
  T default_value;
 
440
  bool have_default_value;
 
441
public:
 
442
  sys_var_constrained_value(const char *name_arg,
 
443
                            constrained_value<T> &value_arg) :
 
444
    sys_var(name_arg),
 
445
    value(value_arg),
 
446
    default_value(0),
 
447
    have_default_value(false)
 
448
  { }
 
449
 
 
450
  sys_var_constrained_value(const char *name_arg,
 
451
                            constrained_value<T> &value_arg,
 
452
                            T default_value_arg) :
 
453
    sys_var(name_arg),
 
454
    value(value_arg),
 
455
    default_value(default_value_arg),
 
456
    have_default_value(true)
 
457
  { }
 
458
 
 
459
public:
 
460
  bool is_readonly() const
 
461
  {
 
462
    return false;
 
463
  }
 
464
 
 
465
  SHOW_TYPE show_type() { return SHOW_INT; }
 
466
 
 
467
  bool update(Session *, set_var *var)
 
468
  {
 
469
    value= var->save_result.uint32_t_value;
 
470
    return false;
 
471
  }
 
472
 
 
473
  bool check_default(sql_var_t)
 
474
  {
 
475
    return not have_default_value;
 
476
  }
 
477
 
 
478
  void set_default(Session *, sql_var_t)
 
479
  {
 
480
    value= default_value;
 
481
  }
 
482
 
 
483
  unsigned char *value_ptr(Session *, sql_var_t, const LEX_STRING *)
 
484
  {
 
485
    basic_value= T(value);
 
486
    return (unsigned char*)&basic_value;
 
487
  }
 
488
};
 
489
 
 
490
template<>
 
491
inline bool sys_var_constrained_value<const uint64_t>::is_readonly() const
 
492
{
 
493
  return true;
 
494
}
 
495
 
 
496
template<>
 
497
inline bool sys_var_constrained_value<const uint32_t>::is_readonly() const
 
498
{
 
499
  return true;
 
500
}
 
501
 
 
502
template<>
 
503
inline SHOW_TYPE sys_var_constrained_value<uint64_t>::show_type()
 
504
{
 
505
  return SHOW_LONGLONG;
 
506
}
 
507
 
 
508
template<>
 
509
inline SHOW_TYPE sys_var_constrained_value<int64_t>::show_type()
 
510
{
 
511
  return SHOW_LONGLONG;
 
512
}
 
513
 
 
514
template<>
 
515
inline SHOW_TYPE sys_var_constrained_value<uint32_t>::show_type()
 
516
{
 
517
  return SHOW_LONG;
 
518
}
 
519
 
 
520
template<>
 
521
inline SHOW_TYPE sys_var_constrained_value<int32_t>::show_type()
 
522
{
 
523
  return SHOW_LONG;
 
524
}
 
525
 
 
526
template<>
 
527
inline bool sys_var_constrained_value<uint64_t>::update(Session *, set_var *var)
 
528
{
 
529
  value= var->save_result.uint64_t_value;
 
530
  return false;
 
531
}
 
532
 
 
533
template<>
 
534
inline bool sys_var_constrained_value<uint32_t>::update(Session *, set_var *var)
 
535
{
 
536
  value= var->save_result.uint32_t_value;
 
537
  return false;
 
538
}
 
539
 
 
540
template<>
 
541
inline unsigned char *sys_var_constrained_value<const uint64_t>::value_ptr(Session *, sql_var_t, const LEX_STRING *)
 
542
{
 
543
  return (unsigned char*)&basic_value;
 
544
}
 
545
 
 
546
template<>
 
547
inline unsigned char *sys_var_constrained_value<const uint32_t>::value_ptr(Session *, sql_var_t, const LEX_STRING *)
 
548
{
 
549
  return (unsigned char*)&basic_value;
 
550
}
 
551
 
375
552
class sys_var_const_string :
376
553
  public sys_var
377
554
{
909
1086
};
910
1087
 
911
1088
 
912
 
/****************************************************************************
913
 
  Classes for parsing of the SET command
914
 
****************************************************************************/
915
 
 
916
 
class set_var_base :public memory::SqlAlloc
917
 
{
918
 
public:
919
 
  set_var_base() {}
920
 
  virtual ~set_var_base() {}
921
 
  virtual int check(Session *session)=0;        /* To check privileges etc. */
922
 
  virtual int update(Session *session)=0;       /* To set the value */
923
 
  /* light check for PS */
924
 
};
925
 
 
926
 
/* MySQL internal variables */
927
 
class set_var :public set_var_base
928
 
{
929
 
public:
930
 
  sys_var *var;
931
 
  Item *value;
932
 
  sql_var_t type;
933
 
  union
934
 
  {
935
 
    const CHARSET_INFO *charset;
936
 
    uint32_t uint32_t_value;
937
 
    uint64_t uint64_t_value;
938
 
    size_t size_t_value;
939
 
    plugin::StorageEngine *storage_engine;
940
 
    Time_zone *time_zone;
941
 
    MY_LOCALE *locale_value;
942
 
  } save_result;
943
 
  LEX_STRING base;                      /* for structs */
944
 
 
945
 
  set_var(sql_var_t type_arg, sys_var *var_arg,
946
 
          const LEX_STRING *base_name_arg, Item *value_arg)
947
 
    :var(var_arg), type(type_arg), base(*base_name_arg)
948
 
  {
949
 
    /*
950
 
      If the set value is a field, change it to a string to allow things like
951
 
      SET table_type=MYISAM;
952
 
    */
953
 
    if (value_arg && value_arg->type() == Item::FIELD_ITEM)
954
 
    {
955
 
      Item_field *item= (Item_field*) value_arg;
956
 
      if (!(value=new Item_string(item->field_name,
957
 
                  (uint32_t) strlen(item->field_name),
958
 
                                  item->collation.collation)))
959
 
        value=value_arg;                        /* Give error message later */
960
 
    }
961
 
    else
962
 
      value=value_arg;
963
 
  }
964
 
  int check(Session *session);
965
 
  int update(Session *session);
966
 
};
967
 
 
968
 
 
969
1089
/* User variables like @my_own_variable */
970
1090
 
971
1091
class set_var_user: public set_var_base