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