~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/sys_var.cc

  • Committer: Brian Aker
  • Date: 2010-12-24 03:44:02 UTC
  • mfrom: (2015.1.3 timestamp)
  • mto: This revision was merged to the branch mainline in revision 2028.
  • Revision ID: brian@tangent.org-20101224034402-n1hpg1yxwjz59hpw
Finish up issues with unsigned/int by fixing cast().

Show diffs side-by-side

added added

removed removed

Lines of Context:
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>
92
94
 
93
95
extern TYPELIB tx_isolation_typelib;
94
96
 
95
 
namespace
96
 
{
97
 
static size_t revno= DRIZZLE7_VC_REVNO;
98
 
static size_t release_id= DRIZZLE7_RELEASE_ID;
99
 
}
100
 
 
101
97
const char *bool_type_names[]= { "OFF", "ON", NULL };
102
98
TYPELIB bool_typelib=
103
99
{
114
110
static void fix_max_join_size(Session *session, sql_var_t type);
115
111
static void fix_session_mem_root(Session *session, sql_var_t type);
116
112
static void fix_server_id(Session *session, sql_var_t type);
 
113
static bool get_unsigned32(Session *session, set_var *var);
 
114
static bool get_unsigned64(Session *session, set_var *var);
117
115
bool throw_bounds_warning(Session *session, bool fixed, bool unsignd,
118
116
                          const std::string &name, int64_t val);
119
117
static unsigned char *get_error_count(Session *session);
158
156
                                                     &drizzle_system_variables::join_buff_size);
159
157
static sys_var_session_uint32_t sys_max_allowed_packet("max_allowed_packet",
160
158
                                                       &drizzle_system_variables::max_allowed_packet);
 
159
static sys_var_uint64_t_ptr     sys_max_connect_errors("max_connect_errors",
 
160
                                               &max_connect_errors);
161
161
static sys_var_session_uint64_t sys_max_error_count("max_error_count",
162
162
                                                  &drizzle_system_variables::max_error_count);
163
163
static sys_var_session_uint64_t sys_max_heap_table_size("max_heap_table_size",
220
220
static sys_var_session_size_t   sys_sort_buffer("sort_buffer_size",
221
221
                                                &drizzle_system_variables::sortbuff_size);
222
222
 
223
 
static sys_var_size_t_ptr_readonly sys_transaction_message_threshold("transaction_message_threshold",
224
 
                                                                &transaction_message_threshold);
 
223
static sys_var_session_size_t sys_transaction_message_threshold("transaction_message_threshold",
 
224
                                                                &drizzle_system_variables::transaction_message_threshold);
225
225
 
226
226
static sys_var_session_storage_engine sys_storage_engine("storage_engine",
227
227
                                       &drizzle_system_variables::storage_engine);
 
228
static sys_var_const_str        sys_system_time_zone("system_time_zone",
 
229
                                             system_time_zone);
228
230
static sys_var_size_t_ptr       sys_table_def_size("table_definition_cache",
229
231
                                             &table_def_size);
230
232
static sys_var_uint64_t_ptr     sys_table_cache_size("table_open_cache",
313
315
sys_var_session_uint64_t sys_group_concat_max_len("group_concat_max_len",
314
316
                                                  &drizzle_system_variables::group_concat_max_len);
315
317
 
 
318
sys_var_session_time_zone sys_time_zone("time_zone");
 
319
 
316
320
/* 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);
 
321
static sys_var_const_str        sys_hostname("hostname", glob_hostname);
323
322
 
324
323
bool sys_var::check(Session *session, set_var *var)
325
324
{
330
329
      my_error(ER_WRONG_VALUE_FOR_VAR, MYF(0), getName().c_str(), var->value->str_value.ptr());
331
330
    return res;
332
331
  }
333
 
  var->updateValue();
 
332
  var->save_result.uint64_t_value= var->value->val_int();
334
333
  return 0;
335
334
}
336
335
 
440
439
{
441
440
  if (fixed)
442
441
  {
443
 
    char buf[DECIMAL_LONGLONG_DIGITS];
 
442
    char buf[22];
444
443
 
445
444
    if (unsignd)
446
445
      internal::ullstr((uint64_t) val, buf);
475
474
  return out;
476
475
}
477
476
 
 
477
static bool get_unsigned32(Session *session, set_var *var)
 
478
{
 
479
  if (var->value->unsigned_flag)
 
480
    var->save_result.uint32_t_value= 
 
481
      static_cast<uint32_t>(var->value->val_int());
 
482
  else
 
483
  {
 
484
    int64_t v= var->value->val_int();
 
485
    if (v > UINT32_MAX)
 
486
      throw_bounds_warning(session, true, true,var->var->getName().c_str(), v);
 
487
    
 
488
    var->save_result.uint32_t_value= 
 
489
      static_cast<uint32_t>((v > UINT32_MAX) ? UINT32_MAX : (v < 0) ? 0 : v);
 
490
  }
 
491
  return false;
 
492
}
 
493
 
 
494
static bool get_unsigned64(Session *, set_var *var)
 
495
{
 
496
  if (var->value->unsigned_flag)
 
497
      var->save_result.uint64_t_value=(uint64_t) var->value->val_int();
 
498
  else
 
499
  {
 
500
    int64_t v= var->value->val_int();
 
501
      var->save_result.uint64_t_value= (uint64_t) ((v < 0) ? 0 : v);
 
502
  }
 
503
  return 0;
 
504
}
 
505
 
 
506
static bool get_size_t(Session *, set_var *var)
 
507
{
 
508
  if (var->value->unsigned_flag)
 
509
    var->save_result.size_t_value= (size_t) var->value->val_int();
 
510
  else
 
511
  {
 
512
    ssize_t v= (ssize_t)var->value->val_int();
 
513
    var->save_result.size_t_value= (size_t) ((v < 0) ? 0 : v);
 
514
  }
 
515
  return 0;
 
516
}
 
517
 
478
518
bool sys_var_uint32_t_ptr::check(Session *, set_var *var)
479
519
{
480
 
  var->updateValue();
 
520
  var->save_result.uint32_t_value= (uint32_t)var->value->val_int();
481
521
  return 0;
482
522
}
483
523
 
484
524
bool sys_var_uint32_t_ptr::update(Session *session, set_var *var)
485
525
{
486
 
  uint64_t tmp= var->getInteger();
487
 
  boost::mutex::scoped_lock scopedLock(session->catalog().systemVariableLock());
488
 
 
 
526
  uint32_t tmp= var->save_result.uint32_t_value;
 
527
  LOCK_global_system_variables.lock();
489
528
  if (option_limits)
490
529
  {
491
530
    uint32_t newvalue= (uint32_t) fix_unsigned(session, tmp, option_limits);
492
 
    if(static_cast<uint64_t>(newvalue) == tmp)
 
531
    if(newvalue==tmp)
493
532
      *value= newvalue;
494
533
  }
495
534
  else
496
 
  {
497
 
    *value= static_cast<uint32_t>(tmp);
498
 
  }
499
 
 
 
535
    *value= (uint32_t) tmp;
 
536
  LOCK_global_system_variables.unlock();
500
537
  return 0;
501
538
}
502
539
 
503
540
 
504
 
void sys_var_uint32_t_ptr::set_default(Session *session, sql_var_t)
 
541
void sys_var_uint32_t_ptr::set_default(Session *, sql_var_t)
505
542
{
506
543
  bool not_used;
507
 
  boost::mutex::scoped_lock scopedLock(session->catalog().systemVariableLock());
 
544
  LOCK_global_system_variables.lock();
508
545
  *value= (uint32_t)getopt_ull_limit_value((uint32_t) option_limits->def_value,
509
546
                                           option_limits, &not_used);
 
547
  LOCK_global_system_variables.unlock();
510
548
}
511
549
 
512
550
 
513
551
bool sys_var_uint64_t_ptr::update(Session *session, set_var *var)
514
552
{
515
 
  uint64_t tmp= var->getInteger();
516
 
  boost::mutex::scoped_lock scopedLock(session->catalog().systemVariableLock());
517
 
 
 
553
  uint64_t tmp= var->save_result.uint64_t_value;
 
554
  LOCK_global_system_variables.lock();
518
555
  if (option_limits)
519
556
  {
520
 
    uint64_t newvalue= fix_unsigned(session, tmp, option_limits);
 
557
    uint64_t newvalue= (uint64_t) fix_unsigned(session, tmp, option_limits);
521
558
    if(newvalue==tmp)
522
559
      *value= newvalue;
523
560
  }
524
561
  else
525
 
  {
526
 
    *value= tmp;
527
 
  }
528
 
 
 
562
    *value= (uint64_t) tmp;
 
563
  LOCK_global_system_variables.unlock();
529
564
  return 0;
530
565
}
531
566
 
532
567
 
533
 
void sys_var_uint64_t_ptr::set_default(Session *session, sql_var_t)
 
568
void sys_var_uint64_t_ptr::set_default(Session *, sql_var_t)
534
569
{
535
570
  if (have_default_value)
536
571
  {
539
574
  else
540
575
  {
541
576
    bool not_used;
542
 
    boost::mutex::scoped_lock scopedLock(session->catalog().systemVariableLock());
 
577
    LOCK_global_system_variables.lock();
543
578
    *value= getopt_ull_limit_value((uint64_t) option_limits->def_value,
544
579
                                   option_limits, &not_used);
 
580
    LOCK_global_system_variables.unlock();
545
581
  }
546
582
}
547
583
 
548
584
 
549
585
bool sys_var_size_t_ptr::update(Session *session, set_var *var)
550
586
{
551
 
  size_t tmp= size_t(var->getInteger());
552
 
 
553
 
  boost::mutex::scoped_lock scopedLock(session->catalog().systemVariableLock());
554
 
 
 
587
  size_t tmp= var->save_result.size_t_value;
 
588
  LOCK_global_system_variables.lock();
555
589
  if (option_limits)
556
590
    *value= fix_size_t(session, tmp, option_limits);
557
591
  else
558
592
    *value= tmp;
559
 
 
 
593
  LOCK_global_system_variables.unlock();
560
594
  return 0;
561
595
}
562
596
 
563
597
 
564
 
void sys_var_size_t_ptr::set_default(Session *session, sql_var_t)
 
598
void sys_var_size_t_ptr::set_default(Session *, sql_var_t)
565
599
{
566
600
  bool not_used;
567
 
  boost::mutex::scoped_lock scopedLock(session->catalog().systemVariableLock());
 
601
  LOCK_global_system_variables.lock();
568
602
  *value= (size_t)getopt_ull_limit_value((size_t) option_limits->def_value,
569
603
                                         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);
 
604
  LOCK_global_system_variables.unlock();
575
605
}
576
606
 
577
607
bool sys_var_bool_ptr::update(Session *, set_var *var)
578
608
{
579
 
  *value= bool(var->getInteger());
 
609
  *value= (bool) var->save_result.uint32_t_value;
580
610
  return 0;
581
611
}
582
612
 
592
622
*/
593
623
bool sys_var_session_uint32_t::check(Session *session, set_var *var)
594
624
{
595
 
  var->updateValue();
596
 
  return (check_func && (*check_func)(session, var));
 
625
  return (get_unsigned32(session, var) ||
 
626
          (check_func && (*check_func)(session, var)));
597
627
}
598
628
 
599
629
bool sys_var_session_uint32_t::update(Session *session, set_var *var)
600
630
{
601
 
  uint64_t tmp= var->getInteger();
 
631
  uint64_t tmp= (uint64_t) var->save_result.uint32_t_value;
602
632
 
603
633
  /* Don't use bigger value than given with --maximum-variable-name=.. */
604
634
  if ((uint32_t) tmp > max_system_variables.*offset)
612
642
  else if (tmp > UINT32_MAX)
613
643
  {
614
644
    tmp= UINT32_MAX;
615
 
    throw_bounds_warning(session, true, true, getName(), int64_t(var->getInteger()));
 
645
    throw_bounds_warning(session, true, true, getName(), (int64_t) var->save_result.uint64_t_value);
616
646
  }
617
647
 
618
648
  if (var->type == OPT_GLOBAL)
651
681
 
652
682
bool sys_var_session_ha_rows::update(Session *session, set_var *var)
653
683
{
654
 
  uint64_t tmp= var->getInteger();
 
684
  uint64_t tmp= var->save_result.uint64_t_value;
655
685
 
656
686
  /* Don't use bigger value than given with --maximum-variable-name=.. */
657
687
  if ((ha_rows) tmp > max_system_variables.*offset)
662
692
  if (var->type == OPT_GLOBAL)
663
693
  {
664
694
    /* Lock is needed to make things safe on 32 bit systems */
665
 
    boost::mutex::scoped_lock scopedLock(session->catalog().systemVariableLock());
 
695
    LOCK_global_system_variables.lock();
666
696
    global_system_variables.*offset= (ha_rows) tmp;
 
697
    LOCK_global_system_variables.unlock();
667
698
  }
668
699
  else
669
 
  {
670
700
    session->variables.*offset= (ha_rows) tmp;
671
 
  }
672
 
 
673
701
  return 0;
674
702
}
675
703
 
680
708
  {
681
709
    bool not_used;
682
710
    /* We will not come here if option_limits is not set */
683
 
    boost::mutex::scoped_lock scopedLock(session->catalog().systemVariableLock());
 
711
    LOCK_global_system_variables.lock();
684
712
    global_system_variables.*offset=
685
713
      (ha_rows) getopt_ull_limit_value((ha_rows) option_limits->def_value,
686
714
                                       option_limits, &not_used);
 
715
    LOCK_global_system_variables.unlock();
687
716
  }
688
717
  else
689
 
  {
690
718
    session->variables.*offset= global_system_variables.*offset;
691
 
  }
692
719
}
693
720
 
694
721
 
703
730
 
704
731
bool sys_var_session_uint64_t::check(Session *session, set_var *var)
705
732
{
706
 
  var->updateValue();
707
 
  return (check_func && (*check_func)(session, var));
 
733
  return (get_unsigned64(session, var) ||
 
734
          (check_func && (*check_func)(session, var)));
708
735
}
709
736
 
710
737
bool sys_var_session_uint64_t::update(Session *session,  set_var *var)
711
738
{
712
 
  uint64_t tmp= var->getInteger();
 
739
  uint64_t tmp= var->save_result.uint64_t_value;
713
740
 
714
741
  if (tmp > max_system_variables.*offset)
715
742
  {
722
749
  if (var->type == OPT_GLOBAL)
723
750
  {
724
751
    /* Lock is needed to make things safe on 32 bit systems */
725
 
    boost::mutex::scoped_lock scopedLock(session->catalog().systemVariableLock());
 
752
    LOCK_global_system_variables.lock();
726
753
    global_system_variables.*offset= (uint64_t) tmp;
 
754
    LOCK_global_system_variables.unlock();
727
755
  }
728
756
  else
729
 
  {
730
757
    session->variables.*offset= (uint64_t) tmp;
731
 
  }
732
 
 
733
758
  return 0;
734
759
}
735
760
 
739
764
  if (type == OPT_GLOBAL)
740
765
  {
741
766
    bool not_used;
742
 
    boost::mutex::scoped_lock scopedLock(session->catalog().systemVariableLock());
 
767
    LOCK_global_system_variables.lock();
743
768
    global_system_variables.*offset=
744
769
      getopt_ull_limit_value((uint64_t) option_limits->def_value,
745
770
                             option_limits, &not_used);
 
771
    LOCK_global_system_variables.unlock();
746
772
  }
747
773
  else
748
 
  {
749
774
    session->variables.*offset= global_system_variables.*offset;
750
 
  }
751
775
}
752
776
 
753
777
 
762
786
 
763
787
bool sys_var_session_size_t::check(Session *session, set_var *var)
764
788
{
765
 
  var->updateValue();
766
 
  return (check_func && (*check_func)(session, var));
 
789
  return (get_size_t(session, var) ||
 
790
          (check_func && (*check_func)(session, var)));
767
791
}
768
792
 
769
793
bool sys_var_session_size_t::update(Session *session,  set_var *var)
770
794
{
771
 
  size_t tmp= size_t(var->getInteger());
 
795
  size_t tmp= var->save_result.size_t_value;
772
796
 
773
797
  if (tmp > max_system_variables.*offset)
774
798
    tmp= max_system_variables.*offset;
778
802
  if (var->type == OPT_GLOBAL)
779
803
  {
780
804
    /* Lock is needed to make things safe on 32 bit systems */
781
 
    boost::mutex::scoped_lock scopedLock(session->catalog().systemVariableLock());
 
805
    LOCK_global_system_variables.lock();
782
806
    global_system_variables.*offset= tmp;
 
807
    LOCK_global_system_variables.unlock();
783
808
  }
784
809
  else
785
 
  {
786
810
    session->variables.*offset= tmp;
787
 
  }
788
 
 
789
811
  return 0;
790
812
}
791
813
 
795
817
  if (type == OPT_GLOBAL)
796
818
  {
797
819
    bool not_used;
798
 
    boost::mutex::scoped_lock scopedLock(session->catalog().systemVariableLock());
 
820
    LOCK_global_system_variables.lock();
799
821
    global_system_variables.*offset=
800
822
      (size_t)getopt_ull_limit_value((size_t) option_limits->def_value,
801
823
                                     option_limits, &not_used);
 
824
    LOCK_global_system_variables.unlock();
802
825
  }
803
826
  else
804
 
  {
805
827
    session->variables.*offset= global_system_variables.*offset;
806
 
  }
807
828
}
808
829
 
809
830
 
816
837
  return (unsigned char*) &(session->variables.*offset);
817
838
}
818
839
 
819
 
bool sys_var_session_bool::check(Session *session, set_var *var)
820
 
{
821
 
  return check_enum(session, var, &bool_typelib);
822
 
}
823
840
 
824
841
bool sys_var_session_bool::update(Session *session,  set_var *var)
825
842
{
826
843
  if (var->type == OPT_GLOBAL)
827
 
    global_system_variables.*offset= bool(var->getInteger());
 
844
    global_system_variables.*offset= (bool) var->save_result.uint32_t_value;
828
845
  else
829
 
    session->variables.*offset= bool(var->getInteger());
830
 
 
 
846
    session->variables.*offset= (bool) var->save_result.uint32_t_value;
831
847
  return 0;
832
848
}
833
849
 
860
876
 
861
877
  if (var->value->result_type() == STRING_RESULT)
862
878
  {
863
 
    res= var->value->val_str(&str);
864
 
    if (res == NULL)
 
879
    if (!(res=var->value->val_str(&str)) ||
 
880
        (var->save_result.uint32_t_value= find_type(enum_names, res->ptr(),
 
881
                                                    res->length(),1)) == 0)
865
882
    {
866
 
      value= "NULL";
 
883
      value= res ? res->c_ptr() : "NULL";
867
884
      goto err;
868
885
    }
869
886
 
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);
 
887
    var->save_result.uint32_t_value--;
877
888
  }
878
889
  else
879
890
  {
880
 
    uint64_t tmp= var->value->val_int();
 
891
    uint64_t tmp=var->value->val_int();
881
892
    if (tmp >= enum_names->count)
882
893
    {
883
894
      internal::llstr(tmp,buff);
884
895
      value=buff;                               // Wrong value is here
885
896
      goto err;
886
897
    }
887
 
    var->setValue(tmp); // Save for update
 
898
    var->save_result.uint32_t_value= (uint32_t) tmp;    // Save for update
888
899
  }
889
900
  return 0;
890
901
 
920
931
  case SHOW_INT:
921
932
  {
922
933
    uint32_t value;
923
 
    boost::mutex::scoped_lock scopedLock(session->catalog().systemVariableLock());
 
934
    LOCK_global_system_variables.lock();
924
935
    value= *(uint*) value_ptr(session, var_type, base);
925
 
 
 
936
    LOCK_global_system_variables.unlock();
926
937
    return new Item_uint((uint64_t) value);
927
938
  }
928
939
  case SHOW_LONGLONG:
929
940
  {
930
941
    int64_t value;
931
 
    boost::mutex::scoped_lock scopedLock(session->catalog().systemVariableLock());
 
942
    LOCK_global_system_variables.lock();
932
943
    value= *(int64_t*) value_ptr(session, var_type, base);
933
 
 
 
944
    LOCK_global_system_variables.unlock();
934
945
    return new Item_int(value);
935
946
  }
936
947
  case SHOW_DOUBLE:
937
948
  {
938
949
    double value;
939
 
    {
940
 
      boost::mutex::scoped_lock scopedLock(session->catalog().systemVariableLock());
941
 
      value= *(double*) value_ptr(session, var_type, base);
942
 
    }
943
 
 
 
950
    LOCK_global_system_variables.lock();
 
951
    value= *(double*) value_ptr(session, var_type, base);
 
952
    LOCK_global_system_variables.unlock();
944
953
    /* 6, as this is for now only used with microseconds */
945
954
    return new Item_float(value, 6);
946
955
  }
947
956
  case SHOW_HA_ROWS:
948
957
  {
949
958
    ha_rows value;
950
 
    boost::mutex::scoped_lock scopedLock(session->catalog().systemVariableLock());
 
959
    LOCK_global_system_variables.lock();
951
960
    value= *(ha_rows*) value_ptr(session, var_type, base);
952
 
 
 
961
    LOCK_global_system_variables.unlock();
953
962
    return new Item_int((uint64_t) value);
954
963
  }
955
964
  case SHOW_SIZE:
956
965
  {
957
966
    size_t value;
958
 
    boost::mutex::scoped_lock scopedLock(session->catalog().systemVariableLock());
 
967
    LOCK_global_system_variables.lock();
959
968
    value= *(size_t*) value_ptr(session, var_type, base);
960
 
 
 
969
    LOCK_global_system_variables.unlock();
961
970
    return new Item_int((uint64_t) value);
962
971
  }
963
972
  case SHOW_MY_BOOL:
964
973
  {
965
974
    int32_t value;
966
 
    boost::mutex::scoped_lock scopedLock(session->catalog().systemVariableLock());
 
975
    LOCK_global_system_variables.lock();
967
976
    value= *(bool*) value_ptr(session, var_type, base);
 
977
    LOCK_global_system_variables.unlock();
968
978
    return new Item_int(value,1);
969
979
  }
970
980
  case SHOW_CHAR_PTR:
971
981
  {
972
982
    Item *tmp;
973
 
    boost::mutex::scoped_lock scopedLock(session->catalog().systemVariableLock());
 
983
    LOCK_global_system_variables.lock();
974
984
    char *str= *(char**) value_ptr(session, var_type, base);
975
985
    if (str)
976
986
    {
983
993
      tmp= new Item_null();
984
994
      tmp->collation.set(system_charset_info, DERIVATION_SYSCONST);
985
995
    }
986
 
 
 
996
    LOCK_global_system_variables.unlock();
987
997
    return tmp;
988
998
  }
989
999
  case SHOW_CHAR:
990
1000
  {
991
1001
    Item *tmp;
992
 
    boost::mutex::scoped_lock scopedLock(session->catalog().systemVariableLock());
 
1002
    LOCK_global_system_variables.lock();
993
1003
    char *str= (char*) value_ptr(session, var_type, base);
994
1004
    if (str)
995
1005
      tmp= new Item_string(str, strlen(str),
999
1009
      tmp= new Item_null();
1000
1010
      tmp->collation.set(system_charset_info, DERIVATION_SYSCONST);
1001
1011
    }
1002
 
 
 
1012
    LOCK_global_system_variables.unlock();
1003
1013
    return tmp;
1004
1014
  }
1005
1015
  default:
1012
1022
bool sys_var_session_enum::update(Session *session, set_var *var)
1013
1023
{
1014
1024
  if (var->type == OPT_GLOBAL)
1015
 
    global_system_variables.*offset= var->getInteger();
 
1025
    global_system_variables.*offset= var->save_result.uint32_t_value;
1016
1026
  else
1017
 
    session->variables.*offset= var->getInteger();
 
1027
    session->variables.*offset= var->save_result.uint32_t_value;
1018
1028
  return 0;
1019
1029
}
1020
1030
 
1064
1074
}
1065
1075
 
1066
1076
 
1067
 
bool sys_var_collation_sv::update(Session *session, set_var *var)
 
1077
typedef struct old_names_map_st
 
1078
{
 
1079
  const char *old_name;
 
1080
  const char *new_name;
 
1081
} my_old_conv;
 
1082
 
 
1083
bool sys_var_collation::check(Session *, set_var *var)
1068
1084
{
1069
1085
  const CHARSET_INFO *tmp;
1070
1086
 
1074
1090
    String str(buff,sizeof(buff), system_charset_info), *res;
1075
1091
    if (!(res=var->value->val_str(&str)))
1076
1092
    {
1077
 
      boost::throw_exception(invalid_option_value(var->var->getName()) << invalid_value(std::string("NULL")));
 
1093
      my_error(ER_WRONG_VALUE_FOR_VAR, MYF(0), name.c_str(), "NULL");
1078
1094
      return 1;
1079
1095
    }
1080
1096
    if (!(tmp=get_charset_by_name(res->c_ptr())))
1081
1097
    {
1082
1098
      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
1099
      return 1;
1085
1100
    }
1086
1101
  }
1091
1106
      char buf[20];
1092
1107
      internal::int10_to_str((int) var->value->val_int(), buf, -10);
1093
1108
      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
1109
      return 1;
1096
1110
    }
1097
1111
  }
 
1112
  var->save_result.charset= tmp;        // Save for update
 
1113
  return 0;
 
1114
}
 
1115
 
 
1116
 
 
1117
bool sys_var_collation_sv::update(Session *session, set_var *var)
 
1118
{
1098
1119
  if (var->type == OPT_GLOBAL)
1099
 
    global_system_variables.*offset= tmp;
 
1120
    global_system_variables.*offset= var->save_result.charset;
1100
1121
  else
1101
1122
  {
1102
 
    session->variables.*offset= tmp;
 
1123
    session->variables.*offset= var->save_result.charset;
1103
1124
  }
1104
1125
  return 0;
1105
1126
}
1130
1151
 
1131
1152
bool sys_var_timestamp::update(Session *session,  set_var *var)
1132
1153
{
1133
 
  session->set_time(time_t(var->getInteger()));
 
1154
  session->set_time((time_t) var->save_result.uint64_t_value);
1134
1155
  return 0;
1135
1156
}
1136
1157
 
1137
1158
 
1138
1159
void sys_var_timestamp::set_default(Session *session, sql_var_t)
1139
1160
{
1140
 
  session->resetUserTime();
 
1161
  session->user_time=0;
1141
1162
}
1142
1163
 
1143
1164
 
1144
1165
unsigned char *sys_var_timestamp::value_ptr(Session *session, sql_var_t,
1145
1166
                                            const LEX_STRING *)
1146
1167
{
1147
 
  session->sys_var_tmp.int32_t_value= (int32_t) session->getCurrentTimestampEpoch();
 
1168
  session->sys_var_tmp.int32_t_value= (int32_t) session->start_time;
1148
1169
  return (unsigned char*) &session->sys_var_tmp.int32_t_value;
1149
1170
}
1150
1171
 
1151
1172
 
1152
1173
bool sys_var_last_insert_id::update(Session *session, set_var *var)
1153
1174
{
1154
 
  session->first_successful_insert_id_in_prev_stmt= var->getInteger();
 
1175
  session->first_successful_insert_id_in_prev_stmt=
 
1176
    var->save_result.uint64_t_value;
1155
1177
  return 0;
1156
1178
}
1157
1179
 
1169
1191
  return (unsigned char*) &session->sys_var_tmp.uint64_t_value;
1170
1192
}
1171
1193
 
1172
 
bool sys_var_session_lc_time_names::update(Session *session, set_var *var)
 
1194
 
 
1195
bool sys_var_session_time_zone::check(Session *session, set_var *var)
 
1196
{
 
1197
  char buff[MAX_TIME_ZONE_NAME_LENGTH];
 
1198
  String str(buff, sizeof(buff), &my_charset_utf8_general_ci);
 
1199
  String *res= var->value->val_str(&str);
 
1200
 
 
1201
  if (!(var->save_result.time_zone= my_tz_find(session, res)))
 
1202
  {
 
1203
    my_error(ER_UNKNOWN_TIME_ZONE, MYF(0), res ? res->c_ptr() : "NULL");
 
1204
    return 1;
 
1205
  }
 
1206
  return 0;
 
1207
}
 
1208
 
 
1209
 
 
1210
bool sys_var_session_time_zone::update(Session *session, set_var *var)
 
1211
{
 
1212
  /* We are using Time_zone object found during check() phase. */
 
1213
  if (var->type == OPT_GLOBAL)
 
1214
  {
 
1215
    LOCK_global_system_variables.lock();
 
1216
    global_system_variables.time_zone= var->save_result.time_zone;
 
1217
    LOCK_global_system_variables.unlock();
 
1218
  }
 
1219
  else
 
1220
    session->variables.time_zone= var->save_result.time_zone;
 
1221
  return 0;
 
1222
}
 
1223
 
 
1224
 
 
1225
unsigned char *sys_var_session_time_zone::value_ptr(Session *session,
 
1226
                                                    sql_var_t type,
 
1227
                                                    const LEX_STRING *)
 
1228
{
 
1229
  /*
 
1230
    We can use ptr() instead of c_ptr() here because String contaning
 
1231
    time zone name is guaranteed to be zero ended.
 
1232
  */
 
1233
  if (type == OPT_GLOBAL)
 
1234
    return (unsigned char *)(global_system_variables.time_zone->get_name()->ptr());
 
1235
  else
 
1236
  {
 
1237
    /*
 
1238
      This is an ugly fix for replication: we don't replicate properly queries
 
1239
      invoking system variables' values to update tables; but
 
1240
      CONVERT_TZ(,,@@session.time_zone) is so popular that we make it
 
1241
      replicable (i.e. we tell the binlog code to store the session
 
1242
      timezone). If it's the global value which was used we can't replicate
 
1243
      (binlog code stores session value only).
 
1244
    */
 
1245
    return (unsigned char *)(session->variables.time_zone->get_name()->ptr());
 
1246
  }
 
1247
}
 
1248
 
 
1249
 
 
1250
void sys_var_session_time_zone::set_default(Session *session, sql_var_t type)
 
1251
{
 
1252
 LOCK_global_system_variables.lock();
 
1253
 if (type == OPT_GLOBAL)
 
1254
 {
 
1255
   if (default_tz_name)
 
1256
   {
 
1257
     String str(default_tz_name, &my_charset_utf8_general_ci);
 
1258
     /*
 
1259
       We are guaranteed to find this time zone since its existence
 
1260
       is checked during start-up.
 
1261
     */
 
1262
     global_system_variables.time_zone= my_tz_find(session, &str);
 
1263
   }
 
1264
   else
 
1265
     global_system_variables.time_zone= my_tz_SYSTEM;
 
1266
 }
 
1267
 else
 
1268
   session->variables.time_zone= global_system_variables.time_zone;
 
1269
 LOCK_global_system_variables.unlock();
 
1270
}
 
1271
 
 
1272
 
 
1273
bool sys_var_session_lc_time_names::check(Session *, set_var *var)
1173
1274
{
1174
1275
  MY_LOCALE *locale_match;
1175
1276
 
1177
1278
  {
1178
1279
    if (!(locale_match= my_locale_by_number((uint32_t) var->value->val_int())))
1179
1280
    {
1180
 
      char buf[DECIMAL_LONGLONG_DIGITS];
 
1281
      char buf[20];
1181
1282
      internal::int10_to_str((int) var->value->val_int(), buf, -10);
1182
1283
      my_printf_error(ER_UNKNOWN_ERROR, "Unknown locale: '%s'", MYF(0), buf);
1183
1284
      return 1;
1201
1302
    }
1202
1303
  }
1203
1304
 
 
1305
  var->save_result.locale_value= locale_match;
 
1306
  return 0;
 
1307
}
 
1308
 
 
1309
 
 
1310
bool sys_var_session_lc_time_names::update(Session *session, set_var *var)
 
1311
{
1204
1312
  if (var->type == OPT_GLOBAL)
1205
 
    global_system_variables.lc_time_names= locale_match;
 
1313
    global_system_variables.lc_time_names= var->save_result.locale_value;
1206
1314
  else
1207
 
    session->variables.lc_time_names= locale_match;
 
1315
    session->variables.lc_time_names= var->save_result.locale_value;
1208
1316
  return 0;
1209
1317
}
1210
1318
 
1247
1355
  microseconds= (int64_t) (num * 1000000.0 + 0.5);
1248
1356
  if (var->type == OPT_GLOBAL)
1249
1357
  {
1250
 
    boost::mutex::scoped_lock scopedLock(session->catalog().systemVariableLock());
 
1358
    LOCK_global_system_variables.lock();
1251
1359
    (global_system_variables.*offset)= microseconds;
 
1360
    LOCK_global_system_variables.unlock();
1252
1361
  }
1253
1362
  else
1254
1363
    session->variables.*offset= microseconds;
1261
1370
  int64_t microseconds= (int64_t) (option_limits->def_value * 1000000.0);
1262
1371
  if (type == OPT_GLOBAL)
1263
1372
  {
1264
 
    boost::mutex::scoped_lock scopedLock(session->catalog().systemVariableLock());
 
1373
    LOCK_global_system_variables.lock();
1265
1374
    global_system_variables.*offset= microseconds;
 
1375
    LOCK_global_system_variables.unlock();
1266
1376
  }
1267
1377
  else
1268
1378
    session->variables.*offset= microseconds;
1275
1385
static bool set_option_bit(Session *session, set_var *var)
1276
1386
{
1277
1387
  sys_var_session_bit *sys_var= ((sys_var_session_bit*) var->var);
1278
 
  if ((var->getInteger() != 0) == sys_var->reverse)
 
1388
  if ((var->save_result.uint32_t_value != 0) == sys_var->reverse)
1279
1389
    session->options&= ~sys_var->bit_flag;
1280
1390
  else
1281
1391
    session->options|= sys_var->bit_flag;
1285
1395
 
1286
1396
static bool set_option_autocommit(Session *session, set_var *var)
1287
1397
{
1288
 
  bool success= true;
1289
1398
  /* The test is negative as the flag we use is NOT autocommit */
1290
1399
 
1291
1400
  uint64_t org_options= session->options;
1292
 
  uint64_t new_options= session->options;
1293
1401
 
1294
 
  if (var->getInteger() != 0)
1295
 
    new_options&= ~((sys_var_session_bit*) var->var)->bit_flag;
 
1402
  if (var->save_result.uint32_t_value != 0)
 
1403
    session->options&= ~((sys_var_session_bit*) var->var)->bit_flag;
1296
1404
  else
1297
 
    new_options|= ((sys_var_session_bit*) var->var)->bit_flag;
 
1405
    session->options|= ((sys_var_session_bit*) var->var)->bit_flag;
1298
1406
 
1299
 
  if ((org_options ^ new_options) & OPTION_NOT_AUTOCOMMIT)
 
1407
  if ((org_options ^ session->options) & OPTION_NOT_AUTOCOMMIT)
1300
1408
  {
1301
1409
    if ((org_options & OPTION_NOT_AUTOCOMMIT))
1302
1410
    {
1303
 
      success= session->endActiveTransaction();
1304
1411
      /* We changed to auto_commit mode */
1305
1412
      session->options&= ~(uint64_t) (OPTION_BEGIN);
1306
1413
      session->server_status|= SERVER_STATUS_AUTOCOMMIT;
 
1414
      TransactionServices &transaction_services= TransactionServices::singleton();
 
1415
      if (transaction_services.commitTransaction(session, true))
 
1416
        return 1;
1307
1417
    }
1308
1418
    else
1309
1419
    {
1310
1420
      session->server_status&= ~SERVER_STATUS_AUTOCOMMIT;
1311
1421
    }
1312
1422
  }
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
1423
  return 0;
1323
1424
}
1324
1425
 
1325
1426
static int check_pseudo_thread_id(Session *, set_var *var)
1326
1427
{
1327
 
  var->updateValue();
 
1428
  var->save_result.uint64_t_value= var->value->val_int();
1328
1429
  return 0;
1329
1430
}
1330
1431
 
1422
1523
drizzle_show_var* enumerate_sys_vars(Session *session)
1423
1524
{
1424
1525
  int size= sizeof(drizzle_show_var) * (system_variable_map.size() + 1);
1425
 
  drizzle_show_var *result= (drizzle_show_var*) session->getMemRoot()->allocate(size);
 
1526
  drizzle_show_var *result= (drizzle_show_var*) session->alloc(size);
1426
1527
 
1427
1528
  if (result)
1428
1529
  {
1456
1557
  /* this fails if there is a conflicting variable name. */
1457
1558
  if (system_variable_map.find(lower_name) != system_variable_map.end())
1458
1559
  {
1459
 
    errmsg_printf(error::ERROR, _("Variable named %s already exists!\n"),
 
1560
    errmsg_printf(ERRMSG_LVL_ERROR, _("Variable named %s already exists!\n"),
1460
1561
                  var->getName().c_str());
1461
1562
    throw exception();
1462
1563
  } 
1465
1566
    system_variable_map.insert(make_pair(lower_name, var));
1466
1567
  if (ret.second == false)
1467
1568
  {
1468
 
    errmsg_printf(error::ERROR, _("Could not add Variable: %s\n"),
 
1569
    errmsg_printf(ERRMSG_LVL_ERROR, _("Could not add Variable: %s\n"),
1469
1570
                  var->getName().c_str());
1470
1571
    throw exception();
1471
1572
  }
1498
1599
    add_sys_var_to_list(&sys_back_log, my_long_options);
1499
1600
    add_sys_var_to_list(&sys_basedir, my_long_options);
1500
1601
    add_sys_var_to_list(&sys_big_selects, my_long_options);
1501
 
    add_sys_var_to_list(&sys_branch, my_long_options);
1502
1602
    add_sys_var_to_list(&sys_buffer_results, my_long_options);
1503
1603
    add_sys_var_to_list(&sys_bulk_insert_buff_size, my_long_options);
1504
1604
    add_sys_var_to_list(&sys_collation_server, my_long_options);
1514
1614
    add_sys_var_to_list(&sys_last_insert_id, my_long_options);
1515
1615
    add_sys_var_to_list(&sys_lc_time_names, my_long_options);
1516
1616
    add_sys_var_to_list(&sys_max_allowed_packet, my_long_options);
 
1617
    add_sys_var_to_list(&sys_max_connect_errors, my_long_options);
1517
1618
    add_sys_var_to_list(&sys_max_error_count, my_long_options);
1518
1619
    add_sys_var_to_list(&sys_max_heap_table_size, my_long_options);
1519
1620
    add_sys_var_to_list(&sys_max_join_size, my_long_options);
1533
1634
    add_sys_var_to_list(&sys_range_alloc_block_size, my_long_options);
1534
1635
    add_sys_var_to_list(&sys_read_buff_size, my_long_options);
1535
1636
    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
1637
    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
1638
    add_sys_var_to_list(&sys_scheduler, my_long_options);
1541
1639
    add_sys_var_to_list(&sys_secure_file_priv, my_long_options);
1542
1640
    add_sys_var_to_list(&sys_select_limit, my_long_options);
1545
1643
    add_sys_var_to_list(&sys_sql_notes, my_long_options);
1546
1644
    add_sys_var_to_list(&sys_sql_warnings, my_long_options);
1547
1645
    add_sys_var_to_list(&sys_storage_engine, my_long_options);
 
1646
    add_sys_var_to_list(&sys_system_time_zone, my_long_options);
1548
1647
    add_sys_var_to_list(&sys_table_cache_size, my_long_options);
1549
1648
    add_sys_var_to_list(&sys_table_def_size, my_long_options);
1550
1649
    add_sys_var_to_list(&sys_table_lock_wait_timeout, my_long_options);
1551
1650
    add_sys_var_to_list(&sys_thread_stack_size, my_long_options);
 
1651
    add_sys_var_to_list(&sys_time_zone, my_long_options);
1552
1652
    add_sys_var_to_list(&sys_timed_mutexes, my_long_options);
1553
1653
    add_sys_var_to_list(&sys_timestamp, my_long_options);
1554
1654
    add_sys_var_to_list(&sys_tmp_table_size, my_long_options);
1565
1665
  }
1566
1666
  catch (std::exception&)
1567
1667
  {
1568
 
    errmsg_printf(error::ERROR, _("Failed to initialize system variables"));
 
1668
    errmsg_printf(ERRMSG_LVL_ERROR, _("Failed to initialize system variables"));
1569
1669
    return(1);
1570
1670
  }
1571
1671
  return(0);
1575
1675
/**
1576
1676
  Find a user set-table variable.
1577
1677
 
1578
 
  @param name      Name of system variable to find
 
1678
  @param str       Name of system variable to find
 
1679
  @param length    Length of variable.  zero means that we should use strlen()
 
1680
                   on the variable
 
1681
  @param no_error  Refuse to emit an error, even if one occurred.
1579
1682
 
1580
1683
  @retval
1581
1684
    pointer     pointer to variable definitions
1583
1686
    0           Unknown variable (error message is given)
1584
1687
*/
1585
1688
 
1586
 
sys_var *find_sys_var(const std::string &name)
 
1689
sys_var *intern_find_sys_var(const char *str, uint32_t, bool no_error)
1587
1690
{
1588
 
  string lower_name(name);
 
1691
  string lower_name(str);
1589
1692
  transform(lower_name.begin(), lower_name.end(),
1590
1693
            lower_name.begin(), ::tolower);
1591
1694
 
1597
1700
    result= (*iter).second;
1598
1701
  } 
1599
1702
 
 
1703
  /*
 
1704
    This function is only called from the sql_plugin.cc.
 
1705
    A lock on LOCK_system_variable_hash should be held
 
1706
  */
1600
1707
  if (result == NULL)
1601
1708
  {
1602
 
    my_error(ER_UNKNOWN_SYSTEM_VARIABLE, MYF(0), name.c_str());
1603
 
    return NULL;
 
1709
    if (no_error)
 
1710
    {
 
1711
      return NULL;
 
1712
    }
 
1713
    else
 
1714
    {
 
1715
      my_error(ER_UNKNOWN_SYSTEM_VARIABLE, MYF(0), (char*) str);
 
1716
      return NULL;
 
1717
    }
1604
1718
  }
1605
1719
 
1606
1720
  return result;
1611
1725
 Functions to handle table_type
1612
1726
****************************************************************************/
1613
1727
 
 
1728
/* Based upon sys_var::check_enum() */
 
1729
 
 
1730
bool sys_var_session_storage_engine::check(Session *session, set_var *var)
 
1731
{
 
1732
  char buff[STRING_BUFFER_USUAL_SIZE];
 
1733
  const char *value;
 
1734
  String str(buff, sizeof(buff), &my_charset_utf8_general_ci), *res;
 
1735
 
 
1736
  var->save_result.storage_engine= NULL;
 
1737
  if (var->value->result_type() == STRING_RESULT)
 
1738
  {
 
1739
    res= var->value->val_str(&str);
 
1740
    if (res == NULL || res->ptr() == NULL)
 
1741
    {
 
1742
      value= "NULL";
 
1743
      goto err;
 
1744
    }
 
1745
    else
 
1746
    {
 
1747
      const std::string engine_name(res->ptr());
 
1748
      plugin::StorageEngine *engine;
 
1749
      var->save_result.storage_engine= plugin::StorageEngine::findByName(*session, engine_name);
 
1750
      if (var->save_result.storage_engine == NULL)
 
1751
      {
 
1752
        value= res->c_ptr();
 
1753
        goto err;
 
1754
      }
 
1755
      engine= var->save_result.storage_engine;
 
1756
    }
 
1757
    return 0;
 
1758
  }
 
1759
  value= "unknown";
 
1760
 
 
1761
err:
 
1762
  my_error(ER_UNKNOWN_STORAGE_ENGINE, MYF(0), value);
 
1763
  return 1;
 
1764
}
 
1765
 
 
1766
 
1614
1767
unsigned char *sys_var_session_storage_engine::value_ptr(Session *session,
1615
1768
                                                         sql_var_t type,
1616
1769
                                                         const LEX_STRING *)
1648
1801
 
1649
1802
bool sys_var_session_storage_engine::update(Session *session, set_var *var)
1650
1803
{
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);
 
1804
  plugin::StorageEngine **value= &(global_system_variables.*offset), *old_value;
1683
1805
   if (var->type != OPT_GLOBAL)
1684
1806
     value= &(session->variables.*offset);
1685
 
  if (*value != tmp)
 
1807
  old_value= *value;
 
1808
  if (old_value != var->save_result.storage_engine)
1686
1809
  {
1687
 
    *value= tmp;
 
1810
    *value= var->save_result.storage_engine;
1688
1811
  }
1689
1812
  return 0;
1690
 
err:
1691
 
  my_error(ER_UNKNOWN_STORAGE_ENGINE, MYF(0), name_value);
1692
 
  return 1;
1693
1813
}
1694
1814
 
1695
1815
} /* namespace drizzled */