Drizzled Public API Documentation

sys_var.cc
1 /* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2  * vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
3  *
4  * Copyright (C) 2008 Sun Microsystems, Inc.
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; version 2 of the License.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18  */
19 
41 #include <config.h>
42 #include <drizzled/option.h>
43 #include <drizzled/error.h>
44 #include <drizzled/gettext.h>
45 #include <drizzled/data_home.h>
46 #include <drizzled/set_var.h>
47 #include <drizzled/session.h>
48 #include <drizzled/session/times.h>
49 #include <drizzled/sql_base.h>
50 #include <drizzled/lock.h>
51 #include <drizzled/item/uint.h>
52 #include <drizzled/item/null.h>
53 #include <drizzled/item/float.h>
54 #include <drizzled/item/string.h>
55 #include <drizzled/plugin.h>
56 #include <drizzled/version.h>
57 #include <drizzled/internal/m_string.h>
58 #include <drizzled/pthread_globals.h>
59 #include <drizzled/charset.h>
60 #include <drizzled/transaction_services.h>
61 #include <drizzled/constrained_value.h>
62 #include <drizzled/visibility.h>
63 #include <drizzled/typelib.h>
64 #include <drizzled/plugin/storage_engine.h>
65 #include <drizzled/system_variables.h>
66 #include <drizzled/catalog/instance.h>
67 
68 #include <cstdio>
69 #include <map>
70 #include <vector>
71 #include <algorithm>
72 
73 using namespace std;
74 
75 namespace drizzled {
76 
77 namespace internal
78 {
79  extern bool timed_mutexes;
80 }
81 
82 extern plugin::StorageEngine *myisam_engine;
83 extern bool timed_mutexes;
84 
85 extern struct option my_long_options[];
86 extern const charset_info_st *character_set_filesystem;
87 extern size_t my_thread_stack_size;
88 
89 typedef map<string, sys_var *> SystemVariableMap;
90 static SystemVariableMap system_variable_map;
91 extern char *opt_drizzle_tmpdir;
92 
93 extern TYPELIB tx_isolation_typelib;
94 
95 namespace
96 {
97  static size_t revno= DRIZZLE_VC_REVNO;
98  static size_t release_id= DRIZZLE_RELEASE_ID;
99 }
100 
101 const char *bool_type_names[]= { "OFF", "ON", NULL };
102 TYPELIB bool_typelib=
103 {
104  array_elements(bool_type_names)-1, "", bool_type_names, NULL
105 };
106 
107 static bool set_option_bit(Session*, set_var*);
108 static bool set_option_autocommit(Session*, set_var*);
109 static int check_pseudo_thread_id(Session*, set_var*);
110 static int check_tx_isolation(Session*, set_var*);
111 static void fix_tx_isolation(Session*, sql_var_t);
112 static int check_completion_type(Session*, set_var*);
113 static void fix_max_join_size(Session*, sql_var_t);
114 static void fix_session_mem_root(Session*, sql_var_t);
115 void throw_bounds_warning(Session*, bool fixed, bool unsignd, const std::string &name, int64_t);
116 static unsigned char *get_error_count(Session*);
117 static unsigned char *get_warning_count(Session*);
118 static unsigned char *get_tmpdir(Session*);
119 
120 /*
121  Variable definition list
122 
123  These are variables that can be set from the command line, in
124  alphabetic order.
125 
126  The variables are linked into the list. A variable is added to
127  it in the constructor (see sys_var class for details).
128 */
129 static sys_var_session_uint64_t
130 sys_auto_increment_increment("auto_increment_increment", &drizzle_system_variables::auto_increment_increment);
131 static sys_var_session_uint64_t
132 sys_auto_increment_offset("auto_increment_offset", &drizzle_system_variables::auto_increment_offset);
133 
134 static sys_var_fs_path sys_basedir("basedir", basedir);
135 static sys_var_fs_path sys_pid_file("pid_file", pid_file);
136 static sys_var_fs_path sys_plugin_dir("plugin_dir", plugin_dir);
137 
138 static sys_var_size_t_ptr sys_thread_stack_size("thread_stack", &my_thread_stack_size);
139 static sys_var_constrained_value_readonly<uint32_t> sys_back_log("back_log", back_log);
140 
141 static sys_var_session_uint64_t sys_bulk_insert_buff_size("bulk_insert_buffer_size", &drizzle_system_variables::bulk_insert_buff_size);
142 static sys_var_session_uint32_t sys_completion_type("completion_type", &drizzle_system_variables::completion_type, check_completion_type);
143 static sys_var_collation_sv
144 sys_collation_server("collation_server", &drizzle_system_variables::collation_server, &default_charset_info);
145 static sys_var_fs_path sys_datadir("datadir", getDataHome());
146 
147 static sys_var_session_uint64_t sys_join_buffer_size("join_buffer_size", &drizzle_system_variables::join_buff_size);
148 static sys_var_session_uint32_t sys_max_allowed_packet("max_allowed_packet", &drizzle_system_variables::max_allowed_packet);
149 static sys_var_session_uint64_t sys_max_error_count("max_error_count", &drizzle_system_variables::max_error_count);
150 static sys_var_session_uint64_t sys_max_heap_table_size("max_heap_table_size", &drizzle_system_variables::max_heap_table_size);
151 static sys_var_session_uint64_t sys_pseudo_thread_id("pseudo_thread_id", &drizzle_system_variables::pseudo_thread_id, 0, check_pseudo_thread_id);
152 static sys_var_session_ha_rows sys_max_join_size("max_join_size", &drizzle_system_variables::max_join_size, fix_max_join_size);
153 static sys_var_session_uint64_t sys_max_seeks_for_key("max_seeks_for_key", &drizzle_system_variables::max_seeks_for_key);
154 static sys_var_session_uint64_t sys_max_length_for_sort_data("max_length_for_sort_data", &drizzle_system_variables::max_length_for_sort_data);
155 static sys_var_session_size_t sys_max_sort_length("max_sort_length", &drizzle_system_variables::max_sort_length);
156 static sys_var_uint64_t_ptr sys_max_write_lock_count("max_write_lock_count", &max_write_lock_count);
157 static sys_var_session_uint64_t sys_min_examined_row_limit("min_examined_row_limit", &drizzle_system_variables::min_examined_row_limit);
158 
159 static sys_var_session_bool sys_optimizer_prune_level("optimizer_prune_level", &drizzle_system_variables::optimizer_prune_level);
160 static sys_var_session_uint32_t sys_optimizer_search_depth("optimizer_search_depth", &drizzle_system_variables::optimizer_search_depth);
161 
162 static sys_var_session_uint64_t sys_preload_buff_size("preload_buffer_size", &drizzle_system_variables::preload_buff_size);
163 static sys_var_session_uint32_t sys_read_buff_size("read_buffer_size", &drizzle_system_variables::read_buff_size);
164 static sys_var_session_uint32_t sys_read_rnd_buff_size("read_rnd_buffer_size", &drizzle_system_variables::read_rnd_buff_size);
165 static sys_var_session_uint32_t sys_div_precincrement("div_precision_increment", &drizzle_system_variables::div_precincrement);
166 
167 static sys_var_session_size_t sys_range_alloc_block_size("range_alloc_block_size", &drizzle_system_variables::range_alloc_block_size);
168 
169 static sys_var_session_bool sys_replicate_query("replicate_query", &drizzle_system_variables::replicate_query);
170 
171 static sys_var_session_uint32_t sys_query_alloc_block_size("query_alloc_block_size", &drizzle_system_variables::query_alloc_block_size, NULL, fix_session_mem_root);
172 static sys_var_session_uint32_t sys_query_prealloc_size("query_prealloc_size", &drizzle_system_variables::query_prealloc_size, NULL, fix_session_mem_root);
173 static sys_var_readonly sys_tmpdir("tmpdir", OPT_GLOBAL, SHOW_CHAR, get_tmpdir);
174 
175 static sys_var_fs_path sys_secure_file_priv("secure_file_priv", secure_file_priv);
176 static sys_var_const_str_ptr sys_scheduler("scheduler", (char**)&opt_scheduler);
177 
178 static sys_var_uint32_t_ptr sys_server_id("server_id", &server_id);
179 
180 static sys_var_const_string sys_server_uuid("server_uuid", server_uuid);
181 
182 static sys_var_session_size_t sys_sort_buffer("sort_buffer_size", &drizzle_system_variables::sortbuff_size);
183 
184 static sys_var_size_t_ptr_readonly sys_transaction_message_threshold("transaction_message_threshold", &transaction_message_threshold);
185 
186 static sys_var_session_storage_engine sys_storage_engine("storage_engine", &drizzle_system_variables::storage_engine);
187 static sys_var_size_t_ptr sys_table_def_size("table_definition_cache", &table_def_size);
188 static sys_var_uint64_t_ptr sys_table_cache_size("table_open_cache", &table_cache_size);
189 static sys_var_uint64_t_ptr sys_table_lock_wait_timeout("table_lock_wait_timeout", &table_lock_wait_timeout);
190 static sys_var_session_enum sys_tx_isolation("tx_isolation",
191  &drizzle_system_variables::tx_isolation,
192  &tx_isolation_typelib,
193  fix_tx_isolation,
194  check_tx_isolation);
195 static sys_var_session_uint64_t sys_tmp_table_size("tmp_table_size",
196  &drizzle_system_variables::tmp_table_size);
197 static sys_var_bool_ptr sys_timed_mutexes("timed_mutexes", &internal::timed_mutexes);
198 static sys_var_const_str sys_version("version", version().c_str());
199 
200 static sys_var_const_str sys_version_comment("version_comment", COMPILATION_COMMENT);
201 static sys_var_const_str sys_version_compile_machine("version_compile_machine", HOST_CPU);
202 static sys_var_const_str sys_version_compile_os("version_compile_os", HOST_OS);
203 static sys_var_const_str sys_version_compile_vendor("version_compile_vendor", HOST_VENDOR);
204 
205 /* Variables that are bits in Session */
206 
207 sys_var_session_bit sys_autocommit("autocommit", 0, set_option_autocommit, OPTION_NOT_AUTOCOMMIT, 1);
208 static sys_var_session_bit sys_big_selects("sql_big_selects", 0, set_option_bit, OPTION_BIG_SELECTS);
209 static sys_var_session_bit sys_sql_warnings("sql_warnings", 0, set_option_bit, OPTION_WARNINGS);
210 static sys_var_session_bit sys_sql_notes("sql_notes", 0, set_option_bit, OPTION_SQL_NOTES);
211 static sys_var_session_bit sys_buffer_results("sql_buffer_result", 0, set_option_bit, OPTION_BUFFER_RESULT);
212 static sys_var_session_bit sys_foreign_key_checks("foreign_key_checks", 0, set_option_bit, OPTION_NO_FOREIGN_KEY_CHECKS, 1);
213 static sys_var_session_bit sys_unique_checks("unique_checks", 0, set_option_bit, OPTION_RELAXED_UNIQUE_CHECKS, 1);
214 /* Local state variables */
215 
216 static sys_var_session_ha_rows sys_select_limit("sql_select_limit", &drizzle_system_variables::select_limit);
217 static sys_var_timestamp sys_timestamp("timestamp");
218 static sys_var_last_insert_id
219 sys_last_insert_id("last_insert_id");
220 /*
221  identity is an alias for last_insert_id(), so that we are compatible
222  with Sybase
223 */
224 static sys_var_last_insert_id sys_identity("identity");
225 
226 static sys_var_session_lc_time_names sys_lc_time_names("lc_time_names");
227 
228 /*
229  We want statements referring explicitly to @@session.insert_id to be
230  unsafe, because insert_id is modified internally by the slave sql
231  thread when NULL values are inserted in an AUTO_INCREMENT column.
232  This modification interfers with the value of the
233  @@session.insert_id variable if @@session.insert_id is referred
234  explicitly by an insert statement (as is seen by executing "SET
235  @@session.insert_id=0; CREATE TABLE t (a INT, b INT KEY
236  AUTO_INCREMENT); INSERT INTO t(a) VALUES (@@session.insert_id);" in
237  statement-based logging mode: t will be different on master and
238  slave).
239 */
240 static sys_var_readonly sys_error_count("error_count", OPT_SESSION, SHOW_INT, get_error_count);
241 static sys_var_readonly sys_warning_count("warning_count", OPT_SESSION, SHOW_INT, get_warning_count);
242 
243 sys_var_session_uint64_t sys_group_concat_max_len("group_concat_max_len", &drizzle_system_variables::group_concat_max_len);
244 
245 /* Global read-only variable containing hostname */
246 static sys_var_const_string sys_hostname("hostname", getServerHostname());
247 
248 static sys_var_const_str sys_revid("vc_revid", DRIZZLE_VC_REVID);
249 static sys_var_const_str sys_branch("vc_branch", DRIZZLE_VC_BRANCH);
250 static sys_var_size_t_ptr_readonly sys_revno("vc_revno", &revno);
251 static sys_var_size_t_ptr_readonly sys_release_id("vc_release_id", &release_id);
252 
253 bool sys_var::check(Session *session, set_var *var)
254 {
255  if (check_func)
256  {
257  int res= (*check_func)(session, var);
258  if (res < 0)
259  my_error(ER_WRONG_VALUE_FOR_VAR, MYF(0), getName().c_str(), var->value->str_value.ptr());
260  return res;
261  }
262  var->updateValue();
263  return 0;
264 }
265 
266 bool sys_var_str::check(Session *session, set_var *var)
267 {
268  if (not check_func)
269  return 0;
270 
271  int res= (*check_func)(session, var);
272  if (res < 0)
273  my_error(ER_WRONG_VALUE_FOR_VAR, MYF(0), getName().c_str(), var->value->str_value.ptr());
274  return res;
275 }
276 
277 bool sys_var_std_string::check(Session *session, set_var *var)
278 {
279  if (not check_func)
280  return false;
281 
282  if ((*check_func)(session, var))
283  {
284  my_error(ER_WRONG_VALUE_FOR_VAR, MYF(0), getName().c_str(), var->value->str_value.ptr());
285  return true;
286  }
287  return false;
288 }
289 
290 /*
291  Functions to check and update variables
292 */
293 
294 
299 static void fix_max_join_size(Session *session, sql_var_t type)
300 {
301  if (type != OPT_GLOBAL)
302  {
303  if (session->variables.max_join_size == HA_POS_ERROR)
304  session->options|= OPTION_BIG_SELECTS;
305  else
306  session->options&= ~OPTION_BIG_SELECTS;
307  }
308 }
309 
310 
315 static int check_tx_isolation(Session *session, set_var *var)
316 {
317  if (var->type == OPT_DEFAULT && (session->server_status & SERVER_STATUS_IN_TRANS))
318  {
319  my_error(ER_CANT_CHANGE_TX_ISOLATION, MYF(0));
320  return 1;
321  }
322  return 0;
323 }
324 
325 /*
326  If one doesn't use the SESSION modifier, the isolation level
327  is only active for the next command.
328 */
329 static void fix_tx_isolation(Session *session, sql_var_t type)
330 {
331  if (type == OPT_SESSION)
332  session->session_tx_isolation= (enum_tx_isolation) session->variables.tx_isolation;
333 }
334 
335 static int check_completion_type(Session *, set_var *var)
336 {
337  int64_t val= var->value->val_int();
338  if (val < 0 || val > 2)
339  {
340  char buf[64];
341  my_error(ER_WRONG_VALUE_FOR_VAR, MYF(0), var->var->getName().c_str(), internal::llstr(val, buf));
342  return 1;
343  }
344  return 0;
345 }
346 
347 
348 static void fix_session_mem_root(Session *session, sql_var_t type)
349 {
350  if (type != OPT_GLOBAL)
351  session->mem.reset_defaults(session->variables.query_alloc_block_size, session->variables.query_prealloc_size);
352 }
353 
354 
355 void throw_bounds_warning(Session *session, bool fixed, bool unsignd, const std::string &name, int64_t val)
356 {
357  if (not fixed)
358  return;
359  char buf[DECIMAL_LONGLONG_DIGITS];
360 
361  if (unsignd)
362  internal::ullstr((uint64_t) val, buf);
363  else
364  internal::llstr(val, buf);
365 
366  push_warning_printf(session, DRIZZLE_ERROR::WARN_LEVEL_ERROR,
367  ER_TRUNCATED_WRONG_VALUE, ER(ER_TRUNCATED_WRONG_VALUE), name.c_str(), buf);
368 }
369 
370 uint64_t fix_unsigned(Session *session, uint64_t num, const option& option_limits)
371 {
372  bool fixed= false;
373  uint64_t out= getopt_ull_limit_value(num, option_limits, &fixed);
374 
375  throw_bounds_warning(session, fixed, true, option_limits.name, (int64_t) num);
376  return out;
377 }
378 
379 
380 static size_t fix_size_t(Session *session, size_t num, const option& option_limits)
381 {
382  bool fixed= false;
383  size_t out= (size_t)getopt_ull_limit_value(num, option_limits, &fixed);
384 
385  throw_bounds_warning(session, fixed, true, option_limits.name, (int64_t) num);
386  return out;
387 }
388 
389 bool sys_var_uint32_t_ptr::check(Session *, set_var *var)
390 {
391  var->updateValue();
392  return 0;
393 }
394 
395 bool sys_var_uint32_t_ptr::update(Session *session, set_var *var)
396 {
397  uint64_t tmp= var->getInteger();
398  boost::mutex::scoped_lock scopedLock(session->catalog().systemVariableLock());
399 
400  if (option_limits)
401  {
402  uint32_t newvalue= (uint32_t) fix_unsigned(session, tmp, *option_limits);
403  if (static_cast<uint64_t>(newvalue) == tmp)
404  *value= newvalue;
405  }
406  else
407  {
408  *value= static_cast<uint32_t>(tmp);
409  }
410 
411  return 0;
412 }
413 
414 
415 void sys_var_uint32_t_ptr::set_default(Session *session, sql_var_t)
416 {
417  bool not_used;
418  boost::mutex::scoped_lock scopedLock(session->catalog().systemVariableLock());
419  *value= (uint32_t)getopt_ull_limit_value((uint32_t) option_limits->def_value, *option_limits, &not_used);
420 }
421 
422 
423 bool sys_var_uint64_t_ptr::update(Session *session, set_var *var)
424 {
425  uint64_t tmp= var->getInteger();
426  boost::mutex::scoped_lock scopedLock(session->catalog().systemVariableLock());
427 
428  if (option_limits)
429  {
430  uint64_t newvalue= fix_unsigned(session, tmp, *option_limits);
431  if (newvalue==tmp)
432  *value= newvalue;
433  }
434  else
435  {
436  *value= tmp;
437  }
438 
439  return 0;
440 }
441 
442 
443 void sys_var_uint64_t_ptr::set_default(Session *session, sql_var_t)
444 {
445  if (have_default_value)
446  {
447  *value= default_value;
448  }
449  else
450  {
451  bool not_used;
452  boost::mutex::scoped_lock scopedLock(session->catalog().systemVariableLock());
453  *value= getopt_ull_limit_value((uint64_t) option_limits->def_value, *option_limits, &not_used);
454  }
455 }
456 
457 
458 bool sys_var_size_t_ptr::update(Session *session, set_var *var)
459 {
460  size_t tmp= size_t(var->getInteger());
461 
462  boost::mutex::scoped_lock scopedLock(session->catalog().systemVariableLock());
463 
464  if (option_limits)
465  *value= fix_size_t(session, tmp, *option_limits);
466  else
467  *value= tmp;
468 
469  return 0;
470 }
471 
472 
473 void sys_var_size_t_ptr::set_default(Session *session, sql_var_t)
474 {
475  bool not_used;
476  boost::mutex::scoped_lock scopedLock(session->catalog().systemVariableLock());
477  *value= (size_t)getopt_ull_limit_value((size_t) option_limits->def_value, *option_limits, &not_used);
478 }
479 
480 bool sys_var_bool_ptr::check(Session *session, set_var *var)
481 {
482  return check_enum(session, var, &bool_typelib);
483 }
484 
485 bool sys_var_bool_ptr::update(Session *, set_var *var)
486 {
487  *value= bool(var->getInteger());
488  return 0;
489 }
490 
491 
492 void sys_var_bool_ptr::set_default(Session *, sql_var_t)
493 {
494  *value= default_value;
495 }
496 
497 
498 /*
499  32 bit types for session variables
500 */
501 bool sys_var_session_uint32_t::check(Session *session, set_var *var)
502 {
503  var->updateValue();
504  return (check_func && (*check_func)(session, var));
505 }
506 
507 bool sys_var_session_uint32_t::update(Session *session, set_var *var)
508 {
509  uint64_t tmp= var->getInteger();
510 
511  /* Don't use bigger value than given with --maximum-variable-name=.. */
512  if ((uint32_t) tmp > max_system_variables.*offset)
513  {
514  throw_bounds_warning(session, true, true, getName(), (int64_t) tmp);
515  tmp= max_system_variables.*offset;
516  }
517 
518  if (option_limits)
519  tmp= (uint32_t) fix_unsigned(session, tmp, *option_limits);
520  else if (tmp > UINT32_MAX)
521  {
522  tmp= UINT32_MAX;
523  throw_bounds_warning(session, true, true, getName(), int64_t(var->getInteger()));
524  }
525 
526  if (var->type == OPT_GLOBAL)
527  global_system_variables.*offset= (uint32_t) tmp;
528  else
529  session->variables.*offset= (uint32_t) tmp;
530 
531  return 0;
532  }
533 
534 
535  void sys_var_session_uint32_t::set_default(Session *session, sql_var_t type)
536  {
537  if (type == OPT_GLOBAL)
538  {
539  bool not_used;
540  /* We will not come here if option_limits is not set */
541  global_system_variables.*offset=
542  (uint32_t) getopt_ull_limit_value((uint32_t) option_limits->def_value, *option_limits, &not_used);
543  }
544  else
545  session->variables.*offset= global_system_variables.*offset;
546  }
547 
548 
549 unsigned char *sys_var_session_uint32_t::value_ptr(Session *session, sql_var_t type)
550 {
551  return type == OPT_GLOBAL
552  ? (unsigned char*) &(global_system_variables.*offset)
553  : (unsigned char*) &(session->variables.*offset);
554 }
555 
556 
557 bool sys_var_session_ha_rows::update(Session *session, set_var *var)
558 {
559  uint64_t tmp= var->getInteger();
560 
561  /* Don't use bigger value than given with --maximum-variable-name=.. */
562  if ((ha_rows) tmp > max_system_variables.*offset)
563  tmp= max_system_variables.*offset;
564 
565  if (option_limits)
566  tmp= (ha_rows) fix_unsigned(session, tmp, *option_limits);
567  if (var->type == OPT_GLOBAL)
568  {
569  /* Lock is needed to make things safe on 32 bit systems */
570  boost::mutex::scoped_lock scopedLock(session->catalog().systemVariableLock());
571  global_system_variables.*offset= (ha_rows) tmp;
572  }
573  else
574  {
575  session->variables.*offset= (ha_rows) tmp;
576  }
577 
578  return 0;
579 }
580 
581 
582 void sys_var_session_ha_rows::set_default(Session *session, sql_var_t type)
583 {
584  if (type == OPT_GLOBAL)
585  {
586  bool not_used;
587  /* We will not come here if option_limits is not set */
588  boost::mutex::scoped_lock scopedLock(session->catalog().systemVariableLock());
589  global_system_variables.*offset=
590  (ha_rows) getopt_ull_limit_value((ha_rows) option_limits->def_value, *option_limits, &not_used);
591  }
592  else
593  {
594  session->variables.*offset= global_system_variables.*offset;
595  }
596 }
597 
598 
599 unsigned char *sys_var_session_ha_rows::value_ptr(Session *session, sql_var_t type)
600 {
601  return type == OPT_GLOBAL
602  ? (unsigned char*) &(global_system_variables.*offset)
603  : (unsigned char*) &(session->variables.*offset);
604 }
605 
606 bool sys_var_session_uint64_t::check(Session *session, set_var *var)
607 {
608  var->updateValue();
609  return (check_func && (*check_func)(session, var));
610 }
611 
612 bool sys_var_session_uint64_t::update(Session *session, set_var *var)
613 {
614  uint64_t tmp= var->getInteger();
615 
616  if (tmp > max_system_variables.*offset)
617  {
618  throw_bounds_warning(session, true, true, getName(), (int64_t) tmp);
619  tmp= max_system_variables.*offset;
620  }
621 
622  if (option_limits)
623  tmp= fix_unsigned(session, tmp, *option_limits);
624  if (var->type == OPT_GLOBAL)
625  {
626  /* Lock is needed to make things safe on 32 bit systems */
627  boost::mutex::scoped_lock scopedLock(session->catalog().systemVariableLock());
628  global_system_variables.*offset= (uint64_t) tmp;
629  }
630  else
631  {
632  session->variables.*offset= (uint64_t) tmp;
633  }
634 
635  return 0;
636 }
637 
638 
639 void sys_var_session_uint64_t::set_default(Session *session, sql_var_t type)
640 {
641  if (type == OPT_GLOBAL)
642  {
643  bool not_used;
644  boost::mutex::scoped_lock scopedLock(session->catalog().systemVariableLock());
645  global_system_variables.*offset=
646  getopt_ull_limit_value((uint64_t) option_limits->def_value, *option_limits, &not_used);
647  }
648  else
649  {
650  session->variables.*offset= global_system_variables.*offset;
651  }
652 }
653 
654 
655 unsigned char *sys_var_session_uint64_t::value_ptr(Session *session, sql_var_t type)
656 {
657  return type == OPT_GLOBAL
658  ? (unsigned char*) &(global_system_variables.*offset)
659  : (unsigned char*) &(session->variables.*offset);
660 }
661 
662 bool sys_var_session_size_t::check(Session *session, set_var *var)
663 {
664  var->updateValue();
665  return (check_func && (*check_func)(session, var));
666 }
667 
668 bool sys_var_session_size_t::update(Session *session, set_var *var)
669 {
670  size_t tmp= size_t(var->getInteger());
671 
672  if (tmp > max_system_variables.*offset)
673  tmp= max_system_variables.*offset;
674 
675  if (option_limits)
676  tmp= fix_size_t(session, tmp, *option_limits);
677  if (var->type == OPT_GLOBAL)
678  {
679  /* Lock is needed to make things safe on 32 bit systems */
680  boost::mutex::scoped_lock scopedLock(session->catalog().systemVariableLock());
681  global_system_variables.*offset= tmp;
682  }
683  else
684  {
685  session->variables.*offset= tmp;
686  }
687 
688  return 0;
689 }
690 
691 
692 void sys_var_session_size_t::set_default(Session *session, sql_var_t type)
693 {
694  if (type == OPT_GLOBAL)
695  {
696  bool not_used;
697  boost::mutex::scoped_lock scopedLock(session->catalog().systemVariableLock());
698  global_system_variables.*offset=
699  (size_t)getopt_ull_limit_value((size_t) option_limits->def_value, *option_limits, &not_used);
700  }
701  else
702  {
703  session->variables.*offset= global_system_variables.*offset;
704  }
705 }
706 
707 
708 unsigned char *sys_var_session_size_t::value_ptr(Session *session, sql_var_t type)
709 {
710  return type == OPT_GLOBAL
711  ? (unsigned char*) &(global_system_variables.*offset)
712  : (unsigned char*) &(session->variables.*offset);
713 }
714 
715 bool sys_var_session_bool::check(Session *session, set_var *var)
716 {
717  return check_enum(session, var, &bool_typelib);
718 }
719 
720 bool sys_var_session_bool::update(Session *session, set_var *var)
721 {
722  if (var->type == OPT_GLOBAL)
723  global_system_variables.*offset= bool(var->getInteger());
724  else
725  session->variables.*offset= bool(var->getInteger());
726 
727  return 0;
728 }
729 
730 
731 void sys_var_session_bool::set_default(Session *session, sql_var_t type)
732 {
733  if (type == OPT_GLOBAL)
734  global_system_variables.*offset= (bool) option_limits->def_value;
735  else
736  session->variables.*offset= global_system_variables.*offset;
737 }
738 
739 
740 unsigned char *sys_var_session_bool::value_ptr(Session *session, sql_var_t type)
741 {
742  return type == OPT_GLOBAL
743  ? (unsigned char*) &(global_system_variables.*offset)
744  : (unsigned char*) &(session->variables.*offset);
745 }
746 
747 
748 bool sys_var::check_enum(Session *, set_var *var, const TYPELIB *enum_names)
749 {
750  char buff[STRING_BUFFER_USUAL_SIZE];
751  const char *value;
752  String str(buff, sizeof(buff), system_charset_info), *res;
753 
754  if (var->value->result_type() == STRING_RESULT)
755  {
756  res= var->value->val_str(&str);
757  if (res == NULL)
758  {
759  value= "NULL";
760  goto err;
761  }
762 
763  uint64_t tmp_val= enum_names->find_type(res->ptr(), res->length(), true);
764  if (tmp_val == 0)
765  {
766  value= res->c_ptr();
767  goto err;
768  }
769  var->setValue(tmp_val-1);
770  }
771  else
772  {
773  uint64_t tmp= var->value->val_int();
774  if (tmp >= enum_names->count)
775  {
776  internal::llstr(tmp,buff);
777  value=buff; // Wrong value is here
778  goto err;
779  }
780  var->setValue(tmp); // Save for update
781  }
782  return 0;
783 
784 err:
785  my_error(ER_WRONG_VALUE_FOR_VAR, MYF(0), name.c_str(), value);
786  return 1;
787 }
788 
789 
798 Item *sys_var::item(Session *session, sql_var_t var_type)
799 {
800  if (check_type(var_type))
801  {
802  if (var_type != OPT_DEFAULT)
803  {
804  my_error(ER_INCORRECT_GLOBAL_LOCAL_VAR, MYF(0), name.c_str(), var_type == OPT_GLOBAL ? "SESSION" : "GLOBAL");
805  return 0;
806  }
807  /* As there was no local variable, return the global value */
808  var_type= OPT_GLOBAL;
809  }
810  boost::mutex::scoped_lock lock(session->catalog().systemVariableLock());
811  switch (show_type())
812  {
813  case SHOW_LONG:
814  case SHOW_INT:
815  {
816  uint32_t value= *(uint*) value_ptr(session, var_type);
817  return new Item_uint((uint64_t) value);
818  }
819  case SHOW_LONGLONG:
820  {
821  int64_t value= *(int64_t*) value_ptr(session, var_type);
822  return new Item_int(value);
823  }
824  case SHOW_DOUBLE:
825  {
826  double value= *(double*) value_ptr(session, var_type);
827  /* 6, as this is for now only used with microseconds */
828  return new Item_float(value, 6);
829  }
830  case SHOW_HA_ROWS:
831  {
832  ha_rows value= *(ha_rows*) value_ptr(session, var_type);
833  return new Item_int((uint64_t) value);
834  }
835  case SHOW_SIZE:
836  {
837  size_t value= *(size_t*) value_ptr(session, var_type);
838  return new Item_int((uint64_t) value);
839  }
840  case SHOW_MY_BOOL:
841  {
842  int32_t value= *(bool*) value_ptr(session, var_type);
843  return new Item_int(value, 1);
844  }
845  case SHOW_CHAR_PTR:
846  {
847  if (const char *str= *(char**) value_ptr(session, var_type))
848  {
849  uint32_t length= strlen(str);
850  return new Item_string(session->mem.strdup(str, length), length, system_charset_info, DERIVATION_SYSCONST);
851  }
852  Item* tmp= new Item_null();
853  tmp->collation.set(system_charset_info, DERIVATION_SYSCONST);
854  return tmp;
855  }
856  case SHOW_CHAR:
857  {
858  if (const char* str= (char*) value_ptr(session, var_type))
859  return new Item_string(str_ref(str), system_charset_info, DERIVATION_SYSCONST);
860  Item* tmp= new Item_null();
861  tmp->collation.set(system_charset_info, DERIVATION_SYSCONST);
862  return tmp;
863  }
864  default:
865  my_error(ER_VAR_CANT_BE_READ, MYF(0), name.c_str());
866  }
867  return NULL;
868 }
869 
870 
871 bool sys_var_session_enum::update(Session *session, set_var *var)
872 {
873  if (var->type == OPT_GLOBAL)
874  global_system_variables.*offset= var->getInteger();
875  else
876  session->variables.*offset= var->getInteger();
877  return 0;
878 }
879 
880 
881 void sys_var_session_enum::set_default(Session *session, sql_var_t type)
882 {
883  if (type == OPT_GLOBAL)
884  global_system_variables.*offset= (uint32_t) option_limits->def_value;
885  else
886  session->variables.*offset= global_system_variables.*offset;
887 }
888 
889 
890 unsigned char *sys_var_session_enum::value_ptr(Session *session, sql_var_t type)
891 {
892  uint32_t tmp= type == OPT_GLOBAL ? global_system_variables.*offset : session->variables.*offset;
893  return (unsigned char*) enum_names->type_names[tmp];
894 }
895 
896 bool sys_var_session_bit::check(Session *session, set_var *var)
897 {
898  return check_enum(session, var, &bool_typelib) || (check_func && (*check_func)(session, var));
899 }
900 
901 bool sys_var_session_bit::update(Session *session, set_var *var)
902 {
903  return (*update_func)(session, var);
904 }
905 
906 
907 unsigned char *sys_var_session_bit::value_ptr(Session *session, sql_var_t)
908 {
909  /*
910  If reverse is 0 (default) return 1 if bit is set.
911  If reverse is 1, return 0 if bit is set
912  */
913  session->sys_var_tmp.bool_value= (session->options & bit_flag) ? !reverse : reverse;
914  return (unsigned char*) &session->sys_var_tmp.bool_value;
915 }
916 
917 
918 bool sys_var_collation_sv::update(Session *session, set_var *var)
919 {
920  const charset_info_st *tmp;
921 
922  if (var->value->result_type() == STRING_RESULT)
923  {
924  char buff[STRING_BUFFER_USUAL_SIZE];
925  String str(buff,sizeof(buff), system_charset_info), *res;
926  if (!(res=var->value->val_str(&str)))
927  {
928  boost::throw_exception(invalid_option_value(var->var->getName()) << invalid_value(std::string("NULL")));
929  return 1;
930  }
931  if (!(tmp=get_charset_by_name(res->c_ptr())))
932  {
933  my_error(ER_UNKNOWN_COLLATION, MYF(0), res->c_ptr());
934  boost::throw_exception(invalid_option_value(var->var->getName()) << invalid_value(std::string(res->c_ptr())));
935  return 1;
936  }
937  }
938  else // INT_RESULT
939  {
940  if (!(tmp=get_charset((int) var->value->val_int())))
941  {
942  char buf[20];
943  internal::int10_to_str((int) var->value->val_int(), buf, -10);
944  my_error(ER_UNKNOWN_COLLATION, MYF(0), buf);
945  boost::throw_exception(invalid_option_value(var->var->getName()) << invalid_value(boost::lexical_cast<std::string>(var->value->val_int())));
946  return 1;
947  }
948  }
949  if (var->type == OPT_GLOBAL)
950  global_system_variables.*offset= tmp;
951  else
952  {
953  session->variables.*offset= tmp;
954  }
955  return 0;
956 }
957 
958 
959 void sys_var_collation_sv::set_default(Session *session, sql_var_t type)
960 {
961  if (type == OPT_GLOBAL)
962  global_system_variables.*offset= *global_default;
963  else
964  {
965  session->variables.*offset= global_system_variables.*offset;
966  }
967 }
968 
969 
970 unsigned char *sys_var_collation_sv::value_ptr(Session *session, sql_var_t type)
971 {
972  const charset_info_st *cs= type == OPT_GLOBAL ? global_system_variables.*offset : session->variables.*offset;
973  return cs ? (unsigned char*) cs->name : (unsigned char*) "NULL";
974 }
975 
976 /****************************************************************************/
977 
978 bool sys_var_timestamp::update(Session *session, set_var *var)
979 {
980  session->times.set_time(time_t(var->getInteger()));
981  return 0;
982 }
983 
984 
985 void sys_var_timestamp::set_default(Session *session, sql_var_t)
986 {
987  session->times.resetUserTime();
988 }
989 
990 
991 unsigned char *sys_var_timestamp::value_ptr(Session *session, sql_var_t)
992 {
993  session->sys_var_tmp.int32_t_value= (int32_t) session->times.getCurrentTimestampEpoch();
994  return (unsigned char*) &session->sys_var_tmp.int32_t_value;
995 }
996 
997 
998 bool sys_var_last_insert_id::update(Session *session, set_var *var)
999 {
1000  session->first_successful_insert_id_in_prev_stmt= var->getInteger();
1001  return 0;
1002 }
1003 
1004 
1005 unsigned char *sys_var_last_insert_id::value_ptr(Session *session, sql_var_t)
1006 {
1007  /*
1008  this tmp var makes it robust againt change of type of
1009  read_first_successful_insert_id_in_prev_stmt().
1010  */
1011  session->sys_var_tmp.uint64_t_value=
1012  session->read_first_successful_insert_id_in_prev_stmt();
1013  return (unsigned char*) &session->sys_var_tmp.uint64_t_value;
1014 }
1015 
1016 bool sys_var_session_lc_time_names::update(Session *session, set_var *var)
1017 {
1018  MY_LOCALE *locale_match;
1019 
1020  if (var->value->result_type() == INT_RESULT)
1021  {
1022  if (!(locale_match= my_locale_by_number((uint32_t) var->value->val_int())))
1023  {
1024  char buf[DECIMAL_LONGLONG_DIGITS];
1025  internal::int10_to_str((int) var->value->val_int(), buf, -10);
1026  my_printf_error(ER_UNKNOWN_ERROR, "Unknown locale: '%s'", MYF(0), buf);
1027  return 1;
1028  }
1029  }
1030  else // STRING_RESULT
1031  {
1032  char buff[6];
1033  String str(buff, sizeof(buff), &my_charset_utf8_general_ci), *res;
1034  if (!(res=var->value->val_str(&str)))
1035  {
1036  my_error(ER_WRONG_VALUE_FOR_VAR, MYF(0), name.c_str(), "NULL");
1037  return 1;
1038  }
1039  const char *locale_str= res->c_ptr();
1040  if (!(locale_match= my_locale_by_name(locale_str)))
1041  {
1042  my_printf_error(ER_UNKNOWN_ERROR,
1043  "Unknown locale: '%s'", MYF(0), locale_str);
1044  return 1;
1045  }
1046  }
1047 
1048  if (var->type == OPT_GLOBAL)
1049  global_system_variables.lc_time_names= locale_match;
1050  else
1051  session->variables.lc_time_names= locale_match;
1052  return 0;
1053 }
1054 
1055 
1056 unsigned char *sys_var_session_lc_time_names::value_ptr(Session *session, sql_var_t type)
1057 {
1058  return type == OPT_GLOBAL
1059  ? (unsigned char *) global_system_variables.lc_time_names->name
1060  : (unsigned char *) session->variables.lc_time_names->name;
1061 }
1062 
1063 
1064 void sys_var_session_lc_time_names::set_default(Session *session, sql_var_t type)
1065 {
1066  if (type == OPT_GLOBAL)
1067  global_system_variables.lc_time_names= my_default_lc_time_names;
1068  else
1069  session->variables.lc_time_names= global_system_variables.lc_time_names;
1070 }
1071 
1072 /*
1073  Handling of microseoncds given as seconds.part_seconds
1074 
1075  NOTES
1076  The argument to long query time is in seconds in decimal
1077  which is converted to uint64_t integer holding microseconds for storage.
1078  This is used for handling long_query_time
1079 */
1080 
1081 bool sys_var_microseconds::update(Session *session, set_var *var)
1082 {
1083  double num= var->value->val_real();
1084  int64_t microseconds;
1085  if (num > (double) option_limits->max_value)
1086  num= (double) option_limits->max_value;
1087  if (num < (double) option_limits->min_value)
1088  num= (double) option_limits->min_value;
1089  microseconds= (int64_t) (num * 1000000.0 + 0.5);
1090  if (var->type == OPT_GLOBAL)
1091  {
1092  boost::mutex::scoped_lock scopedLock(session->catalog().systemVariableLock());
1093  (global_system_variables.*offset)= microseconds;
1094  }
1095  else
1096  session->variables.*offset= microseconds;
1097  return 0;
1098 }
1099 
1100 
1101 void sys_var_microseconds::set_default(Session *session, sql_var_t type)
1102 {
1103  int64_t microseconds= (int64_t) (option_limits->def_value * 1000000.0);
1104  if (type == OPT_GLOBAL)
1105  {
1106  boost::mutex::scoped_lock scopedLock(session->catalog().systemVariableLock());
1107  global_system_variables.*offset= microseconds;
1108  }
1109  else
1110  session->variables.*offset= microseconds;
1111 }
1112 
1113 /*
1114  Functions to update session->options bits
1115 */
1116 
1117 static bool set_option_bit(Session *session, set_var *var)
1118 {
1119  sys_var_session_bit *sys_var= ((sys_var_session_bit*) var->var);
1120  if ((var->getInteger() != 0) == sys_var->reverse)
1121  session->options&= ~sys_var->bit_flag;
1122  else
1123  session->options|= sys_var->bit_flag;
1124  return 0;
1125 }
1126 
1127 
1128 static bool set_option_autocommit(Session *session, set_var *var)
1129 {
1130  bool success= true;
1131  /* The test is negative as the flag we use is NOT autocommit */
1132 
1133  uint64_t org_options= session->options;
1134  uint64_t new_options= session->options;
1135 
1136  if (var->getInteger() != 0)
1137  new_options&= ~((sys_var_session_bit*) var->var)->bit_flag;
1138  else
1139  new_options|= ((sys_var_session_bit*) var->var)->bit_flag;
1140 
1141  if ((org_options ^ new_options) & OPTION_NOT_AUTOCOMMIT)
1142  {
1143  if ((org_options & OPTION_NOT_AUTOCOMMIT))
1144  {
1145  success= session->endActiveTransaction();
1146  /* We changed to auto_commit mode */
1147  session->options&= ~(uint64_t) (OPTION_BEGIN);
1148  session->server_status|= SERVER_STATUS_AUTOCOMMIT;
1149  }
1150  else
1151  {
1152  session->server_status&= ~SERVER_STATUS_AUTOCOMMIT;
1153  }
1154  }
1155 
1156  if (var->getInteger() != 0)
1157  session->options&= ~((sys_var_session_bit*) var->var)->bit_flag;
1158  else
1159  session->options|= ((sys_var_session_bit*) var->var)->bit_flag;
1160 
1161  return not success;
1162 }
1163 
1164 static int check_pseudo_thread_id(Session *, set_var *var)
1165 {
1166  var->updateValue();
1167  return 0;
1168 }
1169 
1170 static unsigned char *get_warning_count(Session *session)
1171 {
1172  session->sys_var_tmp.uint32_t_value=
1173  (session->warn_count[(uint32_t) DRIZZLE_ERROR::WARN_LEVEL_NOTE] +
1174  session->warn_count[(uint32_t) DRIZZLE_ERROR::WARN_LEVEL_ERROR] +
1175  session->warn_count[(uint32_t) DRIZZLE_ERROR::WARN_LEVEL_WARN]);
1176  return (unsigned char*) &session->sys_var_tmp.uint32_t_value;
1177 }
1178 
1179 static unsigned char *get_error_count(Session *session)
1180 {
1181  session->sys_var_tmp.uint32_t_value=
1182  session->warn_count[(uint32_t) DRIZZLE_ERROR::WARN_LEVEL_ERROR];
1183  return (unsigned char*) &session->sys_var_tmp.uint32_t_value;
1184 }
1185 
1186 
1201 static unsigned char *get_tmpdir(Session *)
1202 {
1203  assert(drizzle_tmpdir.size());
1204  return (unsigned char*)drizzle_tmpdir.c_str();
1205 }
1206 
1207 /****************************************************************************
1208  Main handling of variables:
1209  - Initialisation
1210  - Searching during parsing
1211  - Update loop
1212 ****************************************************************************/
1213 
1227 static option* find_option(struct option *opt, const char *name)
1228 {
1229  uint32_t length= strlen(name);
1230  for (; opt->name; opt++)
1231  {
1232  if (not getopt_compare_strings(opt->name, name, length) and not opt->name[length])
1233  {
1234  /*
1235  Only accept the option if one can set values through it.
1236  If not, there is no default value or limits in the option.
1237  */
1238  return opt->value ? opt : NULL;
1239  }
1240  }
1241  return NULL;
1242 }
1243 
1244 
1245 
1246 
1247 
1248 /*
1249  Constructs an array of system variables for display to the user.
1250 
1251  SYNOPSIS
1252  enumerate_sys_vars()
1253  session current thread
1254 
1255  RETURN VALUES
1256  pointer Array of drizzle_show_var elements for display
1257  NULL FAILURE
1258 */
1259 
1260 drizzle_show_var* enumerate_sys_vars(Session *session)
1261 {
1262  drizzle_show_var *result= new (session->mem) drizzle_show_var[system_variable_map.size() + 1];
1263  drizzle_show_var *show= result;
1264  BOOST_FOREACH(SystemVariableMap::const_reference iter, system_variable_map)
1265  {
1266  sys_var *var= iter.second;
1267  show->name= var->getName().c_str();
1268  show->value= (char*) var;
1269  show->type= SHOW_SYS;
1270  ++show;
1271  }
1272 
1273  /* make last element empty */
1274  memset(show, 0, sizeof(drizzle_show_var));
1275  return result;
1276 }
1277 
1278 void add_sys_var_to_list(sys_var *var)
1279 {
1280  string lower_name(var->getName());
1281  boost::to_lower(lower_name);
1282 
1283  /* this fails if there is a conflicting variable name. */
1284  if (system_variable_map.count(lower_name))
1285  {
1286  errmsg_printf(error::ERROR, _("Variable named %s already exists!\n"), var->getName().c_str());
1287  throw exception();
1288  }
1289 
1290  pair<SystemVariableMap::iterator, bool> ret= system_variable_map.insert(make_pair(lower_name, var));
1291  if (ret.second == false)
1292  {
1293  errmsg_printf(error::ERROR, _("Could not add Variable: %s\n"), var->getName().c_str());
1294  throw exception();
1295  }
1296 }
1297 
1298 void add_sys_var_to_list(sys_var *var, struct option *long_options)
1299 {
1300  add_sys_var_to_list(var);
1301  var->setOptionLimits(find_option(long_options, var->getName().c_str()));
1302 }
1303 
1304 /*
1305  Initialize the system variables
1306 
1307  SYNOPSIS
1308  sys_var_init()
1309 
1310  RETURN VALUES
1311  0 SUCCESS
1312  otherwise FAILURE
1313 */
1314 
1315 int sys_var_init()
1316 {
1317  try
1318  {
1319  add_sys_var_to_list(&sys_auto_increment_increment, my_long_options);
1320  add_sys_var_to_list(&sys_auto_increment_offset, my_long_options);
1321  add_sys_var_to_list(&sys_autocommit, my_long_options);
1322  add_sys_var_to_list(&sys_back_log, my_long_options);
1323  add_sys_var_to_list(&sys_basedir, my_long_options);
1324  add_sys_var_to_list(&sys_big_selects, my_long_options);
1325  add_sys_var_to_list(&sys_branch, my_long_options);
1326  add_sys_var_to_list(&sys_buffer_results, my_long_options);
1327  add_sys_var_to_list(&sys_bulk_insert_buff_size, my_long_options);
1328  add_sys_var_to_list(&sys_collation_server, my_long_options);
1329  add_sys_var_to_list(&sys_completion_type, my_long_options);
1330  add_sys_var_to_list(&sys_datadir, my_long_options);
1331  add_sys_var_to_list(&sys_div_precincrement, my_long_options);
1332  add_sys_var_to_list(&sys_error_count, my_long_options);
1333  add_sys_var_to_list(&sys_foreign_key_checks, my_long_options);
1334  add_sys_var_to_list(&sys_group_concat_max_len, my_long_options);
1335  add_sys_var_to_list(&sys_hostname, my_long_options);
1336  add_sys_var_to_list(&sys_identity, my_long_options);
1337  add_sys_var_to_list(&sys_join_buffer_size, my_long_options);
1338  add_sys_var_to_list(&sys_last_insert_id, my_long_options);
1339  add_sys_var_to_list(&sys_lc_time_names, my_long_options);
1340  add_sys_var_to_list(&sys_max_allowed_packet, my_long_options);
1341  add_sys_var_to_list(&sys_max_error_count, my_long_options);
1342  add_sys_var_to_list(&sys_max_heap_table_size, my_long_options);
1343  add_sys_var_to_list(&sys_max_join_size, my_long_options);
1344  add_sys_var_to_list(&sys_max_length_for_sort_data, my_long_options);
1345  add_sys_var_to_list(&sys_max_seeks_for_key, my_long_options);
1346  add_sys_var_to_list(&sys_max_sort_length, my_long_options);
1347  add_sys_var_to_list(&sys_max_write_lock_count, my_long_options);
1348  add_sys_var_to_list(&sys_min_examined_row_limit, my_long_options);
1349  add_sys_var_to_list(&sys_optimizer_prune_level, my_long_options);
1350  add_sys_var_to_list(&sys_optimizer_search_depth, my_long_options);
1351  add_sys_var_to_list(&sys_pid_file, my_long_options);
1352  add_sys_var_to_list(&sys_plugin_dir, my_long_options);
1353  add_sys_var_to_list(&sys_preload_buff_size, my_long_options);
1354  add_sys_var_to_list(&sys_pseudo_thread_id, my_long_options);
1355  add_sys_var_to_list(&sys_query_alloc_block_size, my_long_options);
1356  add_sys_var_to_list(&sys_query_prealloc_size, my_long_options);
1357  add_sys_var_to_list(&sys_range_alloc_block_size, my_long_options);
1358  add_sys_var_to_list(&sys_read_buff_size, my_long_options);
1359  add_sys_var_to_list(&sys_read_rnd_buff_size, my_long_options);
1360  add_sys_var_to_list(&sys_release_id, my_long_options);
1361  add_sys_var_to_list(&sys_replicate_query, my_long_options);
1362  add_sys_var_to_list(&sys_revid, my_long_options);
1363  add_sys_var_to_list(&sys_revno, my_long_options);
1364  add_sys_var_to_list(&sys_scheduler, my_long_options);
1365  add_sys_var_to_list(&sys_secure_file_priv, my_long_options);
1366  add_sys_var_to_list(&sys_select_limit, my_long_options);
1367  add_sys_var_to_list(&sys_server_id, my_long_options);
1368  add_sys_var_to_list(&sys_server_uuid, my_long_options);
1369  add_sys_var_to_list(&sys_sort_buffer, my_long_options);
1370  add_sys_var_to_list(&sys_sql_notes, my_long_options);
1371  add_sys_var_to_list(&sys_sql_warnings, my_long_options);
1372  add_sys_var_to_list(&sys_storage_engine, my_long_options);
1373  add_sys_var_to_list(&sys_table_cache_size, my_long_options);
1374  add_sys_var_to_list(&sys_table_def_size, my_long_options);
1375  add_sys_var_to_list(&sys_table_lock_wait_timeout, my_long_options);
1376  add_sys_var_to_list(&sys_thread_stack_size, my_long_options);
1377  add_sys_var_to_list(&sys_timed_mutexes, my_long_options);
1378  add_sys_var_to_list(&sys_timestamp, my_long_options);
1379  add_sys_var_to_list(&sys_tmp_table_size, my_long_options);
1380  add_sys_var_to_list(&sys_tmpdir, my_long_options);
1381  add_sys_var_to_list(&sys_transaction_message_threshold, my_long_options);
1382  add_sys_var_to_list(&sys_tx_isolation, my_long_options);
1383  add_sys_var_to_list(&sys_unique_checks, my_long_options);
1384  add_sys_var_to_list(&sys_version, my_long_options);
1385  add_sys_var_to_list(&sys_version_comment, my_long_options);
1386  add_sys_var_to_list(&sys_version_compile_machine, my_long_options);
1387  add_sys_var_to_list(&sys_version_compile_os, my_long_options);
1388  add_sys_var_to_list(&sys_version_compile_vendor, my_long_options);
1389  add_sys_var_to_list(&sys_warning_count, my_long_options);
1390  }
1391  catch (std::exception&)
1392  {
1393  errmsg_printf(error::ERROR, _("Failed to initialize system variables"));
1394  return 1;
1395  }
1396  return 0;
1397 }
1398 
1399 
1411 sys_var *find_sys_var(const std::string &name)
1412 {
1413  if (sys_var* ptr= find_ptr2(system_variable_map, boost::to_lower_copy(name)))
1414  return ptr;
1415  my_error(ER_UNKNOWN_SYSTEM_VARIABLE, MYF(0), name.c_str());
1416  return NULL;
1417 }
1418 
1419 
1420 /****************************************************************************
1421  Functions to handle table_type
1422 ****************************************************************************/
1423 
1424 unsigned char *sys_var_session_storage_engine::value_ptr(Session *session, sql_var_t type)
1425 {
1426  plugin::StorageEngine *engine= type == OPT_GLOBAL
1427  ? global_system_variables.*offset
1428  : session->variables.*offset;
1429  return (unsigned char *) session->mem.strdup(engine->getName());
1430 }
1431 
1432 
1433 void sys_var_session_storage_engine::set_default(Session *session, sql_var_t type)
1434 {
1435  plugin::StorageEngine *new_value, **value;
1436  if (type == OPT_GLOBAL)
1437  {
1438  value= &(global_system_variables.*offset);
1439  new_value= myisam_engine;
1440  }
1441  else
1442  {
1443  value= &(session->variables.*offset);
1444  new_value= global_system_variables.*offset;
1445  }
1446  assert(new_value);
1447  *value= new_value;
1448 }
1449 
1450 
1451 bool sys_var_session_storage_engine::update(Session *session, set_var *var)
1452 {
1453  char buff[STRING_BUFFER_USUAL_SIZE];
1454  const char *name_value;
1455  String str(buff, sizeof(buff), &my_charset_utf8_general_ci), *res;
1456 
1457  plugin::StorageEngine *tmp= NULL;
1458  plugin::StorageEngine **value= NULL;
1459 
1460  if (var->value->result_type() == STRING_RESULT)
1461  {
1462  res= var->value->val_str(&str);
1463  if (res == NULL || res->ptr() == NULL)
1464  {
1465  name_value= "NULL";
1466  goto err;
1467  }
1468  else
1469  {
1470  const std::string engine_name(res->ptr());
1471  tmp= plugin::StorageEngine::findByName(*session, engine_name);
1472  if (tmp == NULL)
1473  {
1474  name_value= res->c_ptr();
1475  goto err;
1476  }
1477  }
1478  }
1479  else
1480  {
1481  name_value= "unknown";
1482  }
1483 
1484  value= &(global_system_variables.*offset);
1485  if (var->type != OPT_GLOBAL)
1486  value= &(session->variables.*offset);
1487  if (*value != tmp)
1488  {
1489  *value= tmp;
1490  }
1491  return 0;
1492 err:
1493  my_error(ER_UNKNOWN_STORAGE_ENGINE, MYF(0), name_value);
1494  return 1;
1495 }
1496 
1497 } /* namespace drizzled */
static int check_tx_isolation(Session *, set_var *)
Definition: sys_var.cc:315
TODO: Rename this file - func.h is stupid.
static unsigned char * get_tmpdir(Session *)
Definition: sys_var.cc:1201
Visibility Control Macros.
sys_var * find_sys_var(const std::string &name)
Definition: sys_var.cc:1411
uint64_t options
Definition: session.h:400
static void fix_max_join_size(Session *, sql_var_t)
Definition: sys_var.cc:299
drizzle_system_variables & variables
Definition: session.h:199
char * strdup(const char *)
Duplicate a null-terminated string into memory allocated from within the specified Root...
Definition: root.cc:328
static option * find_option(struct option *opt, const char *name)
Definition: sys_var.cc:1227