37
37
Add full support for the variable character_set (for 4.1)
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
46
41
#include "config.h"
110
105
static void fix_max_join_size(Session *session, sql_var_t type);
111
106
static void fix_session_mem_root(Session *session, sql_var_t type);
112
107
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
108
bool throw_bounds_warning(Session *session, bool fixed, bool unsignd,
116
109
const std::string &name, int64_t val);
117
110
static unsigned char *get_error_count(Session *session);
477
static bool get_unsigned32(Session *session, set_var *var)
479
if (var->value->unsigned_flag)
480
var->save_result.uint32_t_value=
481
static_cast<uint32_t>(var->value->val_int());
484
int64_t v= var->value->val_int();
486
throw_bounds_warning(session, true, true,var->var->getName().c_str(), v);
488
var->save_result.uint32_t_value=
489
static_cast<uint32_t>((v > UINT32_MAX) ? UINT32_MAX : (v < 0) ? 0 : v);
494
static bool get_unsigned64(Session *, set_var *var)
496
if (var->value->unsigned_flag)
497
var->save_result.uint64_t_value=(uint64_t) var->value->val_int();
500
int64_t v= var->value->val_int();
501
var->save_result.uint64_t_value= (uint64_t) ((v < 0) ? 0 : v);
506
static bool get_size_t(Session *, set_var *var)
508
if (var->value->unsigned_flag)
509
var->save_result.size_t_value= (size_t) var->value->val_int();
512
ssize_t v= (ssize_t)var->value->val_int();
513
var->save_result.size_t_value= (size_t) ((v < 0) ? 0 : v);
518
470
bool sys_var_uint32_t_ptr::check(Session *, set_var *var)
520
var->save_result.uint32_t_value= (uint32_t)var->value->val_int();
524
476
bool sys_var_uint32_t_ptr::update(Session *session, set_var *var)
526
uint32_t tmp= var->save_result.uint32_t_value;
478
uint64_t tmp= var->getInteger();
527
479
LOCK_global_system_variables.lock();
528
480
if (option_limits)
530
482
uint32_t newvalue= (uint32_t) fix_unsigned(session, tmp, option_limits);
483
if(static_cast<uint64_t>(newvalue) == tmp)
532
484
*value= newvalue;
535
*value= (uint32_t) tmp;
487
*value= static_cast<uint32_t>(tmp);
536
488
LOCK_global_system_variables.unlock();
551
503
bool sys_var_uint64_t_ptr::update(Session *session, set_var *var)
553
uint64_t tmp= var->save_result.uint64_t_value;
505
uint64_t tmp= var->getInteger();
554
506
LOCK_global_system_variables.lock();
555
507
if (option_limits)
557
uint64_t newvalue= (uint64_t) fix_unsigned(session, tmp, option_limits);
509
uint64_t newvalue= fix_unsigned(session, tmp, option_limits);
558
510
if(newvalue==tmp)
559
511
*value= newvalue;
562
*value= (uint64_t) tmp;
563
515
LOCK_global_system_variables.unlock();
585
537
bool sys_var_size_t_ptr::update(Session *session, set_var *var)
587
size_t tmp= var->save_result.size_t_value;
539
size_t tmp= size_t(var->getInteger());
588
540
LOCK_global_system_variables.lock();
589
541
if (option_limits)
590
542
*value= fix_size_t(session, tmp, option_limits);
623
575
bool sys_var_session_uint32_t::check(Session *session, set_var *var)
625
return (get_unsigned32(session, var) ||
626
(check_func && (*check_func)(session, var)));
578
return (check_func && (*check_func)(session, var));
629
581
bool sys_var_session_uint32_t::update(Session *session, set_var *var)
631
uint64_t tmp= (uint64_t) var->save_result.uint32_t_value;
583
uint64_t tmp= var->getInteger();
633
585
/* Don't use bigger value than given with --maximum-variable-name=.. */
634
586
if ((uint32_t) tmp > max_system_variables.*offset)
642
594
else if (tmp > UINT32_MAX)
645
throw_bounds_warning(session, true, true, getName(), (int64_t) var->save_result.uint64_t_value);
597
throw_bounds_warning(session, true, true, getName(), int64_t(var->getInteger()));
648
600
if (var->type == OPT_GLOBAL)
682
634
bool sys_var_session_ha_rows::update(Session *session, set_var *var)
684
uint64_t tmp= var->save_result.uint64_t_value;
636
uint64_t tmp= var->getInteger();
686
638
/* Don't use bigger value than given with --maximum-variable-name=.. */
687
639
if ((ha_rows) tmp > max_system_variables.*offset)
731
683
bool sys_var_session_uint64_t::check(Session *session, set_var *var)
733
return (get_unsigned64(session, var) ||
734
(check_func && (*check_func)(session, var)));
686
return (check_func && (*check_func)(session, var));
737
689
bool sys_var_session_uint64_t::update(Session *session, set_var *var)
739
uint64_t tmp= var->save_result.uint64_t_value;
691
uint64_t tmp= var->getInteger();
741
693
if (tmp > max_system_variables.*offset)
787
739
bool sys_var_session_size_t::check(Session *session, set_var *var)
789
return (get_size_t(session, var) ||
790
(check_func && (*check_func)(session, var)));
742
return (check_func && (*check_func)(session, var));
793
745
bool sys_var_session_size_t::update(Session *session, set_var *var)
795
size_t tmp= var->save_result.size_t_value;
747
size_t tmp= size_t(var->getInteger());
797
749
if (tmp > max_system_variables.*offset)
798
750
tmp= max_system_variables.*offset;
841
793
bool sys_var_session_bool::update(Session *session, set_var *var)
843
795
if (var->type == OPT_GLOBAL)
844
global_system_variables.*offset= (bool) var->save_result.uint32_t_value;
796
global_system_variables.*offset= bool(var->getInteger());
846
session->variables.*offset= (bool) var->save_result.uint32_t_value;
798
session->variables.*offset= bool(var->getInteger());
877
829
if (var->value->result_type() == STRING_RESULT)
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)
831
res= var->value->val_str(&str);
883
value= res ? res->c_ptr() : "NULL";
887
var->save_result.uint32_t_value--;
838
uint64_t tmp_val= find_type(enum_names, res->ptr(), res->length(),1);
844
var->setValue(tmp_val-1);
891
uint64_t tmp=var->value->val_int();
848
uint64_t tmp= var->value->val_int();
892
849
if (tmp >= enum_names->count)
894
851
internal::llstr(tmp,buff);
895
852
value=buff; // Wrong value is here
898
var->save_result.uint32_t_value= (uint32_t) tmp; // Save for update
855
var->setValue(tmp); // Save for update
1022
979
bool sys_var_session_enum::update(Session *session, set_var *var)
1024
981
if (var->type == OPT_GLOBAL)
1025
global_system_variables.*offset= var->save_result.uint32_t_value;
982
global_system_variables.*offset= var->getInteger();
1027
session->variables.*offset= var->save_result.uint32_t_value;
984
session->variables.*offset= var->getInteger();
1090
1041
String str(buff,sizeof(buff), system_charset_info), *res;
1091
1042
if (!(res=var->value->val_str(&str)))
1093
my_error(ER_WRONG_VALUE_FOR_VAR, MYF(0), name.c_str(), "NULL");
1044
boost::throw_exception(invalid_option_value(var->var->getName()) << invalid_value(std::string("NULL")));
1096
1047
if (!(tmp=get_charset_by_name(res->c_ptr())))
1098
1049
my_error(ER_UNKNOWN_COLLATION, MYF(0), res->c_ptr());
1050
boost::throw_exception(invalid_option_value(var->var->getName()) << invalid_value(std::string(res->c_ptr())));
1107
1059
internal::int10_to_str((int) var->value->val_int(), buf, -10);
1108
1060
my_error(ER_UNKNOWN_COLLATION, MYF(0), buf);
1061
boost::throw_exception(invalid_option_value(var->var->getName()) << invalid_value(boost::lexical_cast<std::string>(var->value->val_int())));
1112
var->save_result.charset= tmp; // Save for update
1117
bool sys_var_collation_sv::update(Session *session, set_var *var)
1119
1065
if (var->type == OPT_GLOBAL)
1120
global_system_variables.*offset= var->save_result.charset;
1066
global_system_variables.*offset= tmp;
1123
session->variables.*offset= var->save_result.charset;
1069
session->variables.*offset= tmp;
1173
1119
bool sys_var_last_insert_id::update(Session *session, set_var *var)
1175
session->first_successful_insert_id_in_prev_stmt=
1176
var->save_result.uint64_t_value;
1121
session->first_successful_insert_id_in_prev_stmt= var->getInteger();
1195
bool sys_var_session_time_zone::check(Session *session, set_var *var)
1140
bool sys_var_session_time_zone::update(Session *session, set_var *var)
1197
1142
char buff[MAX_TIME_ZONE_NAME_LENGTH];
1198
1143
String str(buff, sizeof(buff), &my_charset_utf8_general_ci);
1199
1144
String *res= var->value->val_str(&str);
1201
if (!(var->save_result.time_zone= my_tz_find(session, res)))
1146
Time_zone *tmp= my_tz_find(session, res);
1203
my_error(ER_UNKNOWN_TIME_ZONE, MYF(0), res ? res->c_ptr() : "NULL");
1149
boost::throw_exception(invalid_option_value(var->var->getName()) << invalid_value(std::string(res ? res->c_ptr() : "NULL")));
1210
bool sys_var_session_time_zone::update(Session *session, set_var *var)
1212
1152
/* We are using Time_zone object found during check() phase. */
1213
1153
if (var->type == OPT_GLOBAL)
1215
1155
LOCK_global_system_variables.lock();
1216
global_system_variables.time_zone= var->save_result.time_zone;
1156
global_system_variables.time_zone= tmp;
1217
1157
LOCK_global_system_variables.unlock();
1220
session->variables.time_zone= var->save_result.time_zone;
1160
session->variables.time_zone= tmp;
1305
var->save_result.locale_value= locale_match;
1310
bool sys_var_session_lc_time_names::update(Session *session, set_var *var)
1312
1246
if (var->type == OPT_GLOBAL)
1313
global_system_variables.lc_time_names= var->save_result.locale_value;
1247
global_system_variables.lc_time_names= locale_match;
1315
session->variables.lc_time_names= var->save_result.locale_value;
1249
session->variables.lc_time_names= locale_match;
1385
1319
static bool set_option_bit(Session *session, set_var *var)
1387
1321
sys_var_session_bit *sys_var= ((sys_var_session_bit*) var->var);
1388
if ((var->save_result.uint32_t_value != 0) == sys_var->reverse)
1322
if ((var->getInteger() != 0) == sys_var->reverse)
1389
1323
session->options&= ~sys_var->bit_flag;
1391
1325
session->options|= sys_var->bit_flag;
1400
1334
uint64_t org_options= session->options;
1402
if (var->save_result.uint32_t_value != 0)
1336
if (var->getInteger() != 0)
1403
1337
session->options&= ~((sys_var_session_bit*) var->var)->bit_flag;
1405
1339
session->options|= ((sys_var_session_bit*) var->var)->bit_flag;
1711
1645
Functions to handle table_type
1712
1646
****************************************************************************/
1714
/* Based upon sys_var::check_enum() */
1716
bool sys_var_session_storage_engine::check(Session *session, set_var *var)
1718
char buff[STRING_BUFFER_USUAL_SIZE];
1720
String str(buff, sizeof(buff), &my_charset_utf8_general_ci), *res;
1722
var->save_result.storage_engine= NULL;
1723
if (var->value->result_type() == STRING_RESULT)
1725
res= var->value->val_str(&str);
1726
if (res == NULL || res->ptr() == NULL)
1733
const std::string engine_name(res->ptr());
1734
plugin::StorageEngine *engine;
1735
var->save_result.storage_engine= plugin::StorageEngine::findByName(*session, engine_name);
1736
if (var->save_result.storage_engine == NULL)
1738
value= res->c_ptr();
1741
engine= var->save_result.storage_engine;
1748
my_error(ER_UNKNOWN_STORAGE_ENGINE, MYF(0), value);
1753
1648
unsigned char *sys_var_session_storage_engine::value_ptr(Session *session,
1754
1649
sql_var_t type,
1755
1650
const LEX_STRING *)
1788
1683
bool sys_var_session_storage_engine::update(Session *session, set_var *var)
1790
plugin::StorageEngine **value= &(global_system_variables.*offset), *old_value;
1685
char buff[STRING_BUFFER_USUAL_SIZE];
1686
const char *name_value;
1687
String str(buff, sizeof(buff), &my_charset_utf8_general_ci), *res;
1689
plugin::StorageEngine *tmp= NULL;
1690
plugin::StorageEngine **value= NULL;
1692
if (var->value->result_type() == STRING_RESULT)
1694
res= var->value->val_str(&str);
1695
if (res == NULL || res->ptr() == NULL)
1702
const std::string engine_name(res->ptr());
1703
tmp= plugin::StorageEngine::findByName(*session, engine_name);
1706
name_value= res->c_ptr();
1713
name_value= "unknown";
1716
value= &(global_system_variables.*offset);
1791
1717
if (var->type != OPT_GLOBAL)
1792
1718
value= &(session->variables.*offset);
1794
if (old_value != var->save_result.storage_engine)
1796
*value= var->save_result.storage_engine;
1725
my_error(ER_UNKNOWN_STORAGE_ENGINE, MYF(0), name_value);
1801
1729
} /* namespace drizzled */