Drizzled Public API Documentation

sys_var.h
00001 /* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
00002  *  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
00003  *
00004  *  Copyright (C) 2008 Sun Microsystems, Inc.
00005  *
00006  *  This program is free software; you can redistribute it and/or modify
00007  *  it under the terms of the GNU General Public License as published by
00008  *  the Free Software Foundation; version 2 of the License.
00009  *
00010  *  This program is distributed in the hope that it will be useful,
00011  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00012  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013  *  GNU General Public License for more details.
00014  *
00015  *  You should have received a copy of the GNU General Public License
00016  *  along with this program; if not, write to the Free Software
00017  *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
00018  */
00019 
00020 #pragma once
00021 
00022 #include <string>
00023 #include <boost/filesystem.hpp>
00024 
00025 #include <drizzled/common_fwd.h>
00026 #include <drizzled/constrained_value.h>
00027 #include <drizzled/set_var.h>
00028 #include <drizzled/show_type.h>
00029 #include <drizzled/item_result.h>
00030 #include <drizzled/base.h>
00031 #include <drizzled/charset.h>
00032 #include <drizzled/lex_string.h>
00033 #include <drizzled/visibility.h>
00034 
00035 namespace drizzled {
00036 
00037 typedef int (*sys_check_func)(Session *,  set_var *);
00038 typedef bool (*sys_update_func)(Session *, set_var *);
00039 typedef void (*sys_after_update_func)(Session *, sql_var_t);
00040 typedef void (*sys_set_default_func)(Session *, sql_var_t);
00041 typedef unsigned char *(*sys_value_ptr_func)(Session *session);
00042 
00043 static const std::vector<std::string> empty_aliases;
00044 extern struct drizzle_system_variables max_system_variables;
00045 extern size_t table_def_size;
00046 
00047 extern std::string drizzle_tmpdir;
00048 extern const char *first_keyword;
00049 extern const char *in_left_expr_name;
00050 extern const char *in_additional_cond;
00051 extern const char *in_having_cond;
00052 extern boost::filesystem::path basedir;
00053 extern boost::filesystem::path pid_file;
00054 extern boost::filesystem::path secure_file_priv;
00055 extern const char *opt_tc_log_file;
00056 extern uint64_t session_startup_options;
00057 extern uint32_t global_thread_id;
00058 extern uint64_t table_cache_size;
00059 extern back_log_constraints back_log;
00060 extern uint32_t ha_open_options;
00061 extern const char *drizzled_bind_host;
00062 extern uint32_t dropping_tables;
00063 extern bool opt_endinfo;
00064 extern uint32_t volatile thread_running;
00065 extern uint32_t volatile global_read_lock;
00066 extern bool opt_readonly;
00067 extern const char *opt_scheduler;
00068 extern size_t transaction_message_threshold;
00069 
00070 uint64_t fix_unsigned(Session*, uint64_t, const option&);
00071 
00072 DRIZZLED_API const std::string &getServerHostname();
00073 int sys_var_init();
00074 
00079 class DRIZZLED_API sys_var
00080 {
00081 protected:
00082   std::string name; 
00083   sys_check_func check_func;
00084   sys_after_update_func after_update; 
00085   struct option *option_limits; 
00086   bool m_allow_empty_value; 
00087 public:
00088   sys_var(const std::string &name_arg,
00089           sys_after_update_func func= NULL,
00090           sys_check_func check_func_arg= NULL)
00091     :
00092     name(name_arg),
00093     check_func(check_func_arg),
00094     after_update(func),
00095     option_limits(NULL),
00096     m_allow_empty_value(true)
00097   {}
00098   virtual ~sys_var() {}
00099 
00100   void setName(const std::string &name_in)
00101   {
00102     name= name_in;
00103   }
00104 
00112   inline const std::string &getName() const
00113   {
00114     return name;
00115   }
00120   const std::vector<std::string>& getAliases() const
00121   {
00122     return empty_aliases;
00123   }
00127   inline struct option *getOptionLimits() const
00128   {
00129     return option_limits;
00130   }
00136   inline void setOptionLimits(struct option *in_option_limits)
00137   {
00138     option_limits= in_option_limits;
00139   }
00143   inline sys_after_update_func getAfterUpdateTrigger() const
00144   {
00145     return after_update;
00146   }
00147   virtual bool check(Session *session, set_var *var);
00148   bool check_enum(Session *session, set_var *var, const TYPELIB *enum_names);
00149   virtual bool update(Session *session, set_var *var)=0;
00150   virtual void set_default(Session *, sql_var_t)
00151   {}
00152   virtual SHOW_TYPE show_type()
00153   {
00154     return SHOW_UNDEF;
00155   }
00156   virtual unsigned char *value_ptr(Session*, sql_var_t) = 0;
00157   virtual bool check_type(sql_var_t type)
00158   {
00159     return type != OPT_GLOBAL;
00160   }   /* Error if not GLOBAL */
00161   virtual bool check_update_type(Item_result type)
00162   {
00163     return type != INT_RESULT;
00164   }   /* Assume INT */
00165   virtual bool check_default(sql_var_t)
00166   {
00167     return option_limits == 0;
00168   }
00169   Item *item(Session*, sql_var_t);
00170   virtual bool is_readonly() const
00171   {
00172     return 0;
00173   }
00174 };
00175 
00180 class DRIZZLED_API sys_var_global : public sys_var
00181 {
00182 protected:
00183   pthread_mutex_t *guard;
00184 public:
00185   sys_var_global(const char *name_arg, sys_after_update_func after_update_arg, pthread_mutex_t *guard_arg) :
00186     sys_var(name_arg, after_update_arg), 
00187     guard(guard_arg) 
00188   {}
00189 };
00190 
00191 class DRIZZLED_API sys_var_uint32_t_ptr : public sys_var
00192 {
00193   uint32_t *value;
00194 public:
00195   sys_var_uint32_t_ptr(const char *name_arg, uint32_t *value_ptr_arg) :
00196     sys_var(name_arg), value(value_ptr_arg)
00197   {  }
00198   sys_var_uint32_t_ptr(const char *name_arg, uint32_t *value_ptr_arg, sys_after_update_func func) :
00199     sys_var(name_arg,func), value(value_ptr_arg)
00200   {  }
00201   bool check(Session *session, set_var *var);
00202   bool update(Session *session, set_var *var);
00203   void set_default(Session *session, sql_var_t type);
00204   SHOW_TYPE show_type() { return SHOW_INT; }
00205   unsigned char *value_ptr(Session *, sql_var_t)
00206   { return (unsigned char*) value; }
00207 };
00208 
00209 class DRIZZLED_API sys_var_uint32_t_ptr_readonly : public sys_var_uint32_t_ptr
00210 {
00211 public:
00212   sys_var_uint32_t_ptr_readonly(const char *name_arg, uint32_t *value_ptr_arg) :
00213     sys_var_uint32_t_ptr(name_arg, value_ptr_arg)
00214   {}
00215 
00216   sys_var_uint32_t_ptr_readonly(const char *name_arg,
00217                                 uint32_t *value_ptr_arg,
00218                                 sys_after_update_func func) :
00219     sys_var_uint32_t_ptr(name_arg, value_ptr_arg, func)
00220   {}
00221 
00222   bool is_readonly() const
00223   {
00224     return true;
00225   }
00226 };
00227 
00228 
00229 class DRIZZLED_API sys_var_uint64_t_ptr : public sys_var
00230 {
00231   uint64_t *value;
00232   const uint64_t default_value;
00233   bool have_default_value;
00234 public:
00235   sys_var_uint64_t_ptr(const char *name_arg, uint64_t *value_ptr_arg) :
00236     sys_var(name_arg),
00237     value(value_ptr_arg),
00238     default_value(0),
00239     have_default_value(false)
00240   {  }
00241 
00242   sys_var_uint64_t_ptr(const char *name_arg,
00243                        uint64_t *value_ptr_arg,
00244                        const uint64_t default_value_in) :
00245     sys_var(name_arg),
00246     value(value_ptr_arg),
00247     default_value(default_value_in),
00248     have_default_value(true)
00249   {  }
00250 
00251   sys_var_uint64_t_ptr(const char *name_arg,
00252                        uint64_t *value_ptr_arg,
00253                        sys_after_update_func func) :
00254     sys_var(name_arg,func),
00255     value(value_ptr_arg),
00256     default_value(0),
00257     have_default_value(false)
00258   {  }
00259 
00260   sys_var_uint64_t_ptr(const char *name_arg,
00261                        uint64_t *value_ptr_arg,
00262                        sys_after_update_func func,
00263                        const uint64_t default_value_in) :
00264     sys_var(name_arg,func),
00265     value(value_ptr_arg),
00266     default_value(default_value_in),
00267     have_default_value(true)
00268   {  }
00269 
00270   bool update(Session *session, set_var *var);
00271   void set_default(Session *session, sql_var_t type);
00272   virtual bool check_default(sql_var_t)
00273   {
00274     return (not have_default_value) && option_limits == 0;
00275   }
00276   SHOW_TYPE show_type() { return SHOW_LONGLONG; }
00277   unsigned char *value_ptr(Session *, sql_var_t)
00278   { return (unsigned char*) value; }
00279 };
00280 
00281 class DRIZZLED_API sys_var_size_t_ptr :public sys_var
00282 {
00283   size_t *value;
00284 public:
00285   sys_var_size_t_ptr(const char *name_arg, size_t *value_ptr_arg)
00286     :sys_var(name_arg),value(value_ptr_arg)
00287   {  }
00288   sys_var_size_t_ptr(const char *name_arg, size_t *value_ptr_arg,
00289                      sys_after_update_func func)
00290     :sys_var(name_arg,func), value(value_ptr_arg)
00291   {  }
00292   bool update(Session *session, set_var *var);
00293   void set_default(Session *session, sql_var_t type);
00294   SHOW_TYPE show_type() { return SHOW_SIZE; }
00295   unsigned char *value_ptr(Session *, sql_var_t)
00296   { return (unsigned char*) value; }
00297 };
00298 
00299 class DRIZZLED_API sys_var_size_t_ptr_readonly :public sys_var_size_t_ptr
00300 {
00301 public:
00302   sys_var_size_t_ptr_readonly(const char *name_arg,
00303                             size_t *value_arg)
00304     :sys_var_size_t_ptr(name_arg, value_arg)
00305   {}
00306   bool is_readonly() const { return 1; }
00307 };
00308 
00309 class DRIZZLED_API sys_var_bool_ptr :public sys_var
00310 {
00311   bool default_value;
00312 public:
00313   bool *value;
00314   sys_var_bool_ptr(const std::string &name_arg, bool *value_arg,
00315                    sys_after_update_func func= NULL) :
00316     sys_var(name_arg, func), default_value(*value_arg), value(value_arg)
00317   { }
00318   bool check(Session *session, set_var *var);
00319   virtual bool check_default(sql_var_t)
00320   {
00321     return false;
00322   }
00323   bool update(Session *session, set_var *var);
00324   void set_default(Session *session, sql_var_t type);
00325   SHOW_TYPE show_type() { return SHOW_MY_BOOL; }
00326   unsigned char *value_ptr(Session *, sql_var_t)
00327   { return (unsigned char*) value; }
00328   bool check_update_type(Item_result)
00329   { return 0; }
00330 };
00331 
00332 class DRIZZLED_API sys_var_bool_ptr_readonly :public sys_var_bool_ptr
00333 {
00334 public:
00335   sys_var_bool_ptr_readonly(const char *name_arg,
00336                             bool *value_arg)
00337     :sys_var_bool_ptr(name_arg, value_arg)
00338   {}
00339   bool is_readonly() const { return 1; }
00340 };
00341 
00342 
00343 class DRIZZLED_API sys_var_str :public sys_var
00344 {
00345 public:
00346   char *value;          // Pointer to allocated string
00347   uint32_t value_length;
00348   sys_update_func update_func;
00349   sys_set_default_func set_default_func;
00350   sys_var_str(const char *name_arg,
00351               sys_check_func check_func_arg,
00352               sys_update_func update_func_arg,
00353               sys_set_default_func set_default_func_arg,
00354               char *value_arg) :
00355     sys_var(name_arg, NULL, check_func_arg),
00356     value(value_arg),
00357     update_func(update_func_arg),
00358     set_default_func(set_default_func_arg)
00359   {  }
00360   bool check(Session *session, set_var *var);
00361   bool update(Session *session, set_var *var)
00362   {
00363     return (*update_func)(session, var);
00364   }
00365   void set_default(Session *session, sql_var_t type)
00366   {
00367     (*set_default_func)(session, type);
00368   }
00369   SHOW_TYPE show_type() { return SHOW_CHAR; }
00370   unsigned char *value_ptr(Session *, sql_var_t)
00371   { return (unsigned char*) value; }
00372   bool check_update_type(Item_result type)
00373   {
00374     return type != STRING_RESULT;   /* Only accept strings */
00375   }
00376   bool check_default(sql_var_t)
00377   { return 0; }
00378 };
00379 
00380 
00381 class DRIZZLED_API sys_var_fs_path :
00382   public sys_var
00383 {
00384   const boost::filesystem::path &value;
00385 public:
00386   sys_var_fs_path(const char *name_arg,
00387                   const boost::filesystem::path& value_arg) :
00388     sys_var(name_arg),
00389     value(value_arg)
00390   { }
00391 
00392   inline void set(char *)
00393   { }
00394 
00395   bool check(Session *, set_var *)
00396   {
00397     return true;
00398   }
00399   bool update(Session *, set_var *)
00400   {
00401     return true;
00402   }
00403   SHOW_TYPE show_type() { return SHOW_CHAR; }
00404   unsigned char *value_ptr(Session *, sql_var_t)
00405   {
00406     return (unsigned char*)(value.file_string().c_str());
00407   }
00408   bool check_update_type(Item_result)
00409   {
00410     return true;
00411   }
00412   bool check_default(sql_var_t) { return true; }
00413   bool is_readonly() const { return true; }
00414 };
00415 
00416 template<class T>
00417 class sys_var_constrained_value :
00418   public sys_var
00419 {
00420   constrained_value<T> &value;
00421   T basic_value;
00422   T default_value;
00423 public:
00424   sys_var_constrained_value(const char *name_arg,
00425                             constrained_value<T> &value_arg) :
00426     sys_var(name_arg),
00427     value(value_arg),
00428     default_value(value_arg.get())
00429   { }
00430 
00431   sys_var_constrained_value(const char *name_arg,
00432                             constrained_value<T> &value_arg,
00433                             sys_after_update_func after_update_func_arg) :
00434     sys_var(name_arg, after_update_func_arg),
00435     value(value_arg),
00436     default_value(value_arg.get())
00437   { }
00438 
00439   sys_var_constrained_value(const char *name_arg,
00440                             constrained_value<T> &value_arg,
00441                             sys_check_func check_func_arg) :
00442     sys_var(name_arg, NULL, check_func_arg),
00443     value(value_arg),
00444     default_value(value_arg.get())
00445   { }
00446 
00447 public:
00448   bool is_readonly() const
00449   {
00450     return false;
00451   }
00452 
00453   SHOW_TYPE show_type() { return SHOW_INT; }
00454 
00455   bool update(Session *, set_var *var)
00456   {
00457     value= uint32_t(var->getInteger());
00458     return false;
00459   }
00460 
00461   bool check_default(sql_var_t)
00462   {
00463     return false;
00464   }
00465 
00466   void set_default(Session *, sql_var_t)
00467   {
00468     value= default_value;
00469   }
00470 
00471   unsigned char *value_ptr(Session *, sql_var_t)
00472   {
00473     basic_value= value.get();
00474     return (unsigned char*)&basic_value;
00475   }
00476 };
00477 
00478 template<>
00479 inline SHOW_TYPE sys_var_constrained_value<uint64_t>::show_type()
00480 {
00481   return SHOW_LONGLONG;
00482 }
00483 
00484 template<>
00485 inline SHOW_TYPE sys_var_constrained_value<int64_t>::show_type()
00486 {
00487   return SHOW_LONGLONG;
00488 }
00489 
00490 template<>
00491 inline SHOW_TYPE sys_var_constrained_value<uint32_t>::show_type()
00492 {
00493   return SHOW_INT;
00494 }
00495 
00496 template<>
00497 inline SHOW_TYPE sys_var_constrained_value<int32_t>::show_type()
00498 {
00499   return SHOW_LONG;
00500 }
00501 
00502 template<>
00503 inline bool sys_var_constrained_value<uint64_t>::update(Session *, set_var *var)
00504 {
00505   value= var->getInteger();
00506   return false;
00507 }
00508 
00509 template<>
00510 inline bool sys_var_constrained_value<uint32_t>::update(Session *, set_var *var)
00511 {
00512   value= uint32_t(var->getInteger());
00513   return false;
00514 }
00515 
00516 template<class T>
00517 class sys_var_constrained_value_readonly :
00518   public sys_var_constrained_value<T>
00519 {
00520 public:
00521   sys_var_constrained_value_readonly(const char *name_arg,
00522                                      constrained_value<T> &value_arg) :
00523     sys_var_constrained_value<T>(name_arg, value_arg)
00524   { }
00525 
00526   sys_var_constrained_value_readonly(const char *name_arg,
00527                                      constrained_value<T> &value_arg,
00528                                      T default_value_arg) :
00529     sys_var_constrained_value<T>(name_arg, value_arg, default_value_arg)
00530   { }
00531 
00532 public:
00533   bool is_readonly() const
00534   {
00535     return true;
00536   }
00537 };
00538 
00539 class DRIZZLED_API sys_var_std_string :
00540   public sys_var
00541 {
00542   std::string &value;
00543   sys_check_func check_func;
00544   sys_update_func update_func;
00545   sys_set_default_func set_default_func;
00546 public:
00547   sys_var_std_string(const std::string &name_arg,
00548                      std::string &value_arg,
00549                      sys_check_func check_func_arg= NULL,
00550                      sys_update_func update_func_arg= NULL) :
00551     sys_var(name_arg),
00552     value(value_arg),
00553     check_func(check_func_arg),
00554     update_func(update_func_arg)
00555   {  }
00556 
00557   inline void set(char *val_in)
00558   {
00559     value= val_in; 
00560   }
00561 
00562   void set_check_func(sys_check_func check_func_arg= NULL)
00563   {
00564     check_func= check_func_arg;
00565   }
00566 
00567   void set_update_func(sys_update_func update_func_arg= NULL)
00568   {
00569     update_func= update_func_arg;
00570   }
00571 
00572   bool check(Session *session, set_var *var);
00573     
00574   bool update(Session *session, set_var *var)
00575   {
00576     if (update_func != NULL)
00577     {
00578       return (*update_func)(session, var);
00579     }
00580     return false;
00581   }
00582   SHOW_TYPE show_type() { return SHOW_CHAR; }
00583   unsigned char *value_ptr(Session *, sql_var_t)
00584   {
00585     return (unsigned char*)(value.c_str());
00586   }
00587   bool check_update_type(Item_result type)
00588   {
00589     return type != STRING_RESULT;   /* Only accept strings */
00590   }
00591   bool check_default(sql_var_t)
00592   { return true; }
00593   bool is_readonly() const { return false; }
00594 };
00595 
00596 class DRIZZLED_API sys_var_const_string :
00597   public sys_var
00598 {
00599   const std::string &value;
00600 public:
00601   sys_var_const_string(const char *name_arg,
00602                        const std::string& value_arg) :
00603     sys_var(name_arg),
00604     value(value_arg)
00605   { }
00606 
00607   inline void set(char *)
00608   { }
00609 
00610   bool check(Session *, set_var *)
00611   {
00612     return true;
00613   }
00614   bool update(Session *, set_var *)
00615   {
00616     return true;
00617   }
00618   SHOW_TYPE show_type() { return SHOW_CHAR; }
00619   unsigned char *value_ptr(Session *, sql_var_t)
00620   {
00621     return (unsigned char*)(value.c_str());
00622   }
00623   bool check_update_type(Item_result)
00624   {
00625     return true;
00626   }
00627   bool check_default(sql_var_t) { return true; }
00628   bool is_readonly() const { return true; }
00629 };
00630 
00631 class DRIZZLED_API sys_var_const_string_val :
00632   public sys_var
00633 {
00634   const std::string value;
00635 public:
00636   sys_var_const_string_val(const char *name_arg,
00637                            const std::string& value_arg) :
00638     sys_var(name_arg),
00639     value(value_arg)
00640   { }
00641 
00642   inline void set(char *)
00643   { }
00644 
00645   bool check(Session *, set_var *)
00646   {
00647     return true;
00648   }
00649   bool update(Session *, set_var *)
00650   {
00651     return true;
00652   }
00653   SHOW_TYPE show_type() { return SHOW_CHAR; }
00654   unsigned char *value_ptr(Session *, sql_var_t)
00655   {
00656     return (unsigned char*)(value.c_str());
00657   }
00658   bool check_update_type(Item_result)
00659   {
00660     return true;
00661   }
00662   bool check_default(sql_var_t) { return true; }
00663   bool is_readonly() const { return true; }
00664 };
00665 
00666 class DRIZZLED_API sys_var_const_str :public sys_var
00667 {
00668   char *value;          // Pointer to const value
00669 public:
00670   sys_var_const_str(const char *name_arg,
00671                     const char *value_arg)
00672     :sys_var(name_arg), value((char*) value_arg)
00673   {  }
00674   inline void set (char *new_value)
00675   {
00676     value= new_value;
00677   }
00678   bool check(Session *, set_var *)
00679   {
00680     return 1;
00681   }
00682   bool update(Session *, set_var *)
00683   {
00684     return 1;
00685   }
00686   SHOW_TYPE show_type() { return SHOW_CHAR; }
00687   unsigned char *value_ptr(Session *, sql_var_t)
00688   {
00689     return (unsigned char*) value;
00690   }
00691   bool check_update_type(Item_result)
00692   {
00693     return 1;
00694   }
00695   bool check_default(sql_var_t)
00696   { return 1; }
00697   bool is_readonly() const { return 1; }
00698 };
00699 
00700 
00701 class DRIZZLED_API sys_var_const_str_ptr :public sys_var
00702 {
00703   char **value;         // Pointer to const value
00704 public:
00705   sys_var_const_str_ptr(const char *name_arg, char **value_arg)
00706     :sys_var(name_arg),value(value_arg)
00707   {  }
00708   bool check(Session *, set_var *)
00709   {
00710     return 1;
00711   }
00712   bool update(Session *, set_var *)
00713   {
00714     return 1;
00715   }
00716   SHOW_TYPE show_type() { return SHOW_CHAR; }
00717   unsigned char *value_ptr(Session *, sql_var_t)
00718   {
00719     return (unsigned char*) *value;
00720   }
00721   bool check_update_type(Item_result)
00722   {
00723     return 1;
00724   }
00725   bool check_default(sql_var_t)
00726   { return 1; }
00727   bool is_readonly(void) const { return 1; }
00728 };
00729 
00730 
00731 class DRIZZLED_API sys_var_session :public sys_var
00732 {
00733 public:
00734   sys_var_session(const char *name_arg,
00735               sys_after_update_func func= NULL)
00736     :sys_var(name_arg, func)
00737   {}
00738   bool check_type(sql_var_t)
00739   { return 0; }
00740   bool check_default(sql_var_t type)
00741   {
00742     return type == OPT_GLOBAL && !option_limits;
00743   }
00744 };
00745 
00746 class DRIZZLED_API sys_var_session_uint32_t :public sys_var_session
00747 {
00748   sys_check_func check_func;
00749 public:
00750   uint32_t drizzle_system_variables::*offset;
00751   sys_var_session_uint32_t(const char *name_arg,
00752                            uint32_t drizzle_system_variables::*offset_arg,
00753                            sys_check_func c_func= NULL,
00754                            sys_after_update_func au_func= NULL)
00755     :sys_var_session(name_arg, au_func), check_func(c_func),
00756     offset(offset_arg)
00757   {  }
00758   bool check(Session *session, set_var *var);
00759   bool update(Session *session, set_var *var);
00760   void set_default(Session *session, sql_var_t type);
00761   SHOW_TYPE show_type() { return SHOW_INT; }
00762   unsigned char *value_ptr(Session *session, sql_var_t type);
00763 };
00764 
00765 
00766 class DRIZZLED_API sys_var_session_ha_rows :public sys_var_session
00767 {
00768 public:
00769   ha_rows drizzle_system_variables::*offset;
00770   sys_var_session_ha_rows(const char *name_arg,
00771                       ha_rows drizzle_system_variables::*offset_arg)
00772     :sys_var_session(name_arg), offset(offset_arg)
00773   {  }
00774   sys_var_session_ha_rows(const char *name_arg,
00775                       ha_rows drizzle_system_variables::*offset_arg,
00776           sys_after_update_func func)
00777     :sys_var_session(name_arg,func), offset(offset_arg)
00778   {  }
00779   bool update(Session *session, set_var *var);
00780   void set_default(Session *session, sql_var_t type);
00781   SHOW_TYPE show_type() { return SHOW_HA_ROWS; }
00782   unsigned char *value_ptr(Session *session, sql_var_t type);
00783 };
00784 
00785 
00786 class DRIZZLED_API sys_var_session_uint64_t :public sys_var_session
00787 {
00788   sys_check_func check_func;
00789 public:
00790   uint64_t drizzle_system_variables::*offset;
00791   bool only_global;
00792   sys_var_session_uint64_t(
00793                            const char *name_arg,
00794                            uint64_t drizzle_system_variables::*offset_arg,
00795                            sys_after_update_func au_func= NULL,
00796                            sys_check_func c_func= NULL)
00797     :sys_var_session(name_arg, au_func),
00798     check_func(c_func),
00799     offset(offset_arg)
00800   {  }
00801   sys_var_session_uint64_t(const char *name_arg,
00802                            uint64_t drizzle_system_variables::*offset_arg,
00803                            sys_after_update_func func,
00804                            bool only_global_arg,
00805                            sys_check_func cfunc= NULL)
00806     :sys_var_session(name_arg, func),
00807     check_func(cfunc),
00808     offset(offset_arg),
00809     only_global(only_global_arg)
00810   {  }
00811   bool update(Session *session, set_var *var);
00812   void set_default(Session *session, sql_var_t type);
00813   SHOW_TYPE show_type() { return SHOW_LONGLONG; }
00814   unsigned char *value_ptr(Session *session, sql_var_t type);
00815   bool check(Session *session, set_var *var);
00816   bool check_default(sql_var_t type)
00817   {
00818     return type == OPT_GLOBAL && !option_limits;
00819   }
00820   bool check_type(sql_var_t type)
00821   {
00822     return (only_global && type != OPT_GLOBAL);
00823   }
00824 };
00825 
00826 class DRIZZLED_API sys_var_session_size_t :public sys_var_session
00827 {
00828   sys_check_func check_func;
00829 public:
00830   size_t drizzle_system_variables::*offset;
00831   bool only_global;
00832   sys_var_session_size_t(const char *name_arg,
00833                          size_t drizzle_system_variables::*offset_arg,
00834                          sys_after_update_func au_func= NULL,
00835                          sys_check_func c_func= NULL)
00836     :sys_var_session(name_arg, au_func),
00837      check_func(c_func),
00838      offset(offset_arg)
00839   {  }
00840   sys_var_session_size_t(const char *name_arg,
00841                          size_t drizzle_system_variables::*offset_arg,
00842                          sys_after_update_func func,
00843                          bool only_global_arg,
00844                          sys_check_func cfunc= NULL)
00845     :sys_var_session(name_arg, func),
00846      check_func(cfunc),
00847      offset(offset_arg),
00848      only_global(only_global_arg)
00849   {  }
00850   bool update(Session *session, set_var *var);
00851   void set_default(Session *session, sql_var_t type);
00852   SHOW_TYPE show_type() { return SHOW_SIZE; }
00853   unsigned char *value_ptr(Session *session, sql_var_t type);
00854   bool check(Session *session, set_var *var);
00855   bool check_default(sql_var_t type)
00856   {
00857     return type == OPT_GLOBAL && !option_limits;
00858   }
00859   bool check_type(sql_var_t type)
00860   {
00861     return (only_global && type != OPT_GLOBAL);
00862   }
00863 };
00864 
00865 
00866 class DRIZZLED_API sys_var_session_bool :public sys_var_session
00867 {
00868 public:
00869   bool drizzle_system_variables::*offset;
00870   sys_var_session_bool(const char *name_arg, bool drizzle_system_variables::*offset_arg)
00871     :sys_var_session(name_arg), offset(offset_arg)
00872   {  }
00873   sys_var_session_bool(const char *name_arg, bool drizzle_system_variables::*offset_arg,
00874        sys_after_update_func func)
00875     :sys_var_session(name_arg,func), offset(offset_arg)
00876   {  }
00877   bool update(Session *session, set_var *var);
00878   void set_default(Session *session, sql_var_t type);
00879   SHOW_TYPE show_type() { return SHOW_MY_BOOL; }
00880   unsigned char *value_ptr(Session *session, sql_var_t type);
00881   bool check(Session *session, set_var *var);
00882   bool check_update_type(Item_result)
00883   { return 0; }
00884 };
00885 
00886 
00887 class DRIZZLED_API sys_var_session_enum :public sys_var_session
00888 {
00889 protected:
00890   uint32_t drizzle_system_variables::*offset;
00891   TYPELIB *enum_names;
00892   sys_check_func check_func;
00893 public:
00894   sys_var_session_enum(const char *name_arg,
00895                    uint32_t drizzle_system_variables::*offset_arg, TYPELIB *typelib,
00896                    sys_after_update_func func= NULL,
00897                    sys_check_func check_f= NULL)
00898     :sys_var_session(name_arg, func), offset(offset_arg),
00899     enum_names(typelib), check_func(check_f)
00900   {  }
00901   bool check(Session *session, set_var *var)
00902   {
00903     int ret= 0;
00904     if (check_func)
00905       ret= (*check_func)(session, var);
00906     return ret ? ret : check_enum(session, var, enum_names);
00907   }
00908   bool update(Session *session, set_var *var);
00909   void set_default(Session *session, sql_var_t type);
00910   SHOW_TYPE show_type() { return SHOW_CHAR; }
00911   unsigned char *value_ptr(Session *session, sql_var_t type);
00912   bool check_update_type(Item_result)
00913   { return 0; }
00914 };
00915 
00916 
00917 class DRIZZLED_API sys_var_session_storage_engine :public sys_var_session
00918 {
00919 protected:
00920   plugin::StorageEngine *drizzle_system_variables::*offset;
00921 public:
00922   sys_var_session_storage_engine(const char *name_arg,
00923                                  plugin::StorageEngine *drizzle_system_variables::*offset_arg)
00924     :sys_var_session(name_arg), offset(offset_arg)
00925   {  }
00926   SHOW_TYPE show_type() { return SHOW_CHAR; }
00927   bool check_update_type(Item_result type)
00928   {
00929     return type != STRING_RESULT;   /* Only accept strings */
00930   }
00931   void set_default(Session *session, sql_var_t type);
00932   bool update(Session *session, set_var *var);
00933   unsigned char *value_ptr(Session *session, sql_var_t type);
00934 };
00935 
00936 class DRIZZLED_API sys_var_session_bit :public sys_var_session
00937 {
00938   sys_check_func check_func;
00939   sys_update_func update_func;
00940 public:
00941   uint64_t bit_flag;
00942   bool reverse;
00943   sys_var_session_bit(const char *name_arg,
00944                   sys_check_func c_func, sys_update_func u_func,
00945                   uint64_t bit, bool reverse_arg=0)
00946     :sys_var_session(name_arg, NULL), check_func(c_func),
00947     update_func(u_func), bit_flag(bit), reverse(reverse_arg)
00948   {  }
00949   bool check(Session *session, set_var *var);
00950   bool update(Session *session, set_var *var);
00951   bool check_update_type(Item_result)
00952   { return 0; }
00953   bool check_type(sql_var_t type) { return type == OPT_GLOBAL; }
00954   SHOW_TYPE show_type() { return SHOW_MY_BOOL; }
00955   unsigned char *value_ptr(Session *session, sql_var_t type);
00956 };
00957 
00958 /* some variables that require special handling */
00959 
00960 class DRIZZLED_API sys_var_timestamp :public sys_var
00961 {
00962 public:
00963   sys_var_timestamp(const char *name_arg)
00964     :sys_var(name_arg, NULL)
00965   {  }
00966   bool update(Session *session, set_var *var);
00967   void set_default(Session *session, sql_var_t type);
00968   bool check_type(sql_var_t type)    { return type == OPT_GLOBAL; }
00969   bool check_default(sql_var_t)
00970   { return 0; }
00971   SHOW_TYPE show_type(void) { return SHOW_LONG; }
00972   unsigned char *value_ptr(Session *session, sql_var_t type);
00973 };
00974 
00975 
00976 class DRIZZLED_API sys_var_last_insert_id :public sys_var
00977 {
00978 public:
00979   sys_var_last_insert_id(const char *name_arg)
00980     :sys_var(name_arg, NULL)
00981   {  }
00982   bool update(Session *session, set_var *var);
00983   bool check_type(sql_var_t type) { return type == OPT_GLOBAL; }
00984   SHOW_TYPE show_type() { return SHOW_LONGLONG; }
00985   unsigned char *value_ptr(Session *session, sql_var_t type);
00986 };
00987 
00988 
00989 class DRIZZLED_API sys_var_collation :public sys_var_session
00990 {
00991 public:
00992   sys_var_collation(const char *name_arg)
00993     :sys_var_session(name_arg, NULL)
00994   { }
00995   SHOW_TYPE show_type() { return SHOW_CHAR; }
00996   bool check_update_type(Item_result type)
00997   {
00998     return ((type != STRING_RESULT) && (type != INT_RESULT));
00999   }
01000   bool check_default(sql_var_t) { return 0; }
01001   virtual void set_default(Session *session, sql_var_t type)= 0;
01002 };
01003 
01004 class DRIZZLED_API sys_var_collation_sv :public sys_var_collation
01005 {
01006   const charset_info_st *drizzle_system_variables::*offset;
01007   const charset_info_st **global_default;
01008 public:
01009   sys_var_collation_sv(const char *name_arg,
01010                        const charset_info_st *drizzle_system_variables::*offset_arg,
01011                        const charset_info_st **global_default_arg)
01012     :sys_var_collation(name_arg),
01013     offset(offset_arg), global_default(global_default_arg)
01014   {
01015     
01016   }
01017   bool update(Session *session, set_var *var);
01018   void set_default(Session *session, sql_var_t type);
01019   unsigned char *value_ptr(Session *session, sql_var_t type);
01020 };
01021 
01022 /* Variable that you can only read from */
01023 
01024 class DRIZZLED_API sys_var_readonly: public sys_var
01025 {
01026 public:
01027   sql_var_t var_type;
01028   SHOW_TYPE show_type_value;
01029   sys_value_ptr_func value_ptr_func;
01030   sys_var_readonly(const char *name_arg, sql_var_t type,
01031        SHOW_TYPE show_type_arg,
01032        sys_value_ptr_func value_ptr_func_arg)
01033     :sys_var(name_arg), var_type(type),
01034        show_type_value(show_type_arg), value_ptr_func(value_ptr_func_arg)
01035   {  }
01036   bool update(Session *, set_var *)
01037   { return 1; }
01038   bool check_default(sql_var_t)
01039   { return 1; }
01040   bool check_type(sql_var_t type) { return type != var_type; }
01041   bool check_update_type(Item_result)
01042   { return 1; }
01043   unsigned char *value_ptr(Session *session, sql_var_t)
01044   {
01045     return (*value_ptr_func)(session);
01046   }
01047   SHOW_TYPE show_type(void) { return show_type_value; }
01048   bool is_readonly(void) const { return 1; }
01049 };
01050 
01051 class DRIZZLED_API sys_var_microseconds :public sys_var_session
01052 {
01053   uint64_t drizzle_system_variables::*offset;
01054 public:
01055   sys_var_microseconds(const char *name_arg,
01056                        uint64_t drizzle_system_variables::*offset_arg):
01057     sys_var_session(name_arg), offset(offset_arg)
01058   {  }
01059   bool check(Session *, set_var *) {return 0;}
01060   bool update(Session *session, set_var *var);
01061   void set_default(Session *session, sql_var_t type);
01062   SHOW_TYPE show_type() { return SHOW_DOUBLE; }
01063   bool check_update_type(Item_result type)
01064   {
01065     return (type != INT_RESULT && type != REAL_RESULT && type != DECIMAL_RESULT);
01066   }
01067 };
01068 
01069 class DRIZZLED_API sys_var_session_lc_time_names :public sys_var_session
01070 {
01071 public:
01072   sys_var_session_lc_time_names(const char *name_arg)
01073     : sys_var_session(name_arg, NULL)
01074   {
01075     
01076   }
01077   SHOW_TYPE show_type() { return SHOW_CHAR; }
01078   bool check_update_type(Item_result type)
01079   {
01080     return ((type != STRING_RESULT) && (type != INT_RESULT));
01081   }
01082   bool check_default(sql_var_t)
01083   { return 0; }
01084   bool update(Session *session, set_var *var);
01085   unsigned char *value_ptr(Session *session, sql_var_t type);
01086   virtual void set_default(Session *session, sql_var_t type);
01087 };
01088 
01089 /* For sql_yacc */
01090 struct sys_var_with_base
01091 {
01092   sys_var* var;
01093   lex_string_t base_name;
01094 };
01095 
01096 /*
01097   Prototypes for helper functions
01098 */
01099 
01100 drizzle_show_var* enumerate_sys_vars(Session*);
01101 void add_sys_var_to_list(sys_var*, option*);
01102 void add_sys_var_to_list(sys_var*);
01103 sys_var* find_sys_var(const std::string&);
01104 
01105 extern sys_var_str sys_var_general_log_path, sys_var_slow_log_path;
01106 
01107 } /* namespace drizzled */