~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to sql/set_var.cc

  • Committer: Brian Aker
  • Date: 2008-07-03 00:14:39 UTC
  • Revision ID: brian@tangent.org-20080703001439-pit0mcl0wk8elxlq
Cleanup of sql-common and mysqldump

Show diffs side-by-side

added added

removed removed

Lines of Context:
42
42
 
43
43
  @note
44
44
    Be careful with var->save_result: sys_var::check() only updates
45
 
    uint64_t_value; so other members of the union are garbage then; to use
 
45
    ulonglong_value; so other members of the union are garbage then; to use
46
46
    them you must first assign a value to them (in specific ::check() for
47
47
    example).
48
48
*/
49
 
#include <drizzled/server_includes.h>
 
49
 
 
50
#ifdef USE_PRAGMA_IMPLEMENTATION
 
51
#pragma implementation                          // gcc: Class implementation
 
52
#endif
 
53
 
 
54
#include "mysql_priv.h"
 
55
#include <mysql.h>
 
56
#include "slave.h"
50
57
#include "rpl_mi.h"
51
 
#include <mysys/my_getopt.h>
52
 
#include <mysys/thr_alarm.h>
53
 
#include <storage/myisam/myisam.h>
54
 
#include <drizzled/drizzled_error_messages.h>
55
 
#include <libdrizzle/gettext.h>
 
58
#include <my_getopt.h>
 
59
#include <thr_alarm.h>
 
60
#include <myisam.h>
 
61
#include <my_dir.h>
56
62
 
57
 
extern const CHARSET_INFO *character_set_filesystem;
 
63
extern CHARSET_INFO *character_set_filesystem;
58
64
 
59
65
 
60
66
static DYNAMIC_ARRAY fixed_show_vars;
61
67
static HASH system_variable_hash;
62
68
 
63
 
const char *bool_type_names[]= { "OFF", "ON", NULL };
 
69
const char *bool_type_names[]= { "OFF", "ON", NullS };
64
70
TYPELIB bool_typelib=
65
71
{
66
72
  array_elements(bool_type_names)-1, "", bool_type_names, NULL
67
73
};
68
74
 
69
 
const char *delay_key_write_type_names[]= { "OFF", "ON", "ALL", NULL };
 
75
const char *delay_key_write_type_names[]= { "OFF", "ON", "ALL", NullS };
70
76
TYPELIB delay_key_write_typelib=
71
77
{
72
78
  array_elements(delay_key_write_type_names)-1, "",
74
80
};
75
81
 
76
82
const char *slave_exec_mode_names[]=
77
 
{ "STRICT", "IDEMPOTENT", NULL };
 
83
{ "STRICT", "IDEMPOTENT", NullS };
78
84
static const unsigned int slave_exec_mode_names_len[]=
79
85
{ sizeof("STRICT") - 1, sizeof("IDEMPOTENT") - 1, 0 };
80
86
TYPELIB slave_exec_mode_typelib=
90
96
static bool set_option_bit(THD *thd, set_var *var);
91
97
static bool set_option_autocommit(THD *thd, set_var *var);
92
98
static int  check_log_update(THD *thd, set_var *var);
 
99
static bool set_log_update(THD *thd, set_var *var);
93
100
static int  check_pseudo_thread_id(THD *thd, set_var *var);
 
101
void fix_binlog_format_after_update(THD *thd, enum_var_type type);
94
102
static void fix_low_priority_updates(THD *thd, enum_var_type type);
95
103
static int check_tx_isolation(THD *thd, set_var *var);
96
104
static void fix_tx_isolation(THD *thd, enum_var_type type);
107
115
static void fix_thd_mem_root(THD *thd, enum_var_type type);
108
116
static void fix_trans_mem_root(THD *thd, enum_var_type type);
109
117
static void fix_server_id(THD *thd, enum_var_type type);
110
 
static uint64_t fix_unsigned(THD *, uint64_t, const struct my_option *);
 
118
static ulonglong fix_unsigned(THD *, ulonglong, const struct my_option *);
111
119
static bool get_unsigned(THD *thd, set_var *var);
112
120
bool throw_bounds_warning(THD *thd, bool fixed, bool unsignd,
113
 
                          const char *name, int64_t val);
114
 
static KEY_CACHE *create_key_cache(const char *name, uint32_t length);
115
 
static unsigned char *get_error_count(THD *thd);
116
 
static unsigned char *get_warning_count(THD *thd);
117
 
static unsigned char *get_tmpdir(THD *thd);
 
121
                          const char *name, longlong val);
 
122
static KEY_CACHE *create_key_cache(const char *name, uint length);
 
123
static uchar *get_error_count(THD *thd);
 
124
static uchar *get_warning_count(THD *thd);
 
125
static uchar *get_tmpdir(THD *thd);
 
126
static int  sys_check_log_path(THD *thd,  set_var *var);
 
127
static bool sys_update_general_log_path(THD *thd, set_var * var);
 
128
static void sys_default_general_log_path(THD *thd, enum_var_type type);
 
129
static bool sys_update_slow_log_path(THD *thd, set_var * var);
 
130
static void sys_default_slow_log_path(THD *thd, enum_var_type type);
118
131
 
119
132
/*
120
133
  Variable definition list
185
198
sys_collation_server(&vars, "collation_server", &SV::collation_server,
186
199
                     &default_charset_info,
187
200
                     sys_var::SESSION_VARIABLE_IN_BINLOG);
 
201
static sys_var_long_ptr sys_concurrent_insert(&vars, "concurrent_insert",
 
202
                                              &myisam_concurrent_insert);
188
203
static sys_var_long_ptr sys_connect_timeout(&vars, "connect_timeout",
189
204
                                            &connect_timeout);
190
205
static sys_var_const_str       sys_datadir(&vars, "datadir", mysql_real_data_home);
 
206
#ifndef DBUG_OFF
 
207
static sys_var_thd_dbug        sys_dbug(&vars, "debug");
 
208
#endif
191
209
static sys_var_enum             sys_delay_key_write(&vars, "delay_key_write",
192
210
                                            &delay_key_write_options,
193
211
                                            &delay_key_write_typelib,
196
214
static sys_var_long_ptr sys_expire_logs_days(&vars, "expire_logs_days",
197
215
                                             &expire_logs_days);
198
216
static sys_var_bool_ptr sys_flush(&vars, "flush", &myisam_flush);
 
217
static sys_var_long_ptr sys_flush_time(&vars, "flush_time", &flush_time);
199
218
sys_var_str             sys_init_connect(&vars, "init_connect", 0,
200
219
                                         sys_update_init_connect,
201
220
                                         sys_default_init_connect,0);
218
237
                                                              param_age_threshold));
219
238
static sys_var_bool_ptr sys_local_infile(&vars, "local_infile",
220
239
                                         &opt_local_infile);
 
240
static sys_var_bool_ptr
 
241
  sys_log_queries_not_using_indexes(&vars, "log_queries_not_using_indexes",
 
242
                                    &opt_log_queries_not_using_indexes);
 
243
static sys_var_thd_ulong        sys_log_warnings(&vars, "log_warnings", &SV::log_warnings);
 
244
static sys_var_microseconds     sys_var_long_query_time(&vars, "long_query_time",
 
245
                                                        &SV::long_query_time);
221
246
static sys_var_thd_bool sys_low_priority_updates(&vars, "low_priority_updates",
222
247
                                                 &SV::low_priority_updates,
223
248
                                                 fix_low_priority_updates);
240
265
                                               &max_connect_errors);
241
266
static sys_var_thd_ulong        sys_max_error_count(&vars, "max_error_count",
242
267
                                            &SV::max_error_count);
243
 
static sys_var_thd_uint64_t     sys_max_heap_table_size(&vars, "max_heap_table_size",
 
268
static sys_var_thd_ulonglong    sys_max_heap_table_size(&vars, "max_heap_table_size",
244
269
                                                &SV::max_heap_table_size);
245
270
static sys_var_thd_ulong sys_pseudo_thread_id(&vars, "pseudo_thread_id",
246
271
                                              &SV::pseudo_thread_id,
253
278
                                              &SV::max_seeks_for_key);
254
279
static sys_var_thd_ulong   sys_max_length_for_sort_data(&vars, "max_length_for_sort_data",
255
280
                                                 &SV::max_length_for_sort_data);
 
281
#ifndef TO_BE_DELETED   /* Alias for max_join_size */
 
282
static sys_var_thd_ha_rows      sys_sql_max_join_size(&vars, "sql_max_join_size",
 
283
                                              &SV::max_join_size,
 
284
                                              fix_max_join_size);
 
285
#endif
256
286
static sys_var_long_ptr sys_max_relay_log_size(&vars, "max_relay_log_size",
257
287
                                               &max_relay_log_size,
258
288
                                               fix_max_relay_log_size);
265
295
                                                 &max_write_lock_count);
266
296
static sys_var_thd_ulong       sys_min_examined_row_limit(&vars, "min_examined_row_limit",
267
297
                                                          &SV::min_examined_row_limit);
268
 
static sys_var_thd_uint64_t     sys_myisam_max_sort_file_size(&vars, "myisam_max_sort_file_size", &SV::myisam_max_sort_file_size, fix_myisam_max_sort_file_size, 1);
 
298
static sys_var_long_ptr sys_myisam_data_pointer_size(&vars, "myisam_data_pointer_size",
 
299
                                                    &myisam_data_pointer_size);
 
300
static sys_var_thd_ulonglong    sys_myisam_max_sort_file_size(&vars, "myisam_max_sort_file_size", &SV::myisam_max_sort_file_size, fix_myisam_max_sort_file_size, 1);
269
301
static sys_var_thd_ulong       sys_myisam_repair_threads(&vars, "myisam_repair_threads", &SV::myisam_repair_threads);
270
302
static sys_var_thd_ulong        sys_myisam_sort_buffer_size(&vars, "myisam_sort_buffer_size", &SV::myisam_sort_buff_size);
271
303
 
290
322
/* these two cannot be static */
291
323
sys_var_thd_bool                sys_old_alter_table(&vars, "old_alter_table",
292
324
                                            &SV::old_alter_table);
 
325
sys_var_thd_bool                sys_old_passwords(&vars, "old_passwords", &SV::old_passwords);
293
326
static sys_var_thd_ulong        sys_optimizer_prune_level(&vars, "optimizer_prune_level",
294
327
                                                  &SV::optimizer_prune_level);
295
328
static sys_var_thd_ulong        sys_optimizer_search_depth(&vars, "optimizer_search_depth",
296
329
                                                   &SV::optimizer_search_depth);
297
330
 
298
 
const char *optimizer_use_mrr_names[] = {"auto", "force", "disable", NULL};
 
331
const char *optimizer_use_mrr_names[] = {"auto", "force", "disable", NullS};
299
332
TYPELIB optimizer_use_mrr_typelib= {
300
333
  array_elements(optimizer_use_mrr_names) - 1, "",
301
334
  optimizer_use_mrr_names, NULL
340
373
static sys_var_long_ptr sys_server_id(&vars, "server_id", &server_id, fix_server_id);
341
374
static sys_var_bool_ptr sys_slave_compressed_protocol(&vars, "slave_compressed_protocol",
342
375
                                                      &opt_slave_compressed_protocol);
 
376
#ifdef HAVE_REPLICATION
343
377
static sys_var_bool_ptr         sys_slave_allow_batching(&vars, "slave_allow_batching",
344
378
                                                         &slave_allow_batching);
345
379
static sys_var_set_slave_mode slave_exec_mode(&vars,
347
381
                                              &slave_exec_mode_options,
348
382
                                              &slave_exec_mode_typelib,
349
383
                                              0);
 
384
#endif
350
385
static sys_var_long_ptr sys_slow_launch_time(&vars, "slow_launch_time",
351
386
                                             &slow_launch_time);
352
387
static sys_var_thd_ulong        sys_sort_buffer(&vars, "sort_buffer_size",
359
394
*/
360
395
static sys_var_thd_optimizer_switch   sys_optimizer_switch(&vars, "optimizer_switch",
361
396
                                     &SV::optimizer_switch);
 
397
static sys_var_const_str        sys_ssl_ca(&vars, "ssl_ca", NULL);
 
398
static sys_var_const_str        sys_ssl_capath(&vars, "ssl_capath", NULL);
 
399
static sys_var_const_str        sys_ssl_cert(&vars, "ssl_cert", NULL);
 
400
static sys_var_const_str        sys_ssl_cipher(&vars, "ssl_cipher", NULL);
 
401
static sys_var_const_str        sys_ssl_key(&vars, "ssl_key", NULL);
362
402
 
363
403
static sys_var_thd_storage_engine sys_storage_engine(&vars, "storage_engine",
364
404
                                       &SV::table_plugin);
 
405
static sys_var_bool_ptr sys_sync_frm(&vars, "sync_frm", &opt_sync_frm);
365
406
static sys_var_const_str        sys_system_time_zone(&vars, "system_time_zone",
366
407
                                             system_time_zone);
367
408
static sys_var_long_ptr sys_table_def_size(&vars, "table_definition_cache",
379
420
                                         &tx_isolation_typelib,
380
421
                                         fix_tx_isolation,
381
422
                                         check_tx_isolation);
382
 
static sys_var_thd_uint64_t     sys_tmp_table_size(&vars, "tmp_table_size",
 
423
static sys_var_thd_ulonglong    sys_tmp_table_size(&vars, "tmp_table_size",
383
424
                                           &SV::tmp_table_size);
384
 
static sys_var_bool_ptr  sys_timed_mutexes(&vars, "timed_mutexes", &timed_mutexes);
 
425
static sys_var_bool_ptr  sys_timed_mutexes(&vars, "timed_mutexes",
 
426
                                    &timed_mutexes);
385
427
static sys_var_const_str        sys_version(&vars, "version", server_version);
386
428
static sys_var_const_str        sys_version_comment(&vars, "version_comment",
387
 
                                            DRIZZLE_COMPILATION_COMMENT);
 
429
                                            MYSQL_COMPILATION_COMMENT);
388
430
static sys_var_const_str        sys_version_compile_machine(&vars, "version_compile_machine",
389
431
                                                    MACHINE_TYPE);
390
432
static sys_var_const_str        sys_version_compile_os(&vars, "version_compile_os",
401
443
 
402
444
static sys_var_thd_date_time_format sys_time_format(&vars, "time_format",
403
445
                                             &SV::time_format,
404
 
                                             DRIZZLE_TIMESTAMP_TIME);
 
446
                                             MYSQL_TIMESTAMP_TIME);
405
447
static sys_var_thd_date_time_format sys_date_format(&vars, "date_format",
406
448
                                             &SV::date_format,
407
 
                                             DRIZZLE_TIMESTAMP_DATE);
 
449
                                             MYSQL_TIMESTAMP_DATE);
408
450
static sys_var_thd_date_time_format sys_datetime_format(&vars, "datetime_format",
409
451
                                                 &SV::datetime_format,
410
 
                                                 DRIZZLE_TIMESTAMP_DATETIME);
 
452
                                                 MYSQL_TIMESTAMP_DATETIME);
411
453
 
412
454
/* Variables that are bits in THD */
413
455
 
426
468
static sys_var_thd_bit  sys_big_selects(&vars, "sql_big_selects", 0,
427
469
                                        set_option_bit,
428
470
                                        OPTION_BIG_SELECTS);
 
471
static sys_var_thd_bit  sys_log_off(&vars, "sql_log_off",
 
472
                                    check_log_update,
 
473
                                    set_option_bit,
 
474
                                    OPTION_LOG_OFF);
 
475
static sys_var_thd_bit  sys_log_update(&vars, "sql_log_update",
 
476
                                       check_log_update,
 
477
                                       set_log_update,
 
478
                                       OPTION_BIN_LOG);
429
479
static sys_var_thd_bit  sys_log_binlog(&vars, "sql_log_bin",
430
480
                                       check_log_update,
431
481
                                       set_option_bit,
436
486
static sys_var_thd_bit  sys_sql_notes(&vars, "sql_notes", 0,
437
487
                                         set_option_bit,
438
488
                                         OPTION_SQL_NOTES);
 
489
static sys_var_thd_bit  sys_auto_is_null(&vars, "sql_auto_is_null", 0,
 
490
                                         set_option_bit,
 
491
                                         OPTION_AUTO_IS_NULL, 0,
 
492
                                         sys_var::SESSION_VARIABLE_IN_BINLOG);
439
493
static sys_var_thd_bit  sys_safe_updates(&vars, "sql_safe_updates", 0,
440
494
                                         set_option_bit,
441
495
                                         OPTION_SAFE_UPDATES);
523
577
static sys_var_const_str_ptr    sys_repl_report_user(&vars, "report_user", &report_user);
524
578
static sys_var_const_str_ptr    sys_repl_report_password(&vars, "report_password", &report_password);
525
579
 
526
 
static unsigned char *slave_get_report_port(THD *thd)
 
580
static uchar *slave_get_report_port(THD *thd)
527
581
{
528
582
  thd->sys_var_tmp.long_value= report_port;
529
 
  return (unsigned char*) &thd->sys_var_tmp.long_value;
 
583
  return (uchar*) &thd->sys_var_tmp.long_value;
530
584
}
531
585
 
532
586
static sys_var_readonly    sys_repl_report_port(&vars, "report_port", OPT_GLOBAL, SHOW_INT, slave_get_report_port);
536
590
/* Read only variables */
537
591
 
538
592
static sys_var_have_variable sys_have_compress(&vars, "have_compress", &have_compress);
 
593
static sys_var_have_variable sys_have_crypt(&vars, "have_crypt", &have_crypt);
 
594
static sys_var_have_plugin sys_have_csv(&vars, "have_csv", C_STRING_WITH_LEN("csv"), MYSQL_STORAGE_ENGINE_PLUGIN);
 
595
static sys_var_have_variable sys_have_dlopen(&vars, "have_dynamic_loading", &have_dlopen);
 
596
static sys_var_have_plugin sys_have_innodb(&vars, "have_innodb", C_STRING_WITH_LEN("innodb"), MYSQL_STORAGE_ENGINE_PLUGIN);
539
597
static sys_var_have_variable sys_have_symlink(&vars, "have_symlink", &have_symlink);
 
598
/* Global read-only variable describing server license */
 
599
static sys_var_const_str        sys_license(&vars, "license", STRINGIFY_ARG(LICENSE));
 
600
/* Global variables which enable|disable logging */
 
601
static sys_var_log_state sys_var_general_log(&vars, "general_log", &opt_log,
 
602
                                      QUERY_LOG_GENERAL);
 
603
/* Synonym of "general_log" for consistency with SHOW VARIABLES output */
 
604
static sys_var_log_state sys_var_log(&vars, "log", &opt_log,
 
605
                                      QUERY_LOG_GENERAL);
 
606
static sys_var_log_state sys_var_slow_query_log(&vars, "slow_query_log", &opt_slow_log,
 
607
                                         QUERY_LOG_SLOW);
 
608
/* Synonym of "slow_query_log" for consistency with SHOW VARIABLES output */
 
609
static sys_var_log_state sys_var_log_slow(&vars, "log_slow_queries",
 
610
                                          &opt_slow_log, QUERY_LOG_SLOW);
 
611
sys_var_str sys_var_general_log_path(&vars, "general_log_file", sys_check_log_path,
 
612
                                     sys_update_general_log_path,
 
613
                                     sys_default_general_log_path,
 
614
                                     opt_logname);
 
615
sys_var_str sys_var_slow_log_path(&vars, "slow_query_log_file", sys_check_log_path,
 
616
                                  sys_update_slow_log_path, 
 
617
                                  sys_default_slow_log_path,
 
618
                                  opt_slow_logname);
 
619
static sys_var_log_output sys_var_log_output_state(&vars, "log_output", &log_output_options,
 
620
                                            &log_output_typelib, 0);
 
621
 
 
622
 
540
623
/*
541
624
  Additional variables (not derived from sys_var class, not accessible as
542
625
  @@varname in SELECT or SET). Sorted in alphabetical order to facilitate
547
630
#define FIXED_VARS_SIZE (sizeof(fixed_vars) / sizeof(SHOW_VAR))
548
631
static SHOW_VAR fixed_vars[]= {
549
632
  {"back_log",                (char*) &back_log,                    SHOW_LONG},
 
633
  {"character_sets_dir",      mysql_charsets_dir,                   SHOW_CHAR},
550
634
  {"init_file",               (char*) &opt_init_file,               SHOW_CHAR_PTR},
551
635
  {"language",                language,                             SHOW_CHAR},
552
636
#ifdef HAVE_MLOCKALL
554
638
#endif
555
639
  {"log_bin",                 (char*) &opt_bin_log,                 SHOW_BOOL},
556
640
  {"log_error",               (char*) log_error_file,               SHOW_CHAR},
 
641
  {"lower_case_file_system",  (char*) &lower_case_file_system,      SHOW_MY_BOOL},
 
642
  {"lower_case_table_names",  (char*) &lower_case_table_names,      SHOW_INT},
557
643
  {"myisam_recover_options",  (char*) &myisam_recover_options_str,  SHOW_CHAR_PTR},
558
644
  {"open_files_limit",        (char*) &open_files_limit,            SHOW_LONG},
559
645
  {"pid_file",                (char*) pidfile_name,                 SHOW_CHAR},
560
646
  {"plugin_dir",              (char*) opt_plugin_dir,               SHOW_CHAR},
561
647
  {"port",                    (char*) &mysqld_port,                 SHOW_INT},
562
648
  {"protocol_version",        (char*) &protocol_version,            SHOW_INT},
 
649
  {"skip_external_locking",   (char*) &my_disable_locking,          SHOW_MY_BOOL},
 
650
  {"skip_networking",         (char*) &opt_disable_networking,      SHOW_BOOL},
 
651
  {"skip_show_database",      (char*) &opt_skip_show_db,            SHOW_BOOL},
563
652
  {"thread_stack",            (char*) &my_thread_stack_size,        SHOW_LONG},
564
653
};
565
654
 
566
655
 
567
 
bool sys_var::check(THD *thd __attribute__((unused)), set_var *var)
 
656
bool sys_var::check(THD *thd, set_var *var)
568
657
{
569
 
  var->save_result.uint64_t_value= var->value->val_int();
 
658
  var->save_result.ulonglong_value= var->value->val_int();
570
659
  return 0;
571
660
}
572
661
 
599
688
                        set_var *var)
600
689
{
601
690
  char *res= 0, *old_value=(char *)(var ? var->value->str_value.ptr() : 0);
602
 
  uint32_t new_length= (var ? var->value->str_value.length() : 0);
 
691
  uint new_length= (var ? var->value->str_value.length() : 0);
603
692
  if (!old_value)
604
693
    old_value= (char*) "";
605
694
  if (!(res= my_strndup(old_value, new_length, MYF(0))))
613
702
  var_str->value= res;
614
703
  var_str->value_length= new_length;
615
704
  rw_unlock(var_mutex);
616
 
  free(old_value);
 
705
  my_free(old_value, MYF(MY_ALLOW_ZERO_PTR));
617
706
  return 0;
618
707
}
619
708
 
620
709
 
621
 
static bool sys_update_init_connect(THD *thd __attribute__((unused)), set_var *var)
 
710
static bool sys_update_init_connect(THD *thd, set_var *var)
622
711
{
623
712
  return update_sys_var_str(&sys_init_connect, &LOCK_sys_init_connect, var);
624
713
}
625
714
 
626
715
 
627
 
static void sys_default_init_connect(THD* thd __attribute__((unused)),
628
 
                                     enum_var_type type __attribute__((unused)))
 
716
static void sys_default_init_connect(THD* thd, enum_var_type type)
629
717
{
630
718
  update_sys_var_str(&sys_init_connect, &LOCK_sys_init_connect, 0);
631
719
}
632
720
 
633
721
 
634
 
static bool sys_update_init_slave(THD *thd __attribute__((unused)),
635
 
                                  set_var *var)
 
722
static bool sys_update_init_slave(THD *thd, set_var *var)
636
723
{
637
724
  return update_sys_var_str(&sys_init_slave, &LOCK_sys_init_slave, var);
638
725
}
639
726
 
640
727
 
641
 
static void sys_default_init_slave(THD* thd __attribute__((unused)),
642
 
                                   enum_var_type type __attribute__((unused)))
 
728
static void sys_default_init_slave(THD* thd, enum_var_type type)
643
729
{
644
730
  update_sys_var_str(&sys_init_slave, &LOCK_sys_init_slave, 0);
645
731
}
663
749
 
664
750
 
665
751
static void
666
 
fix_myisam_max_sort_file_size(THD *thd __attribute__((unused)),
667
 
                              enum_var_type type __attribute__((unused)))
 
752
fix_myisam_max_sort_file_size(THD *thd, enum_var_type type)
668
753
{
669
754
  myisam_max_temp_length=
670
755
    (my_off_t) global_system_variables.myisam_max_sort_file_size;
714
799
static void fix_completion_type(THD *thd __attribute__((unused)),
715
800
                                enum_var_type type __attribute__((unused))) {}
716
801
 
717
 
static int check_completion_type(THD *thd __attribute__((unused)),
718
 
                                 set_var *var)
 
802
static int check_completion_type(THD *thd, set_var *var)
719
803
{
720
 
  int64_t val= var->value->val_int();
 
804
  longlong val= var->value->val_int();
721
805
  if (val < 0 || val > 2)
722
806
  {
723
807
    char buf[64];
732
816
  If we are changing the thread variable, we have to copy it to NET too
733
817
*/
734
818
 
 
819
#ifdef HAVE_REPLICATION
735
820
static void fix_net_read_timeout(THD *thd, enum_var_type type)
736
821
{
737
822
  if (type != OPT_GLOBAL)
750
835
  if (type != OPT_GLOBAL)
751
836
    thd->net.retry_count=thd->variables.net_retry_count;
752
837
}
753
 
 
754
 
 
755
 
extern void fix_delay_key_write(THD *thd __attribute__((unused)),
756
 
                                enum_var_type type __attribute__((unused)))
 
838
#else /* HAVE_REPLICATION */
 
839
static void fix_net_read_timeout(THD *thd __attribute__((unused)),
 
840
                                 enum_var_type type __attribute__((unused)))
 
841
{}
 
842
static void fix_net_write_timeout(THD *thd __attribute__((unused)),
 
843
                                  enum_var_type type __attribute__((unused)))
 
844
{}
 
845
static void fix_net_retry_count(THD *thd __attribute__((unused)),
 
846
                                enum_var_type type __attribute__((unused)))
 
847
{}
 
848
#endif /* HAVE_REPLICATION */
 
849
 
 
850
 
 
851
extern void fix_delay_key_write(THD *thd, enum_var_type type)
757
852
{
758
853
  switch ((enum_delay_key_write) delay_key_write_options) {
759
854
  case DELAY_KEY_WRITE_NONE:
769
864
  }
770
865
}
771
866
 
772
 
bool sys_var_set::update(THD *thd __attribute__((unused)),
773
 
                         set_var *var)
 
867
bool sys_var_set::update(THD *thd, set_var *var)
774
868
{
775
869
  *value= var->save_result.ulong_value;
776
870
  return 0;
777
871
}
778
872
 
779
 
unsigned char *sys_var_set::value_ptr(THD *thd,
780
 
                              enum_var_type type __attribute__((unused)),
781
 
                              LEX_STRING *base __attribute__((unused)))
 
873
uchar *sys_var_set::value_ptr(THD *thd, enum_var_type type,
 
874
                              LEX_STRING *base)
782
875
{
783
876
  char buff[256];
784
 
  String tmp(buff, sizeof(buff), &my_charset_utf8_general_ci);
 
877
  String tmp(buff, sizeof(buff), &my_charset_latin1);
785
878
  ulong length;
786
879
  ulong val= *value;
787
880
 
788
881
  tmp.length(0);
789
 
  for (uint32_t i= 0; val; val>>= 1, i++)
 
882
  for (uint i= 0; val; val>>= 1, i++)
790
883
  {
791
884
    if (val & 1)
792
885
    {
798
891
 
799
892
  if ((length= tmp.length()))
800
893
    length--;
801
 
  return (unsigned char*) thd->strmake(tmp.ptr(), length);
 
894
  return (uchar*) thd->strmake(tmp.ptr(), length);
802
895
}
803
896
 
804
 
void sys_var_set_slave_mode::set_default(THD *thd __attribute__((unused)),
805
 
                                         enum_var_type type __attribute__((unused)))
 
897
void sys_var_set_slave_mode::set_default(THD *thd, enum_var_type type)
806
898
{
807
899
  slave_exec_mode_options= 0;
808
900
  bit_do_set(slave_exec_mode_options, SLAVE_EXEC_MODE_STRICT);
830
922
  return rc;
831
923
}
832
924
 
833
 
void fix_slave_exec_mode(enum_var_type type __attribute__((unused)))
 
925
void fix_slave_exec_mode(enum_var_type type)
834
926
{
 
927
  DBUG_ENTER("fix_slave_exec_mode");
 
928
  compile_time_assert(sizeof(slave_exec_mode_options) * CHAR_BIT
 
929
                      > SLAVE_EXEC_MODE_LAST_BIT - 1);
835
930
  if (bit_is_set(slave_exec_mode_options, SLAVE_EXEC_MODE_STRICT) == 1 &&
836
931
      bit_is_set(slave_exec_mode_options, SLAVE_EXEC_MODE_IDEMPOTENT) == 1)
837
932
  {
838
 
    sql_print_error(_("Ambiguous slave modes combination."
839
 
                    " STRICT will be used"));
 
933
    sql_print_error("Ambiguous slave modes combination."
 
934
                    " STRICT will be used");
840
935
    bit_do_clear(slave_exec_mode_options, SLAVE_EXEC_MODE_IDEMPOTENT);
841
936
  }
842
937
  if (bit_is_set(slave_exec_mode_options, SLAVE_EXEC_MODE_IDEMPOTENT) == 0)
878
973
}
879
974
 
880
975
 
881
 
void fix_binlog_format_after_update(THD *thd,
882
 
                                    enum_var_type type __attribute__((unused)))
 
976
void fix_binlog_format_after_update(THD *thd, enum_var_type type)
883
977
{
884
978
  thd->reset_current_stmt_binlog_row_based();
885
979
}
886
980
 
887
981
 
888
 
static void fix_max_binlog_size(THD *thd __attribute__((unused)),
889
 
                                enum_var_type type __attribute__((unused)))
 
982
static void fix_max_binlog_size(THD *thd, enum_var_type type)
890
983
{
 
984
  DBUG_ENTER("fix_max_binlog_size");
 
985
  DBUG_PRINT("info",("max_binlog_size=%lu max_relay_log_size=%lu",
 
986
                     max_binlog_size, max_relay_log_size));
891
987
  mysql_bin_log.set_max_size(max_binlog_size);
 
988
#ifdef HAVE_REPLICATION
892
989
  if (!max_relay_log_size)
893
990
    active_mi->rli.relay_log.set_max_size(max_binlog_size);
894
 
  return;
 
991
#endif
 
992
  DBUG_VOID_RETURN;
895
993
}
896
994
 
897
 
static void fix_max_relay_log_size(THD *thd __attribute__((unused)),
898
 
                                   enum_var_type type __attribute__((unused)))
 
995
static void fix_max_relay_log_size(THD *thd, enum_var_type type)
899
996
{
 
997
  DBUG_ENTER("fix_max_relay_log_size");
 
998
  DBUG_PRINT("info",("max_binlog_size=%lu max_relay_log_size=%lu",
 
999
                     max_binlog_size, max_relay_log_size));
 
1000
#ifdef HAVE_REPLICATION
900
1001
  active_mi->rli.relay_log.set_max_size(max_relay_log_size ?
901
1002
                                        max_relay_log_size: max_binlog_size);
902
 
  return;
 
1003
#endif
 
1004
  DBUG_VOID_RETURN;
903
1005
}
904
1006
 
905
 
static void fix_max_connections(THD *thd __attribute__((unused)),
906
 
                                enum_var_type type __attribute__((unused)))
 
1007
static void fix_max_connections(THD *thd, enum_var_type type)
907
1008
{
908
1009
  resize_thr_alarm(max_connections +  10);
909
1010
}
927
1028
}
928
1029
 
929
1030
 
930
 
static void fix_server_id(THD *thd __attribute__((unused)),
931
 
                          enum_var_type type __attribute__((unused)))
 
1031
static void fix_server_id(THD *thd, enum_var_type type)
932
1032
{
933
1033
  server_id_supplied = 1;
934
1034
  thd->server_id= server_id;
936
1036
 
937
1037
 
938
1038
bool throw_bounds_warning(THD *thd, bool fixed, bool unsignd,
939
 
                          const char *name, int64_t val)
 
1039
                          const char *name, longlong val)
940
1040
{
941
1041
  if (fixed)
942
1042
  {
943
1043
    char buf[22];
944
1044
 
945
1045
    if (unsignd)
946
 
      ullstr((uint64_t) val, buf);
 
1046
      ullstr((ulonglong) val, buf);
947
1047
    else
948
1048
      llstr(val, buf);
949
1049
 
950
 
    push_warning_printf(thd, DRIZZLE_ERROR::WARN_LEVEL_WARN,
 
1050
    push_warning_printf(thd, MYSQL_ERROR::WARN_LEVEL_WARN,
951
1051
                        ER_TRUNCATED_WRONG_VALUE,
952
1052
                        ER(ER_TRUNCATED_WRONG_VALUE), name, buf);
953
1053
  }
954
 
  return false;
 
1054
  return FALSE;
955
1055
}
956
1056
 
957
 
static uint64_t fix_unsigned(THD *thd, uint64_t num,
 
1057
static ulonglong fix_unsigned(THD *thd, ulonglong num,
958
1058
                              const struct my_option *option_limits)
959
1059
{
960
 
  bool fixed= false;
961
 
  uint64_t out= getopt_ull_limit_value(num, option_limits, &fixed);
 
1060
  my_bool fixed= FALSE;
 
1061
  ulonglong out= getopt_ull_limit_value(num, option_limits, &fixed);
962
1062
 
963
 
  throw_bounds_warning(thd, fixed, true, option_limits->name, (int64_t) num);
 
1063
  throw_bounds_warning(thd, fixed, TRUE, option_limits->name, (longlong) num);
964
1064
  return out;
965
1065
}
966
1066
 
967
 
static bool get_unsigned(THD *thd __attribute__((unused)), set_var *var)
 
1067
static bool get_unsigned(THD *thd, set_var *var)
968
1068
{
969
1069
  if (var->value->unsigned_flag)
970
 
    var->save_result.uint64_t_value= (uint64_t) var->value->val_int();
 
1070
    var->save_result.ulonglong_value= (ulonglong) var->value->val_int();
971
1071
  else
972
1072
  {
973
 
    int64_t v= var->value->val_int();
974
 
    var->save_result.uint64_t_value= (uint64_t) ((v < 0) ? 0 : v);
 
1073
    longlong v= var->value->val_int();
 
1074
    var->save_result.ulonglong_value= (ulonglong) ((v < 0) ? 0 : v);
975
1075
  }
976
1076
  return 0;
977
1077
}
992
1092
 
993
1093
bool sys_var_long_ptr_global::update(THD *thd, set_var *var)
994
1094
{
995
 
  uint64_t tmp= var->save_result.uint64_t_value;
 
1095
  ulonglong tmp= var->save_result.ulonglong_value;
996
1096
  pthread_mutex_lock(guard);
997
1097
  if (option_limits)
998
1098
    *value= (ulong) fix_unsigned(thd, tmp, option_limits);
1003
1103
    if (tmp > ULONG_MAX)
1004
1104
    {
1005
1105
      tmp= ULONG_MAX;
1006
 
      throw_bounds_warning(thd, true, true, name,
1007
 
                           (int64_t) var->save_result.uint64_t_value);
 
1106
      throw_bounds_warning(thd, TRUE, TRUE, name,
 
1107
                           (longlong) var->save_result.ulonglong_value);
1008
1108
    }
1009
1109
#endif
1010
1110
    *value= (ulong) tmp;
1015
1115
}
1016
1116
 
1017
1117
 
1018
 
void sys_var_long_ptr_global::set_default(THD *thd __attribute__((unused)), enum_var_type type __attribute__((unused)))
 
1118
void sys_var_long_ptr_global::set_default(THD *thd, enum_var_type type)
1019
1119
{
1020
 
  bool not_used;
 
1120
  my_bool not_used;
1021
1121
  pthread_mutex_lock(guard);
1022
1122
  *value= (ulong) getopt_ull_limit_value((ulong) option_limits->def_value,
1023
1123
                                         option_limits, &not_used);
1025
1125
}
1026
1126
 
1027
1127
 
1028
 
bool sys_var_uint64_t_ptr::update(THD *thd, set_var *var)
 
1128
bool sys_var_ulonglong_ptr::update(THD *thd, set_var *var)
1029
1129
{
1030
 
  uint64_t tmp= var->save_result.uint64_t_value;
 
1130
  ulonglong tmp= var->save_result.ulonglong_value;
1031
1131
  pthread_mutex_lock(&LOCK_global_system_variables);
1032
1132
  if (option_limits)
1033
 
    *value= (uint64_t) fix_unsigned(thd, tmp, option_limits);
 
1133
    *value= (ulonglong) fix_unsigned(thd, tmp, option_limits);
1034
1134
  else
1035
 
    *value= (uint64_t) tmp;
 
1135
    *value= (ulonglong) tmp;
1036
1136
  pthread_mutex_unlock(&LOCK_global_system_variables);
1037
1137
  return 0;
1038
1138
}
1039
1139
 
1040
1140
 
1041
 
void sys_var_uint64_t_ptr::set_default(THD *thd __attribute__((unused)),
1042
 
                                        enum_var_type type __attribute__((unused)))
 
1141
void sys_var_ulonglong_ptr::set_default(THD *thd, enum_var_type type)
1043
1142
{
1044
 
  bool not_used;
 
1143
  my_bool not_used;
1045
1144
  pthread_mutex_lock(&LOCK_global_system_variables);
1046
 
  *value= getopt_ull_limit_value((uint64_t) option_limits->def_value,
 
1145
  *value= getopt_ull_limit_value((ulonglong) option_limits->def_value,
1047
1146
                                 option_limits, &not_used);
1048
1147
  pthread_mutex_unlock(&LOCK_global_system_variables);
1049
1148
}
1050
1149
 
1051
1150
 
1052
 
bool sys_var_bool_ptr::update(THD *thd __attribute__((unused)), set_var *var)
 
1151
bool sys_var_bool_ptr::update(THD *thd, set_var *var)
1053
1152
{
1054
 
  *value= (bool) var->save_result.ulong_value;
 
1153
  *value= (my_bool) var->save_result.ulong_value;
1055
1154
  return 0;
1056
1155
}
1057
1156
 
1058
1157
 
1059
 
void sys_var_bool_ptr::set_default(THD *thd __attribute__((unused)), enum_var_type type __attribute__((unused)))
 
1158
void sys_var_bool_ptr::set_default(THD *thd, enum_var_type type)
1060
1159
{
1061
 
  *value= (bool) option_limits->def_value;
 
1160
  *value= (my_bool) option_limits->def_value;
1062
1161
}
1063
1162
 
1064
1163
 
1065
 
bool sys_var_enum::update(THD *thd __attribute__((unused)), set_var *var)
 
1164
bool sys_var_enum::update(THD *thd, set_var *var)
1066
1165
{
1067
1166
  *value= (uint) var->save_result.ulong_value;
1068
1167
  return 0;
1069
1168
}
1070
1169
 
1071
1170
 
1072
 
unsigned char *sys_var_enum::value_ptr(THD *thd __attribute__((unused)),
1073
 
                               enum_var_type type __attribute__((unused)),
1074
 
                               LEX_STRING *base __attribute__((unused)))
 
1171
uchar *sys_var_enum::value_ptr(THD *thd, enum_var_type type, LEX_STRING *base)
1075
1172
{
1076
 
  return (unsigned char*) enum_names->type_names[*value];
 
1173
  return (uchar*) enum_names->type_names[*value];
1077
1174
}
1078
1175
 
1079
1176
 
1080
 
unsigned char *sys_var_enum_const::value_ptr(THD *thd __attribute__((unused)),
1081
 
                                     enum_var_type type __attribute__((unused)),
1082
 
                                     LEX_STRING *base __attribute__((unused)))
 
1177
uchar *sys_var_enum_const::value_ptr(THD *thd, enum_var_type type,
 
1178
                                     LEX_STRING *base)
1083
1179
{
1084
 
  return (unsigned char*) enum_names->type_names[global_system_variables.*offset];
 
1180
  return (uchar*) enum_names->type_names[global_system_variables.*offset];
1085
1181
}
1086
1182
 
1087
1183
bool sys_var_thd_ulong::check(THD *thd, set_var *var)
1092
1188
 
1093
1189
bool sys_var_thd_ulong::update(THD *thd, set_var *var)
1094
1190
{
1095
 
  uint64_t tmp= var->save_result.uint64_t_value;
1096
 
  
 
1191
  ulonglong tmp= var->save_result.ulonglong_value;
 
1192
 
1097
1193
  /* Don't use bigger value than given with --maximum-variable-name=.. */
1098
1194
  if ((ulong) tmp > max_system_variables.*offset)
1099
1195
  {
1100
 
    throw_bounds_warning(thd, true, true, name, (int64_t) tmp);
 
1196
    throw_bounds_warning(thd, TRUE, TRUE, name, (longlong) tmp);
1101
1197
    tmp= max_system_variables.*offset;
1102
1198
  }
1103
 
  
 
1199
 
1104
1200
  if (option_limits)
1105
1201
    tmp= (ulong) fix_unsigned(thd, tmp, option_limits);
1106
1202
#if SIZEOF_LONG < SIZEOF_LONG_LONG
1107
1203
  else if (tmp > ULONG_MAX)
1108
1204
  {
1109
1205
    tmp= ULONG_MAX;
1110
 
    throw_bounds_warning(thd, true, true, name, (int64_t) var->save_result.uint64_t_value);
 
1206
    throw_bounds_warning(thd, TRUE, TRUE, name, (longlong) var->save_result.ulonglong_value);
1111
1207
  }
1112
1208
#endif
1113
 
  
 
1209
 
1114
1210
  if (var->type == OPT_GLOBAL)
1115
 
     global_system_variables.*offset= (ulong) tmp;
1116
 
   else
1117
 
     thd->variables.*offset= (ulong) tmp;
1118
 
 
1119
 
   return 0;
1120
 
 }
1121
 
 
1122
 
 
1123
 
 void sys_var_thd_ulong::set_default(THD *thd, enum_var_type type)
1124
 
 {
1125
 
   if (type == OPT_GLOBAL)
1126
 
   {
1127
 
     bool not_used;
1128
 
     /* We will not come here if option_limits is not set */
1129
 
     global_system_variables.*offset=
1130
 
       (ulong) getopt_ull_limit_value((ulong) option_limits->def_value,
1131
 
                                      option_limits, &not_used);
1132
 
   }
1133
 
   else
1134
 
     thd->variables.*offset= global_system_variables.*offset;
1135
 
 }
1136
 
 
1137
 
 
1138
 
unsigned char *sys_var_thd_ulong::value_ptr(THD *thd, enum_var_type type,
1139
 
                                    LEX_STRING *base __attribute__((unused)))
1140
 
{
1141
 
  if (type == OPT_GLOBAL)
1142
 
    return (unsigned char*) &(global_system_variables.*offset);
1143
 
  return (unsigned char*) &(thd->variables.*offset);
 
1211
    global_system_variables.*offset= (ulong) tmp;
 
1212
  else
 
1213
    thd->variables.*offset= (ulong) tmp;
 
1214
 
 
1215
  return 0;
 
1216
}
 
1217
 
 
1218
 
 
1219
void sys_var_thd_ulong::set_default(THD *thd, enum_var_type type)
 
1220
{
 
1221
  if (type == OPT_GLOBAL)
 
1222
  {
 
1223
    my_bool not_used;
 
1224
    /* We will not come here if option_limits is not set */
 
1225
    global_system_variables.*offset=
 
1226
      (ulong) getopt_ull_limit_value((ulong) option_limits->def_value,
 
1227
                                     option_limits, &not_used);
 
1228
  }
 
1229
  else
 
1230
    thd->variables.*offset= global_system_variables.*offset;
 
1231
}
 
1232
 
 
1233
 
 
1234
uchar *sys_var_thd_ulong::value_ptr(THD *thd, enum_var_type type,
 
1235
                                   LEX_STRING *base)
 
1236
{
 
1237
  if (type == OPT_GLOBAL)
 
1238
    return (uchar*) &(global_system_variables.*offset);
 
1239
  return (uchar*) &(thd->variables.*offset);
1144
1240
}
1145
1241
 
1146
1242
 
1147
1243
bool sys_var_thd_ha_rows::update(THD *thd, set_var *var)
1148
1244
{
1149
 
  uint64_t tmp= var->save_result.uint64_t_value;
 
1245
  ulonglong tmp= var->save_result.ulonglong_value;
1150
1246
 
1151
1247
  /* Don't use bigger value than given with --maximum-variable-name=.. */
1152
1248
  if ((ha_rows) tmp > max_system_variables.*offset)
1171
1267
{
1172
1268
  if (type == OPT_GLOBAL)
1173
1269
  {
1174
 
    bool not_used;
 
1270
    my_bool not_used;
1175
1271
    /* We will not come here if option_limits is not set */
1176
1272
    pthread_mutex_lock(&LOCK_global_system_variables);
1177
1273
    global_system_variables.*offset=
1184
1280
}
1185
1281
 
1186
1282
 
1187
 
unsigned char *sys_var_thd_ha_rows::value_ptr(THD *thd, enum_var_type type,
1188
 
                                      LEX_STRING *base __attribute__((unused)))
 
1283
uchar *sys_var_thd_ha_rows::value_ptr(THD *thd, enum_var_type type,
 
1284
                                     LEX_STRING *base)
1189
1285
{
1190
1286
  if (type == OPT_GLOBAL)
1191
 
    return (unsigned char*) &(global_system_variables.*offset);
1192
 
  return (unsigned char*) &(thd->variables.*offset);
 
1287
    return (uchar*) &(global_system_variables.*offset);
 
1288
  return (uchar*) &(thd->variables.*offset);
1193
1289
}
1194
1290
 
1195
 
bool sys_var_thd_uint64_t::check(THD *thd, set_var *var)
 
1291
bool sys_var_thd_ulonglong::check(THD *thd, set_var *var)
1196
1292
{
1197
1293
  return get_unsigned(thd, var);
1198
1294
}
1199
1295
 
1200
 
bool sys_var_thd_uint64_t::update(THD *thd,  set_var *var)
 
1296
bool sys_var_thd_ulonglong::update(THD *thd,  set_var *var)
1201
1297
{
1202
 
  uint64_t tmp= var->save_result.uint64_t_value;
 
1298
  ulonglong tmp= var->save_result.ulonglong_value;
1203
1299
 
1204
1300
  if (tmp > max_system_variables.*offset)
1205
1301
    tmp= max_system_variables.*offset;
1210
1306
  {
1211
1307
    /* Lock is needed to make things safe on 32 bit systems */
1212
1308
    pthread_mutex_lock(&LOCK_global_system_variables);
1213
 
    global_system_variables.*offset= (uint64_t) tmp;
 
1309
    global_system_variables.*offset= (ulonglong) tmp;
1214
1310
    pthread_mutex_unlock(&LOCK_global_system_variables);
1215
1311
  }
1216
1312
  else
1217
 
    thd->variables.*offset= (uint64_t) tmp;
 
1313
    thd->variables.*offset= (ulonglong) tmp;
1218
1314
  return 0;
1219
1315
}
1220
1316
 
1221
1317
 
1222
 
void sys_var_thd_uint64_t::set_default(THD *thd, enum_var_type type)
 
1318
void sys_var_thd_ulonglong::set_default(THD *thd, enum_var_type type)
1223
1319
{
1224
1320
  if (type == OPT_GLOBAL)
1225
1321
  {
1226
 
    bool not_used;
 
1322
    my_bool not_used;
1227
1323
    pthread_mutex_lock(&LOCK_global_system_variables);
1228
1324
    global_system_variables.*offset=
1229
 
      getopt_ull_limit_value((uint64_t) option_limits->def_value,
 
1325
      getopt_ull_limit_value((ulonglong) option_limits->def_value,
1230
1326
                             option_limits, &not_used);
1231
1327
    pthread_mutex_unlock(&LOCK_global_system_variables);
1232
1328
  }
1235
1331
}
1236
1332
 
1237
1333
 
1238
 
unsigned char *sys_var_thd_uint64_t::value_ptr(THD *thd, enum_var_type type,
1239
 
                                        LEX_STRING *base __attribute__((unused)))
 
1334
uchar *sys_var_thd_ulonglong::value_ptr(THD *thd, enum_var_type type,
 
1335
                                       LEX_STRING *base)
1240
1336
{
1241
1337
  if (type == OPT_GLOBAL)
1242
 
    return (unsigned char*) &(global_system_variables.*offset);
1243
 
  return (unsigned char*) &(thd->variables.*offset);
 
1338
    return (uchar*) &(global_system_variables.*offset);
 
1339
  return (uchar*) &(thd->variables.*offset);
1244
1340
}
1245
1341
 
1246
1342
 
1247
1343
bool sys_var_thd_bool::update(THD *thd,  set_var *var)
1248
1344
{
1249
1345
  if (var->type == OPT_GLOBAL)
1250
 
    global_system_variables.*offset= (bool) var->save_result.ulong_value;
 
1346
    global_system_variables.*offset= (my_bool) var->save_result.ulong_value;
1251
1347
  else
1252
 
    thd->variables.*offset= (bool) var->save_result.ulong_value;
 
1348
    thd->variables.*offset= (my_bool) var->save_result.ulong_value;
1253
1349
  return 0;
1254
1350
}
1255
1351
 
1257
1353
void sys_var_thd_bool::set_default(THD *thd,  enum_var_type type)
1258
1354
{
1259
1355
  if (type == OPT_GLOBAL)
1260
 
    global_system_variables.*offset= (bool) option_limits->def_value;
 
1356
    global_system_variables.*offset= (my_bool) option_limits->def_value;
1261
1357
  else
1262
1358
    thd->variables.*offset= global_system_variables.*offset;
1263
1359
}
1264
1360
 
1265
1361
 
1266
 
unsigned char *sys_var_thd_bool::value_ptr(THD *thd, enum_var_type type,
1267
 
                                   LEX_STRING *base __attribute__((unused)))
 
1362
uchar *sys_var_thd_bool::value_ptr(THD *thd, enum_var_type type,
 
1363
                                  LEX_STRING *base)
1268
1364
{
1269
1365
  if (type == OPT_GLOBAL)
1270
 
    return (unsigned char*) &(global_system_variables.*offset);
1271
 
  return (unsigned char*) &(thd->variables.*offset);
 
1366
    return (uchar*) &(global_system_variables.*offset);
 
1367
  return (uchar*) &(thd->variables.*offset);
1272
1368
}
1273
1369
 
1274
1370
 
1275
 
bool sys_var::check_enum(THD *thd __attribute__((unused)),
1276
 
                         set_var *var, const TYPELIB *enum_names)
 
1371
bool sys_var::check_enum(THD *thd, set_var *var, const TYPELIB *enum_names)
1277
1372
{
1278
1373
  char buff[STRING_BUFFER_USUAL_SIZE];
1279
1374
  const char *value;
1292
1387
  }
1293
1388
  else
1294
1389
  {
1295
 
    uint64_t tmp=var->value->val_int();
 
1390
    ulonglong tmp=var->value->val_int();
1296
1391
    if (tmp >= enum_names->count)
1297
1392
    {
1298
1393
      llstr(tmp,buff);
1309
1404
}
1310
1405
 
1311
1406
 
1312
 
bool sys_var::check_set(THD *thd __attribute__((unused)),
1313
 
                        set_var *var, TYPELIB *enum_names)
 
1407
bool sys_var::check_set(THD *thd, set_var *var, TYPELIB *enum_names)
1314
1408
{
1315
1409
  bool not_used;
1316
1410
  char buff[STRING_BUFFER_USUAL_SIZE], *error= 0;
1317
 
  uint32_t error_len= 0;
 
1411
  uint error_len= 0;
1318
1412
  String str(buff, sizeof(buff), system_charset_info), *res;
1319
1413
 
1320
1414
  if (var->value->result_type() == STRING_RESULT)
1321
1415
  {
1322
1416
    if (!(res= var->value->val_str(&str)))
1323
1417
    {
1324
 
      my_stpcpy(buff, "NULL");
 
1418
      strmov(buff, "NULL");
1325
1419
      goto err;
1326
1420
    }
1327
1421
 
1340
1434
                                            &not_used));
1341
1435
    if (error_len)
1342
1436
    {
1343
 
      strmake(buff, error, cmin(sizeof(buff) - 1, (ulong)error_len));
 
1437
      strmake(buff, error, min(sizeof(buff) - 1, error_len));
1344
1438
      goto err;
1345
1439
    }
1346
1440
  }
1347
1441
  else
1348
1442
  {
1349
 
    uint64_t tmp= var->value->val_int();
 
1443
    ulonglong tmp= var->value->val_int();
1350
1444
 
1351
1445
    if (!m_allow_empty_value &&
1352
1446
        tmp == 0)
1360
1454
      For when the enum is made to contain 64 elements, as 1ULL<<64 is
1361
1455
      undefined, we guard with a "count<64" test.
1362
1456
    */
1363
 
    if (unlikely((tmp >= ((1UL) << enum_names->count)) &&
 
1457
    if (unlikely((tmp >= ((ULL(1)) << enum_names->count)) &&
1364
1458
                 (enum_names->count < 64)))
1365
1459
    {
1366
1460
      llstr(tmp, buff);
1400
1494
  switch (show_type()) {
1401
1495
  case SHOW_INT:
1402
1496
  {
1403
 
    uint32_t value;
 
1497
    uint value;
1404
1498
    pthread_mutex_lock(&LOCK_global_system_variables);
1405
1499
    value= *(uint*) value_ptr(thd, var_type, base);
1406
1500
    pthread_mutex_unlock(&LOCK_global_system_variables);
1407
 
    return new Item_uint((uint64_t) value);
 
1501
    return new Item_uint((ulonglong) value);
1408
1502
  }
1409
1503
  case SHOW_LONG:
1410
1504
  {
1412
1506
    pthread_mutex_lock(&LOCK_global_system_variables);
1413
1507
    value= *(ulong*) value_ptr(thd, var_type, base);
1414
1508
    pthread_mutex_unlock(&LOCK_global_system_variables);
1415
 
    return new Item_uint((uint64_t) value);
 
1509
    return new Item_uint((ulonglong) value);
1416
1510
  }
1417
1511
  case SHOW_LONGLONG:
1418
1512
  {
1419
 
    int64_t value;
 
1513
    longlong value;
1420
1514
    pthread_mutex_lock(&LOCK_global_system_variables);
1421
 
    value= *(int64_t*) value_ptr(thd, var_type, base);
 
1515
    value= *(longlong*) value_ptr(thd, var_type, base);
1422
1516
    pthread_mutex_unlock(&LOCK_global_system_variables);
1423
1517
    return new Item_int(value);
1424
1518
  }
1437
1531
    pthread_mutex_lock(&LOCK_global_system_variables);
1438
1532
    value= *(ha_rows*) value_ptr(thd, var_type, base);
1439
1533
    pthread_mutex_unlock(&LOCK_global_system_variables);
1440
 
    return new Item_int((uint64_t) value);
 
1534
    return new Item_int((ulonglong) value);
1441
1535
  }
1442
1536
  case SHOW_MY_BOOL:
1443
1537
  {
1444
 
    int32_t value;
 
1538
    int32 value;
1445
1539
    pthread_mutex_lock(&LOCK_global_system_variables);
1446
 
    value= *(bool*) value_ptr(thd, var_type, base);
 
1540
    value= *(my_bool*) value_ptr(thd, var_type, base);
1447
1541
    pthread_mutex_unlock(&LOCK_global_system_variables);
1448
1542
    return new Item_int(value,1);
1449
1543
  }
1454
1548
    char *str= *(char**) value_ptr(thd, var_type, base);
1455
1549
    if (str)
1456
1550
    {
1457
 
      uint32_t length= strlen(str);
 
1551
      uint length= strlen(str);
1458
1552
      tmp= new Item_string(thd->strmake(str, length), length,
1459
1553
                           system_charset_info, DERIVATION_SYSCONST);
1460
1554
    }
1508
1602
}
1509
1603
 
1510
1604
 
1511
 
unsigned char *sys_var_thd_enum::value_ptr(THD *thd, enum_var_type type,
1512
 
                                   LEX_STRING *base __attribute__((unused)))
 
1605
uchar *sys_var_thd_enum::value_ptr(THD *thd, enum_var_type type,
 
1606
                                  LEX_STRING *base)
1513
1607
{
1514
1608
  ulong tmp= ((type == OPT_GLOBAL) ?
1515
1609
              global_system_variables.*offset :
1516
1610
              thd->variables.*offset);
1517
 
  return (unsigned char*) enum_names->type_names[tmp];
 
1611
  return (uchar*) enum_names->type_names[tmp];
1518
1612
}
1519
1613
 
1520
1614
bool sys_var_thd_bit::check(THD *thd, set_var *var)
1530
1624
}
1531
1625
 
1532
1626
 
1533
 
unsigned char *sys_var_thd_bit::value_ptr(THD *thd,
1534
 
                                  enum_var_type type __attribute__((unused)),
1535
 
                                  LEX_STRING *base __attribute__((unused)))
 
1627
uchar *sys_var_thd_bit::value_ptr(THD *thd, enum_var_type type,
 
1628
                                 LEX_STRING *base)
1536
1629
{
1537
1630
  /*
1538
1631
    If reverse is 0 (default) return 1 if bit is set.
1539
1632
    If reverse is 1, return 0 if bit is set
1540
1633
  */
1541
 
  thd->sys_var_tmp.bool_value= ((thd->options & bit_flag) ?
 
1634
  thd->sys_var_tmp.my_bool_value= ((thd->options & bit_flag) ?
1542
1635
                                   !reverse : reverse);
1543
 
  return (unsigned char*) &thd->sys_var_tmp.bool_value;
 
1636
  return (uchar*) &thd->sys_var_tmp.my_bool_value;
1544
1637
}
1545
1638
 
1546
1639
 
1550
1643
                                           DATE_TIME_FORMAT *new_value)
1551
1644
{
1552
1645
  DATE_TIME_FORMAT *old;
 
1646
  DBUG_ENTER("sys_var_date_time_format::update2");
 
1647
  DBUG_DUMP("positions", (uchar*) new_value->positions,
 
1648
            sizeof(new_value->positions));
1553
1649
 
1554
1650
  if (type == OPT_GLOBAL)
1555
1651
  {
1563
1659
    old= (thd->variables.*offset);
1564
1660
    (thd->variables.*offset)= new_value;
1565
1661
  }
1566
 
  free((char*) old);
1567
 
  return;
 
1662
  my_free((char*) old, MYF(MY_ALLOW_ZERO_PTR));
 
1663
  DBUG_VOID_RETURN;
1568
1664
}
1569
1665
 
1570
1666
 
1602
1698
    update is aborted
1603
1699
  */
1604
1700
  var->save_result.date_time_format= date_time_format_copy(thd, format);
1605
 
  free((char*) format);
 
1701
  my_free((char*) format, MYF(0));
1606
1702
  return var->save_result.date_time_format == 0;
1607
1703
}
1608
1704
 
1628
1724
}
1629
1725
 
1630
1726
 
1631
 
unsigned char *sys_var_thd_date_time_format::value_ptr(THD *thd, enum_var_type type,
1632
 
                                               LEX_STRING *base __attribute__((unused)))
 
1727
uchar *sys_var_thd_date_time_format::value_ptr(THD *thd, enum_var_type type,
 
1728
                                              LEX_STRING *base)
1633
1729
{
1634
1730
  if (type == OPT_GLOBAL)
1635
1731
  {
1641
1737
    */
1642
1738
    res= thd->strmake((global_system_variables.*offset)->format.str,
1643
1739
                      (global_system_variables.*offset)->format.length);
1644
 
    return (unsigned char*) res;
 
1740
    return (uchar*) res;
1645
1741
  }
1646
 
  return (unsigned char*) (thd->variables.*offset)->format.str;
 
1742
  return (uchar*) (thd->variables.*offset)->format.str;
1647
1743
}
1648
1744
 
1649
1745
 
1653
1749
  const char *new_name;
1654
1750
} my_old_conv;
1655
1751
 
1656
 
bool sys_var_collation::check(THD *thd __attribute__((unused)),
1657
 
                              set_var *var)
1658
 
{
1659
 
  const CHARSET_INFO *tmp;
 
1752
static my_old_conv old_conv[]= 
 
1753
{
 
1754
  {     "cp1251_koi8"           ,       "cp1251"        },
 
1755
  {     "cp1250_latin2"         ,       "cp1250"        },
 
1756
  {     "kam_latin2"            ,       "keybcs2"       },
 
1757
  {     "mac_latin2"            ,       "MacRoman"      },
 
1758
  {     "macce_latin2"          ,       "MacCE"         },
 
1759
  {     "pc2_latin2"            ,       "pclatin2"      },
 
1760
  {     "vga_latin2"            ,       "pclatin1"      },
 
1761
  {     "koi8_cp1251"           ,       "koi8r"         },
 
1762
  {     "win1251ukr_koi8_ukr"   ,       "win1251ukr"    },
 
1763
  {     "koi8_ukr_win1251ukr"   ,       "koi8u"         },
 
1764
  {     NULL                    ,       NULL            }
 
1765
};
 
1766
 
 
1767
CHARSET_INFO *get_old_charset_by_name(const char *name)
 
1768
{
 
1769
  my_old_conv *conv;
 
1770
 
 
1771
  for (conv= old_conv; conv->old_name; conv++)
 
1772
  {
 
1773
    if (!my_strcasecmp(&my_charset_latin1, name, conv->old_name))
 
1774
      return get_charset_by_csname(conv->new_name, MY_CS_PRIMARY, MYF(0));
 
1775
  }
 
1776
  return NULL;
 
1777
}
 
1778
 
 
1779
 
 
1780
bool sys_var_collation::check(THD *thd, set_var *var)
 
1781
{
 
1782
  CHARSET_INFO *tmp;
1660
1783
 
1661
1784
  if (var->value->result_type() == STRING_RESULT)
1662
1785
  {
1688
1811
}
1689
1812
 
1690
1813
 
1691
 
bool sys_var_character_set::check(THD *thd __attribute__((unused)),
1692
 
                                  set_var *var)
 
1814
bool sys_var_character_set::check(THD *thd, set_var *var)
1693
1815
{
1694
 
  const CHARSET_INFO *tmp;
 
1816
  CHARSET_INFO *tmp;
1695
1817
 
1696
1818
  if (var->value->result_type() == STRING_RESULT)
1697
1819
  {
1706
1828
      }
1707
1829
      tmp= NULL;
1708
1830
    }
1709
 
    else if (!(tmp= get_charset_by_csname(res->c_ptr(),MY_CS_PRIMARY,MYF(0))))
 
1831
    else if (!(tmp=get_charset_by_csname(res->c_ptr(),MY_CS_PRIMARY,MYF(0))) &&
 
1832
             !(tmp=get_old_charset_by_name(res->c_ptr())))
1710
1833
    {
1711
1834
      my_error(ER_UNKNOWN_CHARACTER_SET, MYF(0), res->c_ptr());
1712
1835
      return 1;
1735
1858
}
1736
1859
 
1737
1860
 
1738
 
unsigned char *sys_var_character_set::value_ptr(THD *thd, enum_var_type type,
1739
 
                                        LEX_STRING *base __attribute__((unused)))
 
1861
uchar *sys_var_character_set::value_ptr(THD *thd, enum_var_type type,
 
1862
                                       LEX_STRING *base)
1740
1863
{
1741
 
  const CHARSET_INFO * const cs= ci_ptr(thd,type)[0];
1742
 
  return cs ? (unsigned char*) cs->csname : (unsigned char*) NULL;
 
1864
  CHARSET_INFO *cs= ci_ptr(thd,type)[0];
 
1865
  return cs ? (uchar*) cs->csname : (uchar*) NULL;
1743
1866
}
1744
1867
 
1745
1868
 
1753
1876
    thd->update_charset();
1754
1877
  }
1755
1878
}
1756
 
const CHARSET_INFO **sys_var_character_set_sv::ci_ptr(THD *thd, enum_var_type type)
 
1879
CHARSET_INFO **sys_var_character_set_sv::ci_ptr(THD *thd, enum_var_type type)
1757
1880
{
1758
1881
  if (type == OPT_GLOBAL)
1759
1882
    return &(global_system_variables.*offset);
1777
1900
}
1778
1901
 
1779
1902
 
1780
 
const CHARSET_INFO ** sys_var_character_set_database::ci_ptr(THD *thd,
 
1903
CHARSET_INFO ** sys_var_character_set_database::ci_ptr(THD *thd,
1781
1904
                                                       enum_var_type type)
1782
1905
{
1783
1906
  if (type == OPT_GLOBAL)
1824
1947
}
1825
1948
 
1826
1949
 
1827
 
unsigned char *sys_var_collation_sv::value_ptr(THD *thd, enum_var_type type,
1828
 
                                       LEX_STRING *base __attribute__((unused)))
 
1950
uchar *sys_var_collation_sv::value_ptr(THD *thd, enum_var_type type,
 
1951
                                       LEX_STRING *base)
1829
1952
{
1830
 
  const CHARSET_INFO *cs= ((type == OPT_GLOBAL) ?
 
1953
  CHARSET_INFO *cs= ((type == OPT_GLOBAL) ?
1831
1954
                     global_system_variables.*offset : thd->variables.*offset);
1832
 
  return cs ? (unsigned char*) cs->name : (unsigned char*) "NULL";
 
1955
  return cs ? (uchar*) cs->name : (uchar*) "NULL";
1833
1956
}
1834
1957
 
1835
1958
 
1847
1970
}
1848
1971
 
1849
1972
 
1850
 
unsigned char *sys_var_key_cache_param::value_ptr(THD *thd __attribute__((unused)),
1851
 
                                          enum_var_type type __attribute__((unused)),
1852
 
                                          LEX_STRING *base __attribute__((unused)))
 
1973
uchar *sys_var_key_cache_param::value_ptr(THD *thd, enum_var_type type,
 
1974
                                         LEX_STRING *base)
1853
1975
{
1854
1976
  KEY_CACHE *key_cache= get_key_cache(base);
1855
1977
  if (!key_cache)
1856
1978
    key_cache= &zero_key_cache;
1857
 
  return (unsigned char*) key_cache + offset ;
 
1979
  return (uchar*) key_cache + offset ;
1858
1980
}
1859
1981
 
1860
1982
 
1861
1983
bool sys_var_key_buffer_size::update(THD *thd, set_var *var)
1862
1984
{
1863
 
  uint64_t tmp= var->save_result.uint64_t_value;
 
1985
  ulonglong tmp= var->save_result.ulonglong_value;
1864
1986
  LEX_STRING *base_name= &var->base;
1865
1987
  KEY_CACHE *key_cache;
1866
1988
  bool error= 0;
1896
2018
  {
1897
2019
    if (key_cache == dflt_key_cache)
1898
2020
    {
1899
 
      push_warning_printf(thd, DRIZZLE_ERROR::WARN_LEVEL_WARN,
 
2021
      push_warning_printf(thd, MYSQL_ERROR::WARN_LEVEL_WARN,
1900
2022
                          ER_WARN_CANT_DROP_DEFAULT_KEYCACHE,
1901
2023
                          ER(ER_WARN_CANT_DROP_DEFAULT_KEYCACHE));
1902
2024
      goto end;                                 // Ignore default key cache
1925
2047
  }
1926
2048
 
1927
2049
  key_cache->param_buff_size=
1928
 
    (uint64_t) fix_unsigned(thd, tmp, option_limits);
 
2050
    (ulonglong) fix_unsigned(thd, tmp, option_limits);
1929
2051
 
1930
2052
  /* If key cache didn't existed initialize it, else resize it */
1931
2053
  key_cache->in_init= 1;
2000
2122
}
2001
2123
 
2002
2124
 
2003
 
bool sys_var_log_state::update(THD *thd __attribute__((unused)), set_var *var)
 
2125
bool sys_var_log_state::update(THD *thd, set_var *var)
2004
2126
{
2005
2127
  bool res;
2006
2128
  pthread_mutex_lock(&LOCK_global_system_variables);
2007
2129
  if (!var->save_result.ulong_value)
 
2130
  {
 
2131
    logger.deactivate_log_handler(thd, log_type);
2008
2132
    res= false;
 
2133
  }
2009
2134
  else
2010
 
    res= true;
 
2135
    res= logger.activate_log_handler(thd, log_type);
2011
2136
  pthread_mutex_unlock(&LOCK_global_system_variables);
2012
2137
  return res;
2013
2138
}
2014
2139
 
2015
 
void sys_var_log_state::set_default(THD *thd __attribute__((unused)),
2016
 
                                    enum_var_type type __attribute__((unused)))
2017
 
{
2018
 
}
2019
 
 
2020
 
 
2021
 
bool update_sys_var_str_path(THD *thd __attribute__((unused)),
2022
 
                             sys_var_str *var_str,
2023
 
                             set_var *var, const char *log_ext,
2024
 
                             bool log_state, uint32_t log_type)
2025
 
{
 
2140
void sys_var_log_state::set_default(THD *thd, enum_var_type type)
 
2141
{
 
2142
  pthread_mutex_lock(&LOCK_global_system_variables);
 
2143
  logger.deactivate_log_handler(thd, log_type);
 
2144
  pthread_mutex_unlock(&LOCK_global_system_variables);
 
2145
}
 
2146
 
 
2147
 
 
2148
static int  sys_check_log_path(THD *thd,  set_var *var)
 
2149
{
 
2150
  char path[FN_REFLEN], buff[FN_REFLEN];
 
2151
  struct stat f_stat;
 
2152
  String str(buff, sizeof(buff), system_charset_info), *res;
 
2153
  const char *log_file_str;
 
2154
  size_t path_length;
 
2155
 
 
2156
  if (!(res= var->value->val_str(&str)))
 
2157
    goto err;
 
2158
 
 
2159
  log_file_str= res->c_ptr();
 
2160
  bzero(&f_stat, sizeof(struct stat));
 
2161
 
 
2162
  path_length= unpack_filename(path, log_file_str);
 
2163
 
 
2164
  if (!path_length)
 
2165
  {
 
2166
    /* File name is empty. */
 
2167
 
 
2168
    goto err;
 
2169
  }
 
2170
 
 
2171
  if (!stat(path, &f_stat))
 
2172
  {
 
2173
    /*
 
2174
      A file system object exists. Check if argument is a file and we have
 
2175
      'write' permission.
 
2176
    */
 
2177
 
 
2178
    if (!MY_S_ISREG(f_stat.st_mode) ||
 
2179
        !(f_stat.st_mode & MY_S_IWRITE))
 
2180
      goto err;
 
2181
 
 
2182
    return 0;
 
2183
  }
 
2184
 
 
2185
  /* Get dirname of the file path. */
 
2186
  (void) dirname_part(path, log_file_str, &path_length);
 
2187
 
 
2188
  /* Dirname is empty if file path is relative. */
 
2189
  if (!path_length)
 
2190
    return 0;
 
2191
 
 
2192
  /*
 
2193
    Check if directory exists and we have permission to create file and
 
2194
    write to file.
 
2195
  */
 
2196
  if (my_access(path, (F_OK|W_OK)))
 
2197
    goto err;
 
2198
 
 
2199
  return 0;
 
2200
 
 
2201
err:
 
2202
  my_error(ER_WRONG_VALUE_FOR_VAR, MYF(0), var->var->name, 
 
2203
           res ? log_file_str : "NULL");
 
2204
  return 1;
 
2205
}
 
2206
 
 
2207
 
 
2208
bool update_sys_var_str_path(THD *thd, sys_var_str *var_str,
 
2209
                             set_var *var, const char *log_ext,
 
2210
                             bool log_state, uint log_type)
 
2211
{
 
2212
  MYSQL_QUERY_LOG *file_log;
2026
2213
  char buff[FN_REFLEN];
2027
2214
  char *res= 0, *old_value=(char *)(var ? var->value->str_value.ptr() : 0);
2028
2215
  bool result= 0;
2029
 
  uint32_t str_length= (var ? var->value->str_value.length() : 0);
 
2216
  uint str_length= (var ? var->value->str_value.length() : 0);
2030
2217
 
2031
2218
  switch (log_type) {
 
2219
  case QUERY_LOG_SLOW:
 
2220
    file_log= logger.get_slow_log_file_handler();
 
2221
    break;
 
2222
  case QUERY_LOG_GENERAL:
 
2223
    file_log= logger.get_log_file_handler();
 
2224
    break;
2032
2225
  default:
2033
2226
    assert(0);                                  // Impossible
2034
2227
  }
2047
2240
  pthread_mutex_lock(&LOCK_global_system_variables);
2048
2241
  logger.lock_exclusive();
2049
2242
 
 
2243
  if (file_log && log_state)
 
2244
    file_log->close(0);
2050
2245
  old_value= var_str->value;
2051
2246
  var_str->value= res;
2052
2247
  var_str->value_length= str_length;
2053
 
  free(old_value);
2054
 
  if (log_state)
 
2248
  my_free(old_value, MYF(MY_ALLOW_ZERO_PTR));
 
2249
  if (file_log && log_state)
2055
2250
  {
2056
2251
    switch (log_type) {
 
2252
    case QUERY_LOG_SLOW:
 
2253
      file_log->open_slow_log(sys_var_slow_log_path.value);
 
2254
      break;
 
2255
    case QUERY_LOG_GENERAL:
 
2256
      file_log->open_query_log(sys_var_general_log_path.value);
 
2257
      break;
2057
2258
    default:
2058
 
      assert(0);
 
2259
      DBUG_ASSERT(0);
2059
2260
    }
2060
2261
  }
2061
2262
 
2067
2268
}
2068
2269
 
2069
2270
 
2070
 
bool sys_var_log_output::update(THD *thd __attribute__((unused)),
2071
 
                                set_var *var)
 
2271
static bool sys_update_general_log_path(THD *thd, set_var * var)
 
2272
{
 
2273
  return update_sys_var_str_path(thd, &sys_var_general_log_path, 
 
2274
                                 var, ".log", opt_log, QUERY_LOG_GENERAL);
 
2275
}
 
2276
 
 
2277
 
 
2278
static void sys_default_general_log_path(THD *thd, enum_var_type type)
 
2279
{
 
2280
  (void) update_sys_var_str_path(thd, &sys_var_general_log_path,
 
2281
                                 0, ".log", opt_log, QUERY_LOG_GENERAL);
 
2282
}
 
2283
 
 
2284
 
 
2285
static bool sys_update_slow_log_path(THD *thd, set_var * var)
 
2286
{
 
2287
  return update_sys_var_str_path(thd, &sys_var_slow_log_path,
 
2288
                                 var, "-slow.log", opt_slow_log,
 
2289
                                 QUERY_LOG_SLOW);
 
2290
}
 
2291
 
 
2292
 
 
2293
static void sys_default_slow_log_path(THD *thd, enum_var_type type)
 
2294
{
 
2295
  (void) update_sys_var_str_path(thd, &sys_var_slow_log_path,
 
2296
                                 0, "-slow.log", opt_slow_log,
 
2297
                                 QUERY_LOG_SLOW);
 
2298
}
 
2299
 
 
2300
 
 
2301
bool sys_var_log_output::update(THD *thd, set_var *var)
2072
2302
{
2073
2303
  pthread_mutex_lock(&LOCK_global_system_variables);
2074
2304
  logger.lock_exclusive();
 
2305
  logger.init_slow_log(var->save_result.ulong_value);
 
2306
  logger.init_general_log(var->save_result.ulong_value);
2075
2307
  *value= var->save_result.ulong_value;
2076
2308
  logger.unlock();
2077
2309
  pthread_mutex_unlock(&LOCK_global_system_variables);
2079
2311
}
2080
2312
 
2081
2313
 
2082
 
void sys_var_log_output::set_default(THD *thd __attribute__((unused)),
2083
 
                                     enum_var_type type __attribute__((unused)))
 
2314
void sys_var_log_output::set_default(THD *thd, enum_var_type type)
2084
2315
{
2085
2316
  pthread_mutex_lock(&LOCK_global_system_variables);
2086
2317
  logger.lock_exclusive();
 
2318
  logger.init_slow_log(LOG_FILE);
 
2319
  logger.init_general_log(LOG_FILE);
2087
2320
  *value= LOG_FILE;
2088
2321
  logger.unlock();
2089
2322
  pthread_mutex_unlock(&LOCK_global_system_variables);
2090
2323
}
2091
2324
 
2092
2325
 
2093
 
unsigned char *sys_var_log_output::value_ptr(THD *thd,
2094
 
                                     enum_var_type type __attribute__((unused)),
2095
 
                                     LEX_STRING *base __attribute__((unused)))
 
2326
uchar *sys_var_log_output::value_ptr(THD *thd, enum_var_type type,
 
2327
                                    LEX_STRING *base)
2096
2328
{
2097
2329
  char buff[256];
2098
 
  String tmp(buff, sizeof(buff), &my_charset_utf8_general_ci);
 
2330
  String tmp(buff, sizeof(buff), &my_charset_latin1);
2099
2331
  ulong length;
2100
2332
  ulong val= *value;
2101
2333
 
2102
2334
  tmp.length(0);
2103
 
  for (uint32_t i= 0; val; val>>= 1, i++)
 
2335
  for (uint i= 0; val; val>>= 1, i++)
2104
2336
  {
2105
2337
    if (val & 1)
2106
2338
    {
2112
2344
 
2113
2345
  if ((length= tmp.length()))
2114
2346
    length--;
2115
 
  return (unsigned char*) thd->strmake(tmp.ptr(), length);
 
2347
  return (uchar*) thd->strmake(tmp.ptr(), length);
2116
2348
}
2117
2349
 
2118
2350
 
2120
2352
  Functions to handle SET NAMES and SET CHARACTER SET
2121
2353
*****************************************************************************/
2122
2354
 
2123
 
int set_var_collation_client::check(THD *thd __attribute__((unused)))
 
2355
int set_var_collation_client::check(THD *thd)
2124
2356
{
2125
2357
  /* Currently, UCS-2 cannot be used as a client character set */
2126
2358
  if (character_set_client->mbminlen > 1)
2146
2378
 
2147
2379
bool sys_var_timestamp::update(THD *thd,  set_var *var)
2148
2380
{
2149
 
  thd->set_time((time_t) var->save_result.uint64_t_value);
 
2381
  thd->set_time((time_t) var->save_result.ulonglong_value);
2150
2382
  return 0;
2151
2383
}
2152
2384
 
2153
2385
 
2154
 
void sys_var_timestamp::set_default(THD *thd,
2155
 
                                    enum_var_type type __attribute__((unused)))
 
2386
void sys_var_timestamp::set_default(THD *thd, enum_var_type type)
2156
2387
{
2157
2388
  thd->user_time=0;
2158
2389
}
2159
2390
 
2160
2391
 
2161
 
unsigned char *sys_var_timestamp::value_ptr(THD *thd,
2162
 
                                    enum_var_type type __attribute__((unused)),
2163
 
                                    LEX_STRING *base __attribute__((unused)))
 
2392
uchar *sys_var_timestamp::value_ptr(THD *thd, enum_var_type type,
 
2393
                                   LEX_STRING *base)
2164
2394
{
2165
2395
  thd->sys_var_tmp.long_value= (long) thd->start_time;
2166
 
  return (unsigned char*) &thd->sys_var_tmp.long_value;
 
2396
  return (uchar*) &thd->sys_var_tmp.long_value;
2167
2397
}
2168
2398
 
2169
2399
 
2170
2400
bool sys_var_last_insert_id::update(THD *thd, set_var *var)
2171
2401
{
2172
 
  thd->first_successful_insert_id_in_prev_stmt=
2173
 
    var->save_result.uint64_t_value;
 
2402
  thd->first_successful_insert_id_in_prev_stmt= 
 
2403
    var->save_result.ulonglong_value;
2174
2404
  return 0;
2175
2405
}
2176
2406
 
2177
2407
 
2178
 
unsigned char *sys_var_last_insert_id::value_ptr(THD *thd,
2179
 
                                         enum_var_type type __attribute__((unused)),
2180
 
                                         LEX_STRING *base __attribute__((unused)))
 
2408
uchar *sys_var_last_insert_id::value_ptr(THD *thd, enum_var_type type,
 
2409
                                        LEX_STRING *base)
2181
2410
{
2182
2411
  /*
2183
 
    this tmp var makes it robust againt change of type of
 
2412
    this tmp var makes it robust againt change of type of 
2184
2413
    read_first_successful_insert_id_in_prev_stmt().
2185
2414
  */
2186
 
  thd->sys_var_tmp.uint64_t_value= 
 
2415
  thd->sys_var_tmp.ulonglong_value= 
2187
2416
    thd->read_first_successful_insert_id_in_prev_stmt();
2188
 
  return (unsigned char*) &thd->sys_var_tmp.uint64_t_value;
 
2417
  return (uchar*) &thd->sys_var_tmp.ulonglong_value;
2189
2418
}
2190
2419
 
2191
2420
 
2192
2421
bool sys_var_insert_id::update(THD *thd, set_var *var)
2193
2422
{
2194
 
  thd->force_one_auto_inc_interval(var->save_result.uint64_t_value);
 
2423
  thd->force_one_auto_inc_interval(var->save_result.ulonglong_value);
2195
2424
  return 0;
2196
2425
}
2197
2426
 
2198
2427
 
2199
 
unsigned char *sys_var_insert_id::value_ptr(THD *thd,
2200
 
                                    enum_var_type type __attribute__((unused)),
2201
 
                                    LEX_STRING *base __attribute__((unused)))
 
2428
uchar *sys_var_insert_id::value_ptr(THD *thd, enum_var_type type,
 
2429
                                   LEX_STRING *base)
2202
2430
{
2203
 
  thd->sys_var_tmp.uint64_t_value=
 
2431
  thd->sys_var_tmp.ulonglong_value= 
2204
2432
    thd->auto_inc_intervals_forced.minimum();
2205
 
  return (unsigned char*) &thd->sys_var_tmp.uint64_t_value;
 
2433
  return (uchar*) &thd->sys_var_tmp.ulonglong_value;
2206
2434
}
2207
2435
 
2208
2436
 
2209
2437
bool sys_var_rand_seed1::update(THD *thd, set_var *var)
2210
2438
{
2211
 
  thd->rand.seed1= (ulong) var->save_result.uint64_t_value;
 
2439
  thd->rand.seed1= (ulong) var->save_result.ulonglong_value;
2212
2440
  return 0;
2213
2441
}
2214
2442
 
2215
2443
bool sys_var_rand_seed2::update(THD *thd, set_var *var)
2216
2444
{
2217
 
  thd->rand.seed2= (ulong) var->save_result.uint64_t_value;
 
2445
  thd->rand.seed2= (ulong) var->save_result.ulonglong_value;
2218
2446
  return 0;
2219
2447
}
2220
2448
 
2222
2450
bool sys_var_thd_time_zone::check(THD *thd, set_var *var)
2223
2451
{
2224
2452
  char buff[MAX_TIME_ZONE_NAME_LENGTH];
2225
 
  String str(buff, sizeof(buff), &my_charset_utf8_general_ci);
 
2453
  String str(buff, sizeof(buff), &my_charset_latin1);
2226
2454
  String *res= var->value->val_str(&str);
2227
2455
 
2228
2456
  if (!(var->save_result.time_zone= my_tz_find(thd, res)))
2249
2477
}
2250
2478
 
2251
2479
 
2252
 
unsigned char *sys_var_thd_time_zone::value_ptr(THD *thd, enum_var_type type,
2253
 
                                        LEX_STRING *base __attribute__((unused)))
 
2480
uchar *sys_var_thd_time_zone::value_ptr(THD *thd, enum_var_type type,
 
2481
                                       LEX_STRING *base)
2254
2482
{
2255
2483
  /* 
2256
2484
    We can use ptr() instead of c_ptr() here because String contaning
2257
2485
    time zone name is guaranteed to be zero ended.
2258
2486
  */
2259
2487
  if (type == OPT_GLOBAL)
2260
 
    return (unsigned char *)(global_system_variables.time_zone->get_name()->ptr());
 
2488
    return (uchar *)(global_system_variables.time_zone->get_name()->ptr());
2261
2489
  else
2262
2490
  {
2263
2491
    /*
2269
2497
      (binlog code stores session value only).
2270
2498
    */
2271
2499
    thd->time_zone_used= 1;
2272
 
    return (unsigned char *)(thd->variables.time_zone->get_name()->ptr());
 
2500
    return (uchar *)(thd->variables.time_zone->get_name()->ptr());
2273
2501
  }
2274
2502
}
2275
2503
 
2281
2509
 {
2282
2510
   if (default_tz_name)
2283
2511
   {
2284
 
     String str(default_tz_name, &my_charset_utf8_general_ci);
 
2512
     String str(default_tz_name, &my_charset_latin1);
2285
2513
     /*
2286
2514
       We are guaranteed to find this time zone since its existence
2287
2515
       is checked during start-up.
2308
2536
      May be we should have a separate error message for this?
2309
2537
    */
2310
2538
    my_error(ER_GLOBAL_VARIABLE, MYF(0), name);
2311
 
    return true;
 
2539
    return TRUE;
2312
2540
  }
2313
2541
}
2314
2542
 
2315
 
bool sys_var_max_user_conn::update(THD *thd __attribute__((unused)),
2316
 
                                   set_var *var)
 
2543
bool sys_var_max_user_conn::update(THD *thd, set_var *var)
2317
2544
{
2318
 
  assert(var->type == OPT_GLOBAL);
 
2545
  DBUG_ASSERT(var->type == OPT_GLOBAL);
2319
2546
  pthread_mutex_lock(&LOCK_global_system_variables);
2320
 
  max_user_connections= (uint)var->save_result.uint64_t_value;
 
2547
  max_user_connections= (uint)var->save_result.ulonglong_value;
2321
2548
  pthread_mutex_unlock(&LOCK_global_system_variables);
2322
2549
  return 0;
2323
2550
}
2324
2551
 
2325
2552
 
2326
 
void sys_var_max_user_conn::set_default(THD *thd __attribute__((unused)),
2327
 
                                        enum_var_type type __attribute__((unused)))
 
2553
void sys_var_max_user_conn::set_default(THD *thd, enum_var_type type)
2328
2554
{
2329
 
  assert(type == OPT_GLOBAL);
 
2555
  DBUG_ASSERT(type == OPT_GLOBAL);
2330
2556
  pthread_mutex_lock(&LOCK_global_system_variables);
2331
2557
  max_user_connections= (ulong) option_limits->def_value;
2332
2558
  pthread_mutex_unlock(&LOCK_global_system_variables);
2333
2559
}
2334
2560
 
2335
2561
 
2336
 
unsigned char *sys_var_max_user_conn::value_ptr(THD *thd, enum_var_type type,
2337
 
                                        LEX_STRING *base __attribute__((unused)))
 
2562
uchar *sys_var_max_user_conn::value_ptr(THD *thd, enum_var_type type,
 
2563
                                       LEX_STRING *base)
2338
2564
{
2339
2565
  if (type != OPT_GLOBAL &&
2340
2566
      thd->user_connect && thd->user_connect->user_resources.user_conn)
2341
 
    return (unsigned char*) &(thd->user_connect->user_resources.user_conn);
2342
 
  return (unsigned char*) &(max_user_connections);
 
2567
    return (uchar*) &(thd->user_connect->user_resources.user_conn);
 
2568
  return (uchar*) &(max_user_connections);
2343
2569
}
2344
2570
 
2345
2571
 
2346
 
bool sys_var_thd_lc_time_names::check(THD *thd __attribute__((unused)),
2347
 
                                      set_var *var)
 
2572
bool sys_var_thd_lc_time_names::check(THD *thd, set_var *var)
2348
2573
{
2349
2574
  MY_LOCALE *locale_match;
2350
2575
 
2361
2586
  else // STRING_RESULT
2362
2587
  {
2363
2588
    char buff[6]; 
2364
 
    String str(buff, sizeof(buff), &my_charset_utf8_general_ci), *res;
 
2589
    String str(buff, sizeof(buff), &my_charset_latin1), *res;
2365
2590
    if (!(res=var->value->val_str(&str)))
2366
2591
    {
2367
2592
      my_error(ER_WRONG_VALUE_FOR_VAR, MYF(0), name, "NULL");
2391
2616
}
2392
2617
 
2393
2618
 
2394
 
unsigned char *sys_var_thd_lc_time_names::value_ptr(THD *thd,
2395
 
                                            enum_var_type type,
2396
 
                                            LEX_STRING *base __attribute__((unused)))
 
2619
uchar *sys_var_thd_lc_time_names::value_ptr(THD *thd, enum_var_type type,
 
2620
                                          LEX_STRING *base)
2397
2621
{
2398
2622
  return type == OPT_GLOBAL ?
2399
 
                 (unsigned char *) global_system_variables.lc_time_names->name :
2400
 
                 (unsigned char *) thd->variables.lc_time_names->name;
 
2623
                 (uchar *) global_system_variables.lc_time_names->name :
 
2624
                 (uchar *) thd->variables.lc_time_names->name;
2401
2625
}
2402
2626
 
2403
2627
 
2414
2638
 
2415
2639
  NOTES
2416
2640
    The argument to long query time is in seconds in decimal
2417
 
    which is converted to uint64_t integer holding microseconds for storage.
 
2641
    which is converted to ulonglong integer holding microseconds for storage.
2418
2642
    This is used for handling long_query_time
2419
2643
*/
2420
2644
 
2421
2645
bool sys_var_microseconds::update(THD *thd, set_var *var)
2422
2646
{
2423
2647
  double num= var->value->val_real();
2424
 
  int64_t microseconds;
 
2648
  longlong microseconds;
2425
2649
  if (num > (double) option_limits->max_value)
2426
2650
    num= (double) option_limits->max_value;
2427
2651
  if (num < (double) option_limits->min_value)
2428
2652
    num= (double) option_limits->min_value;
2429
 
  microseconds= (int64_t) (num * 1000000.0 + 0.5);
 
2653
  microseconds= (longlong) (num * 1000000.0 + 0.5);
2430
2654
  if (var->type == OPT_GLOBAL)
2431
2655
  {
2432
2656
    pthread_mutex_lock(&LOCK_global_system_variables);
2441
2665
 
2442
2666
void sys_var_microseconds::set_default(THD *thd, enum_var_type type)
2443
2667
{
2444
 
  int64_t microseconds= (int64_t) (option_limits->def_value * 1000000.0);
 
2668
  longlong microseconds= (longlong) (option_limits->def_value * 1000000.0);
2445
2669
  if (type == OPT_GLOBAL)
2446
2670
  {
2447
2671
    pthread_mutex_lock(&LOCK_global_system_variables);
2453
2677
}
2454
2678
 
2455
2679
 
2456
 
unsigned char *sys_var_microseconds::value_ptr(THD *thd, enum_var_type type,
2457
 
                                          LEX_STRING *base __attribute__((unused)))
 
2680
uchar *sys_var_microseconds::value_ptr(THD *thd, enum_var_type type,
 
2681
                                          LEX_STRING *base)
2458
2682
{
2459
2683
  thd->tmp_double_value= (double) ((type == OPT_GLOBAL) ?
2460
2684
                                   global_system_variables.*offset :
2461
2685
                                   thd->variables.*offset) / 1000000.0;
2462
 
  return (unsigned char*) &thd->tmp_double_value;
 
2686
  return (uchar*) &thd->tmp_double_value;
2463
2687
}
2464
2688
 
2465
2689
 
2482
2706
{
2483
2707
  /* The test is negative as the flag we use is NOT autocommit */
2484
2708
 
2485
 
  uint64_t org_options= thd->options;
 
2709
  ulonglong org_options= thd->options;
2486
2710
 
2487
2711
  if (var->save_result.ulong_value != 0)
2488
2712
    thd->options&= ~((sys_var_thd_bit*) var->var)->bit_flag;
2494
2718
    if ((org_options & OPTION_NOT_AUTOCOMMIT))
2495
2719
    {
2496
2720
      /* We changed to auto_commit mode */
2497
 
      thd->options&= ~(uint64_t) (OPTION_BEGIN | OPTION_KEEP_LOG);
2498
 
      thd->transaction.all.modified_non_trans_table= false;
 
2721
      thd->options&= ~(ulonglong) (OPTION_BEGIN | OPTION_KEEP_LOG);
 
2722
      thd->transaction.all.modified_non_trans_table= FALSE;
2499
2723
      thd->server_status|= SERVER_STATUS_AUTOCOMMIT;
2500
2724
      if (ha_commit(thd))
2501
2725
        return 1;
2502
2726
    }
2503
2727
    else
2504
2728
    {
2505
 
      thd->transaction.all.modified_non_trans_table= false;
 
2729
      thd->transaction.all.modified_non_trans_table= FALSE;
2506
2730
      thd->server_status&= ~SERVER_STATUS_AUTOCOMMIT;
2507
2731
    }
2508
2732
  }
2509
2733
  return 0;
2510
2734
}
2511
2735
 
2512
 
static int check_log_update(THD *thd __attribute__((unused)),
2513
 
                            set_var *var __attribute__((unused)))
2514
 
{
2515
 
  return 0;
2516
 
}
2517
 
 
2518
 
 
2519
 
static int check_pseudo_thread_id(THD *thd __attribute__((unused)),
2520
 
                                  set_var *var)
2521
 
{
2522
 
  var->save_result.uint64_t_value= var->value->val_int();
2523
 
  return 0;
2524
 
}
2525
 
 
2526
 
static unsigned char *get_warning_count(THD *thd)
 
2736
static int check_log_update(THD *thd, set_var *var)
 
2737
{
 
2738
  return 0;
 
2739
}
 
2740
 
 
2741
static bool set_log_update(THD *thd, set_var *var)
 
2742
{
 
2743
  /*
 
2744
    The update log is not supported anymore since 5.0.
 
2745
    See sql/mysqld.cc/, comments in function init_server_components() for an
 
2746
    explaination of the different warnings we send below
 
2747
  */
 
2748
 
 
2749
  if (opt_sql_bin_update)
 
2750
  {
 
2751
    push_warning(thd, MYSQL_ERROR::WARN_LEVEL_NOTE,
 
2752
                 ER_UPDATE_LOG_DEPRECATED_TRANSLATED,
 
2753
                 ER(ER_UPDATE_LOG_DEPRECATED_TRANSLATED));
 
2754
  }
 
2755
  else
 
2756
    push_warning(thd, MYSQL_ERROR::WARN_LEVEL_NOTE,
 
2757
                 ER_UPDATE_LOG_DEPRECATED_IGNORED,
 
2758
                 ER(ER_UPDATE_LOG_DEPRECATED_IGNORED));
 
2759
  set_option_bit(thd, var);
 
2760
  return 0;
 
2761
}
 
2762
 
 
2763
 
 
2764
static int check_pseudo_thread_id(THD *thd, set_var *var)
 
2765
{
 
2766
  var->save_result.ulonglong_value= var->value->val_int();
 
2767
  return 0;
 
2768
}
 
2769
 
 
2770
static uchar *get_warning_count(THD *thd)
2527
2771
{
2528
2772
  thd->sys_var_tmp.long_value=
2529
 
    (thd->warn_count[(uint) DRIZZLE_ERROR::WARN_LEVEL_NOTE] +
2530
 
     thd->warn_count[(uint) DRIZZLE_ERROR::WARN_LEVEL_ERROR] +
2531
 
     thd->warn_count[(uint) DRIZZLE_ERROR::WARN_LEVEL_WARN]);
2532
 
  return (unsigned char*) &thd->sys_var_tmp.long_value;
 
2773
    (thd->warn_count[(uint) MYSQL_ERROR::WARN_LEVEL_NOTE] +
 
2774
     thd->warn_count[(uint) MYSQL_ERROR::WARN_LEVEL_ERROR] +
 
2775
     thd->warn_count[(uint) MYSQL_ERROR::WARN_LEVEL_WARN]);
 
2776
  return (uchar*) &thd->sys_var_tmp.long_value;
2533
2777
}
2534
2778
 
2535
 
static unsigned char *get_error_count(THD *thd)
 
2779
static uchar *get_error_count(THD *thd)
2536
2780
{
2537
2781
  thd->sys_var_tmp.long_value= 
2538
 
    thd->warn_count[(uint) DRIZZLE_ERROR::WARN_LEVEL_ERROR];
2539
 
  return (unsigned char*) &thd->sys_var_tmp.long_value;
 
2782
    thd->warn_count[(uint) MYSQL_ERROR::WARN_LEVEL_ERROR];
 
2783
  return (uchar*) &thd->sys_var_tmp.long_value;
2540
2784
}
2541
2785
 
2542
2786
 
2554
2798
  @retval
2555
2799
    ptr         pointer to NUL-terminated string
2556
2800
*/
2557
 
static unsigned char *get_tmpdir(THD *thd __attribute__((unused)))
 
2801
static uchar *get_tmpdir(THD *thd)
2558
2802
{
2559
2803
  if (opt_mysql_tmpdir)
2560
 
    return (unsigned char *)opt_mysql_tmpdir;
2561
 
  return (unsigned char*)mysql_tmpdir;
 
2804
    return (uchar *)opt_mysql_tmpdir;
 
2805
  return (uchar*)mysql_tmpdir;
2562
2806
}
2563
2807
 
2564
2808
/****************************************************************************
2583
2827
 
2584
2828
static struct my_option *find_option(struct my_option *opt, const char *name) 
2585
2829
{
2586
 
  uint32_t length=strlen(name);
 
2830
  uint length=strlen(name);
2587
2831
  for (; opt->name; opt++)
2588
2832
  {
2589
2833
    if (!getopt_compare_strings(opt->name, name, length) &&
2604
2848
  Return variable name and length for hashing of variables.
2605
2849
*/
2606
2850
 
2607
 
static unsigned char *get_sys_var_length(const sys_var *var, size_t *length,
2608
 
                                 bool first __attribute__((unused)))
 
2851
static uchar *get_sys_var_length(const sys_var *var, size_t *length,
 
2852
                                 my_bool first)
2609
2853
{
2610
2854
  *length= var->name_length;
2611
 
  return (unsigned char*) var->name;
 
2855
  return (uchar*) var->name;
2612
2856
}
2613
2857
 
2614
2858
 
2636
2880
  {
2637
2881
    var->name_length= strlen(var->name);
2638
2882
    /* this fails if there is a conflicting variable name. see HASH_UNIQUE */
2639
 
    if (my_hash_insert(&system_variable_hash, (unsigned char*) var))
 
2883
    if (my_hash_insert(&system_variable_hash, (uchar*) var))
2640
2884
      goto error;
2641
2885
    if (long_options)
2642
2886
      var->option_limits= find_option(long_options, var->name);
2645
2889
 
2646
2890
error:
2647
2891
  for (; first != var; first= first->next)
2648
 
    hash_delete(&system_variable_hash, (unsigned char*) first);
 
2892
    hash_delete(&system_variable_hash, (uchar*) first);
2649
2893
  return 1;
2650
2894
}
2651
2895
 
2669
2913
  /* A write lock should be held on LOCK_system_variables_hash */
2670
2914
   
2671
2915
  for (sys_var *var= first; var; var= var->next)
2672
 
    result|= hash_delete(&system_variable_hash, (unsigned char*) var);
 
2916
    result|= hash_delete(&system_variable_hash, (uchar*) var);
2673
2917
 
2674
2918
  return result;
2675
2919
}
2721
2965
               (qsort_cmp) show_cmp);
2722
2966
    
2723
2967
    /* make last element empty */
2724
 
    memset(show, 0, sizeof(SHOW_VAR));
 
2968
    bzero(show, sizeof(SHOW_VAR));
2725
2969
  }
2726
2970
  return result;
2727
2971
}
2740
2984
 
2741
2985
int set_var_init()
2742
2986
{
2743
 
  uint32_t count= 0;
 
2987
  uint count= 0;
 
2988
  DBUG_ENTER("set_var_init");
2744
2989
  
2745
2990
  for (sys_var *var=vars.first; var; var= var->next, count++) {};
2746
2991
 
2759
3004
  if (mysql_add_sys_var_chain(vars.first, my_long_options))
2760
3005
    goto error;
2761
3006
 
2762
 
  return(0);
 
3007
  /*
 
3008
    Special cases
 
3009
    Needed because MySQL can't find the limits for a variable it it has
 
3010
    a different name than the command line option.
 
3011
    As these variables are deprecated, this code will disappear soon...
 
3012
  */
 
3013
  sys_sql_max_join_size.option_limits= sys_max_join_size.option_limits;
 
3014
 
 
3015
  DBUG_RETURN(0);
2763
3016
 
2764
3017
error:
2765
3018
  fprintf(stderr, "failed to initialize system variables");
2766
 
  return(1);
 
3019
  DBUG_RETURN(1);
2767
3020
}
2768
3021
 
2769
3022
 
2786
3039
    0           SUCCESS
2787
3040
    otherwise   FAILURE
2788
3041
*/
2789
 
int mysql_append_static_vars(const SHOW_VAR *show_vars, uint32_t count)
 
3042
int mysql_append_static_vars(const SHOW_VAR *show_vars, uint count)
2790
3043
{
2791
3044
  for (; count > 0; count--, show_vars++)
2792
 
    if (insert_dynamic(&fixed_show_vars, (unsigned char*) show_vars))
 
3045
    if (insert_dynamic(&fixed_show_vars, (uchar*) show_vars))
2793
3046
      return 1;
2794
3047
  return 0;
2795
3048
}
2809
3062
    0           Unknown variable (error message is given)
2810
3063
*/
2811
3064
 
2812
 
sys_var *intern_find_sys_var(const char *str, uint32_t length, bool no_error)
 
3065
sys_var *intern_find_sys_var(const char *str, uint length, bool no_error)
2813
3066
{
2814
3067
  sys_var *var;
2815
3068
 
2818
3071
    A lock on LOCK_system_variable_hash should be held
2819
3072
  */
2820
3073
  var= (sys_var*) hash_search(&system_variable_hash,
2821
 
                              (unsigned char*) str, length ? length : strlen(str));
 
3074
                              (uchar*) str, length ? length : strlen(str));
2822
3075
  if (!(var || no_error))
2823
3076
    my_error(ER_UNKNOWN_SYSTEM_VARIABLE, MYF(0), (char*) str);
2824
3077
 
2850
3103
{
2851
3104
  int error;
2852
3105
  List_iterator_fast<set_var_base> it(*var_list);
 
3106
  DBUG_ENTER("sql_set_variables");
2853
3107
 
2854
3108
  set_var_base *var;
2855
3109
  while ((var=it++))
2866
3120
 
2867
3121
err:
2868
3122
  free_underlaid_joins(thd, &thd->lex->select_lex);
2869
 
  return(error);
 
3123
  DBUG_RETURN(error);
2870
3124
}
2871
3125
 
2872
3126
 
2977
3231
}
2978
3232
 
2979
3233
 
2980
 
int set_var_user::update(THD *thd __attribute__((unused)))
 
3234
int set_var_user::update(THD *thd)
2981
3235
{
2982
3236
  if (user_var_item->update())
2983
3237
  {
2998
3252
{
2999
3253
  char buff[STRING_BUFFER_USUAL_SIZE];
3000
3254
  const char *value;
3001
 
  String str(buff, sizeof(buff), &my_charset_utf8_general_ci), *res;
 
3255
  String str(buff, sizeof(buff), &my_charset_latin1), *res;
3002
3256
 
3003
3257
  var->save_result.plugin= NULL;
3004
3258
  if (var->value->result_type() == STRING_RESULT)
3009
3263
        !(engine_name.str= (char *)res->ptr()) ||
3010
3264
        !(engine_name.length= res->length()) ||
3011
3265
        !(var->save_result.plugin= ha_resolve_by_name(thd, &engine_name)) ||
3012
 
        !(hton= plugin_data(var->save_result.plugin, handlerton *)))
 
3266
        !(hton= plugin_data(var->save_result.plugin, handlerton *)) ||
 
3267
        ha_checktype(thd, ha_legacy_type(hton), 1, 0) != hton)
3013
3268
    {
3014
3269
      value= res ? res->c_ptr() : "NULL";
3015
3270
      goto err;
3024
3279
}
3025
3280
 
3026
3281
 
3027
 
unsigned char *sys_var_thd_storage_engine::value_ptr(THD *thd, enum_var_type type,
3028
 
                                             LEX_STRING *base __attribute__((unused)))
 
3282
uchar *sys_var_thd_storage_engine::value_ptr(THD *thd, enum_var_type type,
 
3283
                                            LEX_STRING *base)
3029
3284
{
3030
 
  unsigned char* result;
 
3285
  uchar* result;
3031
3286
  handlerton *hton;
3032
3287
  LEX_STRING *engine_name;
3033
3288
  plugin_ref plugin= thd->variables.*offset;
3035
3290
    plugin= my_plugin_lock(thd, &(global_system_variables.*offset));
3036
3291
  hton= plugin_data(plugin, handlerton*);
3037
3292
  engine_name= &hton2plugin[hton->slot]->name;
3038
 
  result= (unsigned char *) thd->strmake(engine_name->str, engine_name->length);
 
3293
  result= (uchar *) thd->strmake(engine_name->str, engine_name->length);
3039
3294
  if (type == OPT_GLOBAL)
3040
3295
    plugin_unlock(thd, plugin);
3041
3296
  return result;
3055
3310
    value= &(thd->variables.*offset);
3056
3311
    new_value= my_plugin_lock(NULL, &(global_system_variables.*offset));
3057
3312
  }
3058
 
  assert(new_value);
 
3313
  DBUG_ASSERT(new_value);
3059
3314
  old_value= *value;
3060
3315
  *value= new_value;
3061
3316
  plugin_unlock(NULL, old_value);
3078
3333
 
3079
3334
bool
3080
3335
sys_var_thd_optimizer_switch::
3081
 
symbolic_mode_representation(THD *thd, uint64_t val, LEX_STRING *rep)
 
3336
symbolic_mode_representation(THD *thd, ulonglong val, LEX_STRING *rep)
3082
3337
{
3083
3338
  char buff[STRING_BUFFER_USUAL_SIZE*8];
3084
 
  String tmp(buff, sizeof(buff), &my_charset_utf8_general_ci);
 
3339
  String tmp(buff, sizeof(buff), &my_charset_latin1);
3085
3340
 
3086
3341
  tmp.length(0);
3087
3342
 
3088
 
  for (uint32_t i= 0; val; val>>= 1, i++)
 
3343
  for (uint i= 0; val; val>>= 1, i++)
3089
3344
  {
3090
3345
    if (val & 1)
3091
3346
    {
3106
3361
}
3107
3362
 
3108
3363
 
3109
 
unsigned char *sys_var_thd_optimizer_switch::value_ptr(THD *thd, enum_var_type type,
3110
 
                                               LEX_STRING *base __attribute__((unused)))
 
3364
uchar *sys_var_thd_optimizer_switch::value_ptr(THD *thd, enum_var_type type,
 
3365
                                               LEX_STRING *base)
3111
3366
{
3112
3367
  LEX_STRING opts;
3113
 
  uint64_t val= ((type == OPT_GLOBAL) ? global_system_variables.*offset :
 
3368
  ulonglong val= ((type == OPT_GLOBAL) ? global_system_variables.*offset :
3114
3369
                  thd->variables.*offset);
3115
3370
  (void) symbolic_mode_representation(thd, val, &opts);
3116
 
  return (unsigned char *) opts.str;
 
3371
  return (uchar *) opts.str;
3117
3372
}
3118
3373
 
3119
3374
 
3130
3385
  Named list handling
3131
3386
****************************************************************************/
3132
3387
 
3133
 
unsigned char* find_named(I_List<NAMED_LIST> *list, const char *name, uint32_t length,
 
3388
uchar* find_named(I_List<NAMED_LIST> *list, const char *name, uint length,
3134
3389
                NAMED_LIST **found)
3135
3390
{
3136
3391
  I_List_iterator<NAMED_LIST> it(*list);
3149
3404
 
3150
3405
 
3151
3406
void delete_elements(I_List<NAMED_LIST> *list,
3152
 
                     void (*free_element)(const char *name, unsigned char*))
 
3407
                     void (*free_element)(const char *name, uchar*))
3153
3408
{
3154
3409
  NAMED_LIST *element;
 
3410
  DBUG_ENTER("delete_elements");
3155
3411
  while ((element= list->get()))
3156
3412
  {
3157
3413
    (*free_element)(element->name, element->data);
3158
3414
    delete element;
3159
3415
  }
3160
 
  return;
 
3416
  DBUG_VOID_RETURN;
3161
3417
}
3162
3418
 
3163
3419
 
3164
3420
/* Key cache functions */
3165
3421
 
3166
 
static KEY_CACHE *create_key_cache(const char *name, uint32_t length)
 
3422
static KEY_CACHE *create_key_cache(const char *name, uint length)
3167
3423
{
3168
3424
  KEY_CACHE *key_cache;
 
3425
  DBUG_ENTER("create_key_cache");
 
3426
  DBUG_PRINT("enter",("name: %.*s", length, name));
3169
3427
  
3170
3428
  if ((key_cache= (KEY_CACHE*) my_malloc(sizeof(KEY_CACHE),
3171
3429
                                             MYF(MY_ZEROFILL | MY_WME))))
3172
3430
  {
3173
 
    if (!new NAMED_LIST(&key_caches, name, length, (unsigned char*) key_cache))
 
3431
    if (!new NAMED_LIST(&key_caches, name, length, (uchar*) key_cache))
3174
3432
    {
3175
 
      free((char*) key_cache);
 
3433
      my_free((char*) key_cache, MYF(0));
3176
3434
      key_cache= 0;
3177
3435
    }
3178
3436
    else
3188
3446
      key_cache->param_age_threshold=  dflt_key_cache_var.param_age_threshold;
3189
3447
    }
3190
3448
  }
3191
 
  return(key_cache);
 
3449
  DBUG_RETURN(key_cache);
3192
3450
}
3193
3451
 
3194
3452
 
3195
 
KEY_CACHE *get_or_create_key_cache(const char *name, uint32_t length)
 
3453
KEY_CACHE *get_or_create_key_cache(const char *name, uint length)
3196
3454
{
3197
3455
  LEX_STRING key_cache_name;
3198
3456
  KEY_CACHE *key_cache;
3207
3465
}
3208
3466
 
3209
3467
 
3210
 
void free_key_cache(const char *name __attribute__((unused)),
3211
 
                    KEY_CACHE *key_cache)
 
3468
void free_key_cache(const char *name, KEY_CACHE *key_cache)
3212
3469
{
3213
3470
  ha_end_key_cache(key_cache);
3214
 
  free((char*) key_cache);
 
3471
  my_free((char*) key_cache, MYF(0));
3215
3472
}
3216
3473
 
3217
3474
 
3233
3490
{
3234
3491
  bool result;
3235
3492
 
 
3493
  DBUG_ENTER("sys_var_opt_readonly::update");
 
3494
 
3236
3495
  /* Prevent self dead-lock */
3237
3496
  if (thd->locked_tables || thd->active_transaction())
3238
3497
  {
3239
3498
    my_error(ER_LOCK_OR_ACTIVE_TRANSACTION, MYF(0));
3240
 
    return(true);
 
3499
    DBUG_RETURN(true);
3241
3500
  }
3242
3501
 
3243
3502
  if (thd->global_read_lock)
3249
3508
      - SET GLOBAL READ_ONLY = 1
3250
3509
    */
3251
3510
    result= sys_var_bool_ptr::update(thd, var);
3252
 
    return(result);
 
3511
    DBUG_RETURN(result);
3253
3512
  }
3254
3513
 
3255
3514
  /*
3264
3523
  */
3265
3524
 
3266
3525
  if (lock_global_read_lock(thd))
3267
 
    return(true);
 
3526
    DBUG_RETURN(true);
3268
3527
 
3269
3528
  /*
3270
3529
    This call will be blocked by any connection holding a READ or WRITE lock.
3275
3534
    can cause to wait on a read lock, it's required for the client application
3276
3535
    to unlock everything, and acceptable for the server to wait on all locks.
3277
3536
  */
3278
 
  if ((result= close_cached_tables(thd, NULL, false, true, true)) == true)
 
3537
  if ((result= close_cached_tables(thd, NULL, FALSE, TRUE, TRUE)) == true)
3279
3538
    goto end_with_read_lock;
3280
3539
 
3281
3540
  if ((result= make_global_read_lock_block_commit(thd)) == true)
3287
3546
end_with_read_lock:
3288
3547
  /* Release the lock */
3289
3548
  unlock_global_read_lock(thd);
3290
 
  return(result);
 
3549
  DBUG_RETURN(result);
 
3550
}
 
3551
 
 
3552
bool sys_var_thd_dbug::update(THD *thd, set_var *var)
 
3553
{
 
3554
  if (var->type == OPT_GLOBAL)
 
3555
  {
 
3556
    DBUG_SET_INITIAL(var ? var->value->str_value.c_ptr() : "");
 
3557
  }
 
3558
  else
 
3559
  {
 
3560
    DBUG_SET(var ? var->value->str_value.c_ptr() : "");
 
3561
  }
 
3562
 
 
3563
  return 0;
 
3564
}
 
3565
 
 
3566
 
 
3567
uchar *sys_var_thd_dbug::value_ptr(THD *thd, enum_var_type type, LEX_STRING *b)
 
3568
{
 
3569
  char buf[256];
 
3570
  if (type == OPT_GLOBAL)
 
3571
  {
 
3572
    DBUG_EXPLAIN_INITIAL(buf, sizeof(buf));
 
3573
  }
 
3574
  else
 
3575
  {
 
3576
    DBUG_EXPLAIN(buf, sizeof(buf));
 
3577
  }
 
3578
  return (uchar*) thd->strdup(buf);
3291
3579
}
3292
3580
 
3293
3581
/****************************************************************************