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>
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"
220
211
static sys_var_session_size_t sys_sort_buffer("sort_buffer_size",
221
212
&drizzle_system_variables::sortbuff_size);
223
static sys_var_size_t_ptr_readonly sys_transaction_message_threshold("transaction_message_threshold",
224
&transaction_message_threshold);
214
static sys_var_session_size_t sys_transaction_message_threshold("transaction_message_threshold",
215
&drizzle_system_variables::transaction_message_threshold);
226
217
static sys_var_session_storage_engine sys_storage_engine("storage_engine",
227
218
&drizzle_system_variables::storage_engine);
219
static sys_var_const_str sys_system_time_zone("system_time_zone",
228
221
static sys_var_size_t_ptr sys_table_def_size("table_definition_cache",
229
222
&table_def_size);
230
223
static sys_var_uint64_t_ptr sys_table_cache_size("table_open_cache",
313
306
sys_var_session_uint64_t sys_group_concat_max_len("group_concat_max_len",
314
307
&drizzle_system_variables::group_concat_max_len);
309
sys_var_session_time_zone sys_time_zone("time_zone");
316
311
/* Global read-only variable containing hostname */
317
static sys_var_const_string sys_hostname("hostname", getServerHostname());
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);
312
static sys_var_const_str sys_hostname("hostname", glob_hostname);
324
314
bool sys_var::check(Session *session, set_var *var)
484
474
bool sys_var_uint32_t_ptr::update(Session *session, set_var *var)
486
476
uint64_t tmp= var->getInteger();
487
boost::mutex::scoped_lock scopedLock(session->catalog().systemVariableLock());
477
LOCK_global_system_variables.lock();
489
478
if (option_limits)
491
480
uint32_t newvalue= (uint32_t) fix_unsigned(session, tmp, option_limits);
493
482
*value= newvalue;
497
485
*value= static_cast<uint32_t>(tmp);
486
LOCK_global_system_variables.unlock();
504
void sys_var_uint32_t_ptr::set_default(Session *session, sql_var_t)
491
void sys_var_uint32_t_ptr::set_default(Session *, sql_var_t)
507
boost::mutex::scoped_lock scopedLock(session->catalog().systemVariableLock());
494
LOCK_global_system_variables.lock();
508
495
*value= (uint32_t)getopt_ull_limit_value((uint32_t) option_limits->def_value,
509
496
option_limits, ¬_used);
497
LOCK_global_system_variables.unlock();
513
501
bool sys_var_uint64_t_ptr::update(Session *session, set_var *var)
515
503
uint64_t tmp= var->getInteger();
516
boost::mutex::scoped_lock scopedLock(session->catalog().systemVariableLock());
504
LOCK_global_system_variables.lock();
518
505
if (option_limits)
520
507
uint64_t newvalue= fix_unsigned(session, tmp, option_limits);
542
boost::mutex::scoped_lock scopedLock(session->catalog().systemVariableLock());
527
LOCK_global_system_variables.lock();
543
528
*value= getopt_ull_limit_value((uint64_t) option_limits->def_value,
544
529
option_limits, ¬_used);
530
LOCK_global_system_variables.unlock();
549
535
bool sys_var_size_t_ptr::update(Session *session, set_var *var)
551
537
size_t tmp= size_t(var->getInteger());
553
boost::mutex::scoped_lock scopedLock(session->catalog().systemVariableLock());
538
LOCK_global_system_variables.lock();
555
539
if (option_limits)
556
540
*value= fix_size_t(session, tmp, option_limits);
543
LOCK_global_system_variables.unlock();
564
void sys_var_size_t_ptr::set_default(Session *session, sql_var_t)
548
void sys_var_size_t_ptr::set_default(Session *, sql_var_t)
567
boost::mutex::scoped_lock scopedLock(session->catalog().systemVariableLock());
551
LOCK_global_system_variables.lock();
568
552
*value= (size_t)getopt_ull_limit_value((size_t) option_limits->def_value,
569
553
option_limits, ¬_used);
572
bool sys_var_bool_ptr::check(Session *session, set_var *var)
574
return check_enum(session, var, &bool_typelib);
554
LOCK_global_system_variables.unlock();
577
557
bool sys_var_bool_ptr::update(Session *, set_var *var)
662
642
if (var->type == OPT_GLOBAL)
664
644
/* Lock is needed to make things safe on 32 bit systems */
665
boost::mutex::scoped_lock scopedLock(session->catalog().systemVariableLock());
645
LOCK_global_system_variables.lock();
666
646
global_system_variables.*offset= (ha_rows) tmp;
647
LOCK_global_system_variables.unlock();
670
650
session->variables.*offset= (ha_rows) tmp;
682
660
/* We will not come here if option_limits is not set */
683
boost::mutex::scoped_lock scopedLock(session->catalog().systemVariableLock());
661
LOCK_global_system_variables.lock();
684
662
global_system_variables.*offset=
685
663
(ha_rows) getopt_ull_limit_value((ha_rows) option_limits->def_value,
686
664
option_limits, ¬_used);
665
LOCK_global_system_variables.unlock();
690
668
session->variables.*offset= global_system_variables.*offset;
722
699
if (var->type == OPT_GLOBAL)
724
701
/* Lock is needed to make things safe on 32 bit systems */
725
boost::mutex::scoped_lock scopedLock(session->catalog().systemVariableLock());
702
LOCK_global_system_variables.lock();
726
703
global_system_variables.*offset= (uint64_t) tmp;
704
LOCK_global_system_variables.unlock();
730
707
session->variables.*offset= (uint64_t) tmp;
739
714
if (type == OPT_GLOBAL)
742
boost::mutex::scoped_lock scopedLock(session->catalog().systemVariableLock());
717
LOCK_global_system_variables.lock();
743
718
global_system_variables.*offset=
744
719
getopt_ull_limit_value((uint64_t) option_limits->def_value,
745
720
option_limits, ¬_used);
721
LOCK_global_system_variables.unlock();
749
724
session->variables.*offset= global_system_variables.*offset;
778
752
if (var->type == OPT_GLOBAL)
780
754
/* Lock is needed to make things safe on 32 bit systems */
781
boost::mutex::scoped_lock scopedLock(session->catalog().systemVariableLock());
755
LOCK_global_system_variables.lock();
782
756
global_system_variables.*offset= tmp;
757
LOCK_global_system_variables.unlock();
786
760
session->variables.*offset= tmp;
795
767
if (type == OPT_GLOBAL)
798
boost::mutex::scoped_lock scopedLock(session->catalog().systemVariableLock());
770
LOCK_global_system_variables.lock();
799
771
global_system_variables.*offset=
800
772
(size_t)getopt_ull_limit_value((size_t) option_limits->def_value,
801
773
option_limits, ¬_used);
774
LOCK_global_system_variables.unlock();
805
777
session->variables.*offset= global_system_variables.*offset;
816
787
return (unsigned char*) &(session->variables.*offset);
819
bool sys_var_session_bool::check(Session *session, set_var *var)
821
return check_enum(session, var, &bool_typelib);
824
791
bool sys_var_session_bool::update(Session *session, set_var *var)
923
boost::mutex::scoped_lock scopedLock(session->catalog().systemVariableLock());
889
LOCK_global_system_variables.lock();
924
890
value= *(uint*) value_ptr(session, var_type, base);
891
LOCK_global_system_variables.unlock();
926
892
return new Item_uint((uint64_t) value);
928
894
case SHOW_LONGLONG:
931
boost::mutex::scoped_lock scopedLock(session->catalog().systemVariableLock());
897
LOCK_global_system_variables.lock();
932
898
value= *(int64_t*) value_ptr(session, var_type, base);
899
LOCK_global_system_variables.unlock();
934
900
return new Item_int(value);
936
902
case SHOW_DOUBLE:
940
boost::mutex::scoped_lock scopedLock(session->catalog().systemVariableLock());
941
value= *(double*) value_ptr(session, var_type, base);
905
LOCK_global_system_variables.lock();
906
value= *(double*) value_ptr(session, var_type, base);
907
LOCK_global_system_variables.unlock();
944
908
/* 6, as this is for now only used with microseconds */
945
909
return new Item_float(value, 6);
947
911
case SHOW_HA_ROWS:
950
boost::mutex::scoped_lock scopedLock(session->catalog().systemVariableLock());
914
LOCK_global_system_variables.lock();
951
915
value= *(ha_rows*) value_ptr(session, var_type, base);
916
LOCK_global_system_variables.unlock();
953
917
return new Item_int((uint64_t) value);
958
boost::mutex::scoped_lock scopedLock(session->catalog().systemVariableLock());
922
LOCK_global_system_variables.lock();
959
923
value= *(size_t*) value_ptr(session, var_type, base);
924
LOCK_global_system_variables.unlock();
961
925
return new Item_int((uint64_t) value);
963
927
case SHOW_MY_BOOL:
966
boost::mutex::scoped_lock scopedLock(session->catalog().systemVariableLock());
930
LOCK_global_system_variables.lock();
967
931
value= *(bool*) value_ptr(session, var_type, base);
932
LOCK_global_system_variables.unlock();
968
933
return new Item_int(value,1);
970
935
case SHOW_CHAR_PTR:
973
boost::mutex::scoped_lock scopedLock(session->catalog().systemVariableLock());
938
LOCK_global_system_variables.lock();
974
939
char *str= *(char**) value_ptr(session, var_type, base);
983
948
tmp= new Item_null();
984
949
tmp->collation.set(system_charset_info, DERIVATION_SYSCONST);
951
LOCK_global_system_variables.unlock();
992
boost::mutex::scoped_lock scopedLock(session->catalog().systemVariableLock());
957
LOCK_global_system_variables.lock();
993
958
char *str= (char*) value_ptr(session, var_type, base);
995
960
tmp= new Item_string(str, strlen(str),
1169
1134
return (unsigned char*) &session->sys_var_tmp.uint64_t_value;
1138
bool sys_var_session_time_zone::update(Session *session, set_var *var)
1140
char buff[MAX_TIME_ZONE_NAME_LENGTH];
1141
String str(buff, sizeof(buff), &my_charset_utf8_general_ci);
1142
String *res= var->value->val_str(&str);
1144
Time_zone *tmp= my_tz_find(session, res);
1147
boost::throw_exception(invalid_option_value(var->var->getName()) << invalid_value(std::string(res ? res->c_ptr() : "NULL")));
1150
/* We are using Time_zone object found during check() phase. */
1151
if (var->type == OPT_GLOBAL)
1153
LOCK_global_system_variables.lock();
1154
global_system_variables.time_zone= tmp;
1155
LOCK_global_system_variables.unlock();
1158
session->variables.time_zone= tmp;
1163
unsigned char *sys_var_session_time_zone::value_ptr(Session *session,
1168
We can use ptr() instead of c_ptr() here because String contaning
1169
time zone name is guaranteed to be zero ended.
1171
if (type == OPT_GLOBAL)
1172
return (unsigned char *)(global_system_variables.time_zone->get_name()->ptr());
1176
This is an ugly fix for replication: we don't replicate properly queries
1177
invoking system variables' values to update tables; but
1178
CONVERT_TZ(,,@@session.time_zone) is so popular that we make it
1179
replicable (i.e. we tell the binlog code to store the session
1180
timezone). If it's the global value which was used we can't replicate
1181
(binlog code stores session value only).
1183
return (unsigned char *)(session->variables.time_zone->get_name()->ptr());
1188
void sys_var_session_time_zone::set_default(Session *session, sql_var_t type)
1190
LOCK_global_system_variables.lock();
1191
if (type == OPT_GLOBAL)
1193
if (default_tz_name)
1195
String str(default_tz_name, &my_charset_utf8_general_ci);
1197
We are guaranteed to find this time zone since its existence
1198
is checked during start-up.
1200
global_system_variables.time_zone= my_tz_find(session, &str);
1203
global_system_variables.time_zone= my_tz_SYSTEM;
1206
session->variables.time_zone= global_system_variables.time_zone;
1207
LOCK_global_system_variables.unlock();
1172
1212
bool sys_var_session_lc_time_names::update(Session *session, set_var *var)
1174
1214
MY_LOCALE *locale_match;
1178
1218
if (!(locale_match= my_locale_by_number((uint32_t) var->value->val_int())))
1180
char buf[DECIMAL_LONGLONG_DIGITS];
1181
1221
internal::int10_to_str((int) var->value->val_int(), buf, -10);
1182
1222
my_printf_error(ER_UNKNOWN_ERROR, "Unknown locale: '%s'", MYF(0), buf);
1247
1287
microseconds= (int64_t) (num * 1000000.0 + 0.5);
1248
1288
if (var->type == OPT_GLOBAL)
1250
boost::mutex::scoped_lock scopedLock(session->catalog().systemVariableLock());
1290
LOCK_global_system_variables.lock();
1251
1291
(global_system_variables.*offset)= microseconds;
1292
LOCK_global_system_variables.unlock();
1254
1295
session->variables.*offset= microseconds;
1261
1302
int64_t microseconds= (int64_t) (option_limits->def_value * 1000000.0);
1262
1303
if (type == OPT_GLOBAL)
1264
boost::mutex::scoped_lock scopedLock(session->catalog().systemVariableLock());
1305
LOCK_global_system_variables.lock();
1265
1306
global_system_variables.*offset= microseconds;
1307
LOCK_global_system_variables.unlock();
1268
1310
session->variables.*offset= microseconds;
1286
1328
static bool set_option_autocommit(Session *session, set_var *var)
1289
1330
/* The test is negative as the flag we use is NOT autocommit */
1291
1332
uint64_t org_options= session->options;
1292
uint64_t new_options= session->options;
1294
1334
if (var->getInteger() != 0)
1295
new_options&= ~((sys_var_session_bit*) var->var)->bit_flag;
1335
session->options&= ~((sys_var_session_bit*) var->var)->bit_flag;
1297
new_options|= ((sys_var_session_bit*) var->var)->bit_flag;
1337
session->options|= ((sys_var_session_bit*) var->var)->bit_flag;
1299
if ((org_options ^ new_options) & OPTION_NOT_AUTOCOMMIT)
1339
if ((org_options ^ session->options) & OPTION_NOT_AUTOCOMMIT)
1301
1341
if ((org_options & OPTION_NOT_AUTOCOMMIT))
1303
success= session->endActiveTransaction();
1304
1343
/* We changed to auto_commit mode */
1305
1344
session->options&= ~(uint64_t) (OPTION_BEGIN);
1306
1345
session->server_status|= SERVER_STATUS_AUTOCOMMIT;
1346
TransactionServices &transaction_services= TransactionServices::singleton();
1347
if (transaction_services.commitTransaction(session, true))
1310
1352
session->server_status&= ~SERVER_STATUS_AUTOCOMMIT;
1314
if (var->getInteger() != 0)
1315
session->options&= ~((sys_var_session_bit*) var->var)->bit_flag;
1317
session->options|= ((sys_var_session_bit*) var->var)->bit_flag;
1456
1489
/* this fails if there is a conflicting variable name. */
1457
1490
if (system_variable_map.find(lower_name) != system_variable_map.end())
1459
errmsg_printf(error::ERROR, _("Variable named %s already exists!\n"),
1492
errmsg_printf(ERRMSG_LVL_ERROR, _("Variable named %s already exists!\n"),
1460
1493
var->getName().c_str());
1461
1494
throw exception();
1498
1531
add_sys_var_to_list(&sys_back_log, my_long_options);
1499
1532
add_sys_var_to_list(&sys_basedir, my_long_options);
1500
1533
add_sys_var_to_list(&sys_big_selects, my_long_options);
1501
add_sys_var_to_list(&sys_branch, my_long_options);
1502
1534
add_sys_var_to_list(&sys_buffer_results, my_long_options);
1503
1535
add_sys_var_to_list(&sys_bulk_insert_buff_size, my_long_options);
1504
1536
add_sys_var_to_list(&sys_collation_server, my_long_options);
1533
1565
add_sys_var_to_list(&sys_range_alloc_block_size, my_long_options);
1534
1566
add_sys_var_to_list(&sys_read_buff_size, my_long_options);
1535
1567
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
1568
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
1569
add_sys_var_to_list(&sys_scheduler, my_long_options);
1541
1570
add_sys_var_to_list(&sys_secure_file_priv, my_long_options);
1542
1571
add_sys_var_to_list(&sys_select_limit, my_long_options);
1545
1574
add_sys_var_to_list(&sys_sql_notes, my_long_options);
1546
1575
add_sys_var_to_list(&sys_sql_warnings, my_long_options);
1547
1576
add_sys_var_to_list(&sys_storage_engine, my_long_options);
1577
add_sys_var_to_list(&sys_system_time_zone, my_long_options);
1548
1578
add_sys_var_to_list(&sys_table_cache_size, my_long_options);
1549
1579
add_sys_var_to_list(&sys_table_def_size, my_long_options);
1550
1580
add_sys_var_to_list(&sys_table_lock_wait_timeout, my_long_options);
1551
1581
add_sys_var_to_list(&sys_thread_stack_size, my_long_options);
1582
add_sys_var_to_list(&sys_time_zone, my_long_options);
1552
1583
add_sys_var_to_list(&sys_timed_mutexes, my_long_options);
1553
1584
add_sys_var_to_list(&sys_timestamp, my_long_options);
1554
1585
add_sys_var_to_list(&sys_tmp_table_size, my_long_options);