MySQL 5.6.14 Source Code Document
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
set_var.h
Go to the documentation of this file.
1 #ifndef SET_VAR_INCLUDED
2 #define SET_VAR_INCLUDED
3 /* Copyright (c) 2002, 2013 Oracle and/or its affiliates. All rights reserved.
4 
5  This program is free software; you can redistribute it and/or modify
6  it under the terms of the GNU General Public License as published by
7  the Free Software Foundation; version 2 of the License.
8 
9  This program is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  GNU General Public License for more details.
13 
14  You should have received a copy of the GNU General Public License
15  along with this program; if not, write to the Free Software
16  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
17 
23 #include <my_getopt.h>
24 #include <vector>
25 
26 class sys_var;
27 class set_var;
28 class sys_var_pluginvar;
29 class PolyLock;
31 
32 // This include needs to be here since item.h requires enum_var_type :-P
33 #include "item.h" /* Item */
34 #include "sql_class.h" /* THD */
35 
36 extern TYPELIB bool_typelib;
37 
39 {
40  sys_var *first;
41  sys_var *last;
42 };
43 
44 int mysql_add_sys_var_chain(sys_var *chain);
45 int mysql_del_sys_var_chain(sys_var *chain);
46 
54 class sys_var
55 {
56 public:
57  sys_var *next;
58  LEX_CSTRING name;
59  enum flag_enum { GLOBAL, SESSION, ONLY_SESSION, SCOPE_MASK=1023,
60  READONLY=1024, ALLOCATED=2048, INVISIBLE=4096 };
61  static const int PARSE_EARLY= 1;
62  static const int PARSE_NORMAL= 2;
67  enum binlog_status_enum { VARIABLE_NOT_IN_BINLOG,
68  SESSION_VARIABLE_IN_BINLOG } binlog_status;
69 
70 protected:
71  typedef bool (*on_check_function)(sys_var *self, THD *thd, set_var *var);
72  typedef bool (*on_update_function)(sys_var *self, THD *thd, enum_var_type type);
73 
74  int flags;
76  const SHOW_TYPE show_val_type;
79  ptrdiff_t offset;
80  on_check_function on_check;
81  on_update_function on_update;
82  const char *const deprecation_substitute;
84 
85 public:
86  sys_var(sys_var_chain *chain, const char *name_arg, const char *comment,
87  int flag_args, ptrdiff_t off, int getopt_id,
88  enum get_opt_arg_type getopt_arg_type, SHOW_TYPE show_val_type_arg,
89  longlong def_val, PolyLock *lock, enum binlog_status_enum binlog_status_arg,
90  on_check_function on_check_func, on_update_function on_update_func,
91  const char *substitute, int parse_flag);
92 
93  virtual ~sys_var() {}
94 
98  virtual void cleanup() {}
103  virtual sys_var_pluginvar *cast_pluginvar() { return 0; }
104 
105  bool check(THD *thd, set_var *var);
106  uchar *value_ptr(THD *thd, enum_var_type type, LEX_STRING *base);
107  virtual void update_default(longlong new_def_value)
108  { option.def_value= new_def_value; }
109 
115  bool set_default(THD *thd, set_var *var);
116  bool update(THD *thd, set_var *var);
117 
118  SHOW_TYPE show_type() { return show_val_type; }
119  int scope() const { return flags & SCOPE_MASK; }
120  const CHARSET_INFO *charset(THD *thd);
121  bool is_readonly() const { return flags & READONLY; }
122  bool not_visible() const { return flags & INVISIBLE; }
127  bool is_struct() { return option.var_type & GET_ASK_ADDR; }
128  bool is_written_to_binlog(enum_var_type type)
129  { return type != OPT_GLOBAL && binlog_status == SESSION_VARIABLE_IN_BINLOG; }
130  virtual bool check_update_type(Item_result type) = 0;
131  bool check_type(enum_var_type type)
132  {
133  switch (scope())
134  {
135  case GLOBAL: return type != OPT_GLOBAL;
136  case SESSION: return false; // always ok
137  case ONLY_SESSION: return type == OPT_GLOBAL;
138  }
139  return true; // keep gcc happy
140  }
141  bool register_option(std::vector<my_option> *array, int parse_flags)
142  {
143  return (option.id != -1) && (m_parse_flag & parse_flags) &&
144  (array->push_back(option), false);
145  }
146  void do_deprecated_warning(THD *thd);
147 
148 private:
149  virtual bool do_check(THD *thd, set_var *var) = 0;
153  virtual void session_save_default(THD *thd, set_var *var) = 0;
157  virtual void global_save_default(THD *thd, set_var *var) = 0;
158  virtual bool session_update(THD *thd, set_var *var) = 0;
159  virtual bool global_update(THD *thd, set_var *var) = 0;
160 protected:
166  virtual uchar *session_value_ptr(THD *thd, LEX_STRING *base);
167  virtual uchar *global_value_ptr(THD *thd, LEX_STRING *base);
168 
174  uchar *session_var_ptr(THD *thd)
175  { return ((uchar*)&(thd->variables)) + offset; }
176 
177  uchar *global_var_ptr()
178  { return ((uchar*)&global_system_variables) + offset; }
179 };
180 
181 #include "binlog.h" /* binlog_format_typelib */
182 #include "sql_plugin.h" /* SHOW_HA_ROWS, SHOW_MY_BOOL */
183 
184 /****************************************************************************
185  Classes for parsing of the SET command
186 ****************************************************************************/
187 
193 class set_var_base :public Sql_alloc
194 {
195 public:
196  set_var_base() {}
197  virtual ~set_var_base() {}
198  virtual int check(THD *thd)=0; /* To check privileges etc. */
199  virtual int update(THD *thd)=0; /* To set the value */
200  virtual int light_check(THD *thd) { return check(thd); } /* for PS */
201  virtual void print(THD *thd, String *str)=0; /* To self-print */
203  virtual bool is_var_optimizer_trace() const { return false; }
204 };
205 
206 
210 class set_var :public set_var_base
211 {
212 public:
215  enum_var_type type;
216  union
217  {
218  ulonglong ulonglong_value;
219  double double_value;
223  const void *ptr;
224  } save_result;
227  set_var(enum_var_type type_arg, sys_var *var_arg,
228  const LEX_STRING *base_name_arg, Item *value_arg)
229  :var(var_arg), type(type_arg), base(*base_name_arg)
230  {
231  /*
232  If the set value is a field, change it to a string to allow things like
233  SET table_type=MYISAM;
234  */
235  if (value_arg && value_arg->type() == Item::FIELD_ITEM)
236  {
237  Item_field *item= (Item_field*) value_arg;
238  if (item->field_name)
239  {
240  if (!(value= new Item_string(item->field_name,
241  (uint) strlen(item->field_name),
242  system_charset_info))) // names are utf8
243  value= value_arg; /* Give error message later */
244  }
245  else
246  {
247  /* Both Item_field and Item_insert_value will return the type as
248  Item::FIELD_ITEM. If the item->field_name is NULL, we assume the
249  object to be Item_insert_value. */
250  value= value_arg;
251  }
252  }
253  else
254  value= value_arg;
255  }
256  int check(THD *thd);
257  int update(THD *thd);
258  int light_check(THD *thd);
259  void print(THD *thd, String *str); /* To self-print */
260 #ifdef OPTIMIZER_TRACE
261  virtual bool is_var_optimizer_trace() const
262  {
263  extern sys_var *Sys_optimizer_trace_ptr;
264  return var == Sys_optimizer_trace_ptr;
265  }
266 #endif
267 };
268 
269 
270 /* User variables like @my_own_variable */
272 {
273  Item_func_set_user_var *user_var_item;
274 public:
276  :user_var_item(item)
277  {}
278  int check(THD *thd);
279  int update(THD *thd);
280  int light_check(THD *thd);
281  void print(THD *thd, String *str); /* To self-print */
282 };
283 
284 /* For SET PASSWORD */
285 
287 {
288  LEX_USER *user;
289  char *password;
290 public:
291  set_var_password(LEX_USER *user_arg,char *password_arg)
292  :user(user_arg), password(password_arg)
293  {}
294  int check(THD *thd);
295  int update(THD *thd);
296  void print(THD *thd, String *str); /* To self-print */
297 };
298 
299 
300 /* For SET NAMES and SET CHARACTER SET */
301 
303 {
304  int set_cs_flags;
305  const CHARSET_INFO *character_set_client;
306  const CHARSET_INFO *character_set_results;
307  const CHARSET_INFO *collation_connection;
308 public:
309  enum set_cs_flags_enum { SET_CS_NAMES=1, SET_CS_DEFAULT=2, SET_CS_COLLATE=4 };
310  set_var_collation_client(int set_cs_flags_arg,
311  const CHARSET_INFO *client_coll_arg,
312  const CHARSET_INFO *connection_coll_arg,
313  const CHARSET_INFO *result_coll_arg)
314  :set_cs_flags(set_cs_flags_arg),
315  character_set_client(client_coll_arg),
316  character_set_results(result_coll_arg),
317  collation_connection(connection_coll_arg)
318  {}
319  int check(THD *thd);
320  int update(THD *thd);
321  void print(THD *thd, String *str); /* To self-print */
322 };
323 
324 
325 /* optional things, have_* variables */
326 extern SHOW_COMP_OPTION have_csv;
327 extern SHOW_COMP_OPTION have_ndbcluster, have_partitioning;
328 extern SHOW_COMP_OPTION have_profiling;
329 
330 extern SHOW_COMP_OPTION have_ssl, have_symlink, have_dlopen;
331 extern SHOW_COMP_OPTION have_query_cache;
332 extern SHOW_COMP_OPTION have_geometry, have_rtree_keys;
333 extern SHOW_COMP_OPTION have_crypt;
334 extern SHOW_COMP_OPTION have_compress;
335 
336 /*
337  Prototypes for helper functions
338 */
339 
340 SHOW_VAR* enumerate_sys_vars(THD *thd, bool sorted, enum enum_var_type type);
341 
342 sys_var *find_sys_var(THD *thd, const char *str, uint length=0);
343 int sql_set_variables(THD *thd, List<set_var_base> *var_list);
344 
345 bool fix_delay_key_write(sys_var *self, THD *thd, enum_var_type type);
346 
347 sql_mode_t expand_sql_mode(sql_mode_t sql_mode);
348 bool sql_mode_string_representation(THD *thd, sql_mode_t sql_mode, LEX_STRING *ls);
349 
350 extern sys_var *Sys_autocommit_ptr;
351 extern sys_var *Sys_gtid_next_ptr;
352 extern sys_var *Sys_gtid_next_list_ptr;
353 extern sys_var *Sys_gtid_purged_ptr;
354 
355 const CHARSET_INFO *get_old_charset_by_name(const char *old_name);
356 
357 int sys_var_init();
358 int sys_var_add_options(std::vector<my_option> *long_options, int parse_flags);
359 void sys_var_end(void);
360 
361 #endif
362