~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/sys_var.cc

  • Committer: Olaf van der Spek
  • Date: 2011-02-12 18:24:24 UTC
  • mto: (2167.1.2 build) (2172.1.4 build)
  • mto: This revision was merged to the branch mainline in revision 2168.
  • Revision ID: olafvdspek@gmail.com-20110212182424-kgnm9osi7qo97at2
casts

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
2
 *  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
3
3
 *
4
 
 *  Copyright (C) 2008 Sun Microsystems
 
4
 *  Copyright (C) 2008 Sun Microsystems, Inc.
5
5
 *
6
6
 *  This program is free software; you can redistribute it and/or modify
7
7
 *  it under the terms of the GNU General Public License as published by
36
36
  @todo
37
37
    Add full support for the variable character_set (for 4.1)
38
38
 
39
 
  @note
40
 
    Be careful with var->save_result: sys_var::check() only updates
41
 
    uint64_t_value; so other members of the union are garbage then; to use
42
 
    them you must first assign a value to them (in specific ::check() for
43
 
    example).
44
39
*/
45
40
 
46
41
#include "config.h"
47
42
#include "drizzled/option.h"
48
 
#include <drizzled/error.h>
49
 
#include <drizzled/gettext.h>
50
 
#include <drizzled/tztime.h>
51
 
#include <drizzled/data_home.h>
52
 
#include <drizzled/set_var.h>
53
 
#include <drizzled/session.h>
54
 
#include <drizzled/sql_base.h>
55
 
#include <drizzled/lock.h>
56
 
#include <drizzled/item/uint.h>
57
 
#include <drizzled/item/null.h>
58
 
#include <drizzled/item/float.h>
59
 
#include <drizzled/plugin.h>
 
43
#include "drizzled/error.h"
 
44
#include "drizzled/gettext.h"
 
45
#include "drizzled/tztime.h"
 
46
#include "drizzled/data_home.h"
 
47
#include "drizzled/set_var.h"
 
48
#include "drizzled/session.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"
60
56
#include "drizzled/version.h"
61
57
#include "drizzled/strfunc.h"
62
58
#include "drizzled/internal/m_string.h"
63
59
#include "drizzled/pthread_globals.h"
64
60
#include "drizzled/charset.h"
65
61
#include "drizzled/transaction_services.h"
 
62
#include "drizzled/constrained_value.h"
 
63
#include "drizzled/visibility.h"
66
64
 
 
65
#include <cstdio>
67
66
#include <map>
 
67
#include <vector>
68
68
#include <algorithm>
69
69
 
70
70
using namespace std;
84
84
extern const CHARSET_INFO *character_set_filesystem;
85
85
extern size_t my_thread_stack_size;
86
86
 
87
 
class sys_var_pluginvar;
88
 
static DYNAMIC_ARRAY fixed_show_vars;
89
87
typedef map<string, sys_var *> SystemVariableMap;
90
88
static SystemVariableMap system_variable_map;
91
89
extern char *opt_drizzle_tmpdir;
108
106
static void fix_max_join_size(Session *session, sql_var_t type);
109
107
static void fix_session_mem_root(Session *session, sql_var_t type);
110
108
static void fix_server_id(Session *session, sql_var_t type);
111
 
static bool get_unsigned32(Session *session, set_var *var);
112
 
static bool get_unsigned64(Session *session, set_var *var);
113
109
bool throw_bounds_warning(Session *session, bool fixed, bool unsignd,
114
110
                          const std::string &name, int64_t val);
115
111
static unsigned char *get_error_count(Session *session);
125
121
  The variables are linked into the list. A variable is added to
126
122
  it in the constructor (see sys_var class for details).
127
123
*/
128
 
static sys_var_chain vars = { NULL, NULL };
129
 
 
130
 
static sys_var_session_uint64_t
131
 
sys_auto_increment_increment(&vars, "auto_increment_increment",
132
 
                             &system_variables::auto_increment_increment);
133
 
static sys_var_session_uint64_t
134
 
sys_auto_increment_offset(&vars, "auto_increment_offset",
135
 
                          &system_variables::auto_increment_offset);
136
 
 
137
 
static sys_var_const_str       sys_basedir(&vars, "basedir", drizzle_home);
138
 
static sys_var_session_uint64_t sys_bulk_insert_buff_size(&vars, "bulk_insert_buffer_size",
139
 
                                                          &system_variables::bulk_insert_buff_size);
140
 
static sys_var_session_uint32_t sys_completion_type(&vars, "completion_type",
141
 
                                                    &system_variables::completion_type,
 
124
static sys_var_session_uint64_t
 
125
sys_auto_increment_increment("auto_increment_increment",
 
126
                             &drizzle_system_variables::auto_increment_increment);
 
127
static sys_var_session_uint64_t
 
128
sys_auto_increment_offset("auto_increment_offset",
 
129
                          &drizzle_system_variables::auto_increment_offset);
 
130
 
 
131
static sys_var_fs_path sys_basedir("basedir", basedir);
 
132
static sys_var_fs_path sys_pid_file("pid_file", pid_file);
 
133
static sys_var_fs_path sys_plugin_dir("plugin_dir", plugin_dir);
 
134
 
 
135
static sys_var_size_t_ptr sys_thread_stack_size("thread_stack",
 
136
                                                      &my_thread_stack_size);
 
137
static sys_var_constrained_value_readonly<uint32_t> sys_back_log("back_log", back_log);
 
138
 
 
139
static sys_var_session_uint64_t sys_bulk_insert_buff_size("bulk_insert_buffer_size",
 
140
                                                          &drizzle_system_variables::bulk_insert_buff_size);
 
141
static sys_var_session_uint32_t sys_completion_type("completion_type",
 
142
                                                    &drizzle_system_variables::completion_type,
142
143
                                                    check_completion_type,
143
144
                                                    fix_completion_type);
144
145
static sys_var_collation_sv
145
 
sys_collation_server(&vars, "collation_server", &system_variables::collation_server, &default_charset_info);
146
 
static sys_var_const_str       sys_datadir(&vars, "datadir", drizzle_real_data_home);
 
146
sys_collation_server("collation_server", &drizzle_system_variables::collation_server, &default_charset_info);
 
147
static sys_var_fs_path       sys_datadir("datadir", getDataHome());
147
148
 
148
 
static sys_var_session_uint64_t sys_join_buffer_size(&vars, "join_buffer_size",
149
 
                                                     &system_variables::join_buff_size);
150
 
static sys_var_session_uint32_t sys_max_allowed_packet(&vars, "max_allowed_packet",
151
 
                                                       &system_variables::max_allowed_packet);
152
 
static sys_var_uint64_t_ptr     sys_max_connect_errors(&vars, "max_connect_errors",
153
 
                                               &max_connect_errors);
154
 
static sys_var_session_uint64_t sys_max_error_count(&vars, "max_error_count",
155
 
                                                  &system_variables::max_error_count);
156
 
static sys_var_session_uint64_t sys_max_heap_table_size(&vars, "max_heap_table_size",
157
 
                                                        &system_variables::max_heap_table_size);
158
 
static sys_var_session_uint64_t sys_pseudo_thread_id(&vars, "pseudo_thread_id",
159
 
                                              &system_variables::pseudo_thread_id,
 
149
static sys_var_session_uint64_t sys_join_buffer_size("join_buffer_size",
 
150
                                                     &drizzle_system_variables::join_buff_size);
 
151
static sys_var_session_uint32_t sys_max_allowed_packet("max_allowed_packet",
 
152
                                                       &drizzle_system_variables::max_allowed_packet);
 
153
static sys_var_session_uint64_t sys_max_error_count("max_error_count",
 
154
                                                  &drizzle_system_variables::max_error_count);
 
155
static sys_var_session_uint64_t sys_max_heap_table_size("max_heap_table_size",
 
156
                                                        &drizzle_system_variables::max_heap_table_size);
 
157
static sys_var_session_uint64_t sys_pseudo_thread_id("pseudo_thread_id",
 
158
                                              &drizzle_system_variables::pseudo_thread_id,
160
159
                                              0, check_pseudo_thread_id);
161
 
static sys_var_session_ha_rows  sys_max_join_size(&vars, "max_join_size",
162
 
                                                  &system_variables::max_join_size,
 
160
static sys_var_session_ha_rows  sys_max_join_size("max_join_size",
 
161
                                                  &drizzle_system_variables::max_join_size,
163
162
                                                  fix_max_join_size);
164
 
static sys_var_session_uint64_t sys_max_seeks_for_key(&vars, "max_seeks_for_key",
165
 
                                                      &system_variables::max_seeks_for_key);
166
 
static sys_var_session_uint64_t   sys_max_length_for_sort_data(&vars, "max_length_for_sort_data",
167
 
                                                               &system_variables::max_length_for_sort_data);
168
 
static sys_var_session_size_t   sys_max_sort_length(&vars, "max_sort_length",
169
 
                                                    &system_variables::max_sort_length);
170
 
static sys_var_uint64_t_ptr     sys_max_write_lock_count(&vars, "max_write_lock_count",
 
163
static sys_var_session_uint64_t sys_max_seeks_for_key("max_seeks_for_key",
 
164
                                                      &drizzle_system_variables::max_seeks_for_key);
 
165
static sys_var_session_uint64_t   sys_max_length_for_sort_data("max_length_for_sort_data",
 
166
                                                               &drizzle_system_variables::max_length_for_sort_data);
 
167
static sys_var_session_size_t   sys_max_sort_length("max_sort_length",
 
168
                                                    &drizzle_system_variables::max_sort_length);
 
169
static sys_var_uint64_t_ptr     sys_max_write_lock_count("max_write_lock_count",
171
170
                                                 &max_write_lock_count);
172
 
static sys_var_session_uint64_t sys_min_examined_row_limit(&vars, "min_examined_row_limit",
173
 
                                                           &system_variables::min_examined_row_limit);
 
171
static sys_var_session_uint64_t sys_min_examined_row_limit("min_examined_row_limit",
 
172
                                                           &drizzle_system_variables::min_examined_row_limit);
174
173
 
175
174
/* these two cannot be static */
176
 
static sys_var_session_bool sys_optimizer_prune_level(&vars, "optimizer_prune_level",
177
 
                                                      &system_variables::optimizer_prune_level);
178
 
static sys_var_session_uint32_t sys_optimizer_search_depth(&vars, "optimizer_search_depth",
179
 
                                                           &system_variables::optimizer_search_depth);
180
 
 
181
 
static sys_var_session_uint64_t sys_preload_buff_size(&vars, "preload_buffer_size",
182
 
                                                      &system_variables::preload_buff_size);
183
 
static sys_var_session_uint32_t sys_read_buff_size(&vars, "read_buffer_size",
184
 
                                                   &system_variables::read_buff_size);
185
 
static sys_var_session_uint32_t sys_read_rnd_buff_size(&vars, "read_rnd_buffer_size",
186
 
                                                       &system_variables::read_rnd_buff_size);
187
 
static sys_var_session_uint32_t sys_div_precincrement(&vars, "div_precision_increment",
188
 
                                                      &system_variables::div_precincrement);
189
 
 
190
 
static sys_var_session_size_t   sys_range_alloc_block_size(&vars, "range_alloc_block_size",
191
 
                                                           &system_variables::range_alloc_block_size);
192
 
static sys_var_session_uint32_t sys_query_alloc_block_size(&vars, "query_alloc_block_size",
193
 
                                                           &system_variables::query_alloc_block_size,
194
 
                                                           false, fix_session_mem_root);
195
 
static sys_var_session_uint32_t sys_query_prealloc_size(&vars, "query_prealloc_size",
196
 
                                                        &system_variables::query_prealloc_size,
197
 
                                                        false, fix_session_mem_root);
198
 
static sys_var_readonly sys_tmpdir(&vars, "tmpdir", OPT_GLOBAL, SHOW_CHAR, get_tmpdir);
199
 
 
200
 
static sys_var_const_str_ptr sys_secure_file_priv(&vars, "secure_file_priv",
201
 
                                             &opt_secure_file_priv);
202
 
static sys_var_uint32_t_ptr  sys_server_id(&vars, "server_id", &server_id,
 
175
static sys_var_session_bool sys_optimizer_prune_level("optimizer_prune_level",
 
176
                                                      &drizzle_system_variables::optimizer_prune_level);
 
177
static sys_var_session_uint32_t sys_optimizer_search_depth("optimizer_search_depth",
 
178
                                                           &drizzle_system_variables::optimizer_search_depth);
 
179
 
 
180
static sys_var_session_uint64_t sys_preload_buff_size("preload_buffer_size",
 
181
                                                      &drizzle_system_variables::preload_buff_size);
 
182
static sys_var_session_uint32_t sys_read_buff_size("read_buffer_size",
 
183
                                                   &drizzle_system_variables::read_buff_size);
 
184
static sys_var_session_uint32_t sys_read_rnd_buff_size("read_rnd_buffer_size",
 
185
                                                       &drizzle_system_variables::read_rnd_buff_size);
 
186
static sys_var_session_uint32_t sys_div_precincrement("div_precision_increment",
 
187
                                                      &drizzle_system_variables::div_precincrement);
 
188
 
 
189
static sys_var_session_size_t   sys_range_alloc_block_size("range_alloc_block_size",
 
190
                                                           &drizzle_system_variables::range_alloc_block_size);
 
191
 
 
192
static sys_var_session_bool sys_replicate_query("replicate_query",
 
193
                                                &drizzle_system_variables::replicate_query);
 
194
 
 
195
static sys_var_session_uint32_t sys_query_alloc_block_size("query_alloc_block_size",
 
196
                                                           &drizzle_system_variables::query_alloc_block_size,
 
197
                                                           NULL, fix_session_mem_root);
 
198
static sys_var_session_uint32_t sys_query_prealloc_size("query_prealloc_size",
 
199
                                                        &drizzle_system_variables::query_prealloc_size,
 
200
                                                        NULL, fix_session_mem_root);
 
201
static sys_var_readonly sys_tmpdir("tmpdir", OPT_GLOBAL, SHOW_CHAR, get_tmpdir);
 
202
 
 
203
static sys_var_fs_path sys_secure_file_priv("secure_file_priv",
 
204
                                            secure_file_priv);
 
205
 
 
206
static sys_var_const_str_ptr sys_scheduler("scheduler",
 
207
                                           (char**)&opt_scheduler);
 
208
 
 
209
static sys_var_uint32_t_ptr  sys_server_id("server_id", &server_id,
203
210
                                           fix_server_id);
204
211
 
205
 
static sys_var_session_size_t   sys_sort_buffer(&vars, "sort_buffer_size",
206
 
                                                &system_variables::sortbuff_size);
207
 
 
208
 
static sys_var_session_storage_engine sys_storage_engine(&vars, "storage_engine",
209
 
                                       &system_variables::storage_engine);
210
 
static sys_var_const_str        sys_system_time_zone(&vars, "system_time_zone",
 
212
static sys_var_session_size_t   sys_sort_buffer("sort_buffer_size",
 
213
                                                &drizzle_system_variables::sortbuff_size);
 
214
 
 
215
static sys_var_size_t_ptr_readonly sys_transaction_message_threshold("transaction_message_threshold",
 
216
                                                                &transaction_message_threshold);
 
217
 
 
218
static sys_var_session_storage_engine sys_storage_engine("storage_engine",
 
219
                                       &drizzle_system_variables::storage_engine);
 
220
static sys_var_const_str        sys_system_time_zone("system_time_zone",
211
221
                                             system_time_zone);
212
 
static sys_var_size_t_ptr       sys_table_def_size(&vars, "table_definition_cache",
 
222
static sys_var_size_t_ptr       sys_table_def_size("table_definition_cache",
213
223
                                             &table_def_size);
214
 
static sys_var_uint64_t_ptr     sys_table_cache_size(&vars, "table_open_cache",
 
224
static sys_var_uint64_t_ptr     sys_table_cache_size("table_open_cache",
215
225
                                             &table_cache_size);
216
 
static sys_var_uint64_t_ptr     sys_table_lock_wait_timeout(&vars, "table_lock_wait_timeout",
 
226
static sys_var_uint64_t_ptr     sys_table_lock_wait_timeout("table_lock_wait_timeout",
217
227
                                                    &table_lock_wait_timeout);
218
 
static sys_var_session_enum     sys_tx_isolation(&vars, "tx_isolation",
219
 
                                             &system_variables::tx_isolation,
 
228
static sys_var_session_enum     sys_tx_isolation("tx_isolation",
 
229
                                             &drizzle_system_variables::tx_isolation,
220
230
                                             &tx_isolation_typelib,
221
231
                                             fix_tx_isolation,
222
232
                                             check_tx_isolation);
223
 
static sys_var_session_uint64_t sys_tmp_table_size(&vars, "tmp_table_size",
224
 
                                           &system_variables::tmp_table_size);
225
 
static sys_var_bool_ptr  sys_timed_mutexes(&vars, "timed_mutexes", &internal::timed_mutexes);
226
 
static sys_var_const_str  sys_version(&vars, "version", version().c_str());
 
233
static sys_var_session_uint64_t sys_tmp_table_size("tmp_table_size",
 
234
                                           &drizzle_system_variables::tmp_table_size);
 
235
static sys_var_bool_ptr  sys_timed_mutexes("timed_mutexes", &internal::timed_mutexes);
 
236
static sys_var_const_str  sys_version("version", version().c_str());
227
237
 
228
 
static sys_var_const_str        sys_version_comment(&vars, "version_comment",
 
238
static sys_var_const_str        sys_version_comment("version_comment",
229
239
                                            COMPILATION_COMMENT);
230
 
static sys_var_const_str        sys_version_compile_machine(&vars, "version_compile_machine",
 
240
static sys_var_const_str        sys_version_compile_machine("version_compile_machine",
231
241
                                                      HOST_CPU);
232
 
static sys_var_const_str        sys_version_compile_os(&vars, "version_compile_os",
 
242
static sys_var_const_str        sys_version_compile_os("version_compile_os",
233
243
                                                 HOST_OS);
234
 
static sys_var_const_str        sys_version_compile_vendor(&vars, "version_compile_vendor",
 
244
static sys_var_const_str        sys_version_compile_vendor("version_compile_vendor",
235
245
                                                 HOST_VENDOR);
236
246
 
237
247
/* Variables that are bits in Session */
238
248
 
239
 
sys_var_session_bit sys_autocommit(&vars, "autocommit", 0,
 
249
sys_var_session_bit sys_autocommit("autocommit", 0,
240
250
                               set_option_autocommit,
241
251
                               OPTION_NOT_AUTOCOMMIT,
242
252
                               1);
243
 
static sys_var_session_bit      sys_big_selects(&vars, "sql_big_selects", 0,
 
253
static sys_var_session_bit      sys_big_selects("sql_big_selects", 0,
244
254
                                        set_option_bit,
245
255
                                        OPTION_BIG_SELECTS);
246
 
static sys_var_session_bit      sys_sql_warnings(&vars, "sql_warnings", 0,
 
256
static sys_var_session_bit      sys_sql_warnings("sql_warnings", 0,
247
257
                                         set_option_bit,
248
258
                                         OPTION_WARNINGS);
249
 
static sys_var_session_bit      sys_sql_notes(&vars, "sql_notes", 0,
 
259
static sys_var_session_bit      sys_sql_notes("sql_notes", 0,
250
260
                                         set_option_bit,
251
261
                                         OPTION_SQL_NOTES);
252
 
static sys_var_session_bit      sys_buffer_results(&vars, "sql_buffer_result", 0,
 
262
static sys_var_session_bit      sys_buffer_results("sql_buffer_result", 0,
253
263
                                           set_option_bit,
254
264
                                           OPTION_BUFFER_RESULT);
255
 
static sys_var_session_bit      sys_foreign_key_checks(&vars, "foreign_key_checks", 0,
 
265
static sys_var_session_bit      sys_foreign_key_checks("foreign_key_checks", 0,
256
266
                                               set_option_bit,
257
267
                                               OPTION_NO_FOREIGN_KEY_CHECKS, 1);
258
 
static sys_var_session_bit      sys_unique_checks(&vars, "unique_checks", 0,
 
268
static sys_var_session_bit      sys_unique_checks("unique_checks", 0,
259
269
                                          set_option_bit,
260
270
                                          OPTION_RELAXED_UNIQUE_CHECKS, 1);
261
271
/* Local state variables */
262
272
 
263
 
static sys_var_session_ha_rows  sys_select_limit(&vars, "sql_select_limit",
264
 
                                                 &system_variables::select_limit);
265
 
static sys_var_timestamp sys_timestamp(&vars, "timestamp");
 
273
static sys_var_session_ha_rows  sys_select_limit("sql_select_limit",
 
274
                                                 &drizzle_system_variables::select_limit);
 
275
static sys_var_timestamp sys_timestamp("timestamp");
266
276
static sys_var_last_insert_id
267
 
sys_last_insert_id(&vars, "last_insert_id");
 
277
sys_last_insert_id("last_insert_id");
268
278
/*
269
279
  identity is an alias for last_insert_id(), so that we are compatible
270
280
  with Sybase
271
281
*/
272
 
static sys_var_last_insert_id sys_identity(&vars, "identity");
 
282
static sys_var_last_insert_id sys_identity("identity");
273
283
 
274
 
static sys_var_session_lc_time_names sys_lc_time_names(&vars, "lc_time_names");
 
284
static sys_var_session_lc_time_names sys_lc_time_names("lc_time_names");
275
285
 
276
286
/*
277
287
  We want statements referring explicitly to @@session.insert_id to be
285
295
  statement-based logging mode: t will be different on master and
286
296
  slave).
287
297
*/
288
 
static sys_var_readonly sys_error_count(&vars, "error_count",
 
298
static sys_var_readonly sys_error_count("error_count",
289
299
                                        OPT_SESSION,
290
300
                                        SHOW_INT,
291
301
                                        get_error_count);
292
 
static sys_var_readonly sys_warning_count(&vars, "warning_count",
 
302
static sys_var_readonly sys_warning_count("warning_count",
293
303
                                          OPT_SESSION,
294
304
                                          SHOW_INT,
295
305
                                          get_warning_count);
296
306
 
297
 
sys_var_session_uint64_t sys_group_concat_max_len(&vars, "group_concat_max_len",
298
 
                                                  &system_variables::group_concat_max_len);
 
307
sys_var_session_uint64_t sys_group_concat_max_len("group_concat_max_len",
 
308
                                                  &drizzle_system_variables::group_concat_max_len);
299
309
 
300
 
sys_var_session_time_zone sys_time_zone(&vars, "time_zone");
 
310
sys_var_session_time_zone sys_time_zone("time_zone");
301
311
 
302
312
/* Global read-only variable containing hostname */
303
 
static sys_var_const_str        sys_hostname(&vars, "hostname", glob_hostname);
304
 
 
305
 
/*
306
 
  Additional variables (not derived from sys_var class, not accessible as
307
 
  @@varname in SELECT or SET). Sorted in alphabetical order to facilitate
308
 
  maintenance - SHOW VARIABLES will sort its output.
309
 
  TODO: remove this list completely
310
 
*/
311
 
 
312
 
#define FIXED_VARS_SIZE (sizeof(fixed_vars) / sizeof(drizzle_show_var))
313
 
static drizzle_show_var fixed_vars[]= {
314
 
  {"back_log",                (char*) &back_log,                SHOW_INT},
315
 
  {"language",                language,                         SHOW_CHAR},
316
 
  {"pid_file",                (char*) pidfile_name,             SHOW_CHAR},
317
 
  {"plugin_dir",              (char*) opt_plugin_dir,           SHOW_CHAR},
318
 
  {"thread_stack",            (char*) &my_thread_stack_size,    SHOW_INT},
319
 
};
320
 
 
321
 
bool sys_var::check(Session *, set_var *var)
 
313
static sys_var_const_str        sys_hostname("hostname", glob_hostname);
 
314
 
 
315
bool sys_var::check(Session *session, set_var *var)
322
316
{
323
 
  var->save_result.uint64_t_value= var->value->val_int();
 
317
  if (check_func)
 
318
  {
 
319
    int res;
 
320
    if ((res=(*check_func)(session, var)) < 0)
 
321
      my_error(ER_WRONG_VALUE_FOR_VAR, MYF(0), getName().c_str(), var->value->str_value.ptr());
 
322
    return res;
 
323
  }
 
324
  var->updateValue();
324
325
  return 0;
325
326
}
326
327
 
327
328
bool sys_var_str::check(Session *session, set_var *var)
328
329
{
 
330
  if (!check_func)
 
331
    return 0;
 
332
 
329
333
  int res;
330
 
  if (!check_func)
331
 
    return 0;
332
 
 
333
334
  if ((res=(*check_func)(session, var)) < 0)
334
335
    my_error(ER_WRONG_VALUE_FOR_VAR, MYF(0), getName().c_str(), var->value->str_value.ptr());
335
336
  return res;
336
337
}
337
338
 
 
339
bool sys_var_std_string::check(Session *session, set_var *var)
 
340
{
 
341
  if (check_func == NULL)
 
342
  {
 
343
    return false;
 
344
  }
 
345
 
 
346
  int res= (*check_func)(session, var);
 
347
  if (res != 0)
 
348
  {
 
349
    my_error(ER_WRONG_VALUE_FOR_VAR, MYF(0), getName().c_str(), var->value->str_value.ptr());
 
350
    return true;
 
351
  }
 
352
  return false;
 
353
}
 
354
 
338
355
/*
339
356
  Functions to check and update variables
340
357
*/
399
416
static void fix_session_mem_root(Session *session, sql_var_t type)
400
417
{
401
418
  if (type != OPT_GLOBAL)
402
 
    reset_root_defaults(session->mem_root,
403
 
                        session->variables.query_alloc_block_size,
404
 
                        session->variables.query_prealloc_size);
 
419
    session->mem_root->reset_root_defaults(session->variables.query_alloc_block_size,
 
420
                                           session->variables.query_prealloc_size);
405
421
}
406
422
 
407
423
 
415
431
{
416
432
  if (fixed)
417
433
  {
418
 
    char buf[22];
 
434
    char buf[DECIMAL_LONGLONG_DIGITS];
419
435
 
420
436
    if (unsignd)
421
437
      internal::ullstr((uint64_t) val, buf);
450
466
  return out;
451
467
}
452
468
 
453
 
static bool get_unsigned32(Session *session, set_var *var)
454
 
{
455
 
  if (var->value->unsigned_flag)
456
 
    var->save_result.uint32_t_value= 
457
 
      static_cast<uint32_t>(var->value->val_int());
458
 
  else
459
 
  {
460
 
    int64_t v= var->value->val_int();
461
 
    if (v > UINT32_MAX)
462
 
      throw_bounds_warning(session, true, true,var->var->getName().c_str(), v);
463
 
    
464
 
    var->save_result.uint32_t_value= 
465
 
      static_cast<uint32_t>((v > UINT32_MAX) ? UINT32_MAX : (v < 0) ? 0 : v);
466
 
  }
467
 
  return false;
468
 
}
469
 
 
470
 
static bool get_unsigned64(Session *, set_var *var)
471
 
{
472
 
  if (var->value->unsigned_flag)
473
 
      var->save_result.uint64_t_value=(uint64_t) var->value->val_int();
474
 
  else
475
 
  {
476
 
    int64_t v= var->value->val_int();
477
 
      var->save_result.uint64_t_value= (uint64_t) ((v < 0) ? 0 : v);
478
 
  }
479
 
  return 0;
480
 
}
481
 
 
482
 
static bool get_size_t(Session *, set_var *var)
483
 
{
484
 
  if (var->value->unsigned_flag)
485
 
    var->save_result.size_t_value= (size_t) var->value->val_int();
486
 
  else
487
 
  {
488
 
    ssize_t v= (ssize_t)var->value->val_int();
489
 
    var->save_result.size_t_value= (size_t) ((v < 0) ? 0 : v);
490
 
  }
491
 
  return 0;
492
 
}
493
 
 
494
469
bool sys_var_uint32_t_ptr::check(Session *, set_var *var)
495
470
{
496
 
  var->save_result.uint32_t_value= (uint32_t)var->value->val_int();
 
471
  var->updateValue();
497
472
  return 0;
498
473
}
499
474
 
500
475
bool sys_var_uint32_t_ptr::update(Session *session, set_var *var)
501
476
{
502
 
  uint32_t tmp= var->save_result.uint32_t_value;
503
 
  pthread_mutex_lock(&LOCK_global_system_variables);
 
477
  uint64_t tmp= var->getInteger();
 
478
  boost::mutex::scoped_lock scopedLock(session->catalog().systemVariableLock());
 
479
 
504
480
  if (option_limits)
505
481
  {
506
482
    uint32_t newvalue= (uint32_t) fix_unsigned(session, tmp, option_limits);
507
 
    if(newvalue==tmp)
 
483
    if(static_cast<uint64_t>(newvalue) == tmp)
508
484
      *value= newvalue;
509
485
  }
510
486
  else
511
 
    *value= (uint32_t) tmp;
512
 
  pthread_mutex_unlock(&LOCK_global_system_variables);
 
487
  {
 
488
    *value= static_cast<uint32_t>(tmp);
 
489
  }
 
490
 
513
491
  return 0;
514
492
}
515
493
 
516
494
 
517
 
void sys_var_uint32_t_ptr::set_default(Session *, sql_var_t)
 
495
void sys_var_uint32_t_ptr::set_default(Session *session, sql_var_t)
518
496
{
519
497
  bool not_used;
520
 
  pthread_mutex_lock(&LOCK_global_system_variables);
 
498
  boost::mutex::scoped_lock scopedLock(session->catalog().systemVariableLock());
521
499
  *value= (uint32_t)getopt_ull_limit_value((uint32_t) option_limits->def_value,
522
500
                                           option_limits, &not_used);
523
 
  pthread_mutex_unlock(&LOCK_global_system_variables);
524
501
}
525
502
 
526
503
 
527
504
bool sys_var_uint64_t_ptr::update(Session *session, set_var *var)
528
505
{
529
 
  uint64_t tmp= var->save_result.uint64_t_value;
530
 
  pthread_mutex_lock(&LOCK_global_system_variables);
 
506
  uint64_t tmp= var->getInteger();
 
507
  boost::mutex::scoped_lock scopedLock(session->catalog().systemVariableLock());
 
508
 
531
509
  if (option_limits)
532
510
  {
533
 
    uint64_t newvalue= (uint64_t) fix_unsigned(session, tmp, option_limits);
 
511
    uint64_t newvalue= fix_unsigned(session, tmp, option_limits);
534
512
    if(newvalue==tmp)
535
513
      *value= newvalue;
536
514
  }
537
515
  else
538
 
    *value= (uint64_t) tmp;
539
 
  pthread_mutex_unlock(&LOCK_global_system_variables);
 
516
  {
 
517
    *value= tmp;
 
518
  }
 
519
 
540
520
  return 0;
541
521
}
542
522
 
543
523
 
544
 
void sys_var_uint64_t_ptr::set_default(Session *, sql_var_t)
 
524
void sys_var_uint64_t_ptr::set_default(Session *session, sql_var_t)
545
525
{
546
 
  bool not_used;
547
 
  pthread_mutex_lock(&LOCK_global_system_variables);
548
 
  *value= getopt_ull_limit_value((uint64_t) option_limits->def_value,
549
 
                                 option_limits, &not_used);
550
 
  pthread_mutex_unlock(&LOCK_global_system_variables);
 
526
  if (have_default_value)
 
527
  {
 
528
    *value= default_value;
 
529
  }
 
530
  else
 
531
  {
 
532
    bool not_used;
 
533
    boost::mutex::scoped_lock scopedLock(session->catalog().systemVariableLock());
 
534
    *value= getopt_ull_limit_value((uint64_t) option_limits->def_value,
 
535
                                   option_limits, &not_used);
 
536
  }
551
537
}
552
538
 
553
539
 
554
540
bool sys_var_size_t_ptr::update(Session *session, set_var *var)
555
541
{
556
 
  size_t tmp= var->save_result.size_t_value;
557
 
  pthread_mutex_lock(&LOCK_global_system_variables);
 
542
  size_t tmp= size_t(var->getInteger());
 
543
 
 
544
  boost::mutex::scoped_lock scopedLock(session->catalog().systemVariableLock());
 
545
 
558
546
  if (option_limits)
559
547
    *value= fix_size_t(session, tmp, option_limits);
560
548
  else
561
549
    *value= tmp;
562
 
  pthread_mutex_unlock(&LOCK_global_system_variables);
 
550
 
563
551
  return 0;
564
552
}
565
553
 
566
554
 
567
 
void sys_var_size_t_ptr::set_default(Session *, sql_var_t)
 
555
void sys_var_size_t_ptr::set_default(Session *session, sql_var_t)
568
556
{
569
557
  bool not_used;
570
 
  pthread_mutex_lock(&LOCK_global_system_variables);
 
558
  boost::mutex::scoped_lock scopedLock(session->catalog().systemVariableLock());
571
559
  *value= (size_t)getopt_ull_limit_value((size_t) option_limits->def_value,
572
560
                                         option_limits, &not_used);
573
 
  pthread_mutex_unlock(&LOCK_global_system_variables);
 
561
}
 
562
 
 
563
bool sys_var_bool_ptr::check(Session *session, set_var *var)
 
564
{
 
565
  return check_enum(session, var, &bool_typelib);
574
566
}
575
567
 
576
568
bool sys_var_bool_ptr::update(Session *, set_var *var)
577
569
{
578
 
  *value= (bool) var->save_result.uint32_t_value;
 
570
  *value= bool(var->getInteger());
579
571
  return 0;
580
572
}
581
573
 
582
574
 
583
575
void sys_var_bool_ptr::set_default(Session *, sql_var_t)
584
576
{
585
 
  *value= (bool) option_limits->def_value;
 
577
  *value= default_value;
586
578
}
587
579
 
588
580
 
591
583
*/
592
584
bool sys_var_session_uint32_t::check(Session *session, set_var *var)
593
585
{
594
 
  return (get_unsigned32(session, var) ||
595
 
          (check_func && (*check_func)(session, var)));
 
586
  var->updateValue();
 
587
  return (check_func && (*check_func)(session, var));
596
588
}
597
589
 
598
590
bool sys_var_session_uint32_t::update(Session *session, set_var *var)
599
591
{
600
 
  uint64_t tmp= (uint64_t) var->save_result.uint32_t_value;
 
592
  uint64_t tmp= var->getInteger();
601
593
 
602
594
  /* Don't use bigger value than given with --maximum-variable-name=.. */
603
595
  if ((uint32_t) tmp > max_system_variables.*offset)
611
603
  else if (tmp > UINT32_MAX)
612
604
  {
613
605
    tmp= UINT32_MAX;
614
 
    throw_bounds_warning(session, true, true, getName(), (int64_t) var->save_result.uint64_t_value);
 
606
    throw_bounds_warning(session, true, true, getName(), int64_t(var->getInteger()));
615
607
  }
616
608
 
617
609
  if (var->type == OPT_GLOBAL)
650
642
 
651
643
bool sys_var_session_ha_rows::update(Session *session, set_var *var)
652
644
{
653
 
  uint64_t tmp= var->save_result.uint64_t_value;
 
645
  uint64_t tmp= var->getInteger();
654
646
 
655
647
  /* Don't use bigger value than given with --maximum-variable-name=.. */
656
648
  if ((ha_rows) tmp > max_system_variables.*offset)
661
653
  if (var->type == OPT_GLOBAL)
662
654
  {
663
655
    /* Lock is needed to make things safe on 32 bit systems */
664
 
    pthread_mutex_lock(&LOCK_global_system_variables);
 
656
    boost::mutex::scoped_lock scopedLock(session->catalog().systemVariableLock());
665
657
    global_system_variables.*offset= (ha_rows) tmp;
666
 
    pthread_mutex_unlock(&LOCK_global_system_variables);
667
658
  }
668
659
  else
 
660
  {
669
661
    session->variables.*offset= (ha_rows) tmp;
 
662
  }
 
663
 
670
664
  return 0;
671
665
}
672
666
 
677
671
  {
678
672
    bool not_used;
679
673
    /* We will not come here if option_limits is not set */
680
 
    pthread_mutex_lock(&LOCK_global_system_variables);
 
674
    boost::mutex::scoped_lock scopedLock(session->catalog().systemVariableLock());
681
675
    global_system_variables.*offset=
682
676
      (ha_rows) getopt_ull_limit_value((ha_rows) option_limits->def_value,
683
677
                                       option_limits, &not_used);
684
 
    pthread_mutex_unlock(&LOCK_global_system_variables);
685
678
  }
686
679
  else
 
680
  {
687
681
    session->variables.*offset= global_system_variables.*offset;
 
682
  }
688
683
}
689
684
 
690
685
 
699
694
 
700
695
bool sys_var_session_uint64_t::check(Session *session, set_var *var)
701
696
{
702
 
  return (get_unsigned64(session, var) ||
703
 
          (check_func && (*check_func)(session, var)));
 
697
  var->updateValue();
 
698
  return (check_func && (*check_func)(session, var));
704
699
}
705
700
 
706
701
bool sys_var_session_uint64_t::update(Session *session,  set_var *var)
707
702
{
708
 
  uint64_t tmp= var->save_result.uint64_t_value;
 
703
  uint64_t tmp= var->getInteger();
709
704
 
710
705
  if (tmp > max_system_variables.*offset)
711
706
  {
718
713
  if (var->type == OPT_GLOBAL)
719
714
  {
720
715
    /* Lock is needed to make things safe on 32 bit systems */
721
 
    pthread_mutex_lock(&LOCK_global_system_variables);
 
716
    boost::mutex::scoped_lock scopedLock(session->catalog().systemVariableLock());
722
717
    global_system_variables.*offset= (uint64_t) tmp;
723
 
    pthread_mutex_unlock(&LOCK_global_system_variables);
724
718
  }
725
719
  else
 
720
  {
726
721
    session->variables.*offset= (uint64_t) tmp;
 
722
  }
 
723
 
727
724
  return 0;
728
725
}
729
726
 
733
730
  if (type == OPT_GLOBAL)
734
731
  {
735
732
    bool not_used;
736
 
    pthread_mutex_lock(&LOCK_global_system_variables);
 
733
    boost::mutex::scoped_lock scopedLock(session->catalog().systemVariableLock());
737
734
    global_system_variables.*offset=
738
735
      getopt_ull_limit_value((uint64_t) option_limits->def_value,
739
736
                             option_limits, &not_used);
740
 
    pthread_mutex_unlock(&LOCK_global_system_variables);
741
737
  }
742
738
  else
 
739
  {
743
740
    session->variables.*offset= global_system_variables.*offset;
 
741
  }
744
742
}
745
743
 
746
744
 
755
753
 
756
754
bool sys_var_session_size_t::check(Session *session, set_var *var)
757
755
{
758
 
  return (get_size_t(session, var) ||
759
 
          (check_func && (*check_func)(session, var)));
 
756
  var->updateValue();
 
757
  return (check_func && (*check_func)(session, var));
760
758
}
761
759
 
762
760
bool sys_var_session_size_t::update(Session *session,  set_var *var)
763
761
{
764
 
  size_t tmp= var->save_result.size_t_value;
 
762
  size_t tmp= size_t(var->getInteger());
765
763
 
766
764
  if (tmp > max_system_variables.*offset)
767
765
    tmp= max_system_variables.*offset;
771
769
  if (var->type == OPT_GLOBAL)
772
770
  {
773
771
    /* Lock is needed to make things safe on 32 bit systems */
774
 
    pthread_mutex_lock(&LOCK_global_system_variables);
 
772
    boost::mutex::scoped_lock scopedLock(session->catalog().systemVariableLock());
775
773
    global_system_variables.*offset= tmp;
776
 
    pthread_mutex_unlock(&LOCK_global_system_variables);
777
774
  }
778
775
  else
 
776
  {
779
777
    session->variables.*offset= tmp;
 
778
  }
 
779
 
780
780
  return 0;
781
781
}
782
782
 
786
786
  if (type == OPT_GLOBAL)
787
787
  {
788
788
    bool not_used;
789
 
    pthread_mutex_lock(&LOCK_global_system_variables);
 
789
    boost::mutex::scoped_lock scopedLock(session->catalog().systemVariableLock());
790
790
    global_system_variables.*offset=
791
791
      (size_t)getopt_ull_limit_value((size_t) option_limits->def_value,
792
792
                                     option_limits, &not_used);
793
 
    pthread_mutex_unlock(&LOCK_global_system_variables);
794
793
  }
795
794
  else
 
795
  {
796
796
    session->variables.*offset= global_system_variables.*offset;
 
797
  }
797
798
}
798
799
 
799
800
 
806
807
  return (unsigned char*) &(session->variables.*offset);
807
808
}
808
809
 
 
810
bool sys_var_session_bool::check(Session *session, set_var *var)
 
811
{
 
812
  return check_enum(session, var, &bool_typelib);
 
813
}
809
814
 
810
815
bool sys_var_session_bool::update(Session *session,  set_var *var)
811
816
{
812
817
  if (var->type == OPT_GLOBAL)
813
 
    global_system_variables.*offset= (bool) var->save_result.uint32_t_value;
 
818
    global_system_variables.*offset= bool(var->getInteger());
814
819
  else
815
 
    session->variables.*offset= (bool) var->save_result.uint32_t_value;
 
820
    session->variables.*offset= bool(var->getInteger());
 
821
 
816
822
  return 0;
817
823
}
818
824
 
845
851
 
846
852
  if (var->value->result_type() == STRING_RESULT)
847
853
  {
848
 
    if (!(res=var->value->val_str(&str)) ||
849
 
        (var->save_result.uint32_t_value= find_type(enum_names, res->ptr(),
850
 
                                                    res->length(),1)) == 0)
 
854
    res= var->value->val_str(&str);
 
855
    if (res == NULL)
851
856
    {
852
 
      value= res ? res->c_ptr() : "NULL";
 
857
      value= "NULL";
853
858
      goto err;
854
859
    }
855
860
 
856
 
    var->save_result.uint32_t_value--;
 
861
    uint64_t tmp_val= find_type(enum_names, res->ptr(), res->length(),1);
 
862
    if (tmp_val == 0)
 
863
    {
 
864
      value= res->c_ptr();
 
865
      goto err;
 
866
    }
 
867
    var->setValue(tmp_val-1);
857
868
  }
858
869
  else
859
870
  {
860
 
    uint64_t tmp=var->value->val_int();
 
871
    uint64_t tmp= var->value->val_int();
861
872
    if (tmp >= enum_names->count)
862
873
    {
863
874
      internal::llstr(tmp,buff);
864
875
      value=buff;                               // Wrong value is here
865
876
      goto err;
866
877
    }
867
 
    var->save_result.uint32_t_value= (uint32_t) tmp;    // Save for update
 
878
    var->setValue(tmp); // Save for update
868
879
  }
869
880
  return 0;
870
881
 
900
911
  case SHOW_INT:
901
912
  {
902
913
    uint32_t value;
903
 
    pthread_mutex_lock(&LOCK_global_system_variables);
 
914
    boost::mutex::scoped_lock scopedLock(session->catalog().systemVariableLock());
904
915
    value= *(uint*) value_ptr(session, var_type, base);
905
 
    pthread_mutex_unlock(&LOCK_global_system_variables);
 
916
 
906
917
    return new Item_uint((uint64_t) value);
907
918
  }
908
919
  case SHOW_LONGLONG:
909
920
  {
910
921
    int64_t value;
911
 
    pthread_mutex_lock(&LOCK_global_system_variables);
 
922
    boost::mutex::scoped_lock scopedLock(session->catalog().systemVariableLock());
912
923
    value= *(int64_t*) value_ptr(session, var_type, base);
913
 
    pthread_mutex_unlock(&LOCK_global_system_variables);
 
924
 
914
925
    return new Item_int(value);
915
926
  }
916
927
  case SHOW_DOUBLE:
917
928
  {
918
929
    double value;
919
 
    pthread_mutex_lock(&LOCK_global_system_variables);
920
 
    value= *(double*) value_ptr(session, var_type, base);
921
 
    pthread_mutex_unlock(&LOCK_global_system_variables);
 
930
    {
 
931
      boost::mutex::scoped_lock scopedLock(session->catalog().systemVariableLock());
 
932
      value= *(double*) value_ptr(session, var_type, base);
 
933
    }
 
934
 
922
935
    /* 6, as this is for now only used with microseconds */
923
936
    return new Item_float(value, 6);
924
937
  }
925
938
  case SHOW_HA_ROWS:
926
939
  {
927
940
    ha_rows value;
928
 
    pthread_mutex_lock(&LOCK_global_system_variables);
 
941
    boost::mutex::scoped_lock scopedLock(session->catalog().systemVariableLock());
929
942
    value= *(ha_rows*) value_ptr(session, var_type, base);
930
 
    pthread_mutex_unlock(&LOCK_global_system_variables);
 
943
 
931
944
    return new Item_int((uint64_t) value);
932
945
  }
933
946
  case SHOW_SIZE:
934
947
  {
935
948
    size_t value;
936
 
    pthread_mutex_lock(&LOCK_global_system_variables);
 
949
    boost::mutex::scoped_lock scopedLock(session->catalog().systemVariableLock());
937
950
    value= *(size_t*) value_ptr(session, var_type, base);
938
 
    pthread_mutex_unlock(&LOCK_global_system_variables);
 
951
 
939
952
    return new Item_int((uint64_t) value);
940
953
  }
941
954
  case SHOW_MY_BOOL:
942
955
  {
943
956
    int32_t value;
944
 
    pthread_mutex_lock(&LOCK_global_system_variables);
 
957
    boost::mutex::scoped_lock scopedLock(session->catalog().systemVariableLock());
945
958
    value= *(bool*) value_ptr(session, var_type, base);
946
 
    pthread_mutex_unlock(&LOCK_global_system_variables);
947
959
    return new Item_int(value,1);
948
960
  }
949
961
  case SHOW_CHAR_PTR:
950
962
  {
951
963
    Item *tmp;
952
 
    pthread_mutex_lock(&LOCK_global_system_variables);
 
964
    boost::mutex::scoped_lock scopedLock(session->catalog().systemVariableLock());
953
965
    char *str= *(char**) value_ptr(session, var_type, base);
954
966
    if (str)
955
967
    {
962
974
      tmp= new Item_null();
963
975
      tmp->collation.set(system_charset_info, DERIVATION_SYSCONST);
964
976
    }
965
 
    pthread_mutex_unlock(&LOCK_global_system_variables);
 
977
 
966
978
    return tmp;
967
979
  }
968
980
  case SHOW_CHAR:
969
981
  {
970
982
    Item *tmp;
971
 
    pthread_mutex_lock(&LOCK_global_system_variables);
 
983
    boost::mutex::scoped_lock scopedLock(session->catalog().systemVariableLock());
972
984
    char *str= (char*) value_ptr(session, var_type, base);
973
985
    if (str)
974
986
      tmp= new Item_string(str, strlen(str),
978
990
      tmp= new Item_null();
979
991
      tmp->collation.set(system_charset_info, DERIVATION_SYSCONST);
980
992
    }
981
 
    pthread_mutex_unlock(&LOCK_global_system_variables);
 
993
 
982
994
    return tmp;
983
995
  }
984
996
  default:
991
1003
bool sys_var_session_enum::update(Session *session, set_var *var)
992
1004
{
993
1005
  if (var->type == OPT_GLOBAL)
994
 
    global_system_variables.*offset= var->save_result.uint32_t_value;
 
1006
    global_system_variables.*offset= var->getInteger();
995
1007
  else
996
 
    session->variables.*offset= var->save_result.uint32_t_value;
 
1008
    session->variables.*offset= var->getInteger();
997
1009
  return 0;
998
1010
}
999
1011
 
1043
1055
}
1044
1056
 
1045
1057
 
1046
 
typedef struct old_names_map_st
1047
 
{
1048
 
  const char *old_name;
1049
 
  const char *new_name;
1050
 
} my_old_conv;
1051
 
 
1052
 
bool sys_var_collation::check(Session *, set_var *var)
 
1058
bool sys_var_collation_sv::update(Session *session, set_var *var)
1053
1059
{
1054
1060
  const CHARSET_INFO *tmp;
1055
1061
 
1059
1065
    String str(buff,sizeof(buff), system_charset_info), *res;
1060
1066
    if (!(res=var->value->val_str(&str)))
1061
1067
    {
1062
 
      my_error(ER_WRONG_VALUE_FOR_VAR, MYF(0), name.c_str(), "NULL");
 
1068
      boost::throw_exception(invalid_option_value(var->var->getName()) << invalid_value(std::string("NULL")));
1063
1069
      return 1;
1064
1070
    }
1065
1071
    if (!(tmp=get_charset_by_name(res->c_ptr())))
1066
1072
    {
1067
1073
      my_error(ER_UNKNOWN_COLLATION, MYF(0), res->c_ptr());
 
1074
      boost::throw_exception(invalid_option_value(var->var->getName()) << invalid_value(std::string(res->c_ptr())));
1068
1075
      return 1;
1069
1076
    }
1070
1077
  }
1075
1082
      char buf[20];
1076
1083
      internal::int10_to_str((int) var->value->val_int(), buf, -10);
1077
1084
      my_error(ER_UNKNOWN_COLLATION, MYF(0), buf);
 
1085
      boost::throw_exception(invalid_option_value(var->var->getName()) << invalid_value(boost::lexical_cast<std::string>(var->value->val_int())));
1078
1086
      return 1;
1079
1087
    }
1080
1088
  }
1081
 
  var->save_result.charset= tmp;        // Save for update
1082
 
  return 0;
1083
 
}
1084
 
 
1085
 
 
1086
 
bool sys_var_collation_sv::update(Session *session, set_var *var)
1087
 
{
1088
1089
  if (var->type == OPT_GLOBAL)
1089
 
    global_system_variables.*offset= var->save_result.charset;
 
1090
    global_system_variables.*offset= tmp;
1090
1091
  else
1091
1092
  {
1092
 
    session->variables.*offset= var->save_result.charset;
 
1093
    session->variables.*offset= tmp;
1093
1094
  }
1094
1095
  return 0;
1095
1096
}
1120
1121
 
1121
1122
bool sys_var_timestamp::update(Session *session,  set_var *var)
1122
1123
{
1123
 
  session->set_time((time_t) var->save_result.uint64_t_value);
 
1124
  session->set_time(time_t(var->getInteger()));
1124
1125
  return 0;
1125
1126
}
1126
1127
 
1127
1128
 
1128
1129
void sys_var_timestamp::set_default(Session *session, sql_var_t)
1129
1130
{
1130
 
  session->user_time=0;
 
1131
  session->resetUserTime();
1131
1132
}
1132
1133
 
1133
1134
 
1134
1135
unsigned char *sys_var_timestamp::value_ptr(Session *session, sql_var_t,
1135
1136
                                            const LEX_STRING *)
1136
1137
{
1137
 
  session->sys_var_tmp.int32_t_value= (int32_t) session->start_time;
 
1138
  session->sys_var_tmp.int32_t_value= (int32_t) session->getCurrentTimestampEpoch();
1138
1139
  return (unsigned char*) &session->sys_var_tmp.int32_t_value;
1139
1140
}
1140
1141
 
1141
1142
 
1142
1143
bool sys_var_last_insert_id::update(Session *session, set_var *var)
1143
1144
{
1144
 
  session->first_successful_insert_id_in_prev_stmt=
1145
 
    var->save_result.uint64_t_value;
 
1145
  session->first_successful_insert_id_in_prev_stmt= var->getInteger();
1146
1146
  return 0;
1147
1147
}
1148
1148
 
1161
1161
}
1162
1162
 
1163
1163
 
1164
 
bool sys_var_session_time_zone::check(Session *session, set_var *var)
 
1164
bool sys_var_session_time_zone::update(Session *session, set_var *var)
1165
1165
{
1166
1166
  char buff[MAX_TIME_ZONE_NAME_LENGTH];
1167
1167
  String str(buff, sizeof(buff), &my_charset_utf8_general_ci);
1168
1168
  String *res= var->value->val_str(&str);
1169
1169
 
1170
 
  if (!(var->save_result.time_zone= my_tz_find(session, res)))
 
1170
  Time_zone *tmp= my_tz_find(session, res);
 
1171
  if (tmp == NULL)
1171
1172
  {
1172
 
    my_error(ER_UNKNOWN_TIME_ZONE, MYF(0), res ? res->c_ptr() : "NULL");
 
1173
    boost::throw_exception(invalid_option_value(var->var->getName()) << invalid_value(std::string(res ? res->c_ptr() : "NULL")));
1173
1174
    return 1;
1174
1175
  }
1175
 
  return 0;
1176
 
}
1177
 
 
1178
 
 
1179
 
bool sys_var_session_time_zone::update(Session *session, set_var *var)
1180
 
{
1181
1176
  /* We are using Time_zone object found during check() phase. */
1182
1177
  if (var->type == OPT_GLOBAL)
1183
1178
  {
1184
 
    pthread_mutex_lock(&LOCK_global_system_variables);
1185
 
    global_system_variables.time_zone= var->save_result.time_zone;
1186
 
    pthread_mutex_unlock(&LOCK_global_system_variables);
 
1179
    boost::mutex::scoped_lock scopedLock(session->catalog().systemVariableLock());
 
1180
    global_system_variables.time_zone= tmp;
1187
1181
  }
1188
1182
  else
1189
 
    session->variables.time_zone= var->save_result.time_zone;
 
1183
  {
 
1184
    session->variables.time_zone= tmp;
 
1185
  }
 
1186
 
1190
1187
  return 0;
1191
1188
}
1192
1189
 
1218
1215
 
1219
1216
void sys_var_session_time_zone::set_default(Session *session, sql_var_t type)
1220
1217
{
1221
 
 pthread_mutex_lock(&LOCK_global_system_variables);
1222
 
 if (type == OPT_GLOBAL)
1223
 
 {
1224
 
   if (default_tz_name)
1225
 
   {
1226
 
     String str(default_tz_name, &my_charset_utf8_general_ci);
1227
 
     /*
1228
 
       We are guaranteed to find this time zone since its existence
1229
 
       is checked during start-up.
1230
 
     */
1231
 
     global_system_variables.time_zone= my_tz_find(session, &str);
1232
 
   }
1233
 
   else
1234
 
     global_system_variables.time_zone= my_tz_SYSTEM;
1235
 
 }
1236
 
 else
1237
 
   session->variables.time_zone= global_system_variables.time_zone;
1238
 
 pthread_mutex_unlock(&LOCK_global_system_variables);
 
1218
  boost::mutex::scoped_lock scopedLock(session->catalog().systemVariableLock());
 
1219
  if (type == OPT_GLOBAL)
 
1220
  {
 
1221
    if (default_tz_name)
 
1222
    {
 
1223
      String str(default_tz_name, &my_charset_utf8_general_ci);
 
1224
      /*
 
1225
        We are guaranteed to find this time zone since its existence
 
1226
        is checked during start-up.
 
1227
      */
 
1228
      global_system_variables.time_zone= my_tz_find(session, &str);
 
1229
    }
 
1230
    else
 
1231
      global_system_variables.time_zone= my_tz_SYSTEM;
 
1232
  }
 
1233
  else
 
1234
    session->variables.time_zone= global_system_variables.time_zone;
1239
1235
}
1240
1236
 
1241
1237
 
1242
 
bool sys_var_session_lc_time_names::check(Session *, set_var *var)
 
1238
 
 
1239
bool sys_var_session_lc_time_names::update(Session *session, set_var *var)
1243
1240
{
1244
1241
  MY_LOCALE *locale_match;
1245
1242
 
1247
1244
  {
1248
1245
    if (!(locale_match= my_locale_by_number((uint32_t) var->value->val_int())))
1249
1246
    {
1250
 
      char buf[20];
 
1247
      char buf[DECIMAL_LONGLONG_DIGITS];
1251
1248
      internal::int10_to_str((int) var->value->val_int(), buf, -10);
1252
1249
      my_printf_error(ER_UNKNOWN_ERROR, "Unknown locale: '%s'", MYF(0), buf);
1253
1250
      return 1;
1271
1268
    }
1272
1269
  }
1273
1270
 
1274
 
  var->save_result.locale_value= locale_match;
1275
 
  return 0;
1276
 
}
1277
 
 
1278
 
 
1279
 
bool sys_var_session_lc_time_names::update(Session *session, set_var *var)
1280
 
{
1281
1271
  if (var->type == OPT_GLOBAL)
1282
 
    global_system_variables.lc_time_names= var->save_result.locale_value;
 
1272
    global_system_variables.lc_time_names= locale_match;
1283
1273
  else
1284
 
    session->variables.lc_time_names= var->save_result.locale_value;
 
1274
    session->variables.lc_time_names= locale_match;
1285
1275
  return 0;
1286
1276
}
1287
1277
 
1324
1314
  microseconds= (int64_t) (num * 1000000.0 + 0.5);
1325
1315
  if (var->type == OPT_GLOBAL)
1326
1316
  {
1327
 
    pthread_mutex_lock(&LOCK_global_system_variables);
 
1317
    boost::mutex::scoped_lock scopedLock(session->catalog().systemVariableLock());
1328
1318
    (global_system_variables.*offset)= microseconds;
1329
 
    pthread_mutex_unlock(&LOCK_global_system_variables);
1330
1319
  }
1331
1320
  else
1332
1321
    session->variables.*offset= microseconds;
1339
1328
  int64_t microseconds= (int64_t) (option_limits->def_value * 1000000.0);
1340
1329
  if (type == OPT_GLOBAL)
1341
1330
  {
1342
 
    pthread_mutex_lock(&LOCK_global_system_variables);
 
1331
    boost::mutex::scoped_lock scopedLock(session->catalog().systemVariableLock());
1343
1332
    global_system_variables.*offset= microseconds;
1344
 
    pthread_mutex_unlock(&LOCK_global_system_variables);
1345
1333
  }
1346
1334
  else
1347
1335
    session->variables.*offset= microseconds;
1354
1342
static bool set_option_bit(Session *session, set_var *var)
1355
1343
{
1356
1344
  sys_var_session_bit *sys_var= ((sys_var_session_bit*) var->var);
1357
 
  if ((var->save_result.uint32_t_value != 0) == sys_var->reverse)
 
1345
  if ((var->getInteger() != 0) == sys_var->reverse)
1358
1346
    session->options&= ~sys_var->bit_flag;
1359
1347
  else
1360
1348
    session->options|= sys_var->bit_flag;
1364
1352
 
1365
1353
static bool set_option_autocommit(Session *session, set_var *var)
1366
1354
{
 
1355
  bool success= true;
1367
1356
  /* The test is negative as the flag we use is NOT autocommit */
1368
1357
 
1369
1358
  uint64_t org_options= session->options;
 
1359
  uint64_t new_options= session->options;
1370
1360
 
1371
 
  if (var->save_result.uint32_t_value != 0)
1372
 
    session->options&= ~((sys_var_session_bit*) var->var)->bit_flag;
 
1361
  if (var->getInteger() != 0)
 
1362
    new_options&= ~((sys_var_session_bit*) var->var)->bit_flag;
1373
1363
  else
1374
 
    session->options|= ((sys_var_session_bit*) var->var)->bit_flag;
 
1364
    new_options|= ((sys_var_session_bit*) var->var)->bit_flag;
1375
1365
 
1376
 
  if ((org_options ^ session->options) & OPTION_NOT_AUTOCOMMIT)
 
1366
  if ((org_options ^ new_options) & OPTION_NOT_AUTOCOMMIT)
1377
1367
  {
1378
1368
    if ((org_options & OPTION_NOT_AUTOCOMMIT))
1379
1369
    {
 
1370
      success= session->endActiveTransaction();
1380
1371
      /* We changed to auto_commit mode */
1381
1372
      session->options&= ~(uint64_t) (OPTION_BEGIN);
1382
1373
      session->server_status|= SERVER_STATUS_AUTOCOMMIT;
1383
 
      TransactionServices &transaction_services= TransactionServices::singleton();
1384
 
      if (transaction_services.ha_commit_trans(session, true))
1385
 
        return 1;
1386
1374
    }
1387
1375
    else
1388
1376
    {
1389
1377
      session->server_status&= ~SERVER_STATUS_AUTOCOMMIT;
1390
1378
    }
1391
1379
  }
 
1380
 
 
1381
  if (var->getInteger() != 0)
 
1382
    session->options&= ~((sys_var_session_bit*) var->var)->bit_flag;
 
1383
  else
 
1384
    session->options|= ((sys_var_session_bit*) var->var)->bit_flag;
 
1385
 
 
1386
  if (not success)
 
1387
    return true;
 
1388
 
1392
1389
  return 0;
1393
1390
}
1394
1391
 
1395
1392
static int check_pseudo_thread_id(Session *, set_var *var)
1396
1393
{
1397
 
  var->save_result.uint64_t_value= var->value->val_int();
 
1394
  var->updateValue();
1398
1395
  return 0;
1399
1396
}
1400
1397
 
1431
1428
*/
1432
1429
static unsigned char *get_tmpdir(Session *)
1433
1430
{
1434
 
  assert(drizzle_tmpdir);
1435
 
  return (unsigned char*)drizzle_tmpdir;
 
1431
  assert(drizzle_tmpdir.size());
 
1432
  return (unsigned char*)drizzle_tmpdir.c_str();
1436
1433
}
1437
1434
 
1438
1435
/****************************************************************************
1474
1471
}
1475
1472
 
1476
1473
 
1477
 
/*
1478
 
  Add variables to the dynamic hash of system variables
1479
 
 
1480
 
  SYNOPSIS
1481
 
    mysql_add_sys_var_chain()
1482
 
    first       Pointer to first system variable to add
1483
 
    long_opt    (optional)command line arguments may be tied for limit checks.
1484
 
 
1485
 
  RETURN VALUES
1486
 
    0           SUCCESS
1487
 
    otherwise   FAILURE
1488
 
*/
1489
 
 
1490
 
 
1491
 
int mysql_add_sys_var_chain(sys_var *first, struct option *long_options)
1492
 
{
1493
 
  sys_var *var;
1494
 
  /* A write lock should be held on LOCK_system_variables_hash */
1495
 
 
1496
 
  for (var= first; var; var= var->getNext())
1497
 
  {
1498
 
 
1499
 
    string lower_name(var->getName());
1500
 
    transform(lower_name.begin(), lower_name.end(),
1501
 
              lower_name.begin(), ::tolower);
1502
 
 
1503
 
    /* this fails if there is a conflicting variable name. */
1504
 
    if (system_variable_map.find(lower_name) != system_variable_map.end())
1505
 
    {
1506
 
      errmsg_printf(ERRMSG_LVL_ERROR, _("Variable named %s already exists!\n"),
1507
 
                    var->getName().c_str());
1508
 
      return 1;
1509
 
    } 
1510
 
 
1511
 
    pair<SystemVariableMap::iterator, bool> ret= 
1512
 
      system_variable_map.insert(make_pair(lower_name, var));
1513
 
    if (ret.second == false)
1514
 
    {
1515
 
      errmsg_printf(ERRMSG_LVL_ERROR, _("Could not add Variable: %s\n"),
1516
 
                    var->getName().c_str());
1517
 
      return 1;
1518
 
    }
1519
 
 
1520
 
    if (long_options)
1521
 
      var->setOptionLimits(find_option(long_options, var->getName().c_str()));
1522
 
  }
1523
 
  return 0;
1524
 
 
1525
 
}
1526
 
 
1527
 
 
1528
 
/*
1529
 
  Remove variables to the dynamic hash of system variables
1530
 
 
1531
 
  SYNOPSIS
1532
 
    mysql_del_sys_var_chain()
1533
 
    first       Pointer to first system variable to remove
1534
 
 
1535
 
  RETURN VALUES
1536
 
    0           SUCCESS
1537
 
    otherwise   FAILURE
1538
 
*/
1539
 
 
1540
 
int mysql_del_sys_var_chain(sys_var *first)
1541
 
{
1542
 
 
1543
 
  /* A write lock should be held on LOCK_system_variables_hash */
1544
 
  for (sys_var *var= first; var; var= var->getNext())
1545
 
  {
1546
 
    string lower_name(var->getName());
1547
 
    transform(lower_name.begin(), lower_name.end(),
1548
 
              lower_name.begin(), ::tolower);
1549
 
    system_variable_map.erase(lower_name);
1550
 
  }
1551
 
  return 0;
1552
 
}
1553
1474
 
1554
1475
 
1555
1476
 
1559
1480
  SYNOPSIS
1560
1481
    enumerate_sys_vars()
1561
1482
    session         current thread
1562
 
    sorted      If TRUE, the system variables should be sorted
1563
1483
 
1564
1484
  RETURN VALUES
1565
1485
    pointer     Array of drizzle_show_var elements for display
1566
1486
    NULL        FAILURE
1567
1487
*/
1568
1488
 
1569
 
drizzle_show_var* enumerate_sys_vars(Session *session, bool)
 
1489
drizzle_show_var* enumerate_sys_vars(Session *session)
1570
1490
{
1571
 
  int fixed_count= fixed_show_vars.elements;
1572
 
  int size= sizeof(drizzle_show_var) * (system_variable_map.size() + fixed_count + 1);
 
1491
  int size= sizeof(drizzle_show_var) * (system_variable_map.size() + 1);
1573
1492
  drizzle_show_var *result= (drizzle_show_var*) session->alloc(size);
1574
1493
 
1575
1494
  if (result)
1576
1495
  {
1577
 
    drizzle_show_var *show= result + fixed_count;
1578
 
    memcpy(result, fixed_show_vars.buffer, fixed_count * sizeof(drizzle_show_var));
 
1496
    drizzle_show_var *show= result;
1579
1497
 
1580
1498
    SystemVariableMap::const_iterator iter= system_variable_map.begin();
1581
1499
    while (iter != system_variable_map.end())
1584
1502
      show->name= var->getName().c_str();
1585
1503
      show->value= (char*) var;
1586
1504
      show->type= SHOW_SYS;
1587
 
      show++;
 
1505
      ++show;
1588
1506
      ++iter;
1589
1507
    }
1590
1508
 
1595
1513
}
1596
1514
 
1597
1515
 
 
1516
 
 
1517
void add_sys_var_to_list(sys_var *var)
 
1518
{
 
1519
  string lower_name(var->getName());
 
1520
  transform(lower_name.begin(), lower_name.end(),
 
1521
            lower_name.begin(), ::tolower);
 
1522
 
 
1523
  /* this fails if there is a conflicting variable name. */
 
1524
  if (system_variable_map.find(lower_name) != system_variable_map.end())
 
1525
  {
 
1526
    errmsg_printf(error::ERROR, _("Variable named %s already exists!\n"),
 
1527
                  var->getName().c_str());
 
1528
    throw exception();
 
1529
  } 
 
1530
 
 
1531
  pair<SystemVariableMap::iterator, bool> ret= 
 
1532
    system_variable_map.insert(make_pair(lower_name, var));
 
1533
  if (ret.second == false)
 
1534
  {
 
1535
    errmsg_printf(error::ERROR, _("Could not add Variable: %s\n"),
 
1536
                  var->getName().c_str());
 
1537
    throw exception();
 
1538
  }
 
1539
}
 
1540
 
 
1541
void add_sys_var_to_list(sys_var *var, struct option *long_options)
 
1542
{
 
1543
  add_sys_var_to_list(var);
 
1544
  var->setOptionLimits(find_option(long_options, var->getName().c_str()));
 
1545
}
 
1546
 
1598
1547
/*
1599
1548
  Initialize the system variables
1600
1549
 
1601
1550
  SYNOPSIS
1602
 
    set_var_init()
 
1551
    sys_var_init()
1603
1552
 
1604
1553
  RETURN VALUES
1605
1554
    0           SUCCESS
1606
1555
    otherwise   FAILURE
1607
1556
*/
1608
1557
 
1609
 
int set_var_init()
 
1558
int sys_var_init()
1610
1559
{
1611
 
  uint32_t count= 0;
1612
 
 
1613
 
  for (sys_var *var= vars.first; var; var= var->getNext(), count++) {};
1614
 
 
1615
 
  if (my_init_dynamic_array(&fixed_show_vars, sizeof(drizzle_show_var),
1616
 
                            FIXED_VARS_SIZE + 64, 64))
1617
 
    goto error;
1618
 
 
1619
 
  fixed_show_vars.elements= FIXED_VARS_SIZE;
1620
 
  memcpy(fixed_show_vars.buffer, fixed_vars, sizeof(fixed_vars));
1621
 
 
1622
 
  vars.last->setNext(NULL);
1623
 
  if (mysql_add_sys_var_chain(vars.first, my_long_options))
1624
 
    goto error;
1625
 
 
 
1560
  try
 
1561
  {
 
1562
    add_sys_var_to_list(&sys_auto_increment_increment, my_long_options);
 
1563
    add_sys_var_to_list(&sys_auto_increment_offset, my_long_options);
 
1564
    add_sys_var_to_list(&sys_autocommit, my_long_options);
 
1565
    add_sys_var_to_list(&sys_back_log, my_long_options);
 
1566
    add_sys_var_to_list(&sys_basedir, my_long_options);
 
1567
    add_sys_var_to_list(&sys_big_selects, my_long_options);
 
1568
    add_sys_var_to_list(&sys_buffer_results, my_long_options);
 
1569
    add_sys_var_to_list(&sys_bulk_insert_buff_size, my_long_options);
 
1570
    add_sys_var_to_list(&sys_collation_server, my_long_options);
 
1571
    add_sys_var_to_list(&sys_completion_type, my_long_options);
 
1572
    add_sys_var_to_list(&sys_datadir, my_long_options);
 
1573
    add_sys_var_to_list(&sys_div_precincrement, my_long_options);
 
1574
    add_sys_var_to_list(&sys_error_count, my_long_options);
 
1575
    add_sys_var_to_list(&sys_foreign_key_checks, my_long_options);
 
1576
    add_sys_var_to_list(&sys_group_concat_max_len, my_long_options);
 
1577
    add_sys_var_to_list(&sys_hostname, my_long_options);
 
1578
    add_sys_var_to_list(&sys_identity, my_long_options);
 
1579
    add_sys_var_to_list(&sys_join_buffer_size, my_long_options);
 
1580
    add_sys_var_to_list(&sys_last_insert_id, my_long_options);
 
1581
    add_sys_var_to_list(&sys_lc_time_names, my_long_options);
 
1582
    add_sys_var_to_list(&sys_max_allowed_packet, my_long_options);
 
1583
    add_sys_var_to_list(&sys_max_error_count, my_long_options);
 
1584
    add_sys_var_to_list(&sys_max_heap_table_size, my_long_options);
 
1585
    add_sys_var_to_list(&sys_max_join_size, my_long_options);
 
1586
    add_sys_var_to_list(&sys_max_length_for_sort_data, my_long_options);
 
1587
    add_sys_var_to_list(&sys_max_seeks_for_key, my_long_options);
 
1588
    add_sys_var_to_list(&sys_max_sort_length, my_long_options);
 
1589
    add_sys_var_to_list(&sys_max_write_lock_count, my_long_options);
 
1590
    add_sys_var_to_list(&sys_min_examined_row_limit, my_long_options);
 
1591
    add_sys_var_to_list(&sys_optimizer_prune_level, my_long_options);
 
1592
    add_sys_var_to_list(&sys_optimizer_search_depth, my_long_options);
 
1593
    add_sys_var_to_list(&sys_pid_file, my_long_options);
 
1594
    add_sys_var_to_list(&sys_plugin_dir, my_long_options);
 
1595
    add_sys_var_to_list(&sys_preload_buff_size, my_long_options);
 
1596
    add_sys_var_to_list(&sys_pseudo_thread_id, my_long_options);
 
1597
    add_sys_var_to_list(&sys_query_alloc_block_size, my_long_options);
 
1598
    add_sys_var_to_list(&sys_query_prealloc_size, my_long_options);
 
1599
    add_sys_var_to_list(&sys_range_alloc_block_size, my_long_options);
 
1600
    add_sys_var_to_list(&sys_read_buff_size, my_long_options);
 
1601
    add_sys_var_to_list(&sys_read_rnd_buff_size, my_long_options);
 
1602
    add_sys_var_to_list(&sys_replicate_query, my_long_options);
 
1603
    add_sys_var_to_list(&sys_scheduler, my_long_options);
 
1604
    add_sys_var_to_list(&sys_secure_file_priv, my_long_options);
 
1605
    add_sys_var_to_list(&sys_select_limit, my_long_options);
 
1606
    add_sys_var_to_list(&sys_server_id, my_long_options);
 
1607
    add_sys_var_to_list(&sys_sort_buffer, my_long_options);
 
1608
    add_sys_var_to_list(&sys_sql_notes, my_long_options);
 
1609
    add_sys_var_to_list(&sys_sql_warnings, my_long_options);
 
1610
    add_sys_var_to_list(&sys_storage_engine, my_long_options);
 
1611
    add_sys_var_to_list(&sys_system_time_zone, my_long_options);
 
1612
    add_sys_var_to_list(&sys_table_cache_size, my_long_options);
 
1613
    add_sys_var_to_list(&sys_table_def_size, my_long_options);
 
1614
    add_sys_var_to_list(&sys_table_lock_wait_timeout, my_long_options);
 
1615
    add_sys_var_to_list(&sys_thread_stack_size, my_long_options);
 
1616
    add_sys_var_to_list(&sys_time_zone, my_long_options);
 
1617
    add_sys_var_to_list(&sys_timed_mutexes, my_long_options);
 
1618
    add_sys_var_to_list(&sys_timestamp, my_long_options);
 
1619
    add_sys_var_to_list(&sys_tmp_table_size, my_long_options);
 
1620
    add_sys_var_to_list(&sys_tmpdir, my_long_options);
 
1621
    add_sys_var_to_list(&sys_transaction_message_threshold, my_long_options);
 
1622
    add_sys_var_to_list(&sys_tx_isolation, my_long_options);
 
1623
    add_sys_var_to_list(&sys_unique_checks, my_long_options);
 
1624
    add_sys_var_to_list(&sys_version, my_long_options);
 
1625
    add_sys_var_to_list(&sys_version_comment, my_long_options);
 
1626
    add_sys_var_to_list(&sys_version_compile_machine, my_long_options);
 
1627
    add_sys_var_to_list(&sys_version_compile_os, my_long_options);
 
1628
    add_sys_var_to_list(&sys_version_compile_vendor, my_long_options);
 
1629
    add_sys_var_to_list(&sys_warning_count, my_long_options);
 
1630
  }
 
1631
  catch (std::exception&)
 
1632
  {
 
1633
    errmsg_printf(error::ERROR, _("Failed to initialize system variables"));
 
1634
    return(1);
 
1635
  }
1626
1636
  return(0);
1627
 
 
1628
 
error:
1629
 
  fprintf(stderr, "failed to initialize system variables");
1630
 
  return(1);
1631
 
}
1632
 
 
1633
 
 
1634
 
void set_var_free()
1635
 
{
1636
 
  delete_dynamic(&fixed_show_vars);
1637
1637
}
1638
1638
 
1639
1639
 
1640
1640
/**
1641
1641
  Find a user set-table variable.
1642
1642
 
1643
 
  @param str       Name of system variable to find
1644
 
  @param length    Length of variable.  zero means that we should use strlen()
1645
 
                   on the variable
1646
 
  @param no_error  Refuse to emit an error, even if one occurred.
 
1643
  @param name      Name of system variable to find
1647
1644
 
1648
1645
  @retval
1649
1646
    pointer     pointer to variable definitions
1651
1648
    0           Unknown variable (error message is given)
1652
1649
*/
1653
1650
 
1654
 
sys_var *intern_find_sys_var(const char *str, uint32_t, bool no_error)
 
1651
sys_var *find_sys_var(const std::string &name)
1655
1652
{
1656
 
  string lower_name(str);
 
1653
  string lower_name(name);
1657
1654
  transform(lower_name.begin(), lower_name.end(),
1658
1655
            lower_name.begin(), ::tolower);
1659
1656
 
1665
1662
    result= (*iter).second;
1666
1663
  } 
1667
1664
 
1668
 
  /*
1669
 
    This function is only called from the sql_plugin.cc.
1670
 
    A lock on LOCK_system_variable_hash should be held
1671
 
  */
1672
1665
  if (result == NULL)
1673
1666
  {
1674
 
    if (no_error)
1675
 
    {
1676
 
      return NULL;
1677
 
    }
1678
 
    else
1679
 
    {
1680
 
      my_error(ER_UNKNOWN_SYSTEM_VARIABLE, MYF(0), (char*) str);
1681
 
      return NULL;
1682
 
    }
 
1667
    my_error(ER_UNKNOWN_SYSTEM_VARIABLE, MYF(0), name.c_str());
 
1668
    return NULL;
1683
1669
  }
1684
1670
 
1685
1671
  return result;
1686
1672
}
1687
1673
 
1688
1674
 
1689
 
/**
1690
 
  Execute update of all variables.
1691
 
 
1692
 
  First run a check of all variables that all updates will go ok.
1693
 
  If yes, then execute all updates, returning an error if any one failed.
1694
 
 
1695
 
  This should ensure that in all normal cases none all or variables are
1696
 
  updated.
1697
 
 
1698
 
  @param Session                Thread id
1699
 
  @param var_list       List of variables to update
1700
 
 
1701
 
  @retval
1702
 
    0   ok
1703
 
  @retval
1704
 
    1   ERROR, message sent (normally no variables was updated)
1705
 
  @retval
1706
 
    -1  ERROR, message not sent
1707
 
*/
1708
 
 
1709
 
int sql_set_variables(Session *session, List<set_var_base> *var_list)
1710
 
{
1711
 
  int error;
1712
 
  List_iterator_fast<set_var_base> it(*var_list);
1713
 
 
1714
 
  set_var_base *var;
1715
 
  while ((var=it++))
1716
 
  {
1717
 
    if ((error= var->check(session)))
1718
 
      goto err;
1719
 
  }
1720
 
  if (!(error= test(session->is_error())))
1721
 
  {
1722
 
    it.rewind();
1723
 
    while ((var= it++))
1724
 
      error|= var->update(session);         // Returns 0, -1 or 1
1725
 
  }
1726
 
 
1727
 
err:
1728
 
  free_underlaid_joins(session, &session->lex->select_lex);
1729
 
  return(error);
1730
 
}
1731
 
 
1732
 
 
1733
 
/*****************************************************************************
1734
 
  Functions to handle SET mysql_internal_variable=const_expr
1735
 
*****************************************************************************/
1736
 
 
1737
 
int set_var::check(Session *session)
1738
 
{
1739
 
  if (var->is_readonly())
1740
 
  {
1741
 
    my_error(ER_INCORRECT_GLOBAL_LOCAL_VAR, MYF(0), var->getName().c_str(), "read only");
1742
 
    return -1;
1743
 
  }
1744
 
  if (var->check_type(type))
1745
 
  {
1746
 
    int err= type == OPT_GLOBAL ? ER_LOCAL_VARIABLE : ER_GLOBAL_VARIABLE;
1747
 
    my_error(err, MYF(0), var->getName().c_str());
1748
 
    return -1;
1749
 
  }
1750
 
  /* value is a NULL pointer if we are using SET ... = DEFAULT */
1751
 
  if (!value)
1752
 
  {
1753
 
    if (var->check_default(type))
1754
 
    {
1755
 
      my_error(ER_NO_DEFAULT, MYF(0), var->getName().c_str());
1756
 
      return -1;
1757
 
    }
1758
 
    return 0;
1759
 
  }
1760
 
 
1761
 
  if ((!value->fixed &&
1762
 
       value->fix_fields(session, &value)) || value->check_cols(1))
1763
 
    return -1;
1764
 
  if (var->check_update_type(value->result_type()))
1765
 
  {
1766
 
    my_error(ER_WRONG_TYPE_FOR_VAR, MYF(0), var->getName().c_str());
1767
 
    return -1;
1768
 
  }
1769
 
  return var->check(session, this) ? -1 : 0;
1770
 
}
1771
 
 
1772
 
/**
1773
 
  Update variable
1774
 
 
1775
 
  @param   session    thread handler
1776
 
  @returns 0|1    ok or ERROR
1777
 
 
1778
 
  @note ERROR can be only due to abnormal operations involving
1779
 
  the server's execution evironment such as
1780
 
  out of memory, hard disk failure or the computer blows up.
1781
 
  Consider set_var::check() method if there is a need to return
1782
 
  an error due to logics.
1783
 
*/
1784
 
int set_var::update(Session *session)
1785
 
{
1786
 
  if (! value)
1787
 
    var->set_default(session, type);
1788
 
  else if (var->update(session, this))
1789
 
    return -1;                          // should never happen
1790
 
  if (var->getAfterUpdateTrigger())
1791
 
    (*var->getAfterUpdateTrigger())(session, type);
1792
 
  return 0;
1793
 
}
1794
 
 
1795
 
/*****************************************************************************
1796
 
  Functions to handle SET @user_variable=const_expr
1797
 
*****************************************************************************/
1798
 
 
1799
 
int set_var_user::check(Session *session)
1800
 
{
1801
 
  /*
1802
 
    Item_func_set_user_var can't substitute something else on its place =>
1803
 
    0 can be passed as last argument (reference on item)
1804
 
  */
1805
 
  return (user_var_item->fix_fields(session, (Item**) 0) ||
1806
 
          user_var_item->check(0)) ? -1 : 0;
1807
 
}
1808
 
 
1809
 
 
1810
 
int set_var_user::update(Session *)
1811
 
{
1812
 
  if (user_var_item->update())
1813
 
  {
1814
 
    /* Give an error if it's not given already */
1815
 
    my_message(ER_SET_CONSTANTS_ONLY, ER(ER_SET_CONSTANTS_ONLY), MYF(0));
1816
 
    return -1;
1817
 
  }
1818
 
  return 0;
1819
 
}
1820
 
 
1821
1675
/****************************************************************************
1822
1676
 Functions to handle table_type
1823
1677
****************************************************************************/
1824
1678
 
1825
 
/* Based upon sys_var::check_enum() */
1826
 
 
1827
 
bool sys_var_session_storage_engine::check(Session *session, set_var *var)
1828
 
{
1829
 
  char buff[STRING_BUFFER_USUAL_SIZE];
1830
 
  const char *value;
1831
 
  String str(buff, sizeof(buff), &my_charset_utf8_general_ci), *res;
1832
 
 
1833
 
  var->save_result.storage_engine= NULL;
1834
 
  if (var->value->result_type() == STRING_RESULT)
1835
 
  {
1836
 
    res= var->value->val_str(&str);
1837
 
    if (res == NULL || res->ptr() == NULL)
1838
 
    {
1839
 
      value= "NULL";
1840
 
      goto err;
1841
 
    }
1842
 
    else
1843
 
    {
1844
 
      const std::string engine_name(res->ptr());
1845
 
      plugin::StorageEngine *engine;
1846
 
      var->save_result.storage_engine= plugin::StorageEngine::findByName(*session, engine_name);
1847
 
      if (var->save_result.storage_engine == NULL)
1848
 
      {
1849
 
        value= res->c_ptr();
1850
 
        goto err;
1851
 
      }
1852
 
      engine= var->save_result.storage_engine;
1853
 
    }
1854
 
    return 0;
1855
 
  }
1856
 
  value= "unknown";
1857
 
 
1858
 
err:
1859
 
  my_error(ER_UNKNOWN_STORAGE_ENGINE, MYF(0), value);
1860
 
  return 1;
1861
 
}
1862
 
 
1863
 
 
1864
1679
unsigned char *sys_var_session_storage_engine::value_ptr(Session *session,
1865
1680
                                                         sql_var_t type,
1866
1681
                                                         const LEX_STRING *)
1898
1713
 
1899
1714
bool sys_var_session_storage_engine::update(Session *session, set_var *var)
1900
1715
{
1901
 
  plugin::StorageEngine **value= &(global_system_variables.*offset), *old_value;
 
1716
  char buff[STRING_BUFFER_USUAL_SIZE];
 
1717
  const char *name_value;
 
1718
  String str(buff, sizeof(buff), &my_charset_utf8_general_ci), *res;
 
1719
 
 
1720
  plugin::StorageEngine *tmp= NULL;
 
1721
  plugin::StorageEngine **value= NULL;
 
1722
    
 
1723
  if (var->value->result_type() == STRING_RESULT)
 
1724
  {
 
1725
    res= var->value->val_str(&str);
 
1726
    if (res == NULL || res->ptr() == NULL)
 
1727
    {
 
1728
      name_value= "NULL";
 
1729
      goto err;
 
1730
    }
 
1731
    else
 
1732
    {
 
1733
      const std::string engine_name(res->ptr());
 
1734
      tmp= plugin::StorageEngine::findByName(*session, engine_name);
 
1735
      if (tmp == NULL)
 
1736
      {
 
1737
        name_value= res->c_ptr();
 
1738
        goto err;
 
1739
      }
 
1740
    }
 
1741
  }
 
1742
  else
 
1743
  {
 
1744
    name_value= "unknown";
 
1745
  }
 
1746
 
 
1747
  value= &(global_system_variables.*offset);
1902
1748
   if (var->type != OPT_GLOBAL)
1903
1749
     value= &(session->variables.*offset);
1904
 
  old_value= *value;
1905
 
  if (old_value != var->save_result.storage_engine)
 
1750
  if (*value != tmp)
1906
1751
  {
1907
 
    *value= var->save_result.storage_engine;
 
1752
    *value= tmp;
1908
1753
  }
1909
1754
  return 0;
 
1755
err:
 
1756
  my_error(ER_UNKNOWN_STORAGE_ENGINE, MYF(0), name_value);
 
1757
  return 1;
1910
1758
}
1911
1759
 
1912
1760
} /* namespace drizzled */