~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/sys_var.cc

Namespace the parser just a bit, and update our call for the type of parser
we want.

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).
44
39
*/
45
40
 
46
41
#include "config.h"
65
60
#include "drizzled/charset.h"
66
61
#include "drizzled/transaction_services.h"
67
62
#include "drizzled/constrained_value.h"
 
63
#include "drizzled/visibility.h"
 
64
#include "drizzled/plugin/storage_engine.h"
68
65
 
69
66
#include <cstdio>
70
67
#include <map>
110
107
static void fix_max_join_size(Session *session, sql_var_t type);
111
108
static void fix_session_mem_root(Session *session, sql_var_t type);
112
109
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);
115
110
bool throw_bounds_warning(Session *session, bool fixed, bool unsignd,
116
111
                          const std::string &name, int64_t val);
117
112
static unsigned char *get_error_count(Session *session);
156
151
                                                     &drizzle_system_variables::join_buff_size);
157
152
static sys_var_session_uint32_t sys_max_allowed_packet("max_allowed_packet",
158
153
                                                       &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
154
static sys_var_session_uint64_t sys_max_error_count("max_error_count",
162
155
                                                  &drizzle_system_variables::max_error_count);
163
156
static sys_var_session_uint64_t sys_max_heap_table_size("max_heap_table_size",
220
213
static sys_var_session_size_t   sys_sort_buffer("sort_buffer_size",
221
214
                                                &drizzle_system_variables::sortbuff_size);
222
215
 
223
 
static sys_var_session_size_t sys_transaction_message_threshold("transaction_message_threshold",
224
 
                                                                &drizzle_system_variables::transaction_message_threshold);
 
216
static sys_var_size_t_ptr_readonly sys_transaction_message_threshold("transaction_message_threshold",
 
217
                                                                &transaction_message_threshold);
225
218
 
226
219
static sys_var_session_storage_engine sys_storage_engine("storage_engine",
227
220
                                       &drizzle_system_variables::storage_engine);
329
322
      my_error(ER_WRONG_VALUE_FOR_VAR, MYF(0), getName().c_str(), var->value->str_value.ptr());
330
323
    return res;
331
324
  }
332
 
  var->save_result.uint64_t_value= var->value->val_int();
 
325
  var->updateValue();
333
326
  return 0;
334
327
}
335
328
 
439
432
{
440
433
  if (fixed)
441
434
  {
442
 
    char buf[22];
 
435
    char buf[DECIMAL_LONGLONG_DIGITS];
443
436
 
444
437
    if (unsignd)
445
438
      internal::ullstr((uint64_t) val, buf);
474
467
  return out;
475
468
}
476
469
 
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
 
 
518
470
bool sys_var_uint32_t_ptr::check(Session *, set_var *var)
519
471
{
520
 
  var->save_result.uint32_t_value= (uint32_t)var->value->val_int();
 
472
  var->updateValue();
521
473
  return 0;
522
474
}
523
475
 
524
476
bool sys_var_uint32_t_ptr::update(Session *session, set_var *var)
525
477
{
526
 
  uint32_t tmp= var->save_result.uint32_t_value;
527
 
  LOCK_global_system_variables.lock();
 
478
  uint64_t tmp= var->getInteger();
 
479
  boost::mutex::scoped_lock scopedLock(session->catalog().systemVariableLock());
 
480
 
528
481
  if (option_limits)
529
482
  {
530
483
    uint32_t newvalue= (uint32_t) fix_unsigned(session, tmp, option_limits);
531
 
    if(newvalue==tmp)
 
484
    if(static_cast<uint64_t>(newvalue) == tmp)
532
485
      *value= newvalue;
533
486
  }
534
487
  else
535
 
    *value= (uint32_t) tmp;
536
 
  LOCK_global_system_variables.unlock();
 
488
  {
 
489
    *value= static_cast<uint32_t>(tmp);
 
490
  }
 
491
 
537
492
  return 0;
538
493
}
539
494
 
540
495
 
541
 
void sys_var_uint32_t_ptr::set_default(Session *, sql_var_t)
 
496
void sys_var_uint32_t_ptr::set_default(Session *session, sql_var_t)
542
497
{
543
498
  bool not_used;
544
 
  LOCK_global_system_variables.lock();
 
499
  boost::mutex::scoped_lock scopedLock(session->catalog().systemVariableLock());
545
500
  *value= (uint32_t)getopt_ull_limit_value((uint32_t) option_limits->def_value,
546
501
                                           option_limits, &not_used);
547
 
  LOCK_global_system_variables.unlock();
548
502
}
549
503
 
550
504
 
551
505
bool sys_var_uint64_t_ptr::update(Session *session, set_var *var)
552
506
{
553
 
  uint64_t tmp= var->save_result.uint64_t_value;
554
 
  LOCK_global_system_variables.lock();
 
507
  uint64_t tmp= var->getInteger();
 
508
  boost::mutex::scoped_lock scopedLock(session->catalog().systemVariableLock());
 
509
 
555
510
  if (option_limits)
556
511
  {
557
 
    uint64_t newvalue= (uint64_t) fix_unsigned(session, tmp, option_limits);
 
512
    uint64_t newvalue= fix_unsigned(session, tmp, option_limits);
558
513
    if(newvalue==tmp)
559
514
      *value= newvalue;
560
515
  }
561
516
  else
562
 
    *value= (uint64_t) tmp;
563
 
  LOCK_global_system_variables.unlock();
 
517
  {
 
518
    *value= tmp;
 
519
  }
 
520
 
564
521
  return 0;
565
522
}
566
523
 
567
524
 
568
 
void sys_var_uint64_t_ptr::set_default(Session *, sql_var_t)
 
525
void sys_var_uint64_t_ptr::set_default(Session *session, sql_var_t)
569
526
{
570
527
  if (have_default_value)
571
528
  {
574
531
  else
575
532
  {
576
533
    bool not_used;
577
 
    LOCK_global_system_variables.lock();
 
534
    boost::mutex::scoped_lock scopedLock(session->catalog().systemVariableLock());
578
535
    *value= getopt_ull_limit_value((uint64_t) option_limits->def_value,
579
536
                                   option_limits, &not_used);
580
 
    LOCK_global_system_variables.unlock();
581
537
  }
582
538
}
583
539
 
584
540
 
585
541
bool sys_var_size_t_ptr::update(Session *session, set_var *var)
586
542
{
587
 
  size_t tmp= var->save_result.size_t_value;
588
 
  LOCK_global_system_variables.lock();
 
543
  size_t tmp= size_t(var->getInteger());
 
544
 
 
545
  boost::mutex::scoped_lock scopedLock(session->catalog().systemVariableLock());
 
546
 
589
547
  if (option_limits)
590
548
    *value= fix_size_t(session, tmp, option_limits);
591
549
  else
592
550
    *value= tmp;
593
 
  LOCK_global_system_variables.unlock();
 
551
 
594
552
  return 0;
595
553
}
596
554
 
597
555
 
598
 
void sys_var_size_t_ptr::set_default(Session *, sql_var_t)
 
556
void sys_var_size_t_ptr::set_default(Session *session, sql_var_t)
599
557
{
600
558
  bool not_used;
601
 
  LOCK_global_system_variables.lock();
 
559
  boost::mutex::scoped_lock scopedLock(session->catalog().systemVariableLock());
602
560
  *value= (size_t)getopt_ull_limit_value((size_t) option_limits->def_value,
603
561
                                         option_limits, &not_used);
604
 
  LOCK_global_system_variables.unlock();
 
562
}
 
563
 
 
564
bool sys_var_bool_ptr::check(Session *session, set_var *var)
 
565
{
 
566
  return check_enum(session, var, &bool_typelib);
605
567
}
606
568
 
607
569
bool sys_var_bool_ptr::update(Session *, set_var *var)
608
570
{
609
 
  *value= (bool) var->save_result.uint32_t_value;
 
571
  *value= bool(var->getInteger());
610
572
  return 0;
611
573
}
612
574
 
622
584
*/
623
585
bool sys_var_session_uint32_t::check(Session *session, set_var *var)
624
586
{
625
 
  return (get_unsigned32(session, var) ||
626
 
          (check_func && (*check_func)(session, var)));
 
587
  var->updateValue();
 
588
  return (check_func && (*check_func)(session, var));
627
589
}
628
590
 
629
591
bool sys_var_session_uint32_t::update(Session *session, set_var *var)
630
592
{
631
 
  uint64_t tmp= (uint64_t) var->save_result.uint32_t_value;
 
593
  uint64_t tmp= var->getInteger();
632
594
 
633
595
  /* Don't use bigger value than given with --maximum-variable-name=.. */
634
596
  if ((uint32_t) tmp > max_system_variables.*offset)
642
604
  else if (tmp > UINT32_MAX)
643
605
  {
644
606
    tmp= UINT32_MAX;
645
 
    throw_bounds_warning(session, true, true, getName(), (int64_t) var->save_result.uint64_t_value);
 
607
    throw_bounds_warning(session, true, true, getName(), int64_t(var->getInteger()));
646
608
  }
647
609
 
648
610
  if (var->type == OPT_GLOBAL)
681
643
 
682
644
bool sys_var_session_ha_rows::update(Session *session, set_var *var)
683
645
{
684
 
  uint64_t tmp= var->save_result.uint64_t_value;
 
646
  uint64_t tmp= var->getInteger();
685
647
 
686
648
  /* Don't use bigger value than given with --maximum-variable-name=.. */
687
649
  if ((ha_rows) tmp > max_system_variables.*offset)
692
654
  if (var->type == OPT_GLOBAL)
693
655
  {
694
656
    /* Lock is needed to make things safe on 32 bit systems */
695
 
    LOCK_global_system_variables.lock();
 
657
    boost::mutex::scoped_lock scopedLock(session->catalog().systemVariableLock());
696
658
    global_system_variables.*offset= (ha_rows) tmp;
697
 
    LOCK_global_system_variables.unlock();
698
659
  }
699
660
  else
 
661
  {
700
662
    session->variables.*offset= (ha_rows) tmp;
 
663
  }
 
664
 
701
665
  return 0;
702
666
}
703
667
 
708
672
  {
709
673
    bool not_used;
710
674
    /* We will not come here if option_limits is not set */
711
 
    LOCK_global_system_variables.lock();
 
675
    boost::mutex::scoped_lock scopedLock(session->catalog().systemVariableLock());
712
676
    global_system_variables.*offset=
713
677
      (ha_rows) getopt_ull_limit_value((ha_rows) option_limits->def_value,
714
678
                                       option_limits, &not_used);
715
 
    LOCK_global_system_variables.unlock();
716
679
  }
717
680
  else
 
681
  {
718
682
    session->variables.*offset= global_system_variables.*offset;
 
683
  }
719
684
}
720
685
 
721
686
 
730
695
 
731
696
bool sys_var_session_uint64_t::check(Session *session, set_var *var)
732
697
{
733
 
  return (get_unsigned64(session, var) ||
734
 
          (check_func && (*check_func)(session, var)));
 
698
  var->updateValue();
 
699
  return (check_func && (*check_func)(session, var));
735
700
}
736
701
 
737
702
bool sys_var_session_uint64_t::update(Session *session,  set_var *var)
738
703
{
739
 
  uint64_t tmp= var->save_result.uint64_t_value;
 
704
  uint64_t tmp= var->getInteger();
740
705
 
741
706
  if (tmp > max_system_variables.*offset)
742
707
  {
749
714
  if (var->type == OPT_GLOBAL)
750
715
  {
751
716
    /* Lock is needed to make things safe on 32 bit systems */
752
 
    LOCK_global_system_variables.lock();
 
717
    boost::mutex::scoped_lock scopedLock(session->catalog().systemVariableLock());
753
718
    global_system_variables.*offset= (uint64_t) tmp;
754
 
    LOCK_global_system_variables.unlock();
755
719
  }
756
720
  else
 
721
  {
757
722
    session->variables.*offset= (uint64_t) tmp;
 
723
  }
 
724
 
758
725
  return 0;
759
726
}
760
727
 
764
731
  if (type == OPT_GLOBAL)
765
732
  {
766
733
    bool not_used;
767
 
    LOCK_global_system_variables.lock();
 
734
    boost::mutex::scoped_lock scopedLock(session->catalog().systemVariableLock());
768
735
    global_system_variables.*offset=
769
736
      getopt_ull_limit_value((uint64_t) option_limits->def_value,
770
737
                             option_limits, &not_used);
771
 
    LOCK_global_system_variables.unlock();
772
738
  }
773
739
  else
 
740
  {
774
741
    session->variables.*offset= global_system_variables.*offset;
 
742
  }
775
743
}
776
744
 
777
745
 
786
754
 
787
755
bool sys_var_session_size_t::check(Session *session, set_var *var)
788
756
{
789
 
  return (get_size_t(session, var) ||
790
 
          (check_func && (*check_func)(session, var)));
 
757
  var->updateValue();
 
758
  return (check_func && (*check_func)(session, var));
791
759
}
792
760
 
793
761
bool sys_var_session_size_t::update(Session *session,  set_var *var)
794
762
{
795
 
  size_t tmp= var->save_result.size_t_value;
 
763
  size_t tmp= size_t(var->getInteger());
796
764
 
797
765
  if (tmp > max_system_variables.*offset)
798
766
    tmp= max_system_variables.*offset;
802
770
  if (var->type == OPT_GLOBAL)
803
771
  {
804
772
    /* Lock is needed to make things safe on 32 bit systems */
805
 
    LOCK_global_system_variables.lock();
 
773
    boost::mutex::scoped_lock scopedLock(session->catalog().systemVariableLock());
806
774
    global_system_variables.*offset= tmp;
807
 
    LOCK_global_system_variables.unlock();
808
775
  }
809
776
  else
 
777
  {
810
778
    session->variables.*offset= tmp;
 
779
  }
 
780
 
811
781
  return 0;
812
782
}
813
783
 
817
787
  if (type == OPT_GLOBAL)
818
788
  {
819
789
    bool not_used;
820
 
    LOCK_global_system_variables.lock();
 
790
    boost::mutex::scoped_lock scopedLock(session->catalog().systemVariableLock());
821
791
    global_system_variables.*offset=
822
792
      (size_t)getopt_ull_limit_value((size_t) option_limits->def_value,
823
793
                                     option_limits, &not_used);
824
 
    LOCK_global_system_variables.unlock();
825
794
  }
826
795
  else
 
796
  {
827
797
    session->variables.*offset= global_system_variables.*offset;
 
798
  }
828
799
}
829
800
 
830
801
 
837
808
  return (unsigned char*) &(session->variables.*offset);
838
809
}
839
810
 
 
811
bool sys_var_session_bool::check(Session *session, set_var *var)
 
812
{
 
813
  return check_enum(session, var, &bool_typelib);
 
814
}
840
815
 
841
816
bool sys_var_session_bool::update(Session *session,  set_var *var)
842
817
{
843
818
  if (var->type == OPT_GLOBAL)
844
 
    global_system_variables.*offset= (bool) var->save_result.uint32_t_value;
 
819
    global_system_variables.*offset= bool(var->getInteger());
845
820
  else
846
 
    session->variables.*offset= (bool) var->save_result.uint32_t_value;
 
821
    session->variables.*offset= bool(var->getInteger());
 
822
 
847
823
  return 0;
848
824
}
849
825
 
876
852
 
877
853
  if (var->value->result_type() == STRING_RESULT)
878
854
  {
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)
 
855
    res= var->value->val_str(&str);
 
856
    if (res == NULL)
882
857
    {
883
 
      value= res ? res->c_ptr() : "NULL";
 
858
      value= "NULL";
884
859
      goto err;
885
860
    }
886
861
 
887
 
    var->save_result.uint32_t_value--;
 
862
    uint64_t tmp_val= find_type(enum_names, res->ptr(), res->length(),1);
 
863
    if (tmp_val == 0)
 
864
    {
 
865
      value= res->c_ptr();
 
866
      goto err;
 
867
    }
 
868
    var->setValue(tmp_val-1);
888
869
  }
889
870
  else
890
871
  {
891
 
    uint64_t tmp=var->value->val_int();
 
872
    uint64_t tmp= var->value->val_int();
892
873
    if (tmp >= enum_names->count)
893
874
    {
894
875
      internal::llstr(tmp,buff);
895
876
      value=buff;                               // Wrong value is here
896
877
      goto err;
897
878
    }
898
 
    var->save_result.uint32_t_value= (uint32_t) tmp;    // Save for update
 
879
    var->setValue(tmp); // Save for update
899
880
  }
900
881
  return 0;
901
882
 
931
912
  case SHOW_INT:
932
913
  {
933
914
    uint32_t value;
934
 
    LOCK_global_system_variables.lock();
 
915
    boost::mutex::scoped_lock scopedLock(session->catalog().systemVariableLock());
935
916
    value= *(uint*) value_ptr(session, var_type, base);
936
 
    LOCK_global_system_variables.unlock();
 
917
 
937
918
    return new Item_uint((uint64_t) value);
938
919
  }
939
920
  case SHOW_LONGLONG:
940
921
  {
941
922
    int64_t value;
942
 
    LOCK_global_system_variables.lock();
 
923
    boost::mutex::scoped_lock scopedLock(session->catalog().systemVariableLock());
943
924
    value= *(int64_t*) value_ptr(session, var_type, base);
944
 
    LOCK_global_system_variables.unlock();
 
925
 
945
926
    return new Item_int(value);
946
927
  }
947
928
  case SHOW_DOUBLE:
948
929
  {
949
930
    double value;
950
 
    LOCK_global_system_variables.lock();
951
 
    value= *(double*) value_ptr(session, var_type, base);
952
 
    LOCK_global_system_variables.unlock();
 
931
    {
 
932
      boost::mutex::scoped_lock scopedLock(session->catalog().systemVariableLock());
 
933
      value= *(double*) value_ptr(session, var_type, base);
 
934
    }
 
935
 
953
936
    /* 6, as this is for now only used with microseconds */
954
937
    return new Item_float(value, 6);
955
938
  }
956
939
  case SHOW_HA_ROWS:
957
940
  {
958
941
    ha_rows value;
959
 
    LOCK_global_system_variables.lock();
 
942
    boost::mutex::scoped_lock scopedLock(session->catalog().systemVariableLock());
960
943
    value= *(ha_rows*) value_ptr(session, var_type, base);
961
 
    LOCK_global_system_variables.unlock();
 
944
 
962
945
    return new Item_int((uint64_t) value);
963
946
  }
964
947
  case SHOW_SIZE:
965
948
  {
966
949
    size_t value;
967
 
    LOCK_global_system_variables.lock();
 
950
    boost::mutex::scoped_lock scopedLock(session->catalog().systemVariableLock());
968
951
    value= *(size_t*) value_ptr(session, var_type, base);
969
 
    LOCK_global_system_variables.unlock();
 
952
 
970
953
    return new Item_int((uint64_t) value);
971
954
  }
972
955
  case SHOW_MY_BOOL:
973
956
  {
974
957
    int32_t value;
975
 
    LOCK_global_system_variables.lock();
 
958
    boost::mutex::scoped_lock scopedLock(session->catalog().systemVariableLock());
976
959
    value= *(bool*) value_ptr(session, var_type, base);
977
 
    LOCK_global_system_variables.unlock();
978
960
    return new Item_int(value,1);
979
961
  }
980
962
  case SHOW_CHAR_PTR:
981
963
  {
982
964
    Item *tmp;
983
 
    LOCK_global_system_variables.lock();
 
965
    boost::mutex::scoped_lock scopedLock(session->catalog().systemVariableLock());
984
966
    char *str= *(char**) value_ptr(session, var_type, base);
985
967
    if (str)
986
968
    {
993
975
      tmp= new Item_null();
994
976
      tmp->collation.set(system_charset_info, DERIVATION_SYSCONST);
995
977
    }
996
 
    LOCK_global_system_variables.unlock();
 
978
 
997
979
    return tmp;
998
980
  }
999
981
  case SHOW_CHAR:
1000
982
  {
1001
983
    Item *tmp;
1002
 
    LOCK_global_system_variables.lock();
 
984
    boost::mutex::scoped_lock scopedLock(session->catalog().systemVariableLock());
1003
985
    char *str= (char*) value_ptr(session, var_type, base);
1004
986
    if (str)
1005
987
      tmp= new Item_string(str, strlen(str),
1009
991
      tmp= new Item_null();
1010
992
      tmp->collation.set(system_charset_info, DERIVATION_SYSCONST);
1011
993
    }
1012
 
    LOCK_global_system_variables.unlock();
 
994
 
1013
995
    return tmp;
1014
996
  }
1015
997
  default:
1022
1004
bool sys_var_session_enum::update(Session *session, set_var *var)
1023
1005
{
1024
1006
  if (var->type == OPT_GLOBAL)
1025
 
    global_system_variables.*offset= var->save_result.uint32_t_value;
 
1007
    global_system_variables.*offset= var->getInteger();
1026
1008
  else
1027
 
    session->variables.*offset= var->save_result.uint32_t_value;
 
1009
    session->variables.*offset= var->getInteger();
1028
1010
  return 0;
1029
1011
}
1030
1012
 
1074
1056
}
1075
1057
 
1076
1058
 
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)
 
1059
bool sys_var_collation_sv::update(Session *session, set_var *var)
1084
1060
{
1085
1061
  const CHARSET_INFO *tmp;
1086
1062
 
1090
1066
    String str(buff,sizeof(buff), system_charset_info), *res;
1091
1067
    if (!(res=var->value->val_str(&str)))
1092
1068
    {
1093
 
      my_error(ER_WRONG_VALUE_FOR_VAR, MYF(0), name.c_str(), "NULL");
 
1069
      boost::throw_exception(invalid_option_value(var->var->getName()) << invalid_value(std::string("NULL")));
1094
1070
      return 1;
1095
1071
    }
1096
1072
    if (!(tmp=get_charset_by_name(res->c_ptr())))
1097
1073
    {
1098
1074
      my_error(ER_UNKNOWN_COLLATION, MYF(0), res->c_ptr());
 
1075
      boost::throw_exception(invalid_option_value(var->var->getName()) << invalid_value(std::string(res->c_ptr())));
1099
1076
      return 1;
1100
1077
    }
1101
1078
  }
1106
1083
      char buf[20];
1107
1084
      internal::int10_to_str((int) var->value->val_int(), buf, -10);
1108
1085
      my_error(ER_UNKNOWN_COLLATION, MYF(0), buf);
 
1086
      boost::throw_exception(invalid_option_value(var->var->getName()) << invalid_value(boost::lexical_cast<std::string>(var->value->val_int())));
1109
1087
      return 1;
1110
1088
    }
1111
1089
  }
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
 
{
1119
1090
  if (var->type == OPT_GLOBAL)
1120
 
    global_system_variables.*offset= var->save_result.charset;
 
1091
    global_system_variables.*offset= tmp;
1121
1092
  else
1122
1093
  {
1123
 
    session->variables.*offset= var->save_result.charset;
 
1094
    session->variables.*offset= tmp;
1124
1095
  }
1125
1096
  return 0;
1126
1097
}
1151
1122
 
1152
1123
bool sys_var_timestamp::update(Session *session,  set_var *var)
1153
1124
{
1154
 
  session->set_time((time_t) var->save_result.uint64_t_value);
 
1125
  session->set_time(time_t(var->getInteger()));
1155
1126
  return 0;
1156
1127
}
1157
1128
 
1158
1129
 
1159
1130
void sys_var_timestamp::set_default(Session *session, sql_var_t)
1160
1131
{
1161
 
  session->user_time=0;
 
1132
  session->resetUserTime();
1162
1133
}
1163
1134
 
1164
1135
 
1165
1136
unsigned char *sys_var_timestamp::value_ptr(Session *session, sql_var_t,
1166
1137
                                            const LEX_STRING *)
1167
1138
{
1168
 
  session->sys_var_tmp.int32_t_value= (int32_t) session->start_time;
 
1139
  session->sys_var_tmp.int32_t_value= (int32_t) session->getCurrentTimestampEpoch();
1169
1140
  return (unsigned char*) &session->sys_var_tmp.int32_t_value;
1170
1141
}
1171
1142
 
1172
1143
 
1173
1144
bool sys_var_last_insert_id::update(Session *session, set_var *var)
1174
1145
{
1175
 
  session->first_successful_insert_id_in_prev_stmt=
1176
 
    var->save_result.uint64_t_value;
 
1146
  session->first_successful_insert_id_in_prev_stmt= var->getInteger();
1177
1147
  return 0;
1178
1148
}
1179
1149
 
1192
1162
}
1193
1163
 
1194
1164
 
1195
 
bool sys_var_session_time_zone::check(Session *session, set_var *var)
 
1165
bool sys_var_session_time_zone::update(Session *session, set_var *var)
1196
1166
{
1197
1167
  char buff[MAX_TIME_ZONE_NAME_LENGTH];
1198
1168
  String str(buff, sizeof(buff), &my_charset_utf8_general_ci);
1199
1169
  String *res= var->value->val_str(&str);
1200
1170
 
1201
 
  if (!(var->save_result.time_zone= my_tz_find(session, res)))
 
1171
  Time_zone *tmp= my_tz_find(session, res);
 
1172
  if (tmp == NULL)
1202
1173
  {
1203
 
    my_error(ER_UNKNOWN_TIME_ZONE, MYF(0), res ? res->c_ptr() : "NULL");
 
1174
    boost::throw_exception(invalid_option_value(var->var->getName()) << invalid_value(std::string(res ? res->c_ptr() : "NULL")));
1204
1175
    return 1;
1205
1176
  }
1206
 
  return 0;
1207
 
}
1208
 
 
1209
 
 
1210
 
bool sys_var_session_time_zone::update(Session *session, set_var *var)
1211
 
{
1212
1177
  /* We are using Time_zone object found during check() phase. */
1213
1178
  if (var->type == OPT_GLOBAL)
1214
1179
  {
1215
 
    LOCK_global_system_variables.lock();
1216
 
    global_system_variables.time_zone= var->save_result.time_zone;
1217
 
    LOCK_global_system_variables.unlock();
 
1180
    boost::mutex::scoped_lock scopedLock(session->catalog().systemVariableLock());
 
1181
    global_system_variables.time_zone= tmp;
1218
1182
  }
1219
1183
  else
1220
 
    session->variables.time_zone= var->save_result.time_zone;
 
1184
  {
 
1185
    session->variables.time_zone= tmp;
 
1186
  }
 
1187
 
1221
1188
  return 0;
1222
1189
}
1223
1190
 
1249
1216
 
1250
1217
void sys_var_session_time_zone::set_default(Session *session, sql_var_t type)
1251
1218
{
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();
 
1219
  boost::mutex::scoped_lock scopedLock(session->catalog().systemVariableLock());
 
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;
1270
1236
}
1271
1237
 
1272
1238
 
1273
 
bool sys_var_session_lc_time_names::check(Session *, set_var *var)
 
1239
 
 
1240
bool sys_var_session_lc_time_names::update(Session *session, set_var *var)
1274
1241
{
1275
1242
  MY_LOCALE *locale_match;
1276
1243
 
1278
1245
  {
1279
1246
    if (!(locale_match= my_locale_by_number((uint32_t) var->value->val_int())))
1280
1247
    {
1281
 
      char buf[20];
 
1248
      char buf[DECIMAL_LONGLONG_DIGITS];
1282
1249
      internal::int10_to_str((int) var->value->val_int(), buf, -10);
1283
1250
      my_printf_error(ER_UNKNOWN_ERROR, "Unknown locale: '%s'", MYF(0), buf);
1284
1251
      return 1;
1302
1269
    }
1303
1270
  }
1304
1271
 
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
 
{
1312
1272
  if (var->type == OPT_GLOBAL)
1313
 
    global_system_variables.lc_time_names= var->save_result.locale_value;
 
1273
    global_system_variables.lc_time_names= locale_match;
1314
1274
  else
1315
 
    session->variables.lc_time_names= var->save_result.locale_value;
 
1275
    session->variables.lc_time_names= locale_match;
1316
1276
  return 0;
1317
1277
}
1318
1278
 
1355
1315
  microseconds= (int64_t) (num * 1000000.0 + 0.5);
1356
1316
  if (var->type == OPT_GLOBAL)
1357
1317
  {
1358
 
    LOCK_global_system_variables.lock();
 
1318
    boost::mutex::scoped_lock scopedLock(session->catalog().systemVariableLock());
1359
1319
    (global_system_variables.*offset)= microseconds;
1360
 
    LOCK_global_system_variables.unlock();
1361
1320
  }
1362
1321
  else
1363
1322
    session->variables.*offset= microseconds;
1370
1329
  int64_t microseconds= (int64_t) (option_limits->def_value * 1000000.0);
1371
1330
  if (type == OPT_GLOBAL)
1372
1331
  {
1373
 
    LOCK_global_system_variables.lock();
 
1332
    boost::mutex::scoped_lock scopedLock(session->catalog().systemVariableLock());
1374
1333
    global_system_variables.*offset= microseconds;
1375
 
    LOCK_global_system_variables.unlock();
1376
1334
  }
1377
1335
  else
1378
1336
    session->variables.*offset= microseconds;
1385
1343
static bool set_option_bit(Session *session, set_var *var)
1386
1344
{
1387
1345
  sys_var_session_bit *sys_var= ((sys_var_session_bit*) var->var);
1388
 
  if ((var->save_result.uint32_t_value != 0) == sys_var->reverse)
 
1346
  if ((var->getInteger() != 0) == sys_var->reverse)
1389
1347
    session->options&= ~sys_var->bit_flag;
1390
1348
  else
1391
1349
    session->options|= sys_var->bit_flag;
1395
1353
 
1396
1354
static bool set_option_autocommit(Session *session, set_var *var)
1397
1355
{
 
1356
  bool success= true;
1398
1357
  /* The test is negative as the flag we use is NOT autocommit */
1399
1358
 
1400
1359
  uint64_t org_options= session->options;
 
1360
  uint64_t new_options= session->options;
1401
1361
 
1402
 
  if (var->save_result.uint32_t_value != 0)
1403
 
    session->options&= ~((sys_var_session_bit*) var->var)->bit_flag;
 
1362
  if (var->getInteger() != 0)
 
1363
    new_options&= ~((sys_var_session_bit*) var->var)->bit_flag;
1404
1364
  else
1405
 
    session->options|= ((sys_var_session_bit*) var->var)->bit_flag;
 
1365
    new_options|= ((sys_var_session_bit*) var->var)->bit_flag;
1406
1366
 
1407
 
  if ((org_options ^ session->options) & OPTION_NOT_AUTOCOMMIT)
 
1367
  if ((org_options ^ new_options) & OPTION_NOT_AUTOCOMMIT)
1408
1368
  {
1409
1369
    if ((org_options & OPTION_NOT_AUTOCOMMIT))
1410
1370
    {
 
1371
      success= session->endActiveTransaction();
1411
1372
      /* We changed to auto_commit mode */
1412
1373
      session->options&= ~(uint64_t) (OPTION_BEGIN);
1413
1374
      session->server_status|= SERVER_STATUS_AUTOCOMMIT;
1414
 
      TransactionServices &transaction_services= TransactionServices::singleton();
1415
 
      if (transaction_services.commitTransaction(session, true))
1416
 
        return 1;
1417
1375
    }
1418
1376
    else
1419
1377
    {
1420
1378
      session->server_status&= ~SERVER_STATUS_AUTOCOMMIT;
1421
1379
    }
1422
1380
  }
 
1381
 
 
1382
  if (var->getInteger() != 0)
 
1383
    session->options&= ~((sys_var_session_bit*) var->var)->bit_flag;
 
1384
  else
 
1385
    session->options|= ((sys_var_session_bit*) var->var)->bit_flag;
 
1386
 
 
1387
  if (not success)
 
1388
    return true;
 
1389
 
1423
1390
  return 0;
1424
1391
}
1425
1392
 
1426
1393
static int check_pseudo_thread_id(Session *, set_var *var)
1427
1394
{
1428
 
  var->save_result.uint64_t_value= var->value->val_int();
 
1395
  var->updateValue();
1429
1396
  return 0;
1430
1397
}
1431
1398
 
1523
1490
drizzle_show_var* enumerate_sys_vars(Session *session)
1524
1491
{
1525
1492
  int size= sizeof(drizzle_show_var) * (system_variable_map.size() + 1);
1526
 
  drizzle_show_var *result= (drizzle_show_var*) session->alloc(size);
 
1493
  drizzle_show_var *result= (drizzle_show_var*) session->getMemRoot()->allocate(size);
1527
1494
 
1528
1495
  if (result)
1529
1496
  {
1557
1524
  /* this fails if there is a conflicting variable name. */
1558
1525
  if (system_variable_map.find(lower_name) != system_variable_map.end())
1559
1526
  {
1560
 
    errmsg_printf(ERRMSG_LVL_ERROR, _("Variable named %s already exists!\n"),
 
1527
    errmsg_printf(error::ERROR, _("Variable named %s already exists!\n"),
1561
1528
                  var->getName().c_str());
1562
1529
    throw exception();
1563
1530
  } 
1566
1533
    system_variable_map.insert(make_pair(lower_name, var));
1567
1534
  if (ret.second == false)
1568
1535
  {
1569
 
    errmsg_printf(ERRMSG_LVL_ERROR, _("Could not add Variable: %s\n"),
 
1536
    errmsg_printf(error::ERROR, _("Could not add Variable: %s\n"),
1570
1537
                  var->getName().c_str());
1571
1538
    throw exception();
1572
1539
  }
1614
1581
    add_sys_var_to_list(&sys_last_insert_id, my_long_options);
1615
1582
    add_sys_var_to_list(&sys_lc_time_names, my_long_options);
1616
1583
    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);
1618
1584
    add_sys_var_to_list(&sys_max_error_count, my_long_options);
1619
1585
    add_sys_var_to_list(&sys_max_heap_table_size, my_long_options);
1620
1586
    add_sys_var_to_list(&sys_max_join_size, my_long_options);
1665
1631
  }
1666
1632
  catch (std::exception&)
1667
1633
  {
1668
 
    errmsg_printf(ERRMSG_LVL_ERROR, _("Failed to initialize system variables"));
 
1634
    errmsg_printf(error::ERROR, _("Failed to initialize system variables"));
1669
1635
    return(1);
1670
1636
  }
1671
1637
  return(0);
1675
1641
/**
1676
1642
  Find a user set-table variable.
1677
1643
 
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.
 
1644
  @param name      Name of system variable to find
1682
1645
 
1683
1646
  @retval
1684
1647
    pointer     pointer to variable definitions
1686
1649
    0           Unknown variable (error message is given)
1687
1650
*/
1688
1651
 
1689
 
sys_var *intern_find_sys_var(const char *str, uint32_t, bool no_error)
 
1652
sys_var *find_sys_var(const std::string &name)
1690
1653
{
1691
 
  string lower_name(str);
 
1654
  string lower_name(name);
1692
1655
  transform(lower_name.begin(), lower_name.end(),
1693
1656
            lower_name.begin(), ::tolower);
1694
1657
 
1700
1663
    result= (*iter).second;
1701
1664
  } 
1702
1665
 
1703
 
  /*
1704
 
    This function is only called from the sql_plugin.cc.
1705
 
    A lock on LOCK_system_variable_hash should be held
1706
 
  */
1707
1666
  if (result == NULL)
1708
1667
  {
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
 
    }
 
1668
    my_error(ER_UNKNOWN_SYSTEM_VARIABLE, MYF(0), name.c_str());
 
1669
    return NULL;
1718
1670
  }
1719
1671
 
1720
1672
  return result;
1725
1677
 Functions to handle table_type
1726
1678
****************************************************************************/
1727
1679
 
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
 
 
1767
1680
unsigned char *sys_var_session_storage_engine::value_ptr(Session *session,
1768
1681
                                                         sql_var_t type,
1769
1682
                                                         const LEX_STRING *)
1801
1714
 
1802
1715
bool sys_var_session_storage_engine::update(Session *session, set_var *var)
1803
1716
{
1804
 
  plugin::StorageEngine **value= &(global_system_variables.*offset), *old_value;
 
1717
  char buff[STRING_BUFFER_USUAL_SIZE];
 
1718
  const char *name_value;
 
1719
  String str(buff, sizeof(buff), &my_charset_utf8_general_ci), *res;
 
1720
 
 
1721
  plugin::StorageEngine *tmp= NULL;
 
1722
  plugin::StorageEngine **value= NULL;
 
1723
    
 
1724
  if (var->value->result_type() == STRING_RESULT)
 
1725
  {
 
1726
    res= var->value->val_str(&str);
 
1727
    if (res == NULL || res->ptr() == NULL)
 
1728
    {
 
1729
      name_value= "NULL";
 
1730
      goto err;
 
1731
    }
 
1732
    else
 
1733
    {
 
1734
      const std::string engine_name(res->ptr());
 
1735
      tmp= plugin::StorageEngine::findByName(*session, engine_name);
 
1736
      if (tmp == NULL)
 
1737
      {
 
1738
        name_value= res->c_ptr();
 
1739
        goto err;
 
1740
      }
 
1741
    }
 
1742
  }
 
1743
  else
 
1744
  {
 
1745
    name_value= "unknown";
 
1746
  }
 
1747
 
 
1748
  value= &(global_system_variables.*offset);
1805
1749
   if (var->type != OPT_GLOBAL)
1806
1750
     value= &(session->variables.*offset);
1807
 
  old_value= *value;
1808
 
  if (old_value != var->save_result.storage_engine)
 
1751
  if (*value != tmp)
1809
1752
  {
1810
 
    *value= var->save_result.storage_engine;
 
1753
    *value= tmp;
1811
1754
  }
1812
1755
  return 0;
 
1756
err:
 
1757
  my_error(ER_UNKNOWN_STORAGE_ENGINE, MYF(0), name_value);
 
1758
  return 1;
1813
1759
}
1814
1760
 
1815
1761
} /* namespace drizzled */