~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/sys_var.cc

  • Committer: Brian Aker
  • Date: 2010-11-22 00:16:44 UTC
  • mto: (1945.2.1 quick)
  • mto: This revision was merged to the branch mainline in revision 1947.
  • Revision ID: brian@tangent.org-20101122001644-pi6jv0d65e82xn38
Merge in lock refactor, this just encapsulates.

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_readonly<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
 
543
541
 
544
542
void sys_var_uint64_t_ptr::set_default(Session *, sql_var_t)
545
543
{
546
 
  bool not_used;
547
 
  pthread_mutex_lock(&LOCK_global_system_variables);
548
 
  *value= getopt_ull_limit_value((uint64_t) option_limits->def_value,
549
 
                                 option_limits, &not_used);
550
 
  pthread_mutex_unlock(&LOCK_global_system_variables);
 
544
  if (have_default_value)
 
545
  {
 
546
    *value= default_value;
 
547
  }
 
548
  else
 
549
  {
 
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();
 
555
  }
551
556
}
552
557
 
553
558
 
554
559
bool sys_var_size_t_ptr::update(Session *session, set_var *var)
555
560
{
556
561
  size_t tmp= var->save_result.size_t_value;
557
 
  pthread_mutex_lock(&LOCK_global_system_variables);
 
562
  LOCK_global_system_variables.lock();
558
563
  if (option_limits)
559
564
    *value= fix_size_t(session, tmp, option_limits);
560
565
  else
561
566
    *value= tmp;
562
 
  pthread_mutex_unlock(&LOCK_global_system_variables);
 
567
  LOCK_global_system_variables.unlock();
563
568
  return 0;
564
569
}
565
570
 
567
572
void sys_var_size_t_ptr::set_default(Session *, sql_var_t)
568
573
{
569
574
  bool not_used;
570
 
  pthread_mutex_lock(&LOCK_global_system_variables);
 
575
  LOCK_global_system_variables.lock();
571
576
  *value= (size_t)getopt_ull_limit_value((size_t) option_limits->def_value,
572
577
                                         option_limits, &not_used);
573
 
  pthread_mutex_unlock(&LOCK_global_system_variables);
 
578
  LOCK_global_system_variables.unlock();
574
579
}
575
580
 
576
581
bool sys_var_bool_ptr::update(Session *, set_var *var)
661
666
  if (var->type == OPT_GLOBAL)
662
667
  {
663
668
    /* Lock is needed to make things safe on 32 bit systems */
664
 
    pthread_mutex_lock(&LOCK_global_system_variables);
 
669
    LOCK_global_system_variables.lock();
665
670
    global_system_variables.*offset= (ha_rows) tmp;
666
 
    pthread_mutex_unlock(&LOCK_global_system_variables);
 
671
    LOCK_global_system_variables.unlock();
667
672
  }
668
673
  else
669
674
    session->variables.*offset= (ha_rows) tmp;
677
682
  {
678
683
    bool not_used;
679
684
    /* We will not come here if option_limits is not set */
680
 
    pthread_mutex_lock(&LOCK_global_system_variables);
 
685
    LOCK_global_system_variables.lock();
681
686
    global_system_variables.*offset=
682
687
      (ha_rows) getopt_ull_limit_value((ha_rows) option_limits->def_value,
683
688
                                       option_limits, &not_used);
684
 
    pthread_mutex_unlock(&LOCK_global_system_variables);
 
689
    LOCK_global_system_variables.unlock();
685
690
  }
686
691
  else
687
692
    session->variables.*offset= global_system_variables.*offset;
718
723
  if (var->type == OPT_GLOBAL)
719
724
  {
720
725
    /* Lock is needed to make things safe on 32 bit systems */
721
 
    pthread_mutex_lock(&LOCK_global_system_variables);
 
726
    LOCK_global_system_variables.lock();
722
727
    global_system_variables.*offset= (uint64_t) tmp;
723
 
    pthread_mutex_unlock(&LOCK_global_system_variables);
 
728
    LOCK_global_system_variables.unlock();
724
729
  }
725
730
  else
726
731
    session->variables.*offset= (uint64_t) tmp;
733
738
  if (type == OPT_GLOBAL)
734
739
  {
735
740
    bool not_used;
736
 
    pthread_mutex_lock(&LOCK_global_system_variables);
 
741
    LOCK_global_system_variables.lock();
737
742
    global_system_variables.*offset=
738
743
      getopt_ull_limit_value((uint64_t) option_limits->def_value,
739
744
                             option_limits, &not_used);
740
 
    pthread_mutex_unlock(&LOCK_global_system_variables);
 
745
    LOCK_global_system_variables.unlock();
741
746
  }
742
747
  else
743
748
    session->variables.*offset= global_system_variables.*offset;
771
776
  if (var->type == OPT_GLOBAL)
772
777
  {
773
778
    /* Lock is needed to make things safe on 32 bit systems */
774
 
    pthread_mutex_lock(&LOCK_global_system_variables);
 
779
    LOCK_global_system_variables.lock();
775
780
    global_system_variables.*offset= tmp;
776
 
    pthread_mutex_unlock(&LOCK_global_system_variables);
 
781
    LOCK_global_system_variables.unlock();
777
782
  }
778
783
  else
779
784
    session->variables.*offset= tmp;
786
791
  if (type == OPT_GLOBAL)
787
792
  {
788
793
    bool not_used;
789
 
    pthread_mutex_lock(&LOCK_global_system_variables);
 
794
    LOCK_global_system_variables.lock();
790
795
    global_system_variables.*offset=
791
796
      (size_t)getopt_ull_limit_value((size_t) option_limits->def_value,
792
797
                                     option_limits, &not_used);
793
 
    pthread_mutex_unlock(&LOCK_global_system_variables);
 
798
    LOCK_global_system_variables.unlock();
794
799
  }
795
800
  else
796
801
    session->variables.*offset= global_system_variables.*offset;
900
905
  case SHOW_INT:
901
906
  {
902
907
    uint32_t value;
903
 
    pthread_mutex_lock(&LOCK_global_system_variables);
 
908
    LOCK_global_system_variables.lock();
904
909
    value= *(uint*) value_ptr(session, var_type, base);
905
 
    pthread_mutex_unlock(&LOCK_global_system_variables);
 
910
    LOCK_global_system_variables.unlock();
906
911
    return new Item_uint((uint64_t) value);
907
912
  }
908
913
  case SHOW_LONGLONG:
909
914
  {
910
915
    int64_t value;
911
 
    pthread_mutex_lock(&LOCK_global_system_variables);
 
916
    LOCK_global_system_variables.lock();
912
917
    value= *(int64_t*) value_ptr(session, var_type, base);
913
 
    pthread_mutex_unlock(&LOCK_global_system_variables);
 
918
    LOCK_global_system_variables.unlock();
914
919
    return new Item_int(value);
915
920
  }
916
921
  case SHOW_DOUBLE:
917
922
  {
918
923
    double value;
919
 
    pthread_mutex_lock(&LOCK_global_system_variables);
 
924
    LOCK_global_system_variables.lock();
920
925
    value= *(double*) value_ptr(session, var_type, base);
921
 
    pthread_mutex_unlock(&LOCK_global_system_variables);
 
926
    LOCK_global_system_variables.unlock();
922
927
    /* 6, as this is for now only used with microseconds */
923
928
    return new Item_float(value, 6);
924
929
  }
925
930
  case SHOW_HA_ROWS:
926
931
  {
927
932
    ha_rows value;
928
 
    pthread_mutex_lock(&LOCK_global_system_variables);
 
933
    LOCK_global_system_variables.lock();
929
934
    value= *(ha_rows*) value_ptr(session, var_type, base);
930
 
    pthread_mutex_unlock(&LOCK_global_system_variables);
 
935
    LOCK_global_system_variables.unlock();
931
936
    return new Item_int((uint64_t) value);
932
937
  }
933
938
  case SHOW_SIZE:
934
939
  {
935
940
    size_t value;
936
 
    pthread_mutex_lock(&LOCK_global_system_variables);
 
941
    LOCK_global_system_variables.lock();
937
942
    value= *(size_t*) value_ptr(session, var_type, base);
938
 
    pthread_mutex_unlock(&LOCK_global_system_variables);
 
943
    LOCK_global_system_variables.unlock();
939
944
    return new Item_int((uint64_t) value);
940
945
  }
941
946
  case SHOW_MY_BOOL:
942
947
  {
943
948
    int32_t value;
944
 
    pthread_mutex_lock(&LOCK_global_system_variables);
 
949
    LOCK_global_system_variables.lock();
945
950
    value= *(bool*) value_ptr(session, var_type, base);
946
 
    pthread_mutex_unlock(&LOCK_global_system_variables);
 
951
    LOCK_global_system_variables.unlock();
947
952
    return new Item_int(value,1);
948
953
  }
949
954
  case SHOW_CHAR_PTR:
950
955
  {
951
956
    Item *tmp;
952
 
    pthread_mutex_lock(&LOCK_global_system_variables);
 
957
    LOCK_global_system_variables.lock();
953
958
    char *str= *(char**) value_ptr(session, var_type, base);
954
959
    if (str)
955
960
    {
962
967
      tmp= new Item_null();
963
968
      tmp->collation.set(system_charset_info, DERIVATION_SYSCONST);
964
969
    }
965
 
    pthread_mutex_unlock(&LOCK_global_system_variables);
 
970
    LOCK_global_system_variables.unlock();
966
971
    return tmp;
967
972
  }
968
973
  case SHOW_CHAR:
969
974
  {
970
975
    Item *tmp;
971
 
    pthread_mutex_lock(&LOCK_global_system_variables);
 
976
    LOCK_global_system_variables.lock();
972
977
    char *str= (char*) value_ptr(session, var_type, base);
973
978
    if (str)
974
979
      tmp= new Item_string(str, strlen(str),
978
983
      tmp= new Item_null();
979
984
      tmp->collation.set(system_charset_info, DERIVATION_SYSCONST);
980
985
    }
981
 
    pthread_mutex_unlock(&LOCK_global_system_variables);
 
986
    LOCK_global_system_variables.unlock();
982
987
    return tmp;
983
988
  }
984
989
  default:
1181
1186
  /* We are using Time_zone object found during check() phase. */
1182
1187
  if (var->type == OPT_GLOBAL)
1183
1188
  {
1184
 
    pthread_mutex_lock(&LOCK_global_system_variables);
 
1189
    LOCK_global_system_variables.lock();
1185
1190
    global_system_variables.time_zone= var->save_result.time_zone;
1186
 
    pthread_mutex_unlock(&LOCK_global_system_variables);
 
1191
    LOCK_global_system_variables.unlock();
1187
1192
  }
1188
1193
  else
1189
1194
    session->variables.time_zone= var->save_result.time_zone;
1218
1223
 
1219
1224
void sys_var_session_time_zone::set_default(Session *session, sql_var_t type)
1220
1225
{
1221
 
 pthread_mutex_lock(&LOCK_global_system_variables);
 
1226
 LOCK_global_system_variables.lock();
1222
1227
 if (type == OPT_GLOBAL)
1223
1228
 {
1224
1229
   if (default_tz_name)
1235
1240
 }
1236
1241
 else
1237
1242
   session->variables.time_zone= global_system_variables.time_zone;
1238
 
 pthread_mutex_unlock(&LOCK_global_system_variables);
 
1243
 LOCK_global_system_variables.unlock();
1239
1244
}
1240
1245
 
1241
1246
 
1324
1329
  microseconds= (int64_t) (num * 1000000.0 + 0.5);
1325
1330
  if (var->type == OPT_GLOBAL)
1326
1331
  {
1327
 
    pthread_mutex_lock(&LOCK_global_system_variables);
 
1332
    LOCK_global_system_variables.lock();
1328
1333
    (global_system_variables.*offset)= microseconds;
1329
 
    pthread_mutex_unlock(&LOCK_global_system_variables);
 
1334
    LOCK_global_system_variables.unlock();
1330
1335
  }
1331
1336
  else
1332
1337
    session->variables.*offset= microseconds;
1339
1344
  int64_t microseconds= (int64_t) (option_limits->def_value * 1000000.0);
1340
1345
  if (type == OPT_GLOBAL)
1341
1346
  {
1342
 
    pthread_mutex_lock(&LOCK_global_system_variables);
 
1347
    LOCK_global_system_variables.lock();
1343
1348
    global_system_variables.*offset= microseconds;
1344
 
    pthread_mutex_unlock(&LOCK_global_system_variables);
 
1349
    LOCK_global_system_variables.unlock();
1345
1350
  }
1346
1351
  else
1347
1352
    session->variables.*offset= microseconds;
1381
1386
      session->options&= ~(uint64_t) (OPTION_BEGIN);
1382
1387
      session->server_status|= SERVER_STATUS_AUTOCOMMIT;
1383
1388
      TransactionServices &transaction_services= TransactionServices::singleton();
1384
 
      if (transaction_services.ha_commit_trans(session, true))
 
1389
      if (transaction_services.commitTransaction(session, true))
1385
1390
        return 1;
1386
1391
    }
1387
1392
    else
1431
1436
*/
1432
1437
static unsigned char *get_tmpdir(Session *)
1433
1438
{
1434
 
  assert(drizzle_tmpdir);
1435
 
  return (unsigned char*)drizzle_tmpdir;
 
1439
  assert(drizzle_tmpdir.size());
 
1440
  return (unsigned char*)drizzle_tmpdir.c_str();
1436
1441
}
1437
1442
 
1438
1443
/****************************************************************************
1474
1479
}
1475
1480
 
1476
1481
 
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
1482
 
1554
1483
 
1555
1484
 
1559
1488
  SYNOPSIS
1560
1489
    enumerate_sys_vars()
1561
1490
    session         current thread
1562
 
    sorted      If TRUE, the system variables should be sorted
1563
1491
 
1564
1492
  RETURN VALUES
1565
1493
    pointer     Array of drizzle_show_var elements for display
1566
1494
    NULL        FAILURE
1567
1495
*/
1568
1496
 
1569
 
drizzle_show_var* enumerate_sys_vars(Session *session, bool)
 
1497
drizzle_show_var* enumerate_sys_vars(Session *session)
1570
1498
{
1571
 
  int fixed_count= fixed_show_vars.elements;
1572
 
  int size= sizeof(drizzle_show_var) * (system_variable_map.size() + fixed_count + 1);
 
1499
  int size= sizeof(drizzle_show_var) * (system_variable_map.size() + 1);
1573
1500
  drizzle_show_var *result= (drizzle_show_var*) session->alloc(size);
1574
1501
 
1575
1502
  if (result)
1576
1503
  {
1577
 
    drizzle_show_var *show= result + fixed_count;
1578
 
    memcpy(result, fixed_show_vars.buffer, fixed_count * sizeof(drizzle_show_var));
 
1504
    drizzle_show_var *show= result;
1579
1505
 
1580
1506
    SystemVariableMap::const_iterator iter= system_variable_map.begin();
1581
1507
    while (iter != system_variable_map.end())
1584
1510
      show->name= var->getName().c_str();
1585
1511
      show->value= (char*) var;
1586
1512
      show->type= SHOW_SYS;
1587
 
      show++;
 
1513
      ++show;
1588
1514
      ++iter;
1589
1515
    }
1590
1516
 
1595
1521
}
1596
1522
 
1597
1523
 
 
1524
 
 
1525
void add_sys_var_to_list(sys_var *var)
 
1526
{
 
1527
  string lower_name(var->getName());
 
1528
  transform(lower_name.begin(), lower_name.end(),
 
1529
            lower_name.begin(), ::tolower);
 
1530
 
 
1531
  /* this fails if there is a conflicting variable name. */
 
1532
  if (system_variable_map.find(lower_name) != system_variable_map.end())
 
1533
  {
 
1534
    errmsg_printf(ERRMSG_LVL_ERROR, _("Variable named %s already exists!\n"),
 
1535
                  var->getName().c_str());
 
1536
    throw exception();
 
1537
  } 
 
1538
 
 
1539
  pair<SystemVariableMap::iterator, bool> ret= 
 
1540
    system_variable_map.insert(make_pair(lower_name, var));
 
1541
  if (ret.second == false)
 
1542
  {
 
1543
    errmsg_printf(ERRMSG_LVL_ERROR, _("Could not add Variable: %s\n"),
 
1544
                  var->getName().c_str());
 
1545
    throw exception();
 
1546
  }
 
1547
}
 
1548
 
 
1549
void add_sys_var_to_list(sys_var *var, struct option *long_options)
 
1550
{
 
1551
  add_sys_var_to_list(var);
 
1552
  var->setOptionLimits(find_option(long_options, var->getName().c_str()));
 
1553
}
 
1554
 
1598
1555
/*
1599
1556
  Initialize the system variables
1600
1557
 
1601
1558
  SYNOPSIS
1602
 
    set_var_init()
 
1559
    sys_var_init()
1603
1560
 
1604
1561
  RETURN VALUES
1605
1562
    0           SUCCESS
1606
1563
    otherwise   FAILURE
1607
1564
*/
1608
1565
 
1609
 
int set_var_init()
 
1566
int sys_var_init()
1610
1567
{
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
 
 
 
1568
  try
 
1569
  {
 
1570
    add_sys_var_to_list(&sys_auto_increment_increment, my_long_options);
 
1571
    add_sys_var_to_list(&sys_auto_increment_offset, my_long_options);
 
1572
    add_sys_var_to_list(&sys_autocommit, my_long_options);
 
1573
    add_sys_var_to_list(&sys_back_log, my_long_options);
 
1574
    add_sys_var_to_list(&sys_basedir, my_long_options);
 
1575
    add_sys_var_to_list(&sys_big_selects, my_long_options);
 
1576
    add_sys_var_to_list(&sys_buffer_results, my_long_options);
 
1577
    add_sys_var_to_list(&sys_bulk_insert_buff_size, my_long_options);
 
1578
    add_sys_var_to_list(&sys_collation_server, my_long_options);
 
1579
    add_sys_var_to_list(&sys_completion_type, my_long_options);
 
1580
    add_sys_var_to_list(&sys_datadir, my_long_options);
 
1581
    add_sys_var_to_list(&sys_div_precincrement, my_long_options);
 
1582
    add_sys_var_to_list(&sys_error_count, my_long_options);
 
1583
    add_sys_var_to_list(&sys_foreign_key_checks, my_long_options);
 
1584
    add_sys_var_to_list(&sys_group_concat_max_len, my_long_options);
 
1585
    add_sys_var_to_list(&sys_hostname, my_long_options);
 
1586
    add_sys_var_to_list(&sys_identity, my_long_options);
 
1587
    add_sys_var_to_list(&sys_join_buffer_size, my_long_options);
 
1588
    add_sys_var_to_list(&sys_last_insert_id, my_long_options);
 
1589
    add_sys_var_to_list(&sys_lc_time_names, my_long_options);
 
1590
    add_sys_var_to_list(&sys_max_allowed_packet, my_long_options);
 
1591
    add_sys_var_to_list(&sys_max_connect_errors, my_long_options);
 
1592
    add_sys_var_to_list(&sys_max_error_count, my_long_options);
 
1593
    add_sys_var_to_list(&sys_max_heap_table_size, my_long_options);
 
1594
    add_sys_var_to_list(&sys_max_join_size, my_long_options);
 
1595
    add_sys_var_to_list(&sys_max_length_for_sort_data, my_long_options);
 
1596
    add_sys_var_to_list(&sys_max_seeks_for_key, my_long_options);
 
1597
    add_sys_var_to_list(&sys_max_sort_length, my_long_options);
 
1598
    add_sys_var_to_list(&sys_max_write_lock_count, my_long_options);
 
1599
    add_sys_var_to_list(&sys_min_examined_row_limit, my_long_options);
 
1600
    add_sys_var_to_list(&sys_optimizer_prune_level, my_long_options);
 
1601
    add_sys_var_to_list(&sys_optimizer_search_depth, my_long_options);
 
1602
    add_sys_var_to_list(&sys_pid_file, my_long_options);
 
1603
    add_sys_var_to_list(&sys_plugin_dir, my_long_options);
 
1604
    add_sys_var_to_list(&sys_preload_buff_size, my_long_options);
 
1605
    add_sys_var_to_list(&sys_pseudo_thread_id, my_long_options);
 
1606
    add_sys_var_to_list(&sys_query_alloc_block_size, my_long_options);
 
1607
    add_sys_var_to_list(&sys_query_prealloc_size, my_long_options);
 
1608
    add_sys_var_to_list(&sys_range_alloc_block_size, my_long_options);
 
1609
    add_sys_var_to_list(&sys_read_buff_size, my_long_options);
 
1610
    add_sys_var_to_list(&sys_read_rnd_buff_size, my_long_options);
 
1611
    add_sys_var_to_list(&sys_scheduler, my_long_options);
 
1612
    add_sys_var_to_list(&sys_secure_file_priv, my_long_options);
 
1613
    add_sys_var_to_list(&sys_select_limit, my_long_options);
 
1614
    add_sys_var_to_list(&sys_server_id, my_long_options);
 
1615
    add_sys_var_to_list(&sys_sort_buffer, my_long_options);
 
1616
    add_sys_var_to_list(&sys_sql_notes, my_long_options);
 
1617
    add_sys_var_to_list(&sys_sql_warnings, my_long_options);
 
1618
    add_sys_var_to_list(&sys_storage_engine, my_long_options);
 
1619
    add_sys_var_to_list(&sys_system_time_zone, my_long_options);
 
1620
    add_sys_var_to_list(&sys_table_cache_size, my_long_options);
 
1621
    add_sys_var_to_list(&sys_table_def_size, my_long_options);
 
1622
    add_sys_var_to_list(&sys_table_lock_wait_timeout, my_long_options);
 
1623
    add_sys_var_to_list(&sys_thread_stack_size, my_long_options);
 
1624
    add_sys_var_to_list(&sys_time_zone, my_long_options);
 
1625
    add_sys_var_to_list(&sys_timed_mutexes, my_long_options);
 
1626
    add_sys_var_to_list(&sys_timestamp, my_long_options);
 
1627
    add_sys_var_to_list(&sys_tmp_table_size, my_long_options);
 
1628
    add_sys_var_to_list(&sys_tmpdir, my_long_options);
 
1629
    add_sys_var_to_list(&sys_transaction_message_threshold, my_long_options);
 
1630
    add_sys_var_to_list(&sys_tx_isolation, my_long_options);
 
1631
    add_sys_var_to_list(&sys_unique_checks, my_long_options);
 
1632
    add_sys_var_to_list(&sys_version, my_long_options);
 
1633
    add_sys_var_to_list(&sys_version_comment, my_long_options);
 
1634
    add_sys_var_to_list(&sys_version_compile_machine, my_long_options);
 
1635
    add_sys_var_to_list(&sys_version_compile_os, my_long_options);
 
1636
    add_sys_var_to_list(&sys_version_compile_vendor, my_long_options);
 
1637
    add_sys_var_to_list(&sys_warning_count, my_long_options);
 
1638
  }
 
1639
  catch (...)
 
1640
  {
 
1641
    errmsg_printf(ERRMSG_LVL_ERROR, _("Failed to initialize system variables"));
 
1642
    return(1);
 
1643
  }
1626
1644
  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
1645
}
1638
1646
 
1639
1647
 
1686
1694
}
1687
1695
 
1688
1696
 
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
1697
/****************************************************************************
1822
1698
 Functions to handle table_type
1823
1699
****************************************************************************/