~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/sys_var.cc

  • Committer: Brian Aker
  • Date: 2010-10-29 01:13:40 UTC
  • mto: (1890.1.1 build)
  • mto: This revision was merged to the branch mainline in revision 1891.
  • Revision ID: brian@tangent.org-20101029011340-y9ixm180v9daypqr
Remove warnings for c++

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, Inc.
 
4
 *  Copyright (C) 2008 Sun Microsystems
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).
39
44
*/
40
45
 
41
 
#include <config.h>
42
 
#include <drizzled/option.h>
43
 
#include <drizzled/error.h>
44
 
#include <drizzled/gettext.h>
45
 
#include <drizzled/tztime.h>
46
 
#include <drizzled/data_home.h>
47
 
#include <drizzled/set_var.h>
48
 
#include <drizzled/session.h>
49
 
#include <drizzled/sql_base.h>
50
 
#include <drizzled/lock.h>
51
 
#include <drizzled/item/uint.h>
52
 
#include <drizzled/item/null.h>
53
 
#include <drizzled/item/float.h>
54
 
#include <drizzled/item/string.h>
55
 
#include <drizzled/plugin.h>
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>
 
46
#include "config.h"
 
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/item/string.h"
 
60
#include "drizzled/plugin.h"
 
61
#include "drizzled/version.h"
 
62
#include "drizzled/strfunc.h"
 
63
#include "drizzled/internal/m_string.h"
 
64
#include "drizzled/pthread_globals.h"
 
65
#include "drizzled/charset.h"
 
66
#include "drizzled/transaction_services.h"
 
67
#include "drizzled/constrained_value.h"
66
68
 
67
69
#include <cstdio>
68
70
#include <map>
86
88
extern const CHARSET_INFO *character_set_filesystem;
87
89
extern size_t my_thread_stack_size;
88
90
 
 
91
class sys_var_pluginvar;
89
92
typedef map<string, sys_var *> SystemVariableMap;
90
93
static SystemVariableMap system_variable_map;
91
94
extern char *opt_drizzle_tmpdir;
92
95
 
93
96
extern TYPELIB tx_isolation_typelib;
94
97
 
95
 
namespace
96
 
{
97
 
static size_t revno= DRIZZLE7_VC_REVNO;
98
 
static size_t release_id= DRIZZLE7_RELEASE_ID;
99
 
}
100
 
 
101
98
const char *bool_type_names[]= { "OFF", "ON", NULL };
102
99
TYPELIB bool_typelib=
103
100
{
114
111
static void fix_max_join_size(Session *session, sql_var_t type);
115
112
static void fix_session_mem_root(Session *session, sql_var_t type);
116
113
static void fix_server_id(Session *session, sql_var_t type);
 
114
static bool get_unsigned32(Session *session, set_var *var);
 
115
static bool get_unsigned64(Session *session, set_var *var);
117
116
bool throw_bounds_warning(Session *session, bool fixed, bool unsignd,
118
117
                          const std::string &name, int64_t val);
119
118
static unsigned char *get_error_count(Session *session);
142
141
 
143
142
static sys_var_size_t_ptr sys_thread_stack_size("thread_stack",
144
143
                                                      &my_thread_stack_size);
145
 
static sys_var_constrained_value_readonly<uint32_t> sys_back_log("back_log", back_log);
 
144
static sys_var_constrained_value<uint32_t> sys_back_log("back_log", back_log);
146
145
 
147
146
static sys_var_session_uint64_t sys_bulk_insert_buff_size("bulk_insert_buffer_size",
148
147
                                                          &drizzle_system_variables::bulk_insert_buff_size);
158
157
                                                     &drizzle_system_variables::join_buff_size);
159
158
static sys_var_session_uint32_t sys_max_allowed_packet("max_allowed_packet",
160
159
                                                       &drizzle_system_variables::max_allowed_packet);
 
160
static sys_var_uint64_t_ptr     sys_max_connect_errors("max_connect_errors",
 
161
                                               &max_connect_errors);
161
162
static sys_var_session_uint64_t sys_max_error_count("max_error_count",
162
163
                                                  &drizzle_system_variables::max_error_count);
163
164
static sys_var_session_uint64_t sys_max_heap_table_size("max_heap_table_size",
196
197
 
197
198
static sys_var_session_size_t   sys_range_alloc_block_size("range_alloc_block_size",
198
199
                                                           &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
 
 
203
200
static sys_var_session_uint32_t sys_query_alloc_block_size("query_alloc_block_size",
204
201
                                                           &drizzle_system_variables::query_alloc_block_size,
205
202
                                                           NULL, fix_session_mem_root);
220
217
static sys_var_session_size_t   sys_sort_buffer("sort_buffer_size",
221
218
                                                &drizzle_system_variables::sortbuff_size);
222
219
 
223
 
static sys_var_size_t_ptr_readonly sys_transaction_message_threshold("transaction_message_threshold",
224
 
                                                                &transaction_message_threshold);
 
220
static sys_var_session_size_t sys_transaction_message_threshold("transaction_message_threshold",
 
221
                                                                &drizzle_system_variables::transaction_message_threshold);
225
222
 
226
223
static sys_var_session_storage_engine sys_storage_engine("storage_engine",
227
224
                                       &drizzle_system_variables::storage_engine);
 
225
static sys_var_const_str        sys_system_time_zone("system_time_zone",
 
226
                                             system_time_zone);
228
227
static sys_var_size_t_ptr       sys_table_def_size("table_definition_cache",
229
228
                                             &table_def_size);
230
229
static sys_var_uint64_t_ptr     sys_table_cache_size("table_open_cache",
313
312
sys_var_session_uint64_t sys_group_concat_max_len("group_concat_max_len",
314
313
                                                  &drizzle_system_variables::group_concat_max_len);
315
314
 
 
315
sys_var_session_time_zone sys_time_zone("time_zone");
 
316
 
316
317
/* Global read-only variable containing hostname */
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)
 
318
static sys_var_const_str        sys_hostname("hostname", glob_hostname);
 
319
 
 
320
bool sys_var::check(Session *, set_var *var)
325
321
{
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();
 
322
  var->save_result.uint64_t_value= var->value->val_int();
334
323
  return 0;
335
324
}
336
325
 
337
326
bool sys_var_str::check(Session *session, set_var *var)
338
327
{
 
328
  int res;
339
329
  if (!check_func)
340
330
    return 0;
341
331
 
342
 
  int res;
343
332
  if ((res=(*check_func)(session, var)) < 0)
344
333
    my_error(ER_WRONG_VALUE_FOR_VAR, MYF(0), getName().c_str(), var->value->str_value.ptr());
345
334
  return res;
346
335
}
347
336
 
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
 
 
364
337
/*
365
338
  Functions to check and update variables
366
339
*/
440
413
{
441
414
  if (fixed)
442
415
  {
443
 
    char buf[DECIMAL_LONGLONG_DIGITS];
 
416
    char buf[22];
444
417
 
445
418
    if (unsignd)
446
419
      internal::ullstr((uint64_t) val, buf);
475
448
  return out;
476
449
}
477
450
 
 
451
static bool get_unsigned32(Session *session, set_var *var)
 
452
{
 
453
  if (var->value->unsigned_flag)
 
454
    var->save_result.uint32_t_value= 
 
455
      static_cast<uint32_t>(var->value->val_int());
 
456
  else
 
457
  {
 
458
    int64_t v= var->value->val_int();
 
459
    if (v > UINT32_MAX)
 
460
      throw_bounds_warning(session, true, true,var->var->getName().c_str(), v);
 
461
    
 
462
    var->save_result.uint32_t_value= 
 
463
      static_cast<uint32_t>((v > UINT32_MAX) ? UINT32_MAX : (v < 0) ? 0 : v);
 
464
  }
 
465
  return false;
 
466
}
 
467
 
 
468
static bool get_unsigned64(Session *, set_var *var)
 
469
{
 
470
  if (var->value->unsigned_flag)
 
471
      var->save_result.uint64_t_value=(uint64_t) var->value->val_int();
 
472
  else
 
473
  {
 
474
    int64_t v= var->value->val_int();
 
475
      var->save_result.uint64_t_value= (uint64_t) ((v < 0) ? 0 : v);
 
476
  }
 
477
  return 0;
 
478
}
 
479
 
 
480
static bool get_size_t(Session *, set_var *var)
 
481
{
 
482
  if (var->value->unsigned_flag)
 
483
    var->save_result.size_t_value= (size_t) var->value->val_int();
 
484
  else
 
485
  {
 
486
    ssize_t v= (ssize_t)var->value->val_int();
 
487
    var->save_result.size_t_value= (size_t) ((v < 0) ? 0 : v);
 
488
  }
 
489
  return 0;
 
490
}
 
491
 
478
492
bool sys_var_uint32_t_ptr::check(Session *, set_var *var)
479
493
{
480
 
  var->updateValue();
 
494
  var->save_result.uint32_t_value= (uint32_t)var->value->val_int();
481
495
  return 0;
482
496
}
483
497
 
484
498
bool sys_var_uint32_t_ptr::update(Session *session, set_var *var)
485
499
{
486
 
  uint64_t tmp= var->getInteger();
487
 
  boost::mutex::scoped_lock scopedLock(session->catalog().systemVariableLock());
488
 
 
 
500
  uint32_t tmp= var->save_result.uint32_t_value;
 
501
  LOCK_global_system_variables.lock();
489
502
  if (option_limits)
490
503
  {
491
504
    uint32_t newvalue= (uint32_t) fix_unsigned(session, tmp, option_limits);
492
 
    if(static_cast<uint64_t>(newvalue) == tmp)
 
505
    if(newvalue==tmp)
493
506
      *value= newvalue;
494
507
  }
495
508
  else
496
 
  {
497
 
    *value= static_cast<uint32_t>(tmp);
498
 
  }
499
 
 
 
509
    *value= (uint32_t) tmp;
 
510
  LOCK_global_system_variables.unlock();
500
511
  return 0;
501
512
}
502
513
 
503
514
 
504
 
void sys_var_uint32_t_ptr::set_default(Session *session, sql_var_t)
 
515
void sys_var_uint32_t_ptr::set_default(Session *, sql_var_t)
505
516
{
506
517
  bool not_used;
507
 
  boost::mutex::scoped_lock scopedLock(session->catalog().systemVariableLock());
 
518
  LOCK_global_system_variables.lock();
508
519
  *value= (uint32_t)getopt_ull_limit_value((uint32_t) option_limits->def_value,
509
520
                                           option_limits, &not_used);
 
521
  LOCK_global_system_variables.unlock();
510
522
}
511
523
 
512
524
 
513
525
bool sys_var_uint64_t_ptr::update(Session *session, set_var *var)
514
526
{
515
 
  uint64_t tmp= var->getInteger();
516
 
  boost::mutex::scoped_lock scopedLock(session->catalog().systemVariableLock());
517
 
 
 
527
  uint64_t tmp= var->save_result.uint64_t_value;
 
528
  LOCK_global_system_variables.lock();
518
529
  if (option_limits)
519
530
  {
520
 
    uint64_t newvalue= fix_unsigned(session, tmp, option_limits);
 
531
    uint64_t newvalue= (uint64_t) fix_unsigned(session, tmp, option_limits);
521
532
    if(newvalue==tmp)
522
533
      *value= newvalue;
523
534
  }
524
535
  else
525
 
  {
526
 
    *value= tmp;
527
 
  }
528
 
 
 
536
    *value= (uint64_t) tmp;
 
537
  LOCK_global_system_variables.unlock();
529
538
  return 0;
530
539
}
531
540
 
532
541
 
533
 
void sys_var_uint64_t_ptr::set_default(Session *session, sql_var_t)
 
542
void sys_var_uint64_t_ptr::set_default(Session *, sql_var_t)
534
543
{
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
 
  }
 
544
  bool not_used;
 
545
  LOCK_global_system_variables.lock();
 
546
  *value= getopt_ull_limit_value((uint64_t) option_limits->def_value,
 
547
                                 option_limits, &not_used);
 
548
  LOCK_global_system_variables.unlock();
546
549
}
547
550
 
548
551
 
549
552
bool sys_var_size_t_ptr::update(Session *session, set_var *var)
550
553
{
551
 
  size_t tmp= size_t(var->getInteger());
552
 
 
553
 
  boost::mutex::scoped_lock scopedLock(session->catalog().systemVariableLock());
554
 
 
 
554
  size_t tmp= var->save_result.size_t_value;
 
555
  LOCK_global_system_variables.lock();
555
556
  if (option_limits)
556
557
    *value= fix_size_t(session, tmp, option_limits);
557
558
  else
558
559
    *value= tmp;
559
 
 
 
560
  LOCK_global_system_variables.unlock();
560
561
  return 0;
561
562
}
562
563
 
563
564
 
564
 
void sys_var_size_t_ptr::set_default(Session *session, sql_var_t)
 
565
void sys_var_size_t_ptr::set_default(Session *, sql_var_t)
565
566
{
566
567
  bool not_used;
567
 
  boost::mutex::scoped_lock scopedLock(session->catalog().systemVariableLock());
 
568
  LOCK_global_system_variables.lock();
568
569
  *value= (size_t)getopt_ull_limit_value((size_t) option_limits->def_value,
569
570
                                         option_limits, &not_used);
570
 
}
571
 
 
572
 
bool sys_var_bool_ptr::check(Session *session, set_var *var)
573
 
{
574
 
  return check_enum(session, var, &bool_typelib);
 
571
  LOCK_global_system_variables.unlock();
575
572
}
576
573
 
577
574
bool sys_var_bool_ptr::update(Session *, set_var *var)
578
575
{
579
 
  *value= bool(var->getInteger());
 
576
  *value= (bool) var->save_result.uint32_t_value;
580
577
  return 0;
581
578
}
582
579
 
583
580
 
584
581
void sys_var_bool_ptr::set_default(Session *, sql_var_t)
585
582
{
586
 
  *value= default_value;
 
583
  *value= (bool) option_limits->def_value;
587
584
}
588
585
 
589
586
 
592
589
*/
593
590
bool sys_var_session_uint32_t::check(Session *session, set_var *var)
594
591
{
595
 
  var->updateValue();
596
 
  return (check_func && (*check_func)(session, var));
 
592
  return (get_unsigned32(session, var) ||
 
593
          (check_func && (*check_func)(session, var)));
597
594
}
598
595
 
599
596
bool sys_var_session_uint32_t::update(Session *session, set_var *var)
600
597
{
601
 
  uint64_t tmp= var->getInteger();
 
598
  uint64_t tmp= (uint64_t) var->save_result.uint32_t_value;
602
599
 
603
600
  /* Don't use bigger value than given with --maximum-variable-name=.. */
604
601
  if ((uint32_t) tmp > max_system_variables.*offset)
612
609
  else if (tmp > UINT32_MAX)
613
610
  {
614
611
    tmp= UINT32_MAX;
615
 
    throw_bounds_warning(session, true, true, getName(), int64_t(var->getInteger()));
 
612
    throw_bounds_warning(session, true, true, getName(), (int64_t) var->save_result.uint64_t_value);
616
613
  }
617
614
 
618
615
  if (var->type == OPT_GLOBAL)
651
648
 
652
649
bool sys_var_session_ha_rows::update(Session *session, set_var *var)
653
650
{
654
 
  uint64_t tmp= var->getInteger();
 
651
  uint64_t tmp= var->save_result.uint64_t_value;
655
652
 
656
653
  /* Don't use bigger value than given with --maximum-variable-name=.. */
657
654
  if ((ha_rows) tmp > max_system_variables.*offset)
662
659
  if (var->type == OPT_GLOBAL)
663
660
  {
664
661
    /* Lock is needed to make things safe on 32 bit systems */
665
 
    boost::mutex::scoped_lock scopedLock(session->catalog().systemVariableLock());
 
662
    LOCK_global_system_variables.lock();
666
663
    global_system_variables.*offset= (ha_rows) tmp;
 
664
    LOCK_global_system_variables.unlock();
667
665
  }
668
666
  else
669
 
  {
670
667
    session->variables.*offset= (ha_rows) tmp;
671
 
  }
672
 
 
673
668
  return 0;
674
669
}
675
670
 
680
675
  {
681
676
    bool not_used;
682
677
    /* We will not come here if option_limits is not set */
683
 
    boost::mutex::scoped_lock scopedLock(session->catalog().systemVariableLock());
 
678
    LOCK_global_system_variables.lock();
684
679
    global_system_variables.*offset=
685
680
      (ha_rows) getopt_ull_limit_value((ha_rows) option_limits->def_value,
686
681
                                       option_limits, &not_used);
 
682
    LOCK_global_system_variables.unlock();
687
683
  }
688
684
  else
689
 
  {
690
685
    session->variables.*offset= global_system_variables.*offset;
691
 
  }
692
686
}
693
687
 
694
688
 
703
697
 
704
698
bool sys_var_session_uint64_t::check(Session *session, set_var *var)
705
699
{
706
 
  var->updateValue();
707
 
  return (check_func && (*check_func)(session, var));
 
700
  return (get_unsigned64(session, var) ||
 
701
          (check_func && (*check_func)(session, var)));
708
702
}
709
703
 
710
704
bool sys_var_session_uint64_t::update(Session *session,  set_var *var)
711
705
{
712
 
  uint64_t tmp= var->getInteger();
 
706
  uint64_t tmp= var->save_result.uint64_t_value;
713
707
 
714
708
  if (tmp > max_system_variables.*offset)
715
709
  {
722
716
  if (var->type == OPT_GLOBAL)
723
717
  {
724
718
    /* Lock is needed to make things safe on 32 bit systems */
725
 
    boost::mutex::scoped_lock scopedLock(session->catalog().systemVariableLock());
 
719
    LOCK_global_system_variables.lock();
726
720
    global_system_variables.*offset= (uint64_t) tmp;
 
721
    LOCK_global_system_variables.unlock();
727
722
  }
728
723
  else
729
 
  {
730
724
    session->variables.*offset= (uint64_t) tmp;
731
 
  }
732
 
 
733
725
  return 0;
734
726
}
735
727
 
739
731
  if (type == OPT_GLOBAL)
740
732
  {
741
733
    bool not_used;
742
 
    boost::mutex::scoped_lock scopedLock(session->catalog().systemVariableLock());
 
734
    LOCK_global_system_variables.lock();
743
735
    global_system_variables.*offset=
744
736
      getopt_ull_limit_value((uint64_t) option_limits->def_value,
745
737
                             option_limits, &not_used);
 
738
    LOCK_global_system_variables.unlock();
746
739
  }
747
740
  else
748
 
  {
749
741
    session->variables.*offset= global_system_variables.*offset;
750
 
  }
751
742
}
752
743
 
753
744
 
762
753
 
763
754
bool sys_var_session_size_t::check(Session *session, set_var *var)
764
755
{
765
 
  var->updateValue();
766
 
  return (check_func && (*check_func)(session, var));
 
756
  return (get_size_t(session, var) ||
 
757
          (check_func && (*check_func)(session, var)));
767
758
}
768
759
 
769
760
bool sys_var_session_size_t::update(Session *session,  set_var *var)
770
761
{
771
 
  size_t tmp= size_t(var->getInteger());
 
762
  size_t tmp= var->save_result.size_t_value;
772
763
 
773
764
  if (tmp > max_system_variables.*offset)
774
765
    tmp= max_system_variables.*offset;
778
769
  if (var->type == OPT_GLOBAL)
779
770
  {
780
771
    /* Lock is needed to make things safe on 32 bit systems */
781
 
    boost::mutex::scoped_lock scopedLock(session->catalog().systemVariableLock());
 
772
    LOCK_global_system_variables.lock();
782
773
    global_system_variables.*offset= tmp;
 
774
    LOCK_global_system_variables.unlock();
783
775
  }
784
776
  else
785
 
  {
786
777
    session->variables.*offset= tmp;
787
 
  }
788
 
 
789
778
  return 0;
790
779
}
791
780
 
795
784
  if (type == OPT_GLOBAL)
796
785
  {
797
786
    bool not_used;
798
 
    boost::mutex::scoped_lock scopedLock(session->catalog().systemVariableLock());
 
787
    LOCK_global_system_variables.lock();
799
788
    global_system_variables.*offset=
800
789
      (size_t)getopt_ull_limit_value((size_t) option_limits->def_value,
801
790
                                     option_limits, &not_used);
 
791
    LOCK_global_system_variables.unlock();
802
792
  }
803
793
  else
804
 
  {
805
794
    session->variables.*offset= global_system_variables.*offset;
806
 
  }
807
795
}
808
796
 
809
797
 
816
804
  return (unsigned char*) &(session->variables.*offset);
817
805
}
818
806
 
819
 
bool sys_var_session_bool::check(Session *session, set_var *var)
820
 
{
821
 
  return check_enum(session, var, &bool_typelib);
822
 
}
823
807
 
824
808
bool sys_var_session_bool::update(Session *session,  set_var *var)
825
809
{
826
810
  if (var->type == OPT_GLOBAL)
827
 
    global_system_variables.*offset= bool(var->getInteger());
 
811
    global_system_variables.*offset= (bool) var->save_result.uint32_t_value;
828
812
  else
829
 
    session->variables.*offset= bool(var->getInteger());
830
 
 
 
813
    session->variables.*offset= (bool) var->save_result.uint32_t_value;
831
814
  return 0;
832
815
}
833
816
 
860
843
 
861
844
  if (var->value->result_type() == STRING_RESULT)
862
845
  {
863
 
    res= var->value->val_str(&str);
864
 
    if (res == NULL)
 
846
    if (!(res=var->value->val_str(&str)) ||
 
847
        (var->save_result.uint32_t_value= find_type(enum_names, res->ptr(),
 
848
                                                    res->length(),1)) == 0)
865
849
    {
866
 
      value= "NULL";
 
850
      value= res ? res->c_ptr() : "NULL";
867
851
      goto err;
868
852
    }
869
853
 
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);
 
854
    var->save_result.uint32_t_value--;
877
855
  }
878
856
  else
879
857
  {
880
 
    uint64_t tmp= var->value->val_int();
 
858
    uint64_t tmp=var->value->val_int();
881
859
    if (tmp >= enum_names->count)
882
860
    {
883
861
      internal::llstr(tmp,buff);
884
862
      value=buff;                               // Wrong value is here
885
863
      goto err;
886
864
    }
887
 
    var->setValue(tmp); // Save for update
 
865
    var->save_result.uint32_t_value= (uint32_t) tmp;    // Save for update
888
866
  }
889
867
  return 0;
890
868
 
920
898
  case SHOW_INT:
921
899
  {
922
900
    uint32_t value;
923
 
    boost::mutex::scoped_lock scopedLock(session->catalog().systemVariableLock());
 
901
    LOCK_global_system_variables.lock();
924
902
    value= *(uint*) value_ptr(session, var_type, base);
925
 
 
 
903
    LOCK_global_system_variables.unlock();
926
904
    return new Item_uint((uint64_t) value);
927
905
  }
928
906
  case SHOW_LONGLONG:
929
907
  {
930
908
    int64_t value;
931
 
    boost::mutex::scoped_lock scopedLock(session->catalog().systemVariableLock());
 
909
    LOCK_global_system_variables.lock();
932
910
    value= *(int64_t*) value_ptr(session, var_type, base);
933
 
 
 
911
    LOCK_global_system_variables.unlock();
934
912
    return new Item_int(value);
935
913
  }
936
914
  case SHOW_DOUBLE:
937
915
  {
938
916
    double value;
939
 
    {
940
 
      boost::mutex::scoped_lock scopedLock(session->catalog().systemVariableLock());
941
 
      value= *(double*) value_ptr(session, var_type, base);
942
 
    }
943
 
 
 
917
    LOCK_global_system_variables.lock();
 
918
    value= *(double*) value_ptr(session, var_type, base);
 
919
    LOCK_global_system_variables.unlock();
944
920
    /* 6, as this is for now only used with microseconds */
945
921
    return new Item_float(value, 6);
946
922
  }
947
923
  case SHOW_HA_ROWS:
948
924
  {
949
925
    ha_rows value;
950
 
    boost::mutex::scoped_lock scopedLock(session->catalog().systemVariableLock());
 
926
    LOCK_global_system_variables.lock();
951
927
    value= *(ha_rows*) value_ptr(session, var_type, base);
952
 
 
 
928
    LOCK_global_system_variables.unlock();
953
929
    return new Item_int((uint64_t) value);
954
930
  }
955
931
  case SHOW_SIZE:
956
932
  {
957
933
    size_t value;
958
 
    boost::mutex::scoped_lock scopedLock(session->catalog().systemVariableLock());
 
934
    LOCK_global_system_variables.lock();
959
935
    value= *(size_t*) value_ptr(session, var_type, base);
960
 
 
 
936
    LOCK_global_system_variables.unlock();
961
937
    return new Item_int((uint64_t) value);
962
938
  }
963
939
  case SHOW_MY_BOOL:
964
940
  {
965
941
    int32_t value;
966
 
    boost::mutex::scoped_lock scopedLock(session->catalog().systemVariableLock());
 
942
    LOCK_global_system_variables.lock();
967
943
    value= *(bool*) value_ptr(session, var_type, base);
 
944
    LOCK_global_system_variables.unlock();
968
945
    return new Item_int(value,1);
969
946
  }
970
947
  case SHOW_CHAR_PTR:
971
948
  {
972
949
    Item *tmp;
973
 
    boost::mutex::scoped_lock scopedLock(session->catalog().systemVariableLock());
 
950
    LOCK_global_system_variables.lock();
974
951
    char *str= *(char**) value_ptr(session, var_type, base);
975
952
    if (str)
976
953
    {
983
960
      tmp= new Item_null();
984
961
      tmp->collation.set(system_charset_info, DERIVATION_SYSCONST);
985
962
    }
986
 
 
 
963
    LOCK_global_system_variables.unlock();
987
964
    return tmp;
988
965
  }
989
966
  case SHOW_CHAR:
990
967
  {
991
968
    Item *tmp;
992
 
    boost::mutex::scoped_lock scopedLock(session->catalog().systemVariableLock());
 
969
    LOCK_global_system_variables.lock();
993
970
    char *str= (char*) value_ptr(session, var_type, base);
994
971
    if (str)
995
972
      tmp= new Item_string(str, strlen(str),
999
976
      tmp= new Item_null();
1000
977
      tmp->collation.set(system_charset_info, DERIVATION_SYSCONST);
1001
978
    }
1002
 
 
 
979
    LOCK_global_system_variables.unlock();
1003
980
    return tmp;
1004
981
  }
1005
982
  default:
1012
989
bool sys_var_session_enum::update(Session *session, set_var *var)
1013
990
{
1014
991
  if (var->type == OPT_GLOBAL)
1015
 
    global_system_variables.*offset= var->getInteger();
 
992
    global_system_variables.*offset= var->save_result.uint32_t_value;
1016
993
  else
1017
 
    session->variables.*offset= var->getInteger();
 
994
    session->variables.*offset= var->save_result.uint32_t_value;
1018
995
  return 0;
1019
996
}
1020
997
 
1064
1041
}
1065
1042
 
1066
1043
 
1067
 
bool sys_var_collation_sv::update(Session *session, set_var *var)
 
1044
typedef struct old_names_map_st
 
1045
{
 
1046
  const char *old_name;
 
1047
  const char *new_name;
 
1048
} my_old_conv;
 
1049
 
 
1050
bool sys_var_collation::check(Session *, set_var *var)
1068
1051
{
1069
1052
  const CHARSET_INFO *tmp;
1070
1053
 
1074
1057
    String str(buff,sizeof(buff), system_charset_info), *res;
1075
1058
    if (!(res=var->value->val_str(&str)))
1076
1059
    {
1077
 
      boost::throw_exception(invalid_option_value(var->var->getName()) << invalid_value(std::string("NULL")));
 
1060
      my_error(ER_WRONG_VALUE_FOR_VAR, MYF(0), name.c_str(), "NULL");
1078
1061
      return 1;
1079
1062
    }
1080
1063
    if (!(tmp=get_charset_by_name(res->c_ptr())))
1081
1064
    {
1082
1065
      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())));
1084
1066
      return 1;
1085
1067
    }
1086
1068
  }
1091
1073
      char buf[20];
1092
1074
      internal::int10_to_str((int) var->value->val_int(), buf, -10);
1093
1075
      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())));
1095
1076
      return 1;
1096
1077
    }
1097
1078
  }
 
1079
  var->save_result.charset= tmp;        // Save for update
 
1080
  return 0;
 
1081
}
 
1082
 
 
1083
 
 
1084
bool sys_var_collation_sv::update(Session *session, set_var *var)
 
1085
{
1098
1086
  if (var->type == OPT_GLOBAL)
1099
 
    global_system_variables.*offset= tmp;
 
1087
    global_system_variables.*offset= var->save_result.charset;
1100
1088
  else
1101
1089
  {
1102
 
    session->variables.*offset= tmp;
 
1090
    session->variables.*offset= var->save_result.charset;
1103
1091
  }
1104
1092
  return 0;
1105
1093
}
1130
1118
 
1131
1119
bool sys_var_timestamp::update(Session *session,  set_var *var)
1132
1120
{
1133
 
  session->set_time(time_t(var->getInteger()));
 
1121
  session->set_time((time_t) var->save_result.uint64_t_value);
1134
1122
  return 0;
1135
1123
}
1136
1124
 
1137
1125
 
1138
1126
void sys_var_timestamp::set_default(Session *session, sql_var_t)
1139
1127
{
1140
 
  session->resetUserTime();
 
1128
  session->user_time=0;
1141
1129
}
1142
1130
 
1143
1131
 
1144
1132
unsigned char *sys_var_timestamp::value_ptr(Session *session, sql_var_t,
1145
1133
                                            const LEX_STRING *)
1146
1134
{
1147
 
  session->sys_var_tmp.int32_t_value= (int32_t) session->getCurrentTimestampEpoch();
 
1135
  session->sys_var_tmp.int32_t_value= (int32_t) session->start_time;
1148
1136
  return (unsigned char*) &session->sys_var_tmp.int32_t_value;
1149
1137
}
1150
1138
 
1151
1139
 
1152
1140
bool sys_var_last_insert_id::update(Session *session, set_var *var)
1153
1141
{
1154
 
  session->first_successful_insert_id_in_prev_stmt= var->getInteger();
 
1142
  session->first_successful_insert_id_in_prev_stmt=
 
1143
    var->save_result.uint64_t_value;
1155
1144
  return 0;
1156
1145
}
1157
1146
 
1169
1158
  return (unsigned char*) &session->sys_var_tmp.uint64_t_value;
1170
1159
}
1171
1160
 
1172
 
bool sys_var_session_lc_time_names::update(Session *session, set_var *var)
 
1161
 
 
1162
bool sys_var_session_time_zone::check(Session *session, set_var *var)
 
1163
{
 
1164
  char buff[MAX_TIME_ZONE_NAME_LENGTH];
 
1165
  String str(buff, sizeof(buff), &my_charset_utf8_general_ci);
 
1166
  String *res= var->value->val_str(&str);
 
1167
 
 
1168
  if (!(var->save_result.time_zone= my_tz_find(session, res)))
 
1169
  {
 
1170
    my_error(ER_UNKNOWN_TIME_ZONE, MYF(0), res ? res->c_ptr() : "NULL");
 
1171
    return 1;
 
1172
  }
 
1173
  return 0;
 
1174
}
 
1175
 
 
1176
 
 
1177
bool sys_var_session_time_zone::update(Session *session, set_var *var)
 
1178
{
 
1179
  /* We are using Time_zone object found during check() phase. */
 
1180
  if (var->type == OPT_GLOBAL)
 
1181
  {
 
1182
    LOCK_global_system_variables.lock();
 
1183
    global_system_variables.time_zone= var->save_result.time_zone;
 
1184
    LOCK_global_system_variables.unlock();
 
1185
  }
 
1186
  else
 
1187
    session->variables.time_zone= var->save_result.time_zone;
 
1188
  return 0;
 
1189
}
 
1190
 
 
1191
 
 
1192
unsigned char *sys_var_session_time_zone::value_ptr(Session *session,
 
1193
                                                    sql_var_t type,
 
1194
                                                    const LEX_STRING *)
 
1195
{
 
1196
  /*
 
1197
    We can use ptr() instead of c_ptr() here because String contaning
 
1198
    time zone name is guaranteed to be zero ended.
 
1199
  */
 
1200
  if (type == OPT_GLOBAL)
 
1201
    return (unsigned char *)(global_system_variables.time_zone->get_name()->ptr());
 
1202
  else
 
1203
  {
 
1204
    /*
 
1205
      This is an ugly fix for replication: we don't replicate properly queries
 
1206
      invoking system variables' values to update tables; but
 
1207
      CONVERT_TZ(,,@@session.time_zone) is so popular that we make it
 
1208
      replicable (i.e. we tell the binlog code to store the session
 
1209
      timezone). If it's the global value which was used we can't replicate
 
1210
      (binlog code stores session value only).
 
1211
    */
 
1212
    return (unsigned char *)(session->variables.time_zone->get_name()->ptr());
 
1213
  }
 
1214
}
 
1215
 
 
1216
 
 
1217
void sys_var_session_time_zone::set_default(Session *session, sql_var_t type)
 
1218
{
 
1219
 LOCK_global_system_variables.lock();
 
1220
 if (type == OPT_GLOBAL)
 
1221
 {
 
1222
   if (default_tz_name)
 
1223
   {
 
1224
     String str(default_tz_name, &my_charset_utf8_general_ci);
 
1225
     /*
 
1226
       We are guaranteed to find this time zone since its existence
 
1227
       is checked during start-up.
 
1228
     */
 
1229
     global_system_variables.time_zone= my_tz_find(session, &str);
 
1230
   }
 
1231
   else
 
1232
     global_system_variables.time_zone= my_tz_SYSTEM;
 
1233
 }
 
1234
 else
 
1235
   session->variables.time_zone= global_system_variables.time_zone;
 
1236
 LOCK_global_system_variables.unlock();
 
1237
}
 
1238
 
 
1239
 
 
1240
bool sys_var_session_lc_time_names::check(Session *, set_var *var)
1173
1241
{
1174
1242
  MY_LOCALE *locale_match;
1175
1243
 
1177
1245
  {
1178
1246
    if (!(locale_match= my_locale_by_number((uint32_t) var->value->val_int())))
1179
1247
    {
1180
 
      char buf[DECIMAL_LONGLONG_DIGITS];
 
1248
      char buf[20];
1181
1249
      internal::int10_to_str((int) var->value->val_int(), buf, -10);
1182
1250
      my_printf_error(ER_UNKNOWN_ERROR, "Unknown locale: '%s'", MYF(0), buf);
1183
1251
      return 1;
1201
1269
    }
1202
1270
  }
1203
1271
 
 
1272
  var->save_result.locale_value= locale_match;
 
1273
  return 0;
 
1274
}
 
1275
 
 
1276
 
 
1277
bool sys_var_session_lc_time_names::update(Session *session, set_var *var)
 
1278
{
1204
1279
  if (var->type == OPT_GLOBAL)
1205
 
    global_system_variables.lc_time_names= locale_match;
 
1280
    global_system_variables.lc_time_names= var->save_result.locale_value;
1206
1281
  else
1207
 
    session->variables.lc_time_names= locale_match;
 
1282
    session->variables.lc_time_names= var->save_result.locale_value;
1208
1283
  return 0;
1209
1284
}
1210
1285
 
1247
1322
  microseconds= (int64_t) (num * 1000000.0 + 0.5);
1248
1323
  if (var->type == OPT_GLOBAL)
1249
1324
  {
1250
 
    boost::mutex::scoped_lock scopedLock(session->catalog().systemVariableLock());
 
1325
    LOCK_global_system_variables.lock();
1251
1326
    (global_system_variables.*offset)= microseconds;
 
1327
    LOCK_global_system_variables.unlock();
1252
1328
  }
1253
1329
  else
1254
1330
    session->variables.*offset= microseconds;
1261
1337
  int64_t microseconds= (int64_t) (option_limits->def_value * 1000000.0);
1262
1338
  if (type == OPT_GLOBAL)
1263
1339
  {
1264
 
    boost::mutex::scoped_lock scopedLock(session->catalog().systemVariableLock());
 
1340
    LOCK_global_system_variables.lock();
1265
1341
    global_system_variables.*offset= microseconds;
 
1342
    LOCK_global_system_variables.unlock();
1266
1343
  }
1267
1344
  else
1268
1345
    session->variables.*offset= microseconds;
1275
1352
static bool set_option_bit(Session *session, set_var *var)
1276
1353
{
1277
1354
  sys_var_session_bit *sys_var= ((sys_var_session_bit*) var->var);
1278
 
  if ((var->getInteger() != 0) == sys_var->reverse)
 
1355
  if ((var->save_result.uint32_t_value != 0) == sys_var->reverse)
1279
1356
    session->options&= ~sys_var->bit_flag;
1280
1357
  else
1281
1358
    session->options|= sys_var->bit_flag;
1285
1362
 
1286
1363
static bool set_option_autocommit(Session *session, set_var *var)
1287
1364
{
1288
 
  bool success= true;
1289
1365
  /* The test is negative as the flag we use is NOT autocommit */
1290
1366
 
1291
1367
  uint64_t org_options= session->options;
1292
 
  uint64_t new_options= session->options;
1293
1368
 
1294
 
  if (var->getInteger() != 0)
1295
 
    new_options&= ~((sys_var_session_bit*) var->var)->bit_flag;
 
1369
  if (var->save_result.uint32_t_value != 0)
 
1370
    session->options&= ~((sys_var_session_bit*) var->var)->bit_flag;
1296
1371
  else
1297
 
    new_options|= ((sys_var_session_bit*) var->var)->bit_flag;
 
1372
    session->options|= ((sys_var_session_bit*) var->var)->bit_flag;
1298
1373
 
1299
 
  if ((org_options ^ new_options) & OPTION_NOT_AUTOCOMMIT)
 
1374
  if ((org_options ^ session->options) & OPTION_NOT_AUTOCOMMIT)
1300
1375
  {
1301
1376
    if ((org_options & OPTION_NOT_AUTOCOMMIT))
1302
1377
    {
1303
 
      success= session->endActiveTransaction();
1304
1378
      /* We changed to auto_commit mode */
1305
1379
      session->options&= ~(uint64_t) (OPTION_BEGIN);
1306
1380
      session->server_status|= SERVER_STATUS_AUTOCOMMIT;
 
1381
      TransactionServices &transaction_services= TransactionServices::singleton();
 
1382
      if (transaction_services.commitTransaction(session, true))
 
1383
        return 1;
1307
1384
    }
1308
1385
    else
1309
1386
    {
1310
1387
      session->server_status&= ~SERVER_STATUS_AUTOCOMMIT;
1311
1388
    }
1312
1389
  }
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
 
 
1322
1390
  return 0;
1323
1391
}
1324
1392
 
1325
1393
static int check_pseudo_thread_id(Session *, set_var *var)
1326
1394
{
1327
 
  var->updateValue();
 
1395
  var->save_result.uint64_t_value= var->value->val_int();
1328
1396
  return 0;
1329
1397
}
1330
1398
 
1422
1490
drizzle_show_var* enumerate_sys_vars(Session *session)
1423
1491
{
1424
1492
  int size= sizeof(drizzle_show_var) * (system_variable_map.size() + 1);
1425
 
  drizzle_show_var *result= (drizzle_show_var*) session->getMemRoot()->allocate(size);
 
1493
  drizzle_show_var *result= (drizzle_show_var*) session->alloc(size);
1426
1494
 
1427
1495
  if (result)
1428
1496
  {
1456
1524
  /* this fails if there is a conflicting variable name. */
1457
1525
  if (system_variable_map.find(lower_name) != system_variable_map.end())
1458
1526
  {
1459
 
    errmsg_printf(error::ERROR, _("Variable named %s already exists!\n"),
 
1527
    errmsg_printf(ERRMSG_LVL_ERROR, _("Variable named %s already exists!\n"),
1460
1528
                  var->getName().c_str());
1461
1529
    throw exception();
1462
1530
  } 
1465
1533
    system_variable_map.insert(make_pair(lower_name, var));
1466
1534
  if (ret.second == false)
1467
1535
  {
1468
 
    errmsg_printf(error::ERROR, _("Could not add Variable: %s\n"),
 
1536
    errmsg_printf(ERRMSG_LVL_ERROR, _("Could not add Variable: %s\n"),
1469
1537
                  var->getName().c_str());
1470
1538
    throw exception();
1471
1539
  }
1498
1566
    add_sys_var_to_list(&sys_back_log, my_long_options);
1499
1567
    add_sys_var_to_list(&sys_basedir, my_long_options);
1500
1568
    add_sys_var_to_list(&sys_big_selects, my_long_options);
1501
 
    add_sys_var_to_list(&sys_branch, my_long_options);
1502
1569
    add_sys_var_to_list(&sys_buffer_results, my_long_options);
1503
1570
    add_sys_var_to_list(&sys_bulk_insert_buff_size, my_long_options);
1504
1571
    add_sys_var_to_list(&sys_collation_server, my_long_options);
1514
1581
    add_sys_var_to_list(&sys_last_insert_id, my_long_options);
1515
1582
    add_sys_var_to_list(&sys_lc_time_names, my_long_options);
1516
1583
    add_sys_var_to_list(&sys_max_allowed_packet, my_long_options);
 
1584
    add_sys_var_to_list(&sys_max_connect_errors, my_long_options);
1517
1585
    add_sys_var_to_list(&sys_max_error_count, my_long_options);
1518
1586
    add_sys_var_to_list(&sys_max_heap_table_size, my_long_options);
1519
1587
    add_sys_var_to_list(&sys_max_join_size, my_long_options);
1533
1601
    add_sys_var_to_list(&sys_range_alloc_block_size, my_long_options);
1534
1602
    add_sys_var_to_list(&sys_read_buff_size, my_long_options);
1535
1603
    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);
1540
1604
    add_sys_var_to_list(&sys_scheduler, my_long_options);
1541
1605
    add_sys_var_to_list(&sys_secure_file_priv, my_long_options);
1542
1606
    add_sys_var_to_list(&sys_select_limit, my_long_options);
1545
1609
    add_sys_var_to_list(&sys_sql_notes, my_long_options);
1546
1610
    add_sys_var_to_list(&sys_sql_warnings, my_long_options);
1547
1611
    add_sys_var_to_list(&sys_storage_engine, my_long_options);
 
1612
    add_sys_var_to_list(&sys_system_time_zone, my_long_options);
1548
1613
    add_sys_var_to_list(&sys_table_cache_size, my_long_options);
1549
1614
    add_sys_var_to_list(&sys_table_def_size, my_long_options);
1550
1615
    add_sys_var_to_list(&sys_table_lock_wait_timeout, my_long_options);
1551
1616
    add_sys_var_to_list(&sys_thread_stack_size, my_long_options);
 
1617
    add_sys_var_to_list(&sys_time_zone, my_long_options);
1552
1618
    add_sys_var_to_list(&sys_timed_mutexes, my_long_options);
1553
1619
    add_sys_var_to_list(&sys_timestamp, my_long_options);
1554
1620
    add_sys_var_to_list(&sys_tmp_table_size, my_long_options);
1563
1629
    add_sys_var_to_list(&sys_version_compile_vendor, my_long_options);
1564
1630
    add_sys_var_to_list(&sys_warning_count, my_long_options);
1565
1631
  }
1566
 
  catch (std::exception&)
 
1632
  catch (...)
1567
1633
  {
1568
 
    errmsg_printf(error::ERROR, _("Failed to initialize system variables"));
 
1634
    errmsg_printf(ERRMSG_LVL_ERROR, _("Failed to initialize system variables"));
1569
1635
    return(1);
1570
1636
  }
1571
1637
  return(0);
1575
1641
/**
1576
1642
  Find a user set-table variable.
1577
1643
 
1578
 
  @param name      Name of system variable to find
 
1644
  @param str       Name of system variable to find
 
1645
  @param length    Length of variable.  zero means that we should use strlen()
 
1646
                   on the variable
 
1647
  @param no_error  Refuse to emit an error, even if one occurred.
1579
1648
 
1580
1649
  @retval
1581
1650
    pointer     pointer to variable definitions
1583
1652
    0           Unknown variable (error message is given)
1584
1653
*/
1585
1654
 
1586
 
sys_var *find_sys_var(const std::string &name)
 
1655
sys_var *intern_find_sys_var(const char *str, uint32_t, bool no_error)
1587
1656
{
1588
 
  string lower_name(name);
 
1657
  string lower_name(str);
1589
1658
  transform(lower_name.begin(), lower_name.end(),
1590
1659
            lower_name.begin(), ::tolower);
1591
1660
 
1597
1666
    result= (*iter).second;
1598
1667
  } 
1599
1668
 
 
1669
  /*
 
1670
    This function is only called from the sql_plugin.cc.
 
1671
    A lock on LOCK_system_variable_hash should be held
 
1672
  */
1600
1673
  if (result == NULL)
1601
1674
  {
1602
 
    my_error(ER_UNKNOWN_SYSTEM_VARIABLE, MYF(0), name.c_str());
1603
 
    return NULL;
 
1675
    if (no_error)
 
1676
    {
 
1677
      return NULL;
 
1678
    }
 
1679
    else
 
1680
    {
 
1681
      my_error(ER_UNKNOWN_SYSTEM_VARIABLE, MYF(0), (char*) str);
 
1682
      return NULL;
 
1683
    }
1604
1684
  }
1605
1685
 
1606
1686
  return result;
1611
1691
 Functions to handle table_type
1612
1692
****************************************************************************/
1613
1693
 
 
1694
/* Based upon sys_var::check_enum() */
 
1695
 
 
1696
bool sys_var_session_storage_engine::check(Session *session, set_var *var)
 
1697
{
 
1698
  char buff[STRING_BUFFER_USUAL_SIZE];
 
1699
  const char *value;
 
1700
  String str(buff, sizeof(buff), &my_charset_utf8_general_ci), *res;
 
1701
 
 
1702
  var->save_result.storage_engine= NULL;
 
1703
  if (var->value->result_type() == STRING_RESULT)
 
1704
  {
 
1705
    res= var->value->val_str(&str);
 
1706
    if (res == NULL || res->ptr() == NULL)
 
1707
    {
 
1708
      value= "NULL";
 
1709
      goto err;
 
1710
    }
 
1711
    else
 
1712
    {
 
1713
      const std::string engine_name(res->ptr());
 
1714
      plugin::StorageEngine *engine;
 
1715
      var->save_result.storage_engine= plugin::StorageEngine::findByName(*session, engine_name);
 
1716
      if (var->save_result.storage_engine == NULL)
 
1717
      {
 
1718
        value= res->c_ptr();
 
1719
        goto err;
 
1720
      }
 
1721
      engine= var->save_result.storage_engine;
 
1722
    }
 
1723
    return 0;
 
1724
  }
 
1725
  value= "unknown";
 
1726
 
 
1727
err:
 
1728
  my_error(ER_UNKNOWN_STORAGE_ENGINE, MYF(0), value);
 
1729
  return 1;
 
1730
}
 
1731
 
 
1732
 
1614
1733
unsigned char *sys_var_session_storage_engine::value_ptr(Session *session,
1615
1734
                                                         sql_var_t type,
1616
1735
                                                         const LEX_STRING *)
1648
1767
 
1649
1768
bool sys_var_session_storage_engine::update(Session *session, set_var *var)
1650
1769
{
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);
 
1770
  plugin::StorageEngine **value= &(global_system_variables.*offset), *old_value;
1683
1771
   if (var->type != OPT_GLOBAL)
1684
1772
     value= &(session->variables.*offset);
1685
 
  if (*value != tmp)
 
1773
  old_value= *value;
 
1774
  if (old_value != var->save_result.storage_engine)
1686
1775
  {
1687
 
    *value= tmp;
 
1776
    *value= var->save_result.storage_engine;
1688
1777
  }
1689
1778
  return 0;
1690
 
err:
1691
 
  my_error(ER_UNKNOWN_STORAGE_ENGINE, MYF(0), name_value);
1692
 
  return 1;
1693
1779
}
1694
1780
 
1695
1781
} /* namespace drizzled */