My Project
set_var.h
Go to the documentation of this file.
00001 #ifndef SET_VAR_INCLUDED
00002 #define SET_VAR_INCLUDED
00003 /* Copyright (c) 2002, 2013, Oracle and/or its affiliates. All rights reserved.
00004 
00005    This program is free software; you can redistribute it and/or modify
00006    it under the terms of the GNU General Public License as published by
00007    the Free Software Foundation; version 2 of the License.
00008 
00009    This program is distributed in the hope that it will be useful,
00010    but WITHOUT ANY WARRANTY; without even the implied warranty of
00011    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012    GNU General Public License for more details.
00013 
00014    You should have received a copy of the GNU General Public License
00015    along with this program; if not, write to the Free Software
00016    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301  USA */
00017 
00023 #include <my_getopt.h>
00024 #include <vector>
00025 
00026 class sys_var;
00027 class set_var;
00028 class sys_var_pluginvar;
00029 class PolyLock;
00030 class Item_func_set_user_var;
00031 
00032 // This include needs to be here since item.h requires enum_var_type :-P
00033 #include "item.h"                          /* Item */
00034 #include "sql_class.h"                     /* THD  */
00035 
00036 extern TYPELIB bool_typelib;
00037 
00038 struct sys_var_chain
00039 {
00040   sys_var *first;
00041   sys_var *last;
00042 };
00043 
00044 int mysql_add_sys_var_chain(sys_var *chain);
00045 int mysql_del_sys_var_chain(sys_var *chain);
00046 
00054 class sys_var
00055 {
00056 public:
00057   sys_var *next;
00058   LEX_CSTRING name;
00059   enum flag_enum { GLOBAL, SESSION, ONLY_SESSION, SCOPE_MASK=1023,
00060                    READONLY=1024, ALLOCATED=2048, INVISIBLE=4096 };
00061   static const int PARSE_EARLY= 1;
00062   static const int PARSE_NORMAL= 2;
00067   enum binlog_status_enum { VARIABLE_NOT_IN_BINLOG,
00068                             SESSION_VARIABLE_IN_BINLOG } binlog_status;
00069 
00070 protected:
00071   typedef bool (*on_check_function)(sys_var *self, THD *thd, set_var *var);
00072   typedef bool (*on_update_function)(sys_var *self, THD *thd, enum_var_type type);
00073 
00074   int flags;            
00075   int m_parse_flag;     
00076   const SHOW_TYPE show_val_type; 
00077   my_option option;     
00078   PolyLock *guard;      
00079   ptrdiff_t offset;     
00080   on_check_function on_check;
00081   on_update_function on_update;
00082   const char *const deprecation_substitute;
00083   bool is_os_charset; 
00084 
00085 public:
00086   sys_var(sys_var_chain *chain, const char *name_arg, const char *comment,
00087           int flag_args, ptrdiff_t off, int getopt_id,
00088           enum get_opt_arg_type getopt_arg_type, SHOW_TYPE show_val_type_arg,
00089           longlong def_val, PolyLock *lock, enum binlog_status_enum binlog_status_arg,
00090           on_check_function on_check_func, on_update_function on_update_func,
00091           const char *substitute, int parse_flag);
00092 
00093   virtual ~sys_var() {}
00094 
00098   virtual void cleanup() {}
00103   virtual sys_var_pluginvar *cast_pluginvar() { return 0; }
00104 
00105   bool check(THD *thd, set_var *var);
00106   uchar *value_ptr(THD *thd, enum_var_type type, LEX_STRING *base);
00107   virtual void update_default(longlong new_def_value)
00108   { option.def_value= new_def_value; }
00109 
00115   bool set_default(THD *thd, set_var *var);
00116   bool update(THD *thd, set_var *var);
00117 
00118   SHOW_TYPE show_type() { return show_val_type; }
00119   int scope() const { return flags & SCOPE_MASK; }
00120   const CHARSET_INFO *charset(THD *thd);
00121   bool is_readonly() const { return flags & READONLY; }
00122   bool not_visible() const { return flags & INVISIBLE; }
00127   bool is_struct() { return option.var_type & GET_ASK_ADDR; }
00128   bool is_written_to_binlog(enum_var_type type)
00129   { return type != OPT_GLOBAL && binlog_status == SESSION_VARIABLE_IN_BINLOG; }
00130   virtual bool check_update_type(Item_result type) = 0;
00131   bool check_type(enum_var_type type)
00132   {
00133     switch (scope())
00134     {
00135     case GLOBAL:       return type != OPT_GLOBAL;
00136     case SESSION:      return false; // always ok
00137     case ONLY_SESSION: return type == OPT_GLOBAL;
00138     }
00139     return true; // keep gcc happy
00140   }
00141   bool register_option(std::vector<my_option> *array, int parse_flags)
00142   {
00143     return (option.id != -1) && (m_parse_flag & parse_flags) &&
00144       (array->push_back(option), false);
00145   }
00146   void do_deprecated_warning(THD *thd);
00147 
00148 private:
00149   virtual bool do_check(THD *thd, set_var *var) = 0;
00153   virtual void session_save_default(THD *thd, set_var *var) = 0;
00157   virtual void global_save_default(THD *thd, set_var *var) = 0;
00158   virtual bool session_update(THD *thd, set_var *var) = 0;
00159   virtual bool global_update(THD *thd, set_var *var) = 0;
00160 protected:
00166   virtual uchar *session_value_ptr(THD *thd, LEX_STRING *base);
00167   virtual uchar *global_value_ptr(THD *thd, LEX_STRING *base);
00168 
00174   uchar *session_var_ptr(THD *thd)
00175   { return ((uchar*)&(thd->variables)) + offset; }
00176 
00177   uchar *global_var_ptr()
00178   { return ((uchar*)&global_system_variables) + offset; }
00179 };
00180 
00181 #include "binlog.h"                           /* binlog_format_typelib */
00182 #include "sql_plugin.h"                    /* SHOW_HA_ROWS, SHOW_MY_BOOL */
00183 
00184 /****************************************************************************
00185   Classes for parsing of the SET command
00186 ****************************************************************************/
00187 
00193 class set_var_base :public Sql_alloc
00194 {
00195 public:
00196   set_var_base() {}
00197   virtual ~set_var_base() {}
00198   virtual int check(THD *thd)=0;           /* To check privileges etc. */
00199   virtual int update(THD *thd)=0;                  /* To set the value */
00200   virtual int light_check(THD *thd) { return check(thd); }   /* for PS */
00201   virtual void print(THD *thd, String *str)=0;  /* To self-print */
00203   virtual bool is_var_optimizer_trace() const { return false; }
00204 };
00205 
00206 
00210 class set_var :public set_var_base
00211 {
00212 public:
00213   sys_var *var; 
00214   Item *value;  
00215   enum_var_type type;
00216   union 
00217   {
00218     ulonglong ulonglong_value;          
00219     double double_value;                
00220     plugin_ref plugin;                  
00221     Time_zone *time_zone;               
00222     LEX_STRING string_value;            
00223     const void *ptr;                    
00224   } save_result;
00225   LEX_STRING base; 
00227   set_var(enum_var_type type_arg, sys_var *var_arg,
00228           const LEX_STRING *base_name_arg, Item *value_arg)
00229     :var(var_arg), type(type_arg), base(*base_name_arg)
00230   {
00231     /*
00232       If the set value is a field, change it to a string to allow things like
00233       SET table_type=MYISAM;
00234     */
00235     if (value_arg && value_arg->type() == Item::FIELD_ITEM)
00236     {
00237       Item_field *item= (Item_field*) value_arg;
00238       if (item->field_name)
00239       {
00240         if (!(value= new Item_string(item->field_name,
00241                                      (uint) strlen(item->field_name),
00242                                      system_charset_info))) // names are utf8
00243           value= value_arg;                     /* Give error message later */
00244       }
00245       else
00246       {
00247         /* Both Item_field and Item_insert_value will return the type as
00248         Item::FIELD_ITEM. If the item->field_name is NULL, we assume the
00249         object to be Item_insert_value. */
00250         value= value_arg;
00251       }
00252     }
00253     else
00254       value= value_arg;
00255   }
00256   int check(THD *thd);
00257   int update(THD *thd);
00258   int light_check(THD *thd);
00259   void print(THD *thd, String *str);    /* To self-print */
00260 #ifdef OPTIMIZER_TRACE
00261   virtual bool is_var_optimizer_trace() const
00262   {
00263     extern sys_var *Sys_optimizer_trace_ptr;
00264     return var == Sys_optimizer_trace_ptr;
00265   }
00266 #endif
00267 };
00268 
00269 
00270 /* User variables like @my_own_variable */
00271 class set_var_user: public set_var_base
00272 {
00273   Item_func_set_user_var *user_var_item;
00274 public:
00275   set_var_user(Item_func_set_user_var *item)
00276     :user_var_item(item)
00277   {}
00278   int check(THD *thd);
00279   int update(THD *thd);
00280   int light_check(THD *thd);
00281   void print(THD *thd, String *str);    /* To self-print */
00282 };
00283 
00284 /* For SET PASSWORD */
00285 
00286 class set_var_password: public set_var_base
00287 {
00288   LEX_USER *user;
00289   char *password;
00290 public:
00291   set_var_password(LEX_USER *user_arg,char *password_arg)
00292     :user(user_arg), password(password_arg)
00293   {}
00294   int check(THD *thd);
00295   int update(THD *thd);
00296   void print(THD *thd, String *str);    /* To self-print */
00297 };
00298 
00299 
00300 /* For SET NAMES and SET CHARACTER SET */
00301 
00302 class set_var_collation_client: public set_var_base
00303 {
00304   int   set_cs_flags;
00305   const CHARSET_INFO *character_set_client;
00306   const CHARSET_INFO *character_set_results;
00307   const CHARSET_INFO *collation_connection;
00308 public:
00309   enum  set_cs_flags_enum { SET_CS_NAMES=1, SET_CS_DEFAULT=2, SET_CS_COLLATE=4 };
00310   set_var_collation_client(int set_cs_flags_arg,
00311                            const CHARSET_INFO *client_coll_arg,
00312                            const CHARSET_INFO *connection_coll_arg,
00313                            const CHARSET_INFO *result_coll_arg)
00314     :set_cs_flags(set_cs_flags_arg),
00315      character_set_client(client_coll_arg),
00316      character_set_results(result_coll_arg),
00317      collation_connection(connection_coll_arg)
00318   {}
00319   int check(THD *thd);
00320   int update(THD *thd);
00321   void print(THD *thd, String *str);    /* To self-print */
00322 };
00323 
00324 
00325 /* optional things, have_* variables */
00326 extern SHOW_COMP_OPTION have_csv;
00327 extern SHOW_COMP_OPTION have_ndbcluster, have_partitioning;
00328 extern SHOW_COMP_OPTION have_profiling;
00329 
00330 extern SHOW_COMP_OPTION have_ssl, have_symlink, have_dlopen;
00331 extern SHOW_COMP_OPTION have_query_cache;
00332 extern SHOW_COMP_OPTION have_geometry, have_rtree_keys;
00333 extern SHOW_COMP_OPTION have_crypt;
00334 extern SHOW_COMP_OPTION have_compress;
00335 
00336 /*
00337   Prototypes for helper functions
00338 */
00339 
00340 SHOW_VAR* enumerate_sys_vars(THD *thd, bool sorted, enum enum_var_type type);
00341 
00342 sys_var *find_sys_var(THD *thd, const char *str, uint length=0);
00343 int sql_set_variables(THD *thd, List<set_var_base> *var_list);
00344 
00345 bool fix_delay_key_write(sys_var *self, THD *thd, enum_var_type type);
00346 
00347 sql_mode_t expand_sql_mode(sql_mode_t sql_mode);
00348 bool sql_mode_string_representation(THD *thd, sql_mode_t sql_mode, LEX_STRING *ls);
00349 
00350 extern sys_var *Sys_autocommit_ptr;
00351 extern sys_var *Sys_gtid_next_ptr;
00352 extern sys_var *Sys_gtid_next_list_ptr;
00353 extern sys_var *Sys_gtid_purged_ptr;
00354 
00355 const CHARSET_INFO *get_old_charset_by_name(const char *old_name);
00356 
00357 int sys_var_init();
00358 int sys_var_add_options(std::vector<my_option> *long_options, int parse_flags);
00359 void sys_var_end(void);
00360 
00361 #endif
00362 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines