~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/sys_var.cc

  • Committer: Stewart Smith
  • Date: 2010-11-03 03:27:09 UTC
  • mto: (1902.1.1 build) (1910.1.2 build)
  • mto: This revision was merged to the branch mainline in revision 1903.
  • Revision ID: stewart@flamingspork.com-20101103032709-oyvfrc6eb8fzj0mr
fix docs warning: docs/unlock.rst:2: (WARNING/2) Title underline too short.

Show diffs side-by-side

added added

removed removed

Lines of Context:
45
45
 
46
46
#include "config.h"
47
47
#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>
 
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/item/string.h"
 
60
#include "drizzled/plugin.h"
60
61
#include "drizzled/version.h"
61
62
#include "drizzled/strfunc.h"
62
63
#include "drizzled/internal/m_string.h"
63
64
#include "drizzled/pthread_globals.h"
64
65
#include "drizzled/charset.h"
65
66
#include "drizzled/transaction_services.h"
 
67
#include "drizzled/constrained_value.h"
66
68
 
 
69
#include <cstdio>
67
70
#include <map>
 
71
#include <vector>
68
72
#include <algorithm>
69
73
 
70
74
using namespace std;
85
89
extern size_t my_thread_stack_size;
86
90
 
87
91
class sys_var_pluginvar;
88
 
static DYNAMIC_ARRAY fixed_show_vars;
89
92
typedef map<string, sys_var *> SystemVariableMap;
90
93
static SystemVariableMap system_variable_map;
91
94
extern char *opt_drizzle_tmpdir;
125
128
  The variables are linked into the list. A variable is added to
126
129
  it in the constructor (see sys_var class for details).
127
130
*/
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,
 
131
static sys_var_session_uint64_t
 
132
sys_auto_increment_increment("auto_increment_increment",
 
133
                             &drizzle_system_variables::auto_increment_increment);
 
134
static sys_var_session_uint64_t
 
135
sys_auto_increment_offset("auto_increment_offset",
 
136
                          &drizzle_system_variables::auto_increment_offset);
 
137
 
 
138
static sys_var_fs_path sys_basedir("basedir", basedir);
 
139
static sys_var_fs_path sys_pid_file("pid_file", pid_file);
 
140
static sys_var_fs_path sys_plugin_dir("plugin_dir", plugin_dir);
 
141
 
 
142
static sys_var_size_t_ptr sys_thread_stack_size("thread_stack",
 
143
                                                      &my_thread_stack_size);
 
144
static sys_var_constrained_value<uint32_t> sys_back_log("back_log", back_log);
 
145
 
 
146
static sys_var_session_uint64_t sys_bulk_insert_buff_size("bulk_insert_buffer_size",
 
147
                                                          &drizzle_system_variables::bulk_insert_buff_size);
 
148
static sys_var_session_uint32_t sys_completion_type("completion_type",
 
149
                                                    &drizzle_system_variables::completion_type,
142
150
                                                    check_completion_type,
143
151
                                                    fix_completion_type);
144
152
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);
 
153
sys_collation_server("collation_server", &drizzle_system_variables::collation_server, &default_charset_info);
 
154
static sys_var_fs_path       sys_datadir("datadir", getDataHome());
147
155
 
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",
 
156
static sys_var_session_uint64_t sys_join_buffer_size("join_buffer_size",
 
157
                                                     &drizzle_system_variables::join_buff_size);
 
158
static sys_var_session_uint32_t sys_max_allowed_packet("max_allowed_packet",
 
159
                                                       &drizzle_system_variables::max_allowed_packet);
 
160
static sys_var_uint64_t_ptr     sys_max_connect_errors("max_connect_errors",
153
161
                                               &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,
 
162
static sys_var_session_uint64_t sys_max_error_count("max_error_count",
 
163
                                                  &drizzle_system_variables::max_error_count);
 
164
static sys_var_session_uint64_t sys_max_heap_table_size("max_heap_table_size",
 
165
                                                        &drizzle_system_variables::max_heap_table_size);
 
166
static sys_var_session_uint64_t sys_pseudo_thread_id("pseudo_thread_id",
 
167
                                              &drizzle_system_variables::pseudo_thread_id,
160
168
                                              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,
 
169
static sys_var_session_ha_rows  sys_max_join_size("max_join_size",
 
170
                                                  &drizzle_system_variables::max_join_size,
163
171
                                                  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",
 
172
static sys_var_session_uint64_t sys_max_seeks_for_key("max_seeks_for_key",
 
173
                                                      &drizzle_system_variables::max_seeks_for_key);
 
174
static sys_var_session_uint64_t   sys_max_length_for_sort_data("max_length_for_sort_data",
 
175
                                                               &drizzle_system_variables::max_length_for_sort_data);
 
176
static sys_var_session_size_t   sys_max_sort_length("max_sort_length",
 
177
                                                    &drizzle_system_variables::max_sort_length);
 
178
static sys_var_uint64_t_ptr     sys_max_write_lock_count("max_write_lock_count",
171
179
                                                 &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);
 
180
static sys_var_session_uint64_t sys_min_examined_row_limit("min_examined_row_limit",
 
181
                                                           &drizzle_system_variables::min_examined_row_limit);
174
182
 
175
183
/* 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,
 
184
static sys_var_session_bool sys_optimizer_prune_level("optimizer_prune_level",
 
185
                                                      &drizzle_system_variables::optimizer_prune_level);
 
186
static sys_var_session_uint32_t sys_optimizer_search_depth("optimizer_search_depth",
 
187
                                                           &drizzle_system_variables::optimizer_search_depth);
 
188
 
 
189
static sys_var_session_uint64_t sys_preload_buff_size("preload_buffer_size",
 
190
                                                      &drizzle_system_variables::preload_buff_size);
 
191
static sys_var_session_uint32_t sys_read_buff_size("read_buffer_size",
 
192
                                                   &drizzle_system_variables::read_buff_size);
 
193
static sys_var_session_uint32_t sys_read_rnd_buff_size("read_rnd_buffer_size",
 
194
                                                       &drizzle_system_variables::read_rnd_buff_size);
 
195
static sys_var_session_uint32_t sys_div_precincrement("div_precision_increment",
 
196
                                                      &drizzle_system_variables::div_precincrement);
 
197
 
 
198
static sys_var_session_size_t   sys_range_alloc_block_size("range_alloc_block_size",
 
199
                                                           &drizzle_system_variables::range_alloc_block_size);
 
200
static sys_var_session_uint32_t sys_query_alloc_block_size("query_alloc_block_size",
 
201
                                                           &drizzle_system_variables::query_alloc_block_size,
 
202
                                                           NULL, fix_session_mem_root);
 
203
static sys_var_session_uint32_t sys_query_prealloc_size("query_prealloc_size",
 
204
                                                        &drizzle_system_variables::query_prealloc_size,
 
205
                                                        NULL, fix_session_mem_root);
 
206
static sys_var_readonly sys_tmpdir("tmpdir", OPT_GLOBAL, SHOW_CHAR, get_tmpdir);
 
207
 
 
208
static sys_var_fs_path sys_secure_file_priv("secure_file_priv",
 
209
                                            secure_file_priv);
 
210
 
 
211
static sys_var_const_str_ptr sys_scheduler("scheduler",
 
212
                                           (char**)&opt_scheduler);
 
213
 
 
214
static sys_var_uint32_t_ptr  sys_server_id("server_id", &server_id,
203
215
                                           fix_server_id);
204
216
 
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",
 
217
static sys_var_session_size_t   sys_sort_buffer("sort_buffer_size",
 
218
                                                &drizzle_system_variables::sortbuff_size);
 
219
 
 
220
static sys_var_session_size_t sys_transaction_message_threshold("transaction_message_threshold",
 
221
                                                                &drizzle_system_variables::transaction_message_threshold);
 
222
 
 
223
static sys_var_session_storage_engine sys_storage_engine("storage_engine",
 
224
                                       &drizzle_system_variables::storage_engine);
 
225
static sys_var_const_str        sys_system_time_zone("system_time_zone",
211
226
                                             system_time_zone);
212
 
static sys_var_size_t_ptr       sys_table_def_size(&vars, "table_definition_cache",
 
227
static sys_var_size_t_ptr       sys_table_def_size("table_definition_cache",
213
228
                                             &table_def_size);
214
 
static sys_var_uint64_t_ptr     sys_table_cache_size(&vars, "table_open_cache",
 
229
static sys_var_uint64_t_ptr     sys_table_cache_size("table_open_cache",
215
230
                                             &table_cache_size);
216
 
static sys_var_uint64_t_ptr     sys_table_lock_wait_timeout(&vars, "table_lock_wait_timeout",
 
231
static sys_var_uint64_t_ptr     sys_table_lock_wait_timeout("table_lock_wait_timeout",
217
232
                                                    &table_lock_wait_timeout);
218
 
static sys_var_session_enum     sys_tx_isolation(&vars, "tx_isolation",
219
 
                                             &system_variables::tx_isolation,
 
233
static sys_var_session_enum     sys_tx_isolation("tx_isolation",
 
234
                                             &drizzle_system_variables::tx_isolation,
220
235
                                             &tx_isolation_typelib,
221
236
                                             fix_tx_isolation,
222
237
                                             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());
 
238
static sys_var_session_uint64_t sys_tmp_table_size("tmp_table_size",
 
239
                                           &drizzle_system_variables::tmp_table_size);
 
240
static sys_var_bool_ptr  sys_timed_mutexes("timed_mutexes", &internal::timed_mutexes);
 
241
static sys_var_const_str  sys_version("version", version().c_str());
227
242
 
228
 
static sys_var_const_str        sys_version_comment(&vars, "version_comment",
 
243
static sys_var_const_str        sys_version_comment("version_comment",
229
244
                                            COMPILATION_COMMENT);
230
 
static sys_var_const_str        sys_version_compile_machine(&vars, "version_compile_machine",
 
245
static sys_var_const_str        sys_version_compile_machine("version_compile_machine",
231
246
                                                      HOST_CPU);
232
 
static sys_var_const_str        sys_version_compile_os(&vars, "version_compile_os",
 
247
static sys_var_const_str        sys_version_compile_os("version_compile_os",
233
248
                                                 HOST_OS);
234
 
static sys_var_const_str        sys_version_compile_vendor(&vars, "version_compile_vendor",
 
249
static sys_var_const_str        sys_version_compile_vendor("version_compile_vendor",
235
250
                                                 HOST_VENDOR);
236
251
 
237
252
/* Variables that are bits in Session */
238
253
 
239
 
sys_var_session_bit sys_autocommit(&vars, "autocommit", 0,
 
254
sys_var_session_bit sys_autocommit("autocommit", 0,
240
255
                               set_option_autocommit,
241
256
                               OPTION_NOT_AUTOCOMMIT,
242
257
                               1);
243
 
static sys_var_session_bit      sys_big_selects(&vars, "sql_big_selects", 0,
 
258
static sys_var_session_bit      sys_big_selects("sql_big_selects", 0,
244
259
                                        set_option_bit,
245
260
                                        OPTION_BIG_SELECTS);
246
 
static sys_var_session_bit      sys_sql_warnings(&vars, "sql_warnings", 0,
 
261
static sys_var_session_bit      sys_sql_warnings("sql_warnings", 0,
247
262
                                         set_option_bit,
248
263
                                         OPTION_WARNINGS);
249
 
static sys_var_session_bit      sys_sql_notes(&vars, "sql_notes", 0,
 
264
static sys_var_session_bit      sys_sql_notes("sql_notes", 0,
250
265
                                         set_option_bit,
251
266
                                         OPTION_SQL_NOTES);
252
 
static sys_var_session_bit      sys_buffer_results(&vars, "sql_buffer_result", 0,
 
267
static sys_var_session_bit      sys_buffer_results("sql_buffer_result", 0,
253
268
                                           set_option_bit,
254
269
                                           OPTION_BUFFER_RESULT);
255
 
static sys_var_session_bit      sys_foreign_key_checks(&vars, "foreign_key_checks", 0,
 
270
static sys_var_session_bit      sys_foreign_key_checks("foreign_key_checks", 0,
256
271
                                               set_option_bit,
257
272
                                               OPTION_NO_FOREIGN_KEY_CHECKS, 1);
258
 
static sys_var_session_bit      sys_unique_checks(&vars, "unique_checks", 0,
 
273
static sys_var_session_bit      sys_unique_checks("unique_checks", 0,
259
274
                                          set_option_bit,
260
275
                                          OPTION_RELAXED_UNIQUE_CHECKS, 1);
261
276
/* Local state variables */
262
277
 
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");
 
278
static sys_var_session_ha_rows  sys_select_limit("sql_select_limit",
 
279
                                                 &drizzle_system_variables::select_limit);
 
280
static sys_var_timestamp sys_timestamp("timestamp");
266
281
static sys_var_last_insert_id
267
 
sys_last_insert_id(&vars, "last_insert_id");
 
282
sys_last_insert_id("last_insert_id");
268
283
/*
269
284
  identity is an alias for last_insert_id(), so that we are compatible
270
285
  with Sybase
271
286
*/
272
 
static sys_var_last_insert_id sys_identity(&vars, "identity");
 
287
static sys_var_last_insert_id sys_identity("identity");
273
288
 
274
 
static sys_var_session_lc_time_names sys_lc_time_names(&vars, "lc_time_names");
 
289
static sys_var_session_lc_time_names sys_lc_time_names("lc_time_names");
275
290
 
276
291
/*
277
292
  We want statements referring explicitly to @@session.insert_id to be
285
300
  statement-based logging mode: t will be different on master and
286
301
  slave).
287
302
*/
288
 
static sys_var_readonly sys_error_count(&vars, "error_count",
 
303
static sys_var_readonly sys_error_count("error_count",
289
304
                                        OPT_SESSION,
290
305
                                        SHOW_INT,
291
306
                                        get_error_count);
292
 
static sys_var_readonly sys_warning_count(&vars, "warning_count",
 
307
static sys_var_readonly sys_warning_count("warning_count",
293
308
                                          OPT_SESSION,
294
309
                                          SHOW_INT,
295
310
                                          get_warning_count);
296
311
 
297
 
sys_var_session_uint64_t sys_group_concat_max_len(&vars, "group_concat_max_len",
298
 
                                                  &system_variables::group_concat_max_len);
 
312
sys_var_session_uint64_t sys_group_concat_max_len("group_concat_max_len",
 
313
                                                  &drizzle_system_variables::group_concat_max_len);
299
314
 
300
 
sys_var_session_time_zone sys_time_zone(&vars, "time_zone");
 
315
sys_var_session_time_zone sys_time_zone("time_zone");
301
316
 
302
317
/* 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
 
};
 
318
static sys_var_const_str        sys_hostname("hostname", glob_hostname);
320
319
 
321
320
bool sys_var::check(Session *, set_var *var)
322
321
{
399
398
static void fix_session_mem_root(Session *session, sql_var_t type)
400
399
{
401
400
  if (type != OPT_GLOBAL)
402
 
    reset_root_defaults(session->mem_root,
403
 
                        session->variables.query_alloc_block_size,
404
 
                        session->variables.query_prealloc_size);
 
401
    session->mem_root->reset_root_defaults(session->variables.query_alloc_block_size,
 
402
                                           session->variables.query_prealloc_size);
405
403
}
406
404
 
407
405
 
500
498
bool sys_var_uint32_t_ptr::update(Session *session, set_var *var)
501
499
{
502
500
  uint32_t tmp= var->save_result.uint32_t_value;
503
 
  pthread_mutex_lock(&LOCK_global_system_variables);
 
501
  LOCK_global_system_variables.lock();
504
502
  if (option_limits)
505
503
  {
506
504
    uint32_t newvalue= (uint32_t) fix_unsigned(session, tmp, option_limits);
509
507
  }
510
508
  else
511
509
    *value= (uint32_t) tmp;
512
 
  pthread_mutex_unlock(&LOCK_global_system_variables);
 
510
  LOCK_global_system_variables.unlock();
513
511
  return 0;
514
512
}
515
513
 
517
515
void sys_var_uint32_t_ptr::set_default(Session *, sql_var_t)
518
516
{
519
517
  bool not_used;
520
 
  pthread_mutex_lock(&LOCK_global_system_variables);
 
518
  LOCK_global_system_variables.lock();
521
519
  *value= (uint32_t)getopt_ull_limit_value((uint32_t) option_limits->def_value,
522
520
                                           option_limits, &not_used);
523
 
  pthread_mutex_unlock(&LOCK_global_system_variables);
 
521
  LOCK_global_system_variables.unlock();
524
522
}
525
523
 
526
524
 
527
525
bool sys_var_uint64_t_ptr::update(Session *session, set_var *var)
528
526
{
529
527
  uint64_t tmp= var->save_result.uint64_t_value;
530
 
  pthread_mutex_lock(&LOCK_global_system_variables);
 
528
  LOCK_global_system_variables.lock();
531
529
  if (option_limits)
532
530
  {
533
531
    uint64_t newvalue= (uint64_t) fix_unsigned(session, tmp, option_limits);
536
534
  }
537
535
  else
538
536
    *value= (uint64_t) tmp;
539
 
  pthread_mutex_unlock(&LOCK_global_system_variables);
 
537
  LOCK_global_system_variables.unlock();
540
538
  return 0;
541
539
}
542
540
 
544
542
void sys_var_uint64_t_ptr::set_default(Session *, sql_var_t)
545
543
{
546
544
  bool not_used;
547
 
  pthread_mutex_lock(&LOCK_global_system_variables);
 
545
  LOCK_global_system_variables.lock();
548
546
  *value= getopt_ull_limit_value((uint64_t) option_limits->def_value,
549
547
                                 option_limits, &not_used);
550
 
  pthread_mutex_unlock(&LOCK_global_system_variables);
 
548
  LOCK_global_system_variables.unlock();
551
549
}
552
550
 
553
551
 
554
552
bool sys_var_size_t_ptr::update(Session *session, set_var *var)
555
553
{
556
554
  size_t tmp= var->save_result.size_t_value;
557
 
  pthread_mutex_lock(&LOCK_global_system_variables);
 
555
  LOCK_global_system_variables.lock();
558
556
  if (option_limits)
559
557
    *value= fix_size_t(session, tmp, option_limits);
560
558
  else
561
559
    *value= tmp;
562
 
  pthread_mutex_unlock(&LOCK_global_system_variables);
 
560
  LOCK_global_system_variables.unlock();
563
561
  return 0;
564
562
}
565
563
 
567
565
void sys_var_size_t_ptr::set_default(Session *, sql_var_t)
568
566
{
569
567
  bool not_used;
570
 
  pthread_mutex_lock(&LOCK_global_system_variables);
 
568
  LOCK_global_system_variables.lock();
571
569
  *value= (size_t)getopt_ull_limit_value((size_t) option_limits->def_value,
572
570
                                         option_limits, &not_used);
573
 
  pthread_mutex_unlock(&LOCK_global_system_variables);
 
571
  LOCK_global_system_variables.unlock();
574
572
}
575
573
 
576
574
bool sys_var_bool_ptr::update(Session *, set_var *var)
661
659
  if (var->type == OPT_GLOBAL)
662
660
  {
663
661
    /* Lock is needed to make things safe on 32 bit systems */
664
 
    pthread_mutex_lock(&LOCK_global_system_variables);
 
662
    LOCK_global_system_variables.lock();
665
663
    global_system_variables.*offset= (ha_rows) tmp;
666
 
    pthread_mutex_unlock(&LOCK_global_system_variables);
 
664
    LOCK_global_system_variables.unlock();
667
665
  }
668
666
  else
669
667
    session->variables.*offset= (ha_rows) tmp;
677
675
  {
678
676
    bool not_used;
679
677
    /* We will not come here if option_limits is not set */
680
 
    pthread_mutex_lock(&LOCK_global_system_variables);
 
678
    LOCK_global_system_variables.lock();
681
679
    global_system_variables.*offset=
682
680
      (ha_rows) getopt_ull_limit_value((ha_rows) option_limits->def_value,
683
681
                                       option_limits, &not_used);
684
 
    pthread_mutex_unlock(&LOCK_global_system_variables);
 
682
    LOCK_global_system_variables.unlock();
685
683
  }
686
684
  else
687
685
    session->variables.*offset= global_system_variables.*offset;
718
716
  if (var->type == OPT_GLOBAL)
719
717
  {
720
718
    /* Lock is needed to make things safe on 32 bit systems */
721
 
    pthread_mutex_lock(&LOCK_global_system_variables);
 
719
    LOCK_global_system_variables.lock();
722
720
    global_system_variables.*offset= (uint64_t) tmp;
723
 
    pthread_mutex_unlock(&LOCK_global_system_variables);
 
721
    LOCK_global_system_variables.unlock();
724
722
  }
725
723
  else
726
724
    session->variables.*offset= (uint64_t) tmp;
733
731
  if (type == OPT_GLOBAL)
734
732
  {
735
733
    bool not_used;
736
 
    pthread_mutex_lock(&LOCK_global_system_variables);
 
734
    LOCK_global_system_variables.lock();
737
735
    global_system_variables.*offset=
738
736
      getopt_ull_limit_value((uint64_t) option_limits->def_value,
739
737
                             option_limits, &not_used);
740
 
    pthread_mutex_unlock(&LOCK_global_system_variables);
 
738
    LOCK_global_system_variables.unlock();
741
739
  }
742
740
  else
743
741
    session->variables.*offset= global_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
    LOCK_global_system_variables.lock();
775
773
    global_system_variables.*offset= tmp;
776
 
    pthread_mutex_unlock(&LOCK_global_system_variables);
 
774
    LOCK_global_system_variables.unlock();
777
775
  }
778
776
  else
779
777
    session->variables.*offset= tmp;
786
784
  if (type == OPT_GLOBAL)
787
785
  {
788
786
    bool not_used;
789
 
    pthread_mutex_lock(&LOCK_global_system_variables);
 
787
    LOCK_global_system_variables.lock();
790
788
    global_system_variables.*offset=
791
789
      (size_t)getopt_ull_limit_value((size_t) option_limits->def_value,
792
790
                                     option_limits, &not_used);
793
 
    pthread_mutex_unlock(&LOCK_global_system_variables);
 
791
    LOCK_global_system_variables.unlock();
794
792
  }
795
793
  else
796
794
    session->variables.*offset= global_system_variables.*offset;
900
898
  case SHOW_INT:
901
899
  {
902
900
    uint32_t value;
903
 
    pthread_mutex_lock(&LOCK_global_system_variables);
 
901
    LOCK_global_system_variables.lock();
904
902
    value= *(uint*) value_ptr(session, var_type, base);
905
 
    pthread_mutex_unlock(&LOCK_global_system_variables);
 
903
    LOCK_global_system_variables.unlock();
906
904
    return new Item_uint((uint64_t) value);
907
905
  }
908
906
  case SHOW_LONGLONG:
909
907
  {
910
908
    int64_t value;
911
 
    pthread_mutex_lock(&LOCK_global_system_variables);
 
909
    LOCK_global_system_variables.lock();
912
910
    value= *(int64_t*) value_ptr(session, var_type, base);
913
 
    pthread_mutex_unlock(&LOCK_global_system_variables);
 
911
    LOCK_global_system_variables.unlock();
914
912
    return new Item_int(value);
915
913
  }
916
914
  case SHOW_DOUBLE:
917
915
  {
918
916
    double value;
919
 
    pthread_mutex_lock(&LOCK_global_system_variables);
 
917
    LOCK_global_system_variables.lock();
920
918
    value= *(double*) value_ptr(session, var_type, base);
921
 
    pthread_mutex_unlock(&LOCK_global_system_variables);
 
919
    LOCK_global_system_variables.unlock();
922
920
    /* 6, as this is for now only used with microseconds */
923
921
    return new Item_float(value, 6);
924
922
  }
925
923
  case SHOW_HA_ROWS:
926
924
  {
927
925
    ha_rows value;
928
 
    pthread_mutex_lock(&LOCK_global_system_variables);
 
926
    LOCK_global_system_variables.lock();
929
927
    value= *(ha_rows*) value_ptr(session, var_type, base);
930
 
    pthread_mutex_unlock(&LOCK_global_system_variables);
 
928
    LOCK_global_system_variables.unlock();
931
929
    return new Item_int((uint64_t) value);
932
930
  }
933
931
  case SHOW_SIZE:
934
932
  {
935
933
    size_t value;
936
 
    pthread_mutex_lock(&LOCK_global_system_variables);
 
934
    LOCK_global_system_variables.lock();
937
935
    value= *(size_t*) value_ptr(session, var_type, base);
938
 
    pthread_mutex_unlock(&LOCK_global_system_variables);
 
936
    LOCK_global_system_variables.unlock();
939
937
    return new Item_int((uint64_t) value);
940
938
  }
941
939
  case SHOW_MY_BOOL:
942
940
  {
943
941
    int32_t value;
944
 
    pthread_mutex_lock(&LOCK_global_system_variables);
 
942
    LOCK_global_system_variables.lock();
945
943
    value= *(bool*) value_ptr(session, var_type, base);
946
 
    pthread_mutex_unlock(&LOCK_global_system_variables);
 
944
    LOCK_global_system_variables.unlock();
947
945
    return new Item_int(value,1);
948
946
  }
949
947
  case SHOW_CHAR_PTR:
950
948
  {
951
949
    Item *tmp;
952
 
    pthread_mutex_lock(&LOCK_global_system_variables);
 
950
    LOCK_global_system_variables.lock();
953
951
    char *str= *(char**) value_ptr(session, var_type, base);
954
952
    if (str)
955
953
    {
962
960
      tmp= new Item_null();
963
961
      tmp->collation.set(system_charset_info, DERIVATION_SYSCONST);
964
962
    }
965
 
    pthread_mutex_unlock(&LOCK_global_system_variables);
 
963
    LOCK_global_system_variables.unlock();
966
964
    return tmp;
967
965
  }
968
966
  case SHOW_CHAR:
969
967
  {
970
968
    Item *tmp;
971
 
    pthread_mutex_lock(&LOCK_global_system_variables);
 
969
    LOCK_global_system_variables.lock();
972
970
    char *str= (char*) value_ptr(session, var_type, base);
973
971
    if (str)
974
972
      tmp= new Item_string(str, strlen(str),
978
976
      tmp= new Item_null();
979
977
      tmp->collation.set(system_charset_info, DERIVATION_SYSCONST);
980
978
    }
981
 
    pthread_mutex_unlock(&LOCK_global_system_variables);
 
979
    LOCK_global_system_variables.unlock();
982
980
    return tmp;
983
981
  }
984
982
  default:
1181
1179
  /* We are using Time_zone object found during check() phase. */
1182
1180
  if (var->type == OPT_GLOBAL)
1183
1181
  {
1184
 
    pthread_mutex_lock(&LOCK_global_system_variables);
 
1182
    LOCK_global_system_variables.lock();
1185
1183
    global_system_variables.time_zone= var->save_result.time_zone;
1186
 
    pthread_mutex_unlock(&LOCK_global_system_variables);
 
1184
    LOCK_global_system_variables.unlock();
1187
1185
  }
1188
1186
  else
1189
1187
    session->variables.time_zone= var->save_result.time_zone;
1218
1216
 
1219
1217
void sys_var_session_time_zone::set_default(Session *session, sql_var_t type)
1220
1218
{
1221
 
 pthread_mutex_lock(&LOCK_global_system_variables);
 
1219
 LOCK_global_system_variables.lock();
1222
1220
 if (type == OPT_GLOBAL)
1223
1221
 {
1224
1222
   if (default_tz_name)
1235
1233
 }
1236
1234
 else
1237
1235
   session->variables.time_zone= global_system_variables.time_zone;
1238
 
 pthread_mutex_unlock(&LOCK_global_system_variables);
 
1236
 LOCK_global_system_variables.unlock();
1239
1237
}
1240
1238
 
1241
1239
 
1324
1322
  microseconds= (int64_t) (num * 1000000.0 + 0.5);
1325
1323
  if (var->type == OPT_GLOBAL)
1326
1324
  {
1327
 
    pthread_mutex_lock(&LOCK_global_system_variables);
 
1325
    LOCK_global_system_variables.lock();
1328
1326
    (global_system_variables.*offset)= microseconds;
1329
 
    pthread_mutex_unlock(&LOCK_global_system_variables);
 
1327
    LOCK_global_system_variables.unlock();
1330
1328
  }
1331
1329
  else
1332
1330
    session->variables.*offset= microseconds;
1339
1337
  int64_t microseconds= (int64_t) (option_limits->def_value * 1000000.0);
1340
1338
  if (type == OPT_GLOBAL)
1341
1339
  {
1342
 
    pthread_mutex_lock(&LOCK_global_system_variables);
 
1340
    LOCK_global_system_variables.lock();
1343
1341
    global_system_variables.*offset= microseconds;
1344
 
    pthread_mutex_unlock(&LOCK_global_system_variables);
 
1342
    LOCK_global_system_variables.unlock();
1345
1343
  }
1346
1344
  else
1347
1345
    session->variables.*offset= microseconds;
1381
1379
      session->options&= ~(uint64_t) (OPTION_BEGIN);
1382
1380
      session->server_status|= SERVER_STATUS_AUTOCOMMIT;
1383
1381
      TransactionServices &transaction_services= TransactionServices::singleton();
1384
 
      if (transaction_services.ha_commit_trans(session, true))
 
1382
      if (transaction_services.commitTransaction(session, true))
1385
1383
        return 1;
1386
1384
    }
1387
1385
    else
1431
1429
*/
1432
1430
static unsigned char *get_tmpdir(Session *)
1433
1431
{
1434
 
  assert(drizzle_tmpdir);
1435
 
  return (unsigned char*)drizzle_tmpdir;
 
1432
  assert(drizzle_tmpdir.size());
 
1433
  return (unsigned char*)drizzle_tmpdir.c_str();
1436
1434
}
1437
1435
 
1438
1436
/****************************************************************************
1474
1472
}
1475
1473
 
1476
1474
 
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
1475
 
1554
1476
 
1555
1477
 
1559
1481
  SYNOPSIS
1560
1482
    enumerate_sys_vars()
1561
1483
    session         current thread
1562
 
    sorted      If TRUE, the system variables should be sorted
1563
1484
 
1564
1485
  RETURN VALUES
1565
1486
    pointer     Array of drizzle_show_var elements for display
1566
1487
    NULL        FAILURE
1567
1488
*/
1568
1489
 
1569
 
drizzle_show_var* enumerate_sys_vars(Session *session, bool)
 
1490
drizzle_show_var* enumerate_sys_vars(Session *session)
1570
1491
{
1571
 
  int fixed_count= fixed_show_vars.elements;
1572
 
  int size= sizeof(drizzle_show_var) * (system_variable_map.size() + fixed_count + 1);
 
1492
  int size= sizeof(drizzle_show_var) * (system_variable_map.size() + 1);
1573
1493
  drizzle_show_var *result= (drizzle_show_var*) session->alloc(size);
1574
1494
 
1575
1495
  if (result)
1576
1496
  {
1577
 
    drizzle_show_var *show= result + fixed_count;
1578
 
    memcpy(result, fixed_show_vars.buffer, fixed_count * sizeof(drizzle_show_var));
 
1497
    drizzle_show_var *show= result;
1579
1498
 
1580
1499
    SystemVariableMap::const_iterator iter= system_variable_map.begin();
1581
1500
    while (iter != system_variable_map.end())
1584
1503
      show->name= var->getName().c_str();
1585
1504
      show->value= (char*) var;
1586
1505
      show->type= SHOW_SYS;
1587
 
      show++;
 
1506
      ++show;
1588
1507
      ++iter;
1589
1508
    }
1590
1509
 
1595
1514
}
1596
1515
 
1597
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(ERRMSG_LVL_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(ERRMSG_LVL_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
 
1598
1548
/*
1599
1549
  Initialize the system variables
1600
1550
 
1601
1551
  SYNOPSIS
1602
 
    set_var_init()
 
1552
    sys_var_init()
1603
1553
 
1604
1554
  RETURN VALUES
1605
1555
    0           SUCCESS
1606
1556
    otherwise   FAILURE
1607
1557
*/
1608
1558
 
1609
 
int set_var_init()
 
1559
int sys_var_init()
1610
1560
{
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
 
 
 
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_connect_errors, my_long_options);
 
1585
    add_sys_var_to_list(&sys_max_error_count, my_long_options);
 
1586
    add_sys_var_to_list(&sys_max_heap_table_size, my_long_options);
 
1587
    add_sys_var_to_list(&sys_max_join_size, my_long_options);
 
1588
    add_sys_var_to_list(&sys_max_length_for_sort_data, my_long_options);
 
1589
    add_sys_var_to_list(&sys_max_seeks_for_key, my_long_options);
 
1590
    add_sys_var_to_list(&sys_max_sort_length, my_long_options);
 
1591
    add_sys_var_to_list(&sys_max_write_lock_count, my_long_options);
 
1592
    add_sys_var_to_list(&sys_min_examined_row_limit, my_long_options);
 
1593
    add_sys_var_to_list(&sys_optimizer_prune_level, my_long_options);
 
1594
    add_sys_var_to_list(&sys_optimizer_search_depth, my_long_options);
 
1595
    add_sys_var_to_list(&sys_pid_file, my_long_options);
 
1596
    add_sys_var_to_list(&sys_plugin_dir, my_long_options);
 
1597
    add_sys_var_to_list(&sys_preload_buff_size, my_long_options);
 
1598
    add_sys_var_to_list(&sys_pseudo_thread_id, my_long_options);
 
1599
    add_sys_var_to_list(&sys_query_alloc_block_size, my_long_options);
 
1600
    add_sys_var_to_list(&sys_query_prealloc_size, my_long_options);
 
1601
    add_sys_var_to_list(&sys_range_alloc_block_size, my_long_options);
 
1602
    add_sys_var_to_list(&sys_read_buff_size, my_long_options);
 
1603
    add_sys_var_to_list(&sys_read_rnd_buff_size, 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 (...)
 
1633
  {
 
1634
    errmsg_printf(ERRMSG_LVL_ERROR, _("Failed to initialize system variables"));
 
1635
    return(1);
 
1636
  }
1626
1637
  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
1638
}
1638
1639
 
1639
1640
 
1686
1687
}
1687
1688
 
1688
1689
 
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
1690
/****************************************************************************
1822
1691
 Functions to handle table_type
1823
1692
****************************************************************************/