~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/sys_var.cc

  • Committer: Brian Aker
  • Date: 2011-02-22 06:12:02 UTC
  • mfrom: (2190.1.6 drizzle-build)
  • Revision ID: brian@tangent.org-20110222061202-k03czxykqy4x9hjs
List update, header fixes, multiple symbols, and David deletes some code.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
2
 *  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
3
3
 *
4
 
 *  Copyright (C) 2008 Sun Microsystems
 
4
 *  Copyright (C) 2008 Sun Microsystems, Inc.
5
5
 *
6
6
 *  This program is free software; you can redistribute it and/or modify
7
7
 *  it under the terms of the GNU General Public License as published by
36
36
  @todo
37
37
    Add full support for the variable character_set (for 4.1)
38
38
 
39
 
  @note
40
 
    Be careful with var->save_result: sys_var::check() only updates
41
 
    uint64_t_value; so other members of the union are garbage then; to use
42
 
    them you must first assign a value to them (in specific ::check() for
43
 
    example).
44
39
*/
45
40
 
46
 
#include "config.h"
47
 
#include "drizzled/option.h"
 
41
#include <config.h>
 
42
#include <drizzled/option.h>
48
43
#include <drizzled/error.h>
49
44
#include <drizzled/gettext.h>
50
45
#include <drizzled/tztime.h>
56
51
#include <drizzled/item/uint.h>
57
52
#include <drizzled/item/null.h>
58
53
#include <drizzled/item/float.h>
 
54
#include <drizzled/item/string.h>
59
55
#include <drizzled/plugin.h>
60
 
#include "drizzled/version.h"
61
 
#include "drizzled/strfunc.h"
62
 
#include "drizzled/internal/m_string.h"
63
 
#include "drizzled/pthread_globals.h"
64
 
#include "drizzled/charset.h"
65
 
#include "drizzled/transaction_services.h"
 
56
#include <drizzled/version.h>
 
57
#include <drizzled/strfunc.h>
 
58
#include <drizzled/internal/m_string.h>
 
59
#include <drizzled/pthread_globals.h>
 
60
#include <drizzled/charset.h>
 
61
#include <drizzled/transaction_services.h>
 
62
#include <drizzled/constrained_value.h>
 
63
#include <drizzled/visibility.h>
 
64
#include <drizzled/typelib.h>
 
65
#include <drizzled/plugin/storage_engine.h>
66
66
 
67
67
#include <cstdio>
68
68
#include <map>
86
86
extern const CHARSET_INFO *character_set_filesystem;
87
87
extern size_t my_thread_stack_size;
88
88
 
89
 
class sys_var_pluginvar;
90
89
typedef map<string, sys_var *> SystemVariableMap;
91
90
static SystemVariableMap system_variable_map;
92
91
extern char *opt_drizzle_tmpdir;
93
92
 
94
93
extern TYPELIB tx_isolation_typelib;
95
94
 
 
95
namespace
 
96
{
 
97
static size_t revno= DRIZZLE7_VC_REVNO;
 
98
static size_t release_id= DRIZZLE7_RELEASE_ID;
 
99
}
 
100
 
96
101
const char *bool_type_names[]= { "OFF", "ON", NULL };
97
102
TYPELIB bool_typelib=
98
103
{
109
114
static void fix_max_join_size(Session *session, sql_var_t type);
110
115
static void fix_session_mem_root(Session *session, sql_var_t type);
111
116
static void fix_server_id(Session *session, sql_var_t type);
112
 
static bool get_unsigned32(Session *session, set_var *var);
113
 
static bool get_unsigned64(Session *session, set_var *var);
114
117
bool throw_bounds_warning(Session *session, bool fixed, bool unsignd,
115
118
                          const std::string &name, int64_t val);
116
119
static unsigned char *get_error_count(Session *session);
128
131
*/
129
132
static sys_var_session_uint64_t
130
133
sys_auto_increment_increment("auto_increment_increment",
131
 
                             &system_variables::auto_increment_increment);
 
134
                             &drizzle_system_variables::auto_increment_increment);
132
135
static sys_var_session_uint64_t
133
136
sys_auto_increment_offset("auto_increment_offset",
134
 
                          &system_variables::auto_increment_offset);
 
137
                          &drizzle_system_variables::auto_increment_offset);
135
138
 
136
139
static sys_var_fs_path sys_basedir("basedir", basedir);
137
140
static sys_var_fs_path sys_pid_file("pid_file", pid_file);
139
142
 
140
143
static sys_var_size_t_ptr sys_thread_stack_size("thread_stack",
141
144
                                                      &my_thread_stack_size);
142
 
static sys_var_uint32_t_ptr sys_back_log("back_log", &back_log);
 
145
static sys_var_constrained_value_readonly<uint32_t> sys_back_log("back_log", back_log);
143
146
 
144
147
static sys_var_session_uint64_t sys_bulk_insert_buff_size("bulk_insert_buffer_size",
145
 
                                                          &system_variables::bulk_insert_buff_size);
 
148
                                                          &drizzle_system_variables::bulk_insert_buff_size);
146
149
static sys_var_session_uint32_t sys_completion_type("completion_type",
147
 
                                                    &system_variables::completion_type,
 
150
                                                    &drizzle_system_variables::completion_type,
148
151
                                                    check_completion_type,
149
152
                                                    fix_completion_type);
150
153
static sys_var_collation_sv
151
 
sys_collation_server("collation_server", &system_variables::collation_server, &default_charset_info);
 
154
sys_collation_server("collation_server", &drizzle_system_variables::collation_server, &default_charset_info);
152
155
static sys_var_fs_path       sys_datadir("datadir", getDataHome());
153
156
 
154
157
static sys_var_session_uint64_t sys_join_buffer_size("join_buffer_size",
155
 
                                                     &system_variables::join_buff_size);
 
158
                                                     &drizzle_system_variables::join_buff_size);
156
159
static sys_var_session_uint32_t sys_max_allowed_packet("max_allowed_packet",
157
 
                                                       &system_variables::max_allowed_packet);
158
 
static sys_var_uint64_t_ptr     sys_max_connect_errors("max_connect_errors",
159
 
                                               &max_connect_errors);
 
160
                                                       &drizzle_system_variables::max_allowed_packet);
160
161
static sys_var_session_uint64_t sys_max_error_count("max_error_count",
161
 
                                                  &system_variables::max_error_count);
 
162
                                                  &drizzle_system_variables::max_error_count);
162
163
static sys_var_session_uint64_t sys_max_heap_table_size("max_heap_table_size",
163
 
                                                        &system_variables::max_heap_table_size);
 
164
                                                        &drizzle_system_variables::max_heap_table_size);
164
165
static sys_var_session_uint64_t sys_pseudo_thread_id("pseudo_thread_id",
165
 
                                              &system_variables::pseudo_thread_id,
 
166
                                              &drizzle_system_variables::pseudo_thread_id,
166
167
                                              0, check_pseudo_thread_id);
167
168
static sys_var_session_ha_rows  sys_max_join_size("max_join_size",
168
 
                                                  &system_variables::max_join_size,
 
169
                                                  &drizzle_system_variables::max_join_size,
169
170
                                                  fix_max_join_size);
170
171
static sys_var_session_uint64_t sys_max_seeks_for_key("max_seeks_for_key",
171
 
                                                      &system_variables::max_seeks_for_key);
 
172
                                                      &drizzle_system_variables::max_seeks_for_key);
172
173
static sys_var_session_uint64_t   sys_max_length_for_sort_data("max_length_for_sort_data",
173
 
                                                               &system_variables::max_length_for_sort_data);
 
174
                                                               &drizzle_system_variables::max_length_for_sort_data);
174
175
static sys_var_session_size_t   sys_max_sort_length("max_sort_length",
175
 
                                                    &system_variables::max_sort_length);
 
176
                                                    &drizzle_system_variables::max_sort_length);
176
177
static sys_var_uint64_t_ptr     sys_max_write_lock_count("max_write_lock_count",
177
178
                                                 &max_write_lock_count);
178
179
static sys_var_session_uint64_t sys_min_examined_row_limit("min_examined_row_limit",
179
 
                                                           &system_variables::min_examined_row_limit);
 
180
                                                           &drizzle_system_variables::min_examined_row_limit);
180
181
 
181
182
/* these two cannot be static */
182
183
static sys_var_session_bool sys_optimizer_prune_level("optimizer_prune_level",
183
 
                                                      &system_variables::optimizer_prune_level);
 
184
                                                      &drizzle_system_variables::optimizer_prune_level);
184
185
static sys_var_session_uint32_t sys_optimizer_search_depth("optimizer_search_depth",
185
 
                                                           &system_variables::optimizer_search_depth);
 
186
                                                           &drizzle_system_variables::optimizer_search_depth);
186
187
 
187
188
static sys_var_session_uint64_t sys_preload_buff_size("preload_buffer_size",
188
 
                                                      &system_variables::preload_buff_size);
 
189
                                                      &drizzle_system_variables::preload_buff_size);
189
190
static sys_var_session_uint32_t sys_read_buff_size("read_buffer_size",
190
 
                                                   &system_variables::read_buff_size);
 
191
                                                   &drizzle_system_variables::read_buff_size);
191
192
static sys_var_session_uint32_t sys_read_rnd_buff_size("read_rnd_buffer_size",
192
 
                                                       &system_variables::read_rnd_buff_size);
 
193
                                                       &drizzle_system_variables::read_rnd_buff_size);
193
194
static sys_var_session_uint32_t sys_div_precincrement("div_precision_increment",
194
 
                                                      &system_variables::div_precincrement);
 
195
                                                      &drizzle_system_variables::div_precincrement);
195
196
 
196
197
static sys_var_session_size_t   sys_range_alloc_block_size("range_alloc_block_size",
197
 
                                                           &system_variables::range_alloc_block_size);
 
198
                                                           &drizzle_system_variables::range_alloc_block_size);
 
199
 
 
200
static sys_var_session_bool sys_replicate_query("replicate_query",
 
201
                                                &drizzle_system_variables::replicate_query);
 
202
 
198
203
static sys_var_session_uint32_t sys_query_alloc_block_size("query_alloc_block_size",
199
 
                                                           &system_variables::query_alloc_block_size,
 
204
                                                           &drizzle_system_variables::query_alloc_block_size,
200
205
                                                           NULL, fix_session_mem_root);
201
206
static sys_var_session_uint32_t sys_query_prealloc_size("query_prealloc_size",
202
 
                                                        &system_variables::query_prealloc_size,
 
207
                                                        &drizzle_system_variables::query_prealloc_size,
203
208
                                                        NULL, fix_session_mem_root);
204
209
static sys_var_readonly sys_tmpdir("tmpdir", OPT_GLOBAL, SHOW_CHAR, get_tmpdir);
205
210
 
213
218
                                           fix_server_id);
214
219
 
215
220
static sys_var_session_size_t   sys_sort_buffer("sort_buffer_size",
216
 
                                                &system_variables::sortbuff_size);
 
221
                                                &drizzle_system_variables::sortbuff_size);
217
222
 
218
 
static sys_var_session_size_t sys_transaction_message_threshold("transaction_message_threshold",
219
 
                                                                &system_variables::transaction_message_threshold);
 
223
static sys_var_size_t_ptr_readonly sys_transaction_message_threshold("transaction_message_threshold",
 
224
                                                                &transaction_message_threshold);
220
225
 
221
226
static sys_var_session_storage_engine sys_storage_engine("storage_engine",
222
 
                                       &system_variables::storage_engine);
223
 
static sys_var_const_str        sys_system_time_zone("system_time_zone",
224
 
                                             system_time_zone);
 
227
                                       &drizzle_system_variables::storage_engine);
225
228
static sys_var_size_t_ptr       sys_table_def_size("table_definition_cache",
226
229
                                             &table_def_size);
227
230
static sys_var_uint64_t_ptr     sys_table_cache_size("table_open_cache",
229
232
static sys_var_uint64_t_ptr     sys_table_lock_wait_timeout("table_lock_wait_timeout",
230
233
                                                    &table_lock_wait_timeout);
231
234
static sys_var_session_enum     sys_tx_isolation("tx_isolation",
232
 
                                             &system_variables::tx_isolation,
 
235
                                             &drizzle_system_variables::tx_isolation,
233
236
                                             &tx_isolation_typelib,
234
237
                                             fix_tx_isolation,
235
238
                                             check_tx_isolation);
236
239
static sys_var_session_uint64_t sys_tmp_table_size("tmp_table_size",
237
 
                                           &system_variables::tmp_table_size);
 
240
                                           &drizzle_system_variables::tmp_table_size);
238
241
static sys_var_bool_ptr  sys_timed_mutexes("timed_mutexes", &internal::timed_mutexes);
239
242
static sys_var_const_str  sys_version("version", version().c_str());
240
243
 
274
277
/* Local state variables */
275
278
 
276
279
static sys_var_session_ha_rows  sys_select_limit("sql_select_limit",
277
 
                                                 &system_variables::select_limit);
 
280
                                                 &drizzle_system_variables::select_limit);
278
281
static sys_var_timestamp sys_timestamp("timestamp");
279
282
static sys_var_last_insert_id
280
283
sys_last_insert_id("last_insert_id");
308
311
                                          get_warning_count);
309
312
 
310
313
sys_var_session_uint64_t sys_group_concat_max_len("group_concat_max_len",
311
 
                                                  &system_variables::group_concat_max_len);
312
 
 
313
 
sys_var_session_time_zone sys_time_zone("time_zone");
 
314
                                                  &drizzle_system_variables::group_concat_max_len);
314
315
 
315
316
/* Global read-only variable containing hostname */
316
 
static sys_var_const_str        sys_hostname("hostname", glob_hostname);
317
 
 
318
 
bool sys_var::check(Session *, set_var *var)
 
317
static sys_var_const_string sys_hostname("hostname", getServerHostname());
 
318
 
 
319
static sys_var_const_str sys_revid("vc_revid", DRIZZLE7_VC_REVID);
 
320
static sys_var_const_str sys_branch("vc_branch", DRIZZLE7_VC_BRANCH);
 
321
static sys_var_size_t_ptr_readonly sys_revno("vc_revno", &revno);
 
322
static sys_var_size_t_ptr_readonly sys_release_id("vc_release_id", &release_id);
 
323
 
 
324
bool sys_var::check(Session *session, set_var *var)
319
325
{
320
 
  var->save_result.uint64_t_value= var->value->val_int();
 
326
  if (check_func)
 
327
  {
 
328
    int res;
 
329
    if ((res=(*check_func)(session, var)) < 0)
 
330
      my_error(ER_WRONG_VALUE_FOR_VAR, MYF(0), getName().c_str(), var->value->str_value.ptr());
 
331
    return res;
 
332
  }
 
333
  var->updateValue();
321
334
  return 0;
322
335
}
323
336
 
324
337
bool sys_var_str::check(Session *session, set_var *var)
325
338
{
 
339
  if (!check_func)
 
340
    return 0;
 
341
 
326
342
  int res;
327
 
  if (!check_func)
328
 
    return 0;
329
 
 
330
343
  if ((res=(*check_func)(session, var)) < 0)
331
344
    my_error(ER_WRONG_VALUE_FOR_VAR, MYF(0), getName().c_str(), var->value->str_value.ptr());
332
345
  return res;
333
346
}
334
347
 
 
348
bool sys_var_std_string::check(Session *session, set_var *var)
 
349
{
 
350
  if (check_func == NULL)
 
351
  {
 
352
    return false;
 
353
  }
 
354
 
 
355
  int res= (*check_func)(session, var);
 
356
  if (res != 0)
 
357
  {
 
358
    my_error(ER_WRONG_VALUE_FOR_VAR, MYF(0), getName().c_str(), var->value->str_value.ptr());
 
359
    return true;
 
360
  }
 
361
  return false;
 
362
}
 
363
 
335
364
/*
336
365
  Functions to check and update variables
337
366
*/
411
440
{
412
441
  if (fixed)
413
442
  {
414
 
    char buf[22];
 
443
    char buf[DECIMAL_LONGLONG_DIGITS];
415
444
 
416
445
    if (unsignd)
417
446
      internal::ullstr((uint64_t) val, buf);
446
475
  return out;
447
476
}
448
477
 
449
 
static bool get_unsigned32(Session *session, set_var *var)
450
 
{
451
 
  if (var->value->unsigned_flag)
452
 
    var->save_result.uint32_t_value= 
453
 
      static_cast<uint32_t>(var->value->val_int());
454
 
  else
455
 
  {
456
 
    int64_t v= var->value->val_int();
457
 
    if (v > UINT32_MAX)
458
 
      throw_bounds_warning(session, true, true,var->var->getName().c_str(), v);
459
 
    
460
 
    var->save_result.uint32_t_value= 
461
 
      static_cast<uint32_t>((v > UINT32_MAX) ? UINT32_MAX : (v < 0) ? 0 : v);
462
 
  }
463
 
  return false;
464
 
}
465
 
 
466
 
static bool get_unsigned64(Session *, set_var *var)
467
 
{
468
 
  if (var->value->unsigned_flag)
469
 
      var->save_result.uint64_t_value=(uint64_t) var->value->val_int();
470
 
  else
471
 
  {
472
 
    int64_t v= var->value->val_int();
473
 
      var->save_result.uint64_t_value= (uint64_t) ((v < 0) ? 0 : v);
474
 
  }
475
 
  return 0;
476
 
}
477
 
 
478
 
static bool get_size_t(Session *, set_var *var)
479
 
{
480
 
  if (var->value->unsigned_flag)
481
 
    var->save_result.size_t_value= (size_t) var->value->val_int();
482
 
  else
483
 
  {
484
 
    ssize_t v= (ssize_t)var->value->val_int();
485
 
    var->save_result.size_t_value= (size_t) ((v < 0) ? 0 : v);
486
 
  }
487
 
  return 0;
488
 
}
489
 
 
490
478
bool sys_var_uint32_t_ptr::check(Session *, set_var *var)
491
479
{
492
 
  var->save_result.uint32_t_value= (uint32_t)var->value->val_int();
 
480
  var->updateValue();
493
481
  return 0;
494
482
}
495
483
 
496
484
bool sys_var_uint32_t_ptr::update(Session *session, set_var *var)
497
485
{
498
 
  uint32_t tmp= var->save_result.uint32_t_value;
499
 
  LOCK_global_system_variables.lock();
 
486
  uint64_t tmp= var->getInteger();
 
487
  boost::mutex::scoped_lock scopedLock(session->catalog().systemVariableLock());
 
488
 
500
489
  if (option_limits)
501
490
  {
502
491
    uint32_t newvalue= (uint32_t) fix_unsigned(session, tmp, option_limits);
503
 
    if(newvalue==tmp)
 
492
    if(static_cast<uint64_t>(newvalue) == tmp)
504
493
      *value= newvalue;
505
494
  }
506
495
  else
507
 
    *value= (uint32_t) tmp;
508
 
  LOCK_global_system_variables.unlock();
 
496
  {
 
497
    *value= static_cast<uint32_t>(tmp);
 
498
  }
 
499
 
509
500
  return 0;
510
501
}
511
502
 
512
503
 
513
 
void sys_var_uint32_t_ptr::set_default(Session *, sql_var_t)
 
504
void sys_var_uint32_t_ptr::set_default(Session *session, sql_var_t)
514
505
{
515
506
  bool not_used;
516
 
  LOCK_global_system_variables.lock();
 
507
  boost::mutex::scoped_lock scopedLock(session->catalog().systemVariableLock());
517
508
  *value= (uint32_t)getopt_ull_limit_value((uint32_t) option_limits->def_value,
518
509
                                           option_limits, &not_used);
519
 
  LOCK_global_system_variables.unlock();
520
510
}
521
511
 
522
512
 
523
513
bool sys_var_uint64_t_ptr::update(Session *session, set_var *var)
524
514
{
525
 
  uint64_t tmp= var->save_result.uint64_t_value;
526
 
  LOCK_global_system_variables.lock();
 
515
  uint64_t tmp= var->getInteger();
 
516
  boost::mutex::scoped_lock scopedLock(session->catalog().systemVariableLock());
 
517
 
527
518
  if (option_limits)
528
519
  {
529
 
    uint64_t newvalue= (uint64_t) fix_unsigned(session, tmp, option_limits);
 
520
    uint64_t newvalue= fix_unsigned(session, tmp, option_limits);
530
521
    if(newvalue==tmp)
531
522
      *value= newvalue;
532
523
  }
533
524
  else
534
 
    *value= (uint64_t) tmp;
535
 
  LOCK_global_system_variables.unlock();
 
525
  {
 
526
    *value= tmp;
 
527
  }
 
528
 
536
529
  return 0;
537
530
}
538
531
 
539
532
 
540
 
void sys_var_uint64_t_ptr::set_default(Session *, sql_var_t)
 
533
void sys_var_uint64_t_ptr::set_default(Session *session, sql_var_t)
541
534
{
542
 
  bool not_used;
543
 
  LOCK_global_system_variables.lock();
544
 
  *value= getopt_ull_limit_value((uint64_t) option_limits->def_value,
545
 
                                 option_limits, &not_used);
546
 
  LOCK_global_system_variables.unlock();
 
535
  if (have_default_value)
 
536
  {
 
537
    *value= default_value;
 
538
  }
 
539
  else
 
540
  {
 
541
    bool not_used;
 
542
    boost::mutex::scoped_lock scopedLock(session->catalog().systemVariableLock());
 
543
    *value= getopt_ull_limit_value((uint64_t) option_limits->def_value,
 
544
                                   option_limits, &not_used);
 
545
  }
547
546
}
548
547
 
549
548
 
550
549
bool sys_var_size_t_ptr::update(Session *session, set_var *var)
551
550
{
552
 
  size_t tmp= var->save_result.size_t_value;
553
 
  LOCK_global_system_variables.lock();
 
551
  size_t tmp= size_t(var->getInteger());
 
552
 
 
553
  boost::mutex::scoped_lock scopedLock(session->catalog().systemVariableLock());
 
554
 
554
555
  if (option_limits)
555
556
    *value= fix_size_t(session, tmp, option_limits);
556
557
  else
557
558
    *value= tmp;
558
 
  LOCK_global_system_variables.unlock();
 
559
 
559
560
  return 0;
560
561
}
561
562
 
562
563
 
563
 
void sys_var_size_t_ptr::set_default(Session *, sql_var_t)
 
564
void sys_var_size_t_ptr::set_default(Session *session, sql_var_t)
564
565
{
565
566
  bool not_used;
566
 
  LOCK_global_system_variables.lock();
 
567
  boost::mutex::scoped_lock scopedLock(session->catalog().systemVariableLock());
567
568
  *value= (size_t)getopt_ull_limit_value((size_t) option_limits->def_value,
568
569
                                         option_limits, &not_used);
569
 
  LOCK_global_system_variables.unlock();
 
570
}
 
571
 
 
572
bool sys_var_bool_ptr::check(Session *session, set_var *var)
 
573
{
 
574
  return check_enum(session, var, &bool_typelib);
570
575
}
571
576
 
572
577
bool sys_var_bool_ptr::update(Session *, set_var *var)
573
578
{
574
 
  *value= (bool) var->save_result.uint32_t_value;
 
579
  *value= bool(var->getInteger());
575
580
  return 0;
576
581
}
577
582
 
578
583
 
579
584
void sys_var_bool_ptr::set_default(Session *, sql_var_t)
580
585
{
581
 
  *value= (bool) option_limits->def_value;
 
586
  *value= default_value;
582
587
}
583
588
 
584
589
 
587
592
*/
588
593
bool sys_var_session_uint32_t::check(Session *session, set_var *var)
589
594
{
590
 
  return (get_unsigned32(session, var) ||
591
 
          (check_func && (*check_func)(session, var)));
 
595
  var->updateValue();
 
596
  return (check_func && (*check_func)(session, var));
592
597
}
593
598
 
594
599
bool sys_var_session_uint32_t::update(Session *session, set_var *var)
595
600
{
596
 
  uint64_t tmp= (uint64_t) var->save_result.uint32_t_value;
 
601
  uint64_t tmp= var->getInteger();
597
602
 
598
603
  /* Don't use bigger value than given with --maximum-variable-name=.. */
599
604
  if ((uint32_t) tmp > max_system_variables.*offset)
607
612
  else if (tmp > UINT32_MAX)
608
613
  {
609
614
    tmp= UINT32_MAX;
610
 
    throw_bounds_warning(session, true, true, getName(), (int64_t) var->save_result.uint64_t_value);
 
615
    throw_bounds_warning(session, true, true, getName(), int64_t(var->getInteger()));
611
616
  }
612
617
 
613
618
  if (var->type == OPT_GLOBAL)
646
651
 
647
652
bool sys_var_session_ha_rows::update(Session *session, set_var *var)
648
653
{
649
 
  uint64_t tmp= var->save_result.uint64_t_value;
 
654
  uint64_t tmp= var->getInteger();
650
655
 
651
656
  /* Don't use bigger value than given with --maximum-variable-name=.. */
652
657
  if ((ha_rows) tmp > max_system_variables.*offset)
657
662
  if (var->type == OPT_GLOBAL)
658
663
  {
659
664
    /* Lock is needed to make things safe on 32 bit systems */
660
 
    LOCK_global_system_variables.lock();
 
665
    boost::mutex::scoped_lock scopedLock(session->catalog().systemVariableLock());
661
666
    global_system_variables.*offset= (ha_rows) tmp;
662
 
    LOCK_global_system_variables.unlock();
663
667
  }
664
668
  else
 
669
  {
665
670
    session->variables.*offset= (ha_rows) tmp;
 
671
  }
 
672
 
666
673
  return 0;
667
674
}
668
675
 
673
680
  {
674
681
    bool not_used;
675
682
    /* We will not come here if option_limits is not set */
676
 
    LOCK_global_system_variables.lock();
 
683
    boost::mutex::scoped_lock scopedLock(session->catalog().systemVariableLock());
677
684
    global_system_variables.*offset=
678
685
      (ha_rows) getopt_ull_limit_value((ha_rows) option_limits->def_value,
679
686
                                       option_limits, &not_used);
680
 
    LOCK_global_system_variables.unlock();
681
687
  }
682
688
  else
 
689
  {
683
690
    session->variables.*offset= global_system_variables.*offset;
 
691
  }
684
692
}
685
693
 
686
694
 
695
703
 
696
704
bool sys_var_session_uint64_t::check(Session *session, set_var *var)
697
705
{
698
 
  return (get_unsigned64(session, var) ||
699
 
          (check_func && (*check_func)(session, var)));
 
706
  var->updateValue();
 
707
  return (check_func && (*check_func)(session, var));
700
708
}
701
709
 
702
710
bool sys_var_session_uint64_t::update(Session *session,  set_var *var)
703
711
{
704
 
  uint64_t tmp= var->save_result.uint64_t_value;
 
712
  uint64_t tmp= var->getInteger();
705
713
 
706
714
  if (tmp > max_system_variables.*offset)
707
715
  {
714
722
  if (var->type == OPT_GLOBAL)
715
723
  {
716
724
    /* Lock is needed to make things safe on 32 bit systems */
717
 
    LOCK_global_system_variables.lock();
 
725
    boost::mutex::scoped_lock scopedLock(session->catalog().systemVariableLock());
718
726
    global_system_variables.*offset= (uint64_t) tmp;
719
 
    LOCK_global_system_variables.unlock();
720
727
  }
721
728
  else
 
729
  {
722
730
    session->variables.*offset= (uint64_t) tmp;
 
731
  }
 
732
 
723
733
  return 0;
724
734
}
725
735
 
729
739
  if (type == OPT_GLOBAL)
730
740
  {
731
741
    bool not_used;
732
 
    LOCK_global_system_variables.lock();
 
742
    boost::mutex::scoped_lock scopedLock(session->catalog().systemVariableLock());
733
743
    global_system_variables.*offset=
734
744
      getopt_ull_limit_value((uint64_t) option_limits->def_value,
735
745
                             option_limits, &not_used);
736
 
    LOCK_global_system_variables.unlock();
737
746
  }
738
747
  else
 
748
  {
739
749
    session->variables.*offset= global_system_variables.*offset;
 
750
  }
740
751
}
741
752
 
742
753
 
751
762
 
752
763
bool sys_var_session_size_t::check(Session *session, set_var *var)
753
764
{
754
 
  return (get_size_t(session, var) ||
755
 
          (check_func && (*check_func)(session, var)));
 
765
  var->updateValue();
 
766
  return (check_func && (*check_func)(session, var));
756
767
}
757
768
 
758
769
bool sys_var_session_size_t::update(Session *session,  set_var *var)
759
770
{
760
 
  size_t tmp= var->save_result.size_t_value;
 
771
  size_t tmp= size_t(var->getInteger());
761
772
 
762
773
  if (tmp > max_system_variables.*offset)
763
774
    tmp= max_system_variables.*offset;
767
778
  if (var->type == OPT_GLOBAL)
768
779
  {
769
780
    /* Lock is needed to make things safe on 32 bit systems */
770
 
    LOCK_global_system_variables.lock();
 
781
    boost::mutex::scoped_lock scopedLock(session->catalog().systemVariableLock());
771
782
    global_system_variables.*offset= tmp;
772
 
    LOCK_global_system_variables.unlock();
773
783
  }
774
784
  else
 
785
  {
775
786
    session->variables.*offset= tmp;
 
787
  }
 
788
 
776
789
  return 0;
777
790
}
778
791
 
782
795
  if (type == OPT_GLOBAL)
783
796
  {
784
797
    bool not_used;
785
 
    LOCK_global_system_variables.lock();
 
798
    boost::mutex::scoped_lock scopedLock(session->catalog().systemVariableLock());
786
799
    global_system_variables.*offset=
787
800
      (size_t)getopt_ull_limit_value((size_t) option_limits->def_value,
788
801
                                     option_limits, &not_used);
789
 
    LOCK_global_system_variables.unlock();
790
802
  }
791
803
  else
 
804
  {
792
805
    session->variables.*offset= global_system_variables.*offset;
 
806
  }
793
807
}
794
808
 
795
809
 
802
816
  return (unsigned char*) &(session->variables.*offset);
803
817
}
804
818
 
 
819
bool sys_var_session_bool::check(Session *session, set_var *var)
 
820
{
 
821
  return check_enum(session, var, &bool_typelib);
 
822
}
805
823
 
806
824
bool sys_var_session_bool::update(Session *session,  set_var *var)
807
825
{
808
826
  if (var->type == OPT_GLOBAL)
809
 
    global_system_variables.*offset= (bool) var->save_result.uint32_t_value;
 
827
    global_system_variables.*offset= bool(var->getInteger());
810
828
  else
811
 
    session->variables.*offset= (bool) var->save_result.uint32_t_value;
 
829
    session->variables.*offset= bool(var->getInteger());
 
830
 
812
831
  return 0;
813
832
}
814
833
 
841
860
 
842
861
  if (var->value->result_type() == STRING_RESULT)
843
862
  {
844
 
    if (!(res=var->value->val_str(&str)) ||
845
 
        (var->save_result.uint32_t_value= find_type(enum_names, res->ptr(),
846
 
                                                    res->length(),1)) == 0)
 
863
    res= var->value->val_str(&str);
 
864
    if (res == NULL)
847
865
    {
848
 
      value= res ? res->c_ptr() : "NULL";
 
866
      value= "NULL";
849
867
      goto err;
850
868
    }
851
869
 
852
 
    var->save_result.uint32_t_value--;
 
870
    uint64_t tmp_val= enum_names->find_type(res->ptr(), res->length(), true);
 
871
    if (tmp_val == 0)
 
872
    {
 
873
      value= res->c_ptr();
 
874
      goto err;
 
875
    }
 
876
    var->setValue(tmp_val-1);
853
877
  }
854
878
  else
855
879
  {
856
 
    uint64_t tmp=var->value->val_int();
 
880
    uint64_t tmp= var->value->val_int();
857
881
    if (tmp >= enum_names->count)
858
882
    {
859
883
      internal::llstr(tmp,buff);
860
884
      value=buff;                               // Wrong value is here
861
885
      goto err;
862
886
    }
863
 
    var->save_result.uint32_t_value= (uint32_t) tmp;    // Save for update
 
887
    var->setValue(tmp); // Save for update
864
888
  }
865
889
  return 0;
866
890
 
896
920
  case SHOW_INT:
897
921
  {
898
922
    uint32_t value;
899
 
    LOCK_global_system_variables.lock();
 
923
    boost::mutex::scoped_lock scopedLock(session->catalog().systemVariableLock());
900
924
    value= *(uint*) value_ptr(session, var_type, base);
901
 
    LOCK_global_system_variables.unlock();
 
925
 
902
926
    return new Item_uint((uint64_t) value);
903
927
  }
904
928
  case SHOW_LONGLONG:
905
929
  {
906
930
    int64_t value;
907
 
    LOCK_global_system_variables.lock();
 
931
    boost::mutex::scoped_lock scopedLock(session->catalog().systemVariableLock());
908
932
    value= *(int64_t*) value_ptr(session, var_type, base);
909
 
    LOCK_global_system_variables.unlock();
 
933
 
910
934
    return new Item_int(value);
911
935
  }
912
936
  case SHOW_DOUBLE:
913
937
  {
914
938
    double value;
915
 
    LOCK_global_system_variables.lock();
916
 
    value= *(double*) value_ptr(session, var_type, base);
917
 
    LOCK_global_system_variables.unlock();
 
939
    {
 
940
      boost::mutex::scoped_lock scopedLock(session->catalog().systemVariableLock());
 
941
      value= *(double*) value_ptr(session, var_type, base);
 
942
    }
 
943
 
918
944
    /* 6, as this is for now only used with microseconds */
919
945
    return new Item_float(value, 6);
920
946
  }
921
947
  case SHOW_HA_ROWS:
922
948
  {
923
949
    ha_rows value;
924
 
    LOCK_global_system_variables.lock();
 
950
    boost::mutex::scoped_lock scopedLock(session->catalog().systemVariableLock());
925
951
    value= *(ha_rows*) value_ptr(session, var_type, base);
926
 
    LOCK_global_system_variables.unlock();
 
952
 
927
953
    return new Item_int((uint64_t) value);
928
954
  }
929
955
  case SHOW_SIZE:
930
956
  {
931
957
    size_t value;
932
 
    LOCK_global_system_variables.lock();
 
958
    boost::mutex::scoped_lock scopedLock(session->catalog().systemVariableLock());
933
959
    value= *(size_t*) value_ptr(session, var_type, base);
934
 
    LOCK_global_system_variables.unlock();
 
960
 
935
961
    return new Item_int((uint64_t) value);
936
962
  }
937
963
  case SHOW_MY_BOOL:
938
964
  {
939
965
    int32_t value;
940
 
    LOCK_global_system_variables.lock();
 
966
    boost::mutex::scoped_lock scopedLock(session->catalog().systemVariableLock());
941
967
    value= *(bool*) value_ptr(session, var_type, base);
942
 
    LOCK_global_system_variables.unlock();
943
968
    return new Item_int(value,1);
944
969
  }
945
970
  case SHOW_CHAR_PTR:
946
971
  {
947
972
    Item *tmp;
948
 
    LOCK_global_system_variables.lock();
 
973
    boost::mutex::scoped_lock scopedLock(session->catalog().systemVariableLock());
949
974
    char *str= *(char**) value_ptr(session, var_type, base);
950
975
    if (str)
951
976
    {
958
983
      tmp= new Item_null();
959
984
      tmp->collation.set(system_charset_info, DERIVATION_SYSCONST);
960
985
    }
961
 
    LOCK_global_system_variables.unlock();
 
986
 
962
987
    return tmp;
963
988
  }
964
989
  case SHOW_CHAR:
965
990
  {
966
991
    Item *tmp;
967
 
    LOCK_global_system_variables.lock();
 
992
    boost::mutex::scoped_lock scopedLock(session->catalog().systemVariableLock());
968
993
    char *str= (char*) value_ptr(session, var_type, base);
969
994
    if (str)
970
995
      tmp= new Item_string(str, strlen(str),
974
999
      tmp= new Item_null();
975
1000
      tmp->collation.set(system_charset_info, DERIVATION_SYSCONST);
976
1001
    }
977
 
    LOCK_global_system_variables.unlock();
 
1002
 
978
1003
    return tmp;
979
1004
  }
980
1005
  default:
987
1012
bool sys_var_session_enum::update(Session *session, set_var *var)
988
1013
{
989
1014
  if (var->type == OPT_GLOBAL)
990
 
    global_system_variables.*offset= var->save_result.uint32_t_value;
 
1015
    global_system_variables.*offset= var->getInteger();
991
1016
  else
992
 
    session->variables.*offset= var->save_result.uint32_t_value;
 
1017
    session->variables.*offset= var->getInteger();
993
1018
  return 0;
994
1019
}
995
1020
 
1039
1064
}
1040
1065
 
1041
1066
 
1042
 
typedef struct old_names_map_st
1043
 
{
1044
 
  const char *old_name;
1045
 
  const char *new_name;
1046
 
} my_old_conv;
1047
 
 
1048
 
bool sys_var_collation::check(Session *, set_var *var)
 
1067
bool sys_var_collation_sv::update(Session *session, set_var *var)
1049
1068
{
1050
1069
  const CHARSET_INFO *tmp;
1051
1070
 
1055
1074
    String str(buff,sizeof(buff), system_charset_info), *res;
1056
1075
    if (!(res=var->value->val_str(&str)))
1057
1076
    {
1058
 
      my_error(ER_WRONG_VALUE_FOR_VAR, MYF(0), name.c_str(), "NULL");
 
1077
      boost::throw_exception(invalid_option_value(var->var->getName()) << invalid_value(std::string("NULL")));
1059
1078
      return 1;
1060
1079
    }
1061
1080
    if (!(tmp=get_charset_by_name(res->c_ptr())))
1062
1081
    {
1063
1082
      my_error(ER_UNKNOWN_COLLATION, MYF(0), res->c_ptr());
 
1083
      boost::throw_exception(invalid_option_value(var->var->getName()) << invalid_value(std::string(res->c_ptr())));
1064
1084
      return 1;
1065
1085
    }
1066
1086
  }
1071
1091
      char buf[20];
1072
1092
      internal::int10_to_str((int) var->value->val_int(), buf, -10);
1073
1093
      my_error(ER_UNKNOWN_COLLATION, MYF(0), buf);
 
1094
      boost::throw_exception(invalid_option_value(var->var->getName()) << invalid_value(boost::lexical_cast<std::string>(var->value->val_int())));
1074
1095
      return 1;
1075
1096
    }
1076
1097
  }
1077
 
  var->save_result.charset= tmp;        // Save for update
1078
 
  return 0;
1079
 
}
1080
 
 
1081
 
 
1082
 
bool sys_var_collation_sv::update(Session *session, set_var *var)
1083
 
{
1084
1098
  if (var->type == OPT_GLOBAL)
1085
 
    global_system_variables.*offset= var->save_result.charset;
 
1099
    global_system_variables.*offset= tmp;
1086
1100
  else
1087
1101
  {
1088
 
    session->variables.*offset= var->save_result.charset;
 
1102
    session->variables.*offset= tmp;
1089
1103
  }
1090
1104
  return 0;
1091
1105
}
1116
1130
 
1117
1131
bool sys_var_timestamp::update(Session *session,  set_var *var)
1118
1132
{
1119
 
  session->set_time((time_t) var->save_result.uint64_t_value);
 
1133
  session->set_time(time_t(var->getInteger()));
1120
1134
  return 0;
1121
1135
}
1122
1136
 
1123
1137
 
1124
1138
void sys_var_timestamp::set_default(Session *session, sql_var_t)
1125
1139
{
1126
 
  session->user_time=0;
 
1140
  session->resetUserTime();
1127
1141
}
1128
1142
 
1129
1143
 
1130
1144
unsigned char *sys_var_timestamp::value_ptr(Session *session, sql_var_t,
1131
1145
                                            const LEX_STRING *)
1132
1146
{
1133
 
  session->sys_var_tmp.int32_t_value= (int32_t) session->start_time;
 
1147
  session->sys_var_tmp.int32_t_value= (int32_t) session->getCurrentTimestampEpoch();
1134
1148
  return (unsigned char*) &session->sys_var_tmp.int32_t_value;
1135
1149
}
1136
1150
 
1137
1151
 
1138
1152
bool sys_var_last_insert_id::update(Session *session, set_var *var)
1139
1153
{
1140
 
  session->first_successful_insert_id_in_prev_stmt=
1141
 
    var->save_result.uint64_t_value;
 
1154
  session->first_successful_insert_id_in_prev_stmt= var->getInteger();
1142
1155
  return 0;
1143
1156
}
1144
1157
 
1156
1169
  return (unsigned char*) &session->sys_var_tmp.uint64_t_value;
1157
1170
}
1158
1171
 
1159
 
 
1160
 
bool sys_var_session_time_zone::check(Session *session, set_var *var)
1161
 
{
1162
 
  char buff[MAX_TIME_ZONE_NAME_LENGTH];
1163
 
  String str(buff, sizeof(buff), &my_charset_utf8_general_ci);
1164
 
  String *res= var->value->val_str(&str);
1165
 
 
1166
 
  if (!(var->save_result.time_zone= my_tz_find(session, res)))
1167
 
  {
1168
 
    my_error(ER_UNKNOWN_TIME_ZONE, MYF(0), res ? res->c_ptr() : "NULL");
1169
 
    return 1;
1170
 
  }
1171
 
  return 0;
1172
 
}
1173
 
 
1174
 
 
1175
 
bool sys_var_session_time_zone::update(Session *session, set_var *var)
1176
 
{
1177
 
  /* We are using Time_zone object found during check() phase. */
1178
 
  if (var->type == OPT_GLOBAL)
1179
 
  {
1180
 
    LOCK_global_system_variables.lock();
1181
 
    global_system_variables.time_zone= var->save_result.time_zone;
1182
 
    LOCK_global_system_variables.unlock();
1183
 
  }
1184
 
  else
1185
 
    session->variables.time_zone= var->save_result.time_zone;
1186
 
  return 0;
1187
 
}
1188
 
 
1189
 
 
1190
 
unsigned char *sys_var_session_time_zone::value_ptr(Session *session,
1191
 
                                                    sql_var_t type,
1192
 
                                                    const LEX_STRING *)
1193
 
{
1194
 
  /*
1195
 
    We can use ptr() instead of c_ptr() here because String contaning
1196
 
    time zone name is guaranteed to be zero ended.
1197
 
  */
1198
 
  if (type == OPT_GLOBAL)
1199
 
    return (unsigned char *)(global_system_variables.time_zone->get_name()->ptr());
1200
 
  else
1201
 
  {
1202
 
    /*
1203
 
      This is an ugly fix for replication: we don't replicate properly queries
1204
 
      invoking system variables' values to update tables; but
1205
 
      CONVERT_TZ(,,@@session.time_zone) is so popular that we make it
1206
 
      replicable (i.e. we tell the binlog code to store the session
1207
 
      timezone). If it's the global value which was used we can't replicate
1208
 
      (binlog code stores session value only).
1209
 
    */
1210
 
    return (unsigned char *)(session->variables.time_zone->get_name()->ptr());
1211
 
  }
1212
 
}
1213
 
 
1214
 
 
1215
 
void sys_var_session_time_zone::set_default(Session *session, sql_var_t type)
1216
 
{
1217
 
 LOCK_global_system_variables.lock();
1218
 
 if (type == OPT_GLOBAL)
1219
 
 {
1220
 
   if (default_tz_name)
1221
 
   {
1222
 
     String str(default_tz_name, &my_charset_utf8_general_ci);
1223
 
     /*
1224
 
       We are guaranteed to find this time zone since its existence
1225
 
       is checked during start-up.
1226
 
     */
1227
 
     global_system_variables.time_zone= my_tz_find(session, &str);
1228
 
   }
1229
 
   else
1230
 
     global_system_variables.time_zone= my_tz_SYSTEM;
1231
 
 }
1232
 
 else
1233
 
   session->variables.time_zone= global_system_variables.time_zone;
1234
 
 LOCK_global_system_variables.unlock();
1235
 
}
1236
 
 
1237
 
 
1238
 
bool sys_var_session_lc_time_names::check(Session *, set_var *var)
 
1172
bool sys_var_session_lc_time_names::update(Session *session, set_var *var)
1239
1173
{
1240
1174
  MY_LOCALE *locale_match;
1241
1175
 
1243
1177
  {
1244
1178
    if (!(locale_match= my_locale_by_number((uint32_t) var->value->val_int())))
1245
1179
    {
1246
 
      char buf[20];
 
1180
      char buf[DECIMAL_LONGLONG_DIGITS];
1247
1181
      internal::int10_to_str((int) var->value->val_int(), buf, -10);
1248
1182
      my_printf_error(ER_UNKNOWN_ERROR, "Unknown locale: '%s'", MYF(0), buf);
1249
1183
      return 1;
1267
1201
    }
1268
1202
  }
1269
1203
 
1270
 
  var->save_result.locale_value= locale_match;
1271
 
  return 0;
1272
 
}
1273
 
 
1274
 
 
1275
 
bool sys_var_session_lc_time_names::update(Session *session, set_var *var)
1276
 
{
1277
1204
  if (var->type == OPT_GLOBAL)
1278
 
    global_system_variables.lc_time_names= var->save_result.locale_value;
 
1205
    global_system_variables.lc_time_names= locale_match;
1279
1206
  else
1280
 
    session->variables.lc_time_names= var->save_result.locale_value;
 
1207
    session->variables.lc_time_names= locale_match;
1281
1208
  return 0;
1282
1209
}
1283
1210
 
1320
1247
  microseconds= (int64_t) (num * 1000000.0 + 0.5);
1321
1248
  if (var->type == OPT_GLOBAL)
1322
1249
  {
1323
 
    LOCK_global_system_variables.lock();
 
1250
    boost::mutex::scoped_lock scopedLock(session->catalog().systemVariableLock());
1324
1251
    (global_system_variables.*offset)= microseconds;
1325
 
    LOCK_global_system_variables.unlock();
1326
1252
  }
1327
1253
  else
1328
1254
    session->variables.*offset= microseconds;
1335
1261
  int64_t microseconds= (int64_t) (option_limits->def_value * 1000000.0);
1336
1262
  if (type == OPT_GLOBAL)
1337
1263
  {
1338
 
    LOCK_global_system_variables.lock();
 
1264
    boost::mutex::scoped_lock scopedLock(session->catalog().systemVariableLock());
1339
1265
    global_system_variables.*offset= microseconds;
1340
 
    LOCK_global_system_variables.unlock();
1341
1266
  }
1342
1267
  else
1343
1268
    session->variables.*offset= microseconds;
1350
1275
static bool set_option_bit(Session *session, set_var *var)
1351
1276
{
1352
1277
  sys_var_session_bit *sys_var= ((sys_var_session_bit*) var->var);
1353
 
  if ((var->save_result.uint32_t_value != 0) == sys_var->reverse)
 
1278
  if ((var->getInteger() != 0) == sys_var->reverse)
1354
1279
    session->options&= ~sys_var->bit_flag;
1355
1280
  else
1356
1281
    session->options|= sys_var->bit_flag;
1360
1285
 
1361
1286
static bool set_option_autocommit(Session *session, set_var *var)
1362
1287
{
 
1288
  bool success= true;
1363
1289
  /* The test is negative as the flag we use is NOT autocommit */
1364
1290
 
1365
1291
  uint64_t org_options= session->options;
 
1292
  uint64_t new_options= session->options;
1366
1293
 
1367
 
  if (var->save_result.uint32_t_value != 0)
1368
 
    session->options&= ~((sys_var_session_bit*) var->var)->bit_flag;
 
1294
  if (var->getInteger() != 0)
 
1295
    new_options&= ~((sys_var_session_bit*) var->var)->bit_flag;
1369
1296
  else
1370
 
    session->options|= ((sys_var_session_bit*) var->var)->bit_flag;
 
1297
    new_options|= ((sys_var_session_bit*) var->var)->bit_flag;
1371
1298
 
1372
 
  if ((org_options ^ session->options) & OPTION_NOT_AUTOCOMMIT)
 
1299
  if ((org_options ^ new_options) & OPTION_NOT_AUTOCOMMIT)
1373
1300
  {
1374
1301
    if ((org_options & OPTION_NOT_AUTOCOMMIT))
1375
1302
    {
 
1303
      success= session->endActiveTransaction();
1376
1304
      /* We changed to auto_commit mode */
1377
1305
      session->options&= ~(uint64_t) (OPTION_BEGIN);
1378
1306
      session->server_status|= SERVER_STATUS_AUTOCOMMIT;
1379
 
      TransactionServices &transaction_services= TransactionServices::singleton();
1380
 
      if (transaction_services.commitTransaction(session, true))
1381
 
        return 1;
1382
1307
    }
1383
1308
    else
1384
1309
    {
1385
1310
      session->server_status&= ~SERVER_STATUS_AUTOCOMMIT;
1386
1311
    }
1387
1312
  }
 
1313
 
 
1314
  if (var->getInteger() != 0)
 
1315
    session->options&= ~((sys_var_session_bit*) var->var)->bit_flag;
 
1316
  else
 
1317
    session->options|= ((sys_var_session_bit*) var->var)->bit_flag;
 
1318
 
 
1319
  if (not success)
 
1320
    return true;
 
1321
 
1388
1322
  return 0;
1389
1323
}
1390
1324
 
1391
1325
static int check_pseudo_thread_id(Session *, set_var *var)
1392
1326
{
1393
 
  var->save_result.uint64_t_value= var->value->val_int();
 
1327
  var->updateValue();
1394
1328
  return 0;
1395
1329
}
1396
1330
 
1488
1422
drizzle_show_var* enumerate_sys_vars(Session *session)
1489
1423
{
1490
1424
  int size= sizeof(drizzle_show_var) * (system_variable_map.size() + 1);
1491
 
  drizzle_show_var *result= (drizzle_show_var*) session->alloc(size);
 
1425
  drizzle_show_var *result= (drizzle_show_var*) session->getMemRoot()->allocate(size);
1492
1426
 
1493
1427
  if (result)
1494
1428
  {
1522
1456
  /* this fails if there is a conflicting variable name. */
1523
1457
  if (system_variable_map.find(lower_name) != system_variable_map.end())
1524
1458
  {
1525
 
    errmsg_printf(ERRMSG_LVL_ERROR, _("Variable named %s already exists!\n"),
 
1459
    errmsg_printf(error::ERROR, _("Variable named %s already exists!\n"),
1526
1460
                  var->getName().c_str());
1527
1461
    throw exception();
1528
1462
  } 
1531
1465
    system_variable_map.insert(make_pair(lower_name, var));
1532
1466
  if (ret.second == false)
1533
1467
  {
1534
 
    errmsg_printf(ERRMSG_LVL_ERROR, _("Could not add Variable: %s\n"),
 
1468
    errmsg_printf(error::ERROR, _("Could not add Variable: %s\n"),
1535
1469
                  var->getName().c_str());
1536
1470
    throw exception();
1537
1471
  }
1547
1481
  Initialize the system variables
1548
1482
 
1549
1483
  SYNOPSIS
1550
 
    set_var_init()
 
1484
    sys_var_init()
1551
1485
 
1552
1486
  RETURN VALUES
1553
1487
    0           SUCCESS
1554
1488
    otherwise   FAILURE
1555
1489
*/
1556
1490
 
1557
 
int set_var_init()
 
1491
int sys_var_init()
1558
1492
{
1559
1493
  try
1560
1494
  {
1564
1498
    add_sys_var_to_list(&sys_back_log, my_long_options);
1565
1499
    add_sys_var_to_list(&sys_basedir, my_long_options);
1566
1500
    add_sys_var_to_list(&sys_big_selects, my_long_options);
 
1501
    add_sys_var_to_list(&sys_branch, my_long_options);
1567
1502
    add_sys_var_to_list(&sys_buffer_results, my_long_options);
1568
1503
    add_sys_var_to_list(&sys_bulk_insert_buff_size, my_long_options);
1569
1504
    add_sys_var_to_list(&sys_collation_server, my_long_options);
1579
1514
    add_sys_var_to_list(&sys_last_insert_id, my_long_options);
1580
1515
    add_sys_var_to_list(&sys_lc_time_names, my_long_options);
1581
1516
    add_sys_var_to_list(&sys_max_allowed_packet, my_long_options);
1582
 
    add_sys_var_to_list(&sys_max_connect_errors, my_long_options);
1583
1517
    add_sys_var_to_list(&sys_max_error_count, my_long_options);
1584
1518
    add_sys_var_to_list(&sys_max_heap_table_size, my_long_options);
1585
1519
    add_sys_var_to_list(&sys_max_join_size, my_long_options);
1599
1533
    add_sys_var_to_list(&sys_range_alloc_block_size, my_long_options);
1600
1534
    add_sys_var_to_list(&sys_read_buff_size, my_long_options);
1601
1535
    add_sys_var_to_list(&sys_read_rnd_buff_size, my_long_options);
 
1536
    add_sys_var_to_list(&sys_release_id, my_long_options);
 
1537
    add_sys_var_to_list(&sys_replicate_query, my_long_options);
 
1538
    add_sys_var_to_list(&sys_revid, my_long_options);
 
1539
    add_sys_var_to_list(&sys_revno, my_long_options);
1602
1540
    add_sys_var_to_list(&sys_scheduler, my_long_options);
1603
1541
    add_sys_var_to_list(&sys_secure_file_priv, my_long_options);
1604
1542
    add_sys_var_to_list(&sys_select_limit, my_long_options);
1607
1545
    add_sys_var_to_list(&sys_sql_notes, my_long_options);
1608
1546
    add_sys_var_to_list(&sys_sql_warnings, my_long_options);
1609
1547
    add_sys_var_to_list(&sys_storage_engine, my_long_options);
1610
 
    add_sys_var_to_list(&sys_system_time_zone, my_long_options);
1611
1548
    add_sys_var_to_list(&sys_table_cache_size, my_long_options);
1612
1549
    add_sys_var_to_list(&sys_table_def_size, my_long_options);
1613
1550
    add_sys_var_to_list(&sys_table_lock_wait_timeout, my_long_options);
1614
1551
    add_sys_var_to_list(&sys_thread_stack_size, my_long_options);
1615
 
    add_sys_var_to_list(&sys_time_zone, my_long_options);
1616
1552
    add_sys_var_to_list(&sys_timed_mutexes, my_long_options);
1617
1553
    add_sys_var_to_list(&sys_timestamp, my_long_options);
1618
1554
    add_sys_var_to_list(&sys_tmp_table_size, my_long_options);
1627
1563
    add_sys_var_to_list(&sys_version_compile_vendor, my_long_options);
1628
1564
    add_sys_var_to_list(&sys_warning_count, my_long_options);
1629
1565
  }
1630
 
  catch (...)
 
1566
  catch (std::exception&)
1631
1567
  {
1632
 
    errmsg_printf(ERRMSG_LVL_ERROR, _("Failed to initialize system variables"));
 
1568
    errmsg_printf(error::ERROR, _("Failed to initialize system variables"));
1633
1569
    return(1);
1634
1570
  }
1635
1571
  return(0);
1639
1575
/**
1640
1576
  Find a user set-table variable.
1641
1577
 
1642
 
  @param str       Name of system variable to find
1643
 
  @param length    Length of variable.  zero means that we should use strlen()
1644
 
                   on the variable
1645
 
  @param no_error  Refuse to emit an error, even if one occurred.
 
1578
  @param name      Name of system variable to find
1646
1579
 
1647
1580
  @retval
1648
1581
    pointer     pointer to variable definitions
1650
1583
    0           Unknown variable (error message is given)
1651
1584
*/
1652
1585
 
1653
 
sys_var *intern_find_sys_var(const char *str, uint32_t, bool no_error)
 
1586
sys_var *find_sys_var(const std::string &name)
1654
1587
{
1655
 
  string lower_name(str);
 
1588
  string lower_name(name);
1656
1589
  transform(lower_name.begin(), lower_name.end(),
1657
1590
            lower_name.begin(), ::tolower);
1658
1591
 
1664
1597
    result= (*iter).second;
1665
1598
  } 
1666
1599
 
1667
 
  /*
1668
 
    This function is only called from the sql_plugin.cc.
1669
 
    A lock on LOCK_system_variable_hash should be held
1670
 
  */
1671
1600
  if (result == NULL)
1672
1601
  {
1673
 
    if (no_error)
1674
 
    {
1675
 
      return NULL;
1676
 
    }
1677
 
    else
1678
 
    {
1679
 
      my_error(ER_UNKNOWN_SYSTEM_VARIABLE, MYF(0), (char*) str);
1680
 
      return NULL;
1681
 
    }
 
1602
    my_error(ER_UNKNOWN_SYSTEM_VARIABLE, MYF(0), name.c_str());
 
1603
    return NULL;
1682
1604
  }
1683
1605
 
1684
1606
  return result;
1685
1607
}
1686
1608
 
1687
1609
 
1688
 
/**
1689
 
  Execute update of all variables.
1690
 
 
1691
 
  First run a check of all variables that all updates will go ok.
1692
 
  If yes, then execute all updates, returning an error if any one failed.
1693
 
 
1694
 
  This should ensure that in all normal cases none all or variables are
1695
 
  updated.
1696
 
 
1697
 
  @param Session                Thread id
1698
 
  @param var_list       List of variables to update
1699
 
 
1700
 
  @retval
1701
 
    0   ok
1702
 
  @retval
1703
 
    1   ERROR, message sent (normally no variables was updated)
1704
 
  @retval
1705
 
    -1  ERROR, message not sent
1706
 
*/
1707
 
 
1708
 
int sql_set_variables(Session *session, List<set_var_base> *var_list)
1709
 
{
1710
 
  int error;
1711
 
  List_iterator_fast<set_var_base> it(*var_list);
1712
 
 
1713
 
  set_var_base *var;
1714
 
  while ((var=it++))
1715
 
  {
1716
 
    if ((error= var->check(session)))
1717
 
      goto err;
1718
 
  }
1719
 
  if (!(error= test(session->is_error())))
1720
 
  {
1721
 
    it.rewind();
1722
 
    while ((var= it++))
1723
 
      error|= var->update(session);         // Returns 0, -1 or 1
1724
 
  }
1725
 
 
1726
 
err:
1727
 
  free_underlaid_joins(session, &session->lex->select_lex);
1728
 
  return(error);
1729
 
}
1730
 
 
1731
 
 
1732
 
/*****************************************************************************
1733
 
  Functions to handle SET mysql_internal_variable=const_expr
1734
 
*****************************************************************************/
1735
 
 
1736
 
int set_var::check(Session *session)
1737
 
{
1738
 
  if (var->is_readonly())
1739
 
  {
1740
 
    my_error(ER_INCORRECT_GLOBAL_LOCAL_VAR, MYF(0), var->getName().c_str(), "read only");
1741
 
    return -1;
1742
 
  }
1743
 
  if (var->check_type(type))
1744
 
  {
1745
 
    int err= type == OPT_GLOBAL ? ER_LOCAL_VARIABLE : ER_GLOBAL_VARIABLE;
1746
 
    my_error(err, MYF(0), var->getName().c_str());
1747
 
    return -1;
1748
 
  }
1749
 
  /* value is a NULL pointer if we are using SET ... = DEFAULT */
1750
 
  if (!value)
1751
 
  {
1752
 
    if (var->check_default(type))
1753
 
    {
1754
 
      my_error(ER_NO_DEFAULT, MYF(0), var->getName().c_str());
1755
 
      return -1;
1756
 
    }
1757
 
    return 0;
1758
 
  }
1759
 
 
1760
 
  if ((!value->fixed &&
1761
 
       value->fix_fields(session, &value)) || value->check_cols(1))
1762
 
    return -1;
1763
 
  if (var->check_update_type(value->result_type()))
1764
 
  {
1765
 
    my_error(ER_WRONG_TYPE_FOR_VAR, MYF(0), var->getName().c_str());
1766
 
    return -1;
1767
 
  }
1768
 
  return var->check(session, this) ? -1 : 0;
1769
 
}
1770
 
 
1771
 
/**
1772
 
  Update variable
1773
 
 
1774
 
  @param   session    thread handler
1775
 
  @returns 0|1    ok or ERROR
1776
 
 
1777
 
  @note ERROR can be only due to abnormal operations involving
1778
 
  the server's execution evironment such as
1779
 
  out of memory, hard disk failure or the computer blows up.
1780
 
  Consider set_var::check() method if there is a need to return
1781
 
  an error due to logics.
1782
 
*/
1783
 
int set_var::update(Session *session)
1784
 
{
1785
 
  if (! value)
1786
 
    var->set_default(session, type);
1787
 
  else if (var->update(session, this))
1788
 
    return -1;                          // should never happen
1789
 
  if (var->getAfterUpdateTrigger())
1790
 
    (*var->getAfterUpdateTrigger())(session, type);
1791
 
  return 0;
1792
 
}
1793
 
 
1794
 
/*****************************************************************************
1795
 
  Functions to handle SET @user_variable=const_expr
1796
 
*****************************************************************************/
1797
 
 
1798
 
int set_var_user::check(Session *session)
1799
 
{
1800
 
  /*
1801
 
    Item_func_set_user_var can't substitute something else on its place =>
1802
 
    0 can be passed as last argument (reference on item)
1803
 
  */
1804
 
  return (user_var_item->fix_fields(session, (Item**) 0) ||
1805
 
          user_var_item->check(0)) ? -1 : 0;
1806
 
}
1807
 
 
1808
 
 
1809
 
int set_var_user::update(Session *)
1810
 
{
1811
 
  if (user_var_item->update())
1812
 
  {
1813
 
    /* Give an error if it's not given already */
1814
 
    my_message(ER_SET_CONSTANTS_ONLY, ER(ER_SET_CONSTANTS_ONLY), MYF(0));
1815
 
    return -1;
1816
 
  }
1817
 
  return 0;
1818
 
}
1819
 
 
1820
1610
/****************************************************************************
1821
1611
 Functions to handle table_type
1822
1612
****************************************************************************/
1823
1613
 
1824
 
/* Based upon sys_var::check_enum() */
1825
 
 
1826
 
bool sys_var_session_storage_engine::check(Session *session, set_var *var)
1827
 
{
1828
 
  char buff[STRING_BUFFER_USUAL_SIZE];
1829
 
  const char *value;
1830
 
  String str(buff, sizeof(buff), &my_charset_utf8_general_ci), *res;
1831
 
 
1832
 
  var->save_result.storage_engine= NULL;
1833
 
  if (var->value->result_type() == STRING_RESULT)
1834
 
  {
1835
 
    res= var->value->val_str(&str);
1836
 
    if (res == NULL || res->ptr() == NULL)
1837
 
    {
1838
 
      value= "NULL";
1839
 
      goto err;
1840
 
    }
1841
 
    else
1842
 
    {
1843
 
      const std::string engine_name(res->ptr());
1844
 
      plugin::StorageEngine *engine;
1845
 
      var->save_result.storage_engine= plugin::StorageEngine::findByName(*session, engine_name);
1846
 
      if (var->save_result.storage_engine == NULL)
1847
 
      {
1848
 
        value= res->c_ptr();
1849
 
        goto err;
1850
 
      }
1851
 
      engine= var->save_result.storage_engine;
1852
 
    }
1853
 
    return 0;
1854
 
  }
1855
 
  value= "unknown";
1856
 
 
1857
 
err:
1858
 
  my_error(ER_UNKNOWN_STORAGE_ENGINE, MYF(0), value);
1859
 
  return 1;
1860
 
}
1861
 
 
1862
 
 
1863
1614
unsigned char *sys_var_session_storage_engine::value_ptr(Session *session,
1864
1615
                                                         sql_var_t type,
1865
1616
                                                         const LEX_STRING *)
1897
1648
 
1898
1649
bool sys_var_session_storage_engine::update(Session *session, set_var *var)
1899
1650
{
1900
 
  plugin::StorageEngine **value= &(global_system_variables.*offset), *old_value;
 
1651
  char buff[STRING_BUFFER_USUAL_SIZE];
 
1652
  const char *name_value;
 
1653
  String str(buff, sizeof(buff), &my_charset_utf8_general_ci), *res;
 
1654
 
 
1655
  plugin::StorageEngine *tmp= NULL;
 
1656
  plugin::StorageEngine **value= NULL;
 
1657
    
 
1658
  if (var->value->result_type() == STRING_RESULT)
 
1659
  {
 
1660
    res= var->value->val_str(&str);
 
1661
    if (res == NULL || res->ptr() == NULL)
 
1662
    {
 
1663
      name_value= "NULL";
 
1664
      goto err;
 
1665
    }
 
1666
    else
 
1667
    {
 
1668
      const std::string engine_name(res->ptr());
 
1669
      tmp= plugin::StorageEngine::findByName(*session, engine_name);
 
1670
      if (tmp == NULL)
 
1671
      {
 
1672
        name_value= res->c_ptr();
 
1673
        goto err;
 
1674
      }
 
1675
    }
 
1676
  }
 
1677
  else
 
1678
  {
 
1679
    name_value= "unknown";
 
1680
  }
 
1681
 
 
1682
  value= &(global_system_variables.*offset);
1901
1683
   if (var->type != OPT_GLOBAL)
1902
1684
     value= &(session->variables.*offset);
1903
 
  old_value= *value;
1904
 
  if (old_value != var->save_result.storage_engine)
 
1685
  if (*value != tmp)
1905
1686
  {
1906
 
    *value= var->save_result.storage_engine;
 
1687
    *value= tmp;
1907
1688
  }
1908
1689
  return 0;
 
1690
err:
 
1691
  my_error(ER_UNKNOWN_STORAGE_ENGINE, MYF(0), name_value);
 
1692
  return 1;
1909
1693
}
1910
1694
 
1911
1695
} /* namespace drizzled */