~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/sys_var.cc

  • Committer: Monty Taylor
  • Date: 2011-02-13 17:26:39 UTC
  • mfrom: (2157.2.2 give-in-to-pkg-config)
  • mto: This revision was merged to the branch mainline in revision 2166.
  • Revision ID: mordred@inaugust.com-20110213172639-nhy7i72sfhoq13ms
Merged in pkg-config fixes.

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