~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to server/set_var.cc

  • Committer: Brian Aker
  • Date: 2008-07-15 06:45:16 UTC
  • Revision ID: brian@tangent.org-20080715064516-fnbq7kowh7w57bxj
Merge Monty's code.

Show diffs side-by-side

added added

removed removed

Lines of Context:
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 "slave.h"
50
56
#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>
 
57
#include <my_getopt.h>
 
58
#include <thr_alarm.h>
 
59
#include <myisam.h>
 
60
#include <my_dir.h>
56
61
 
57
 
extern const CHARSET_INFO *character_set_filesystem;
 
62
extern CHARSET_INFO *character_set_filesystem;
58
63
 
59
64
 
60
65
static DYNAMIC_ARRAY fixed_show_vars;
61
66
static HASH system_variable_hash;
62
67
 
63
 
const char *bool_type_names[]= { "OFF", "ON", NULL };
 
68
const char *bool_type_names[]= { "OFF", "ON", NullS };
64
69
TYPELIB bool_typelib=
65
70
{
66
71
  array_elements(bool_type_names)-1, "", bool_type_names, NULL
67
72
};
68
73
 
69
 
const char *delay_key_write_type_names[]= { "OFF", "ON", "ALL", NULL };
 
74
const char *delay_key_write_type_names[]= { "OFF", "ON", "ALL", NullS };
70
75
TYPELIB delay_key_write_typelib=
71
76
{
72
77
  array_elements(delay_key_write_type_names)-1, "",
74
79
};
75
80
 
76
81
const char *slave_exec_mode_names[]=
77
 
{ "STRICT", "IDEMPOTENT", NULL };
 
82
{ "STRICT", "IDEMPOTENT", NullS };
78
83
static const unsigned int slave_exec_mode_names_len[]=
79
84
{ sizeof("STRICT") - 1, sizeof("IDEMPOTENT") - 1, 0 };
80
85
TYPELIB slave_exec_mode_typelib=
90
95
static bool set_option_bit(THD *thd, set_var *var);
91
96
static bool set_option_autocommit(THD *thd, set_var *var);
92
97
static int  check_log_update(THD *thd, set_var *var);
 
98
static bool set_log_update(THD *thd, set_var *var);
93
99
static int  check_pseudo_thread_id(THD *thd, set_var *var);
94
100
static void fix_low_priority_updates(THD *thd, enum_var_type type);
95
101
static int check_tx_isolation(THD *thd, set_var *var);
111
117
static bool get_unsigned(THD *thd, set_var *var);
112
118
bool throw_bounds_warning(THD *thd, bool fixed, bool unsignd,
113
119
                          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);
 
120
static KEY_CACHE *create_key_cache(const char *name, uint length);
 
121
static uchar *get_error_count(THD *thd);
 
122
static uchar *get_warning_count(THD *thd);
 
123
static uchar *get_tmpdir(THD *thd);
 
124
static int  sys_check_log_path(THD *thd,  set_var *var);
 
125
static bool sys_update_general_log_path(THD *thd, set_var * var);
 
126
static void sys_default_general_log_path(THD *thd, enum_var_type type);
 
127
static bool sys_update_slow_log_path(THD *thd, set_var * var);
 
128
static void sys_default_slow_log_path(THD *thd, enum_var_type type);
118
129
 
119
130
/*
120
131
  Variable definition list
144
155
                                            &SV::binlog_format);
145
156
static sys_var_thd_ulong        sys_bulk_insert_buff_size(&vars, "bulk_insert_buffer_size",
146
157
                                                  &SV::bulk_insert_buff_size);
 
158
static sys_var_character_set_sv
 
159
sys_character_set_server(&vars, "character_set_server",
 
160
                         &SV::collation_server, &default_charset_info, 0,
 
161
                         sys_var::SESSION_VARIABLE_IN_BINLOG);
 
162
sys_var_const_str       sys_charset_system(&vars, "character_set_system",
 
163
                                           (char *)my_charset_utf8_general_ci.name);
 
164
static sys_var_character_set_database
 
165
sys_character_set_database(&vars, "character_set_database",
 
166
                           sys_var::SESSION_VARIABLE_IN_BINLOG);
 
167
static sys_var_character_set_client
 
168
sys_character_set_client(&vars, "character_set_client",
 
169
                         &SV::character_set_client,
 
170
                         &default_charset_info,
 
171
                         sys_var::SESSION_VARIABLE_IN_BINLOG);
 
172
static sys_var_character_set_sv
 
173
sys_character_set_connection(&vars, "character_set_connection",
 
174
                             &SV::collation_connection,
 
175
                             &default_charset_info, 0,
 
176
                             sys_var::SESSION_VARIABLE_IN_BINLOG);
 
177
static sys_var_character_set_sv sys_character_set_results(&vars, "character_set_results",
 
178
                                        &SV::character_set_results,
 
179
                                        &default_charset_info, true);
 
180
static sys_var_character_set_sv sys_character_set_filesystem(&vars, "character_set_filesystem",
 
181
                                        &SV::character_set_filesystem,
 
182
                                        &character_set_filesystem);
147
183
static sys_var_thd_ulong        sys_completion_type(&vars, "completion_type",
148
184
                                         &SV::completion_type,
149
185
                                         check_completion_type,
160
196
sys_collation_server(&vars, "collation_server", &SV::collation_server,
161
197
                     &default_charset_info,
162
198
                     sys_var::SESSION_VARIABLE_IN_BINLOG);
 
199
static sys_var_long_ptr sys_concurrent_insert(&vars, "concurrent_insert",
 
200
                                              &myisam_concurrent_insert);
163
201
static sys_var_long_ptr sys_connect_timeout(&vars, "connect_timeout",
164
202
                                            &connect_timeout);
165
203
static sys_var_const_str       sys_datadir(&vars, "datadir", mysql_real_data_home);
193
231
                                                              param_age_threshold));
194
232
static sys_var_bool_ptr sys_local_infile(&vars, "local_infile",
195
233
                                         &opt_local_infile);
 
234
static sys_var_bool_ptr
 
235
  sys_log_queries_not_using_indexes(&vars, "log_queries_not_using_indexes",
 
236
                                    &opt_log_queries_not_using_indexes);
 
237
static sys_var_thd_ulong        sys_log_warnings(&vars, "log_warnings", &SV::log_warnings);
 
238
static sys_var_microseconds     sys_var_long_query_time(&vars, "long_query_time",
 
239
                                                        &SV::long_query_time);
196
240
static sys_var_thd_bool sys_low_priority_updates(&vars, "low_priority_updates",
197
241
                                                 &SV::low_priority_updates,
198
242
                                                 fix_low_priority_updates);
228
272
                                              &SV::max_seeks_for_key);
229
273
static sys_var_thd_ulong   sys_max_length_for_sort_data(&vars, "max_length_for_sort_data",
230
274
                                                 &SV::max_length_for_sort_data);
 
275
#ifndef TO_BE_DELETED   /* Alias for max_join_size */
 
276
static sys_var_thd_ha_rows      sys_sql_max_join_size(&vars, "sql_max_join_size",
 
277
                                              &SV::max_join_size,
 
278
                                              fix_max_join_size);
 
279
#endif
231
280
static sys_var_long_ptr sys_max_relay_log_size(&vars, "max_relay_log_size",
232
281
                                               &max_relay_log_size,
233
282
                                               fix_max_relay_log_size);
240
289
                                                 &max_write_lock_count);
241
290
static sys_var_thd_ulong       sys_min_examined_row_limit(&vars, "min_examined_row_limit",
242
291
                                                          &SV::min_examined_row_limit);
 
292
static sys_var_long_ptr sys_myisam_data_pointer_size(&vars, "myisam_data_pointer_size",
 
293
                                                    &myisam_data_pointer_size);
243
294
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);
244
295
static sys_var_thd_ulong       sys_myisam_repair_threads(&vars, "myisam_repair_threads", &SV::myisam_repair_threads);
245
296
static sys_var_thd_ulong        sys_myisam_sort_buffer_size(&vars, "myisam_sort_buffer_size", &SV::myisam_sort_buff_size);
270
321
static sys_var_thd_ulong        sys_optimizer_search_depth(&vars, "optimizer_search_depth",
271
322
                                                   &SV::optimizer_search_depth);
272
323
 
273
 
const char *optimizer_use_mrr_names[] = {"auto", "force", "disable", NULL};
 
324
const char *optimizer_use_mrr_names[] = {"auto", "force", "disable", NullS};
274
325
TYPELIB optimizer_use_mrr_typelib= {
275
326
  array_elements(optimizer_use_mrr_names) - 1, "",
276
327
  optimizer_use_mrr_names, NULL
290
341
                                               &SV::read_rnd_buff_size);
291
342
static sys_var_thd_ulong        sys_div_precincrement(&vars, "div_precision_increment",
292
343
                                              &SV::div_precincrement);
 
344
static sys_var_long_ptr sys_rpl_recovery_rank(&vars, "rpl_recovery_rank",
 
345
                                              &rpl_recovery_rank);
293
346
 
294
347
static sys_var_thd_ulong        sys_range_alloc_block_size(&vars, "range_alloc_block_size",
295
348
                                                   &SV::range_alloc_block_size);
307
360
                                                &SV::trans_prealloc_size,
308
361
                                                0, fix_trans_mem_root);
309
362
 
 
363
static sys_var_bool_ptr sys_secure_auth(&vars, "secure_auth", &opt_secure_auth);
310
364
static sys_var_const_str_ptr sys_secure_file_priv(&vars, "secure_file_priv",
311
365
                                             &opt_secure_file_priv);
312
366
static sys_var_long_ptr sys_server_id(&vars, "server_id", &server_id, fix_server_id);
313
367
static sys_var_bool_ptr sys_slave_compressed_protocol(&vars, "slave_compressed_protocol",
314
368
                                                      &opt_slave_compressed_protocol);
 
369
#ifdef HAVE_REPLICATION
315
370
static sys_var_bool_ptr         sys_slave_allow_batching(&vars, "slave_allow_batching",
316
371
                                                         &slave_allow_batching);
317
372
static sys_var_set_slave_mode slave_exec_mode(&vars,
319
374
                                              &slave_exec_mode_options,
320
375
                                              &slave_exec_mode_typelib,
321
376
                                              0);
 
377
#endif
322
378
static sys_var_long_ptr sys_slow_launch_time(&vars, "slow_launch_time",
323
379
                                             &slow_launch_time);
324
380
static sys_var_thd_ulong        sys_sort_buffer(&vars, "sort_buffer_size",
331
387
*/
332
388
static sys_var_thd_optimizer_switch   sys_optimizer_switch(&vars, "optimizer_switch",
333
389
                                     &SV::optimizer_switch);
 
390
static sys_var_const_str        sys_ssl_ca(&vars, "ssl_ca", NULL);
 
391
static sys_var_const_str        sys_ssl_capath(&vars, "ssl_capath", NULL);
 
392
static sys_var_const_str        sys_ssl_cert(&vars, "ssl_cert", NULL);
 
393
static sys_var_const_str        sys_ssl_cipher(&vars, "ssl_cipher", NULL);
 
394
static sys_var_const_str        sys_ssl_key(&vars, "ssl_key", NULL);
334
395
 
335
396
static sys_var_thd_storage_engine sys_storage_engine(&vars, "storage_engine",
336
397
                                       &SV::table_plugin);
 
398
static sys_var_bool_ptr sys_sync_frm(&vars, "sync_frm", &opt_sync_frm);
337
399
static sys_var_const_str        sys_system_time_zone(&vars, "system_time_zone",
338
400
                                             system_time_zone);
339
401
static sys_var_long_ptr sys_table_def_size(&vars, "table_definition_cache",
356
418
static sys_var_bool_ptr  sys_timed_mutexes(&vars, "timed_mutexes", &timed_mutexes);
357
419
static sys_var_const_str        sys_version(&vars, "version", server_version);
358
420
static sys_var_const_str        sys_version_comment(&vars, "version_comment",
359
 
                                            DRIZZLE_COMPILATION_COMMENT);
 
421
                                            MYSQL_COMPILATION_COMMENT);
360
422
static sys_var_const_str        sys_version_compile_machine(&vars, "version_compile_machine",
361
423
                                                    MACHINE_TYPE);
362
424
static sys_var_const_str        sys_version_compile_os(&vars, "version_compile_os",
373
435
 
374
436
static sys_var_thd_date_time_format sys_time_format(&vars, "time_format",
375
437
                                             &SV::time_format,
376
 
                                             DRIZZLE_TIMESTAMP_TIME);
 
438
                                             MYSQL_TIMESTAMP_TIME);
377
439
static sys_var_thd_date_time_format sys_date_format(&vars, "date_format",
378
440
                                             &SV::date_format,
379
 
                                             DRIZZLE_TIMESTAMP_DATE);
 
441
                                             MYSQL_TIMESTAMP_DATE);
380
442
static sys_var_thd_date_time_format sys_datetime_format(&vars, "datetime_format",
381
443
                                                 &SV::datetime_format,
382
 
                                                 DRIZZLE_TIMESTAMP_DATETIME);
 
444
                                                 MYSQL_TIMESTAMP_DATETIME);
383
445
 
384
446
/* Variables that are bits in THD */
385
447
 
398
460
static sys_var_thd_bit  sys_big_selects(&vars, "sql_big_selects", 0,
399
461
                                        set_option_bit,
400
462
                                        OPTION_BIG_SELECTS);
 
463
static sys_var_thd_bit  sys_log_off(&vars, "sql_log_off",
 
464
                                    check_log_update,
 
465
                                    set_option_bit,
 
466
                                    OPTION_LOG_OFF);
 
467
static sys_var_thd_bit  sys_log_update(&vars, "sql_log_update",
 
468
                                       check_log_update,
 
469
                                       set_log_update,
 
470
                                       OPTION_BIN_LOG);
401
471
static sys_var_thd_bit  sys_log_binlog(&vars, "sql_log_bin",
402
472
                                       check_log_update,
403
473
                                       set_option_bit,
408
478
static sys_var_thd_bit  sys_sql_notes(&vars, "sql_notes", 0,
409
479
                                         set_option_bit,
410
480
                                         OPTION_SQL_NOTES);
 
481
static sys_var_thd_bit  sys_auto_is_null(&vars, "sql_auto_is_null", 0,
 
482
                                         set_option_bit,
 
483
                                         OPTION_AUTO_IS_NULL, 0,
 
484
                                         sys_var::SESSION_VARIABLE_IN_BINLOG);
411
485
static sys_var_thd_bit  sys_safe_updates(&vars, "sql_safe_updates", 0,
412
486
                                         set_option_bit,
413
487
                                         OPTION_SAFE_UPDATES);
495
569
static sys_var_const_str_ptr    sys_repl_report_user(&vars, "report_user", &report_user);
496
570
static sys_var_const_str_ptr    sys_repl_report_password(&vars, "report_password", &report_password);
497
571
 
498
 
static unsigned char *slave_get_report_port(THD *thd)
 
572
static uchar *slave_get_report_port(THD *thd)
499
573
{
500
574
  thd->sys_var_tmp.long_value= report_port;
501
 
  return (unsigned char*) &thd->sys_var_tmp.long_value;
 
575
  return (uchar*) &thd->sys_var_tmp.long_value;
502
576
}
503
577
 
504
578
static sys_var_readonly    sys_repl_report_port(&vars, "report_port", OPT_GLOBAL, SHOW_INT, slave_get_report_port);
508
582
/* Read only variables */
509
583
 
510
584
static sys_var_have_variable sys_have_compress(&vars, "have_compress", &have_compress);
 
585
static sys_var_have_variable sys_have_crypt(&vars, "have_crypt", &have_crypt);
 
586
static sys_var_have_plugin sys_have_csv(&vars, "have_csv", C_STRING_WITH_LEN("csv"), MYSQL_STORAGE_ENGINE_PLUGIN);
 
587
static sys_var_have_variable sys_have_dlopen(&vars, "have_dynamic_loading", &have_dlopen);
 
588
static sys_var_have_plugin sys_have_innodb(&vars, "have_innodb", C_STRING_WITH_LEN("innodb"), MYSQL_STORAGE_ENGINE_PLUGIN);
511
589
static sys_var_have_variable sys_have_symlink(&vars, "have_symlink", &have_symlink);
 
590
/* Global read-only variable describing server license */
 
591
static sys_var_const_str        sys_license(&vars, "license", STRINGIFY_ARG(LICENSE));
 
592
/* Global variables which enable|disable logging */
 
593
static sys_var_log_state sys_var_general_log(&vars, "general_log", &opt_log,
 
594
                                      QUERY_LOG_GENERAL);
 
595
/* Synonym of "general_log" for consistency with SHOW VARIABLES output */
 
596
static sys_var_log_state sys_var_log(&vars, "log", &opt_log, QUERY_LOG_GENERAL);
 
597
static sys_var_log_state sys_var_slow_query_log(&vars, "slow_query_log", &opt_slow_log,
 
598
                                         QUERY_LOG_SLOW);
 
599
/* Synonym of "slow_query_log" for consistency with SHOW VARIABLES output */
 
600
static sys_var_log_state sys_var_log_slow(&vars, "log_slow_queries",
 
601
                                          &opt_slow_log, QUERY_LOG_SLOW);
 
602
sys_var_str sys_var_general_log_path(&vars, "general_log_file", sys_check_log_path,
 
603
                                     sys_update_general_log_path,
 
604
                                     sys_default_general_log_path,
 
605
                                     opt_logname);
 
606
sys_var_str sys_var_slow_log_path(&vars, "slow_query_log_file", sys_check_log_path,
 
607
                                  sys_update_slow_log_path, 
 
608
                                  sys_default_slow_log_path,
 
609
                                  opt_slow_logname);
 
610
static sys_var_log_output sys_var_log_output_state(&vars, "log_output", &log_output_options,
 
611
                                            &log_output_typelib, 0);
 
612
 
 
613
 
512
614
/*
513
615
  Additional variables (not derived from sys_var class, not accessible as
514
616
  @@varname in SELECT or SET). Sorted in alphabetical order to facilitate
519
621
#define FIXED_VARS_SIZE (sizeof(fixed_vars) / sizeof(SHOW_VAR))
520
622
static SHOW_VAR fixed_vars[]= {
521
623
  {"back_log",                (char*) &back_log,                    SHOW_LONG},
 
624
  {"character_sets_dir",      mysql_charsets_dir,                   SHOW_CHAR},
522
625
  {"init_file",               (char*) &opt_init_file,               SHOW_CHAR_PTR},
523
626
  {"language",                language,                             SHOW_CHAR},
524
627
#ifdef HAVE_MLOCKALL
526
629
#endif
527
630
  {"log_bin",                 (char*) &opt_bin_log,                 SHOW_BOOL},
528
631
  {"log_error",               (char*) log_error_file,               SHOW_CHAR},
 
632
  {"lower_case_file_system",  (char*) &lower_case_file_system,      SHOW_MY_BOOL},
 
633
  {"lower_case_table_names",  (char*) &lower_case_table_names,      SHOW_INT},
529
634
  {"myisam_recover_options",  (char*) &myisam_recover_options_str,  SHOW_CHAR_PTR},
530
635
  {"open_files_limit",        (char*) &open_files_limit,            SHOW_LONG},
531
636
  {"pid_file",                (char*) pidfile_name,                 SHOW_CHAR},
532
637
  {"plugin_dir",              (char*) opt_plugin_dir,               SHOW_CHAR},
533
638
  {"port",                    (char*) &mysqld_port,                 SHOW_INT},
534
639
  {"protocol_version",        (char*) &protocol_version,            SHOW_INT},
 
640
  {"skip_networking",         (char*) &opt_disable_networking,      SHOW_BOOL},
 
641
  {"skip_show_database",      (char*) &opt_skip_show_db,            SHOW_BOOL},
535
642
  {"thread_stack",            (char*) &my_thread_stack_size,        SHOW_LONG},
536
643
};
537
644
 
538
645
 
539
 
bool sys_var::check(THD *thd __attribute__((unused)), set_var *var)
 
646
bool sys_var::check(THD *thd __attribute__((__unused__)), set_var *var)
540
647
{
541
648
  var->save_result.uint64_t_value= var->value->val_int();
542
649
  return 0;
571
678
                        set_var *var)
572
679
{
573
680
  char *res= 0, *old_value=(char *)(var ? var->value->str_value.ptr() : 0);
574
 
  uint32_t new_length= (var ? var->value->str_value.length() : 0);
 
681
  uint new_length= (var ? var->value->str_value.length() : 0);
575
682
  if (!old_value)
576
683
    old_value= (char*) "";
577
684
  if (!(res= my_strndup(old_value, new_length, MYF(0))))
585
692
  var_str->value= res;
586
693
  var_str->value_length= new_length;
587
694
  rw_unlock(var_mutex);
588
 
  free(old_value);
 
695
  my_free(old_value, MYF(MY_ALLOW_ZERO_PTR));
589
696
  return 0;
590
697
}
591
698
 
592
699
 
593
 
static bool sys_update_init_connect(THD *thd __attribute__((unused)), set_var *var)
 
700
static bool sys_update_init_connect(THD *thd __attribute__((__unused__)), set_var *var)
594
701
{
595
702
  return update_sys_var_str(&sys_init_connect, &LOCK_sys_init_connect, var);
596
703
}
597
704
 
598
705
 
599
 
static void sys_default_init_connect(THD* thd __attribute__((unused)),
600
 
                                     enum_var_type type __attribute__((unused)))
 
706
static void sys_default_init_connect(THD* thd __attribute__((__unused__)),
 
707
                                     enum_var_type type __attribute__((__unused__)))
601
708
{
602
709
  update_sys_var_str(&sys_init_connect, &LOCK_sys_init_connect, 0);
603
710
}
604
711
 
605
712
 
606
 
static bool sys_update_init_slave(THD *thd __attribute__((unused)),
 
713
static bool sys_update_init_slave(THD *thd __attribute__((__unused__)),
607
714
                                  set_var *var)
608
715
{
609
716
  return update_sys_var_str(&sys_init_slave, &LOCK_sys_init_slave, var);
610
717
}
611
718
 
612
719
 
613
 
static void sys_default_init_slave(THD* thd __attribute__((unused)),
614
 
                                   enum_var_type type __attribute__((unused)))
 
720
static void sys_default_init_slave(THD* thd __attribute__((__unused__)),
 
721
                                   enum_var_type type __attribute__((__unused__)))
615
722
{
616
723
  update_sys_var_str(&sys_init_slave, &LOCK_sys_init_slave, 0);
617
724
}
635
742
 
636
743
 
637
744
static void
638
 
fix_myisam_max_sort_file_size(THD *thd __attribute__((unused)),
639
 
                              enum_var_type type __attribute__((unused)))
 
745
fix_myisam_max_sort_file_size(THD *thd __attribute__((__unused__)),
 
746
                              enum_var_type type __attribute__((__unused__)))
640
747
{
641
748
  myisam_max_temp_length=
642
749
    (my_off_t) global_system_variables.myisam_max_sort_file_size;
686
793
static void fix_completion_type(THD *thd __attribute__((unused)),
687
794
                                enum_var_type type __attribute__((unused))) {}
688
795
 
689
 
static int check_completion_type(THD *thd __attribute__((unused)),
 
796
static int check_completion_type(THD *thd __attribute__((__unused__)),
690
797
                                 set_var *var)
691
798
{
692
799
  int64_t val= var->value->val_int();
704
811
  If we are changing the thread variable, we have to copy it to NET too
705
812
*/
706
813
 
 
814
#ifdef HAVE_REPLICATION
707
815
static void fix_net_read_timeout(THD *thd, enum_var_type type)
708
816
{
709
817
  if (type != OPT_GLOBAL)
722
830
  if (type != OPT_GLOBAL)
723
831
    thd->net.retry_count=thd->variables.net_retry_count;
724
832
}
725
 
 
726
 
 
727
 
extern void fix_delay_key_write(THD *thd __attribute__((unused)),
728
 
                                enum_var_type type __attribute__((unused)))
 
833
#else /* HAVE_REPLICATION */
 
834
static void fix_net_read_timeout(THD *thd __attribute__((unused)),
 
835
                                 enum_var_type type __attribute__((unused)))
 
836
{}
 
837
static void fix_net_write_timeout(THD *thd __attribute__((unused)),
 
838
                                  enum_var_type type __attribute__((unused)))
 
839
{}
 
840
static void fix_net_retry_count(THD *thd __attribute__((unused)),
 
841
                                enum_var_type type __attribute__((unused)))
 
842
{}
 
843
#endif /* HAVE_REPLICATION */
 
844
 
 
845
 
 
846
extern void fix_delay_key_write(THD *thd __attribute__((__unused__)),
 
847
                                enum_var_type type __attribute__((__unused__)))
729
848
{
730
849
  switch ((enum_delay_key_write) delay_key_write_options) {
731
850
  case DELAY_KEY_WRITE_NONE:
741
860
  }
742
861
}
743
862
 
744
 
bool sys_var_set::update(THD *thd __attribute__((unused)),
 
863
bool sys_var_set::update(THD *thd __attribute__((__unused__)),
745
864
                         set_var *var)
746
865
{
747
866
  *value= var->save_result.ulong_value;
748
867
  return 0;
749
868
}
750
869
 
751
 
unsigned char *sys_var_set::value_ptr(THD *thd,
752
 
                              enum_var_type type __attribute__((unused)),
753
 
                              LEX_STRING *base __attribute__((unused)))
 
870
uchar *sys_var_set::value_ptr(THD *thd,
 
871
                              enum_var_type type __attribute__((__unused__)),
 
872
                              LEX_STRING *base __attribute__((__unused__)))
754
873
{
755
874
  char buff[256];
756
 
  String tmp(buff, sizeof(buff), &my_charset_utf8_general_ci);
 
875
  String tmp(buff, sizeof(buff), &my_charset_latin1);
757
876
  ulong length;
758
877
  ulong val= *value;
759
878
 
760
879
  tmp.length(0);
761
 
  for (uint32_t i= 0; val; val>>= 1, i++)
 
880
  for (uint i= 0; val; val>>= 1, i++)
762
881
  {
763
882
    if (val & 1)
764
883
    {
770
889
 
771
890
  if ((length= tmp.length()))
772
891
    length--;
773
 
  return (unsigned char*) thd->strmake(tmp.ptr(), length);
 
892
  return (uchar*) thd->strmake(tmp.ptr(), length);
774
893
}
775
894
 
776
 
void sys_var_set_slave_mode::set_default(THD *thd __attribute__((unused)),
777
 
                                         enum_var_type type __attribute__((unused)))
 
895
void sys_var_set_slave_mode::set_default(THD *thd __attribute__((__unused__)),
 
896
                                         enum_var_type type __attribute__((__unused__)))
778
897
{
779
898
  slave_exec_mode_options= 0;
780
899
  bit_do_set(slave_exec_mode_options, SLAVE_EXEC_MODE_STRICT);
802
921
  return rc;
803
922
}
804
923
 
805
 
void fix_slave_exec_mode(enum_var_type type __attribute__((unused)))
 
924
void fix_slave_exec_mode(enum_var_type type __attribute__((__unused__)))
806
925
{
807
926
  if (bit_is_set(slave_exec_mode_options, SLAVE_EXEC_MODE_STRICT) == 1 &&
808
927
      bit_is_set(slave_exec_mode_options, SLAVE_EXEC_MODE_IDEMPOTENT) == 1)
809
928
  {
810
 
    sql_print_error(_("Ambiguous slave modes combination."
811
 
                    " STRICT will be used"));
 
929
    sql_print_error("Ambiguous slave modes combination."
 
930
                    " STRICT will be used");
812
931
    bit_do_clear(slave_exec_mode_options, SLAVE_EXEC_MODE_IDEMPOTENT);
813
932
  }
814
933
  if (bit_is_set(slave_exec_mode_options, SLAVE_EXEC_MODE_IDEMPOTENT) == 0)
838
957
    my_error(ER_TEMP_TABLE_PREVENTS_SWITCH_OUT_OF_RBR, MYF(0));
839
958
    return 1;
840
959
  }
841
 
  
 
960
  /*
 
961
    if in a stored function/trigger, it's too late to change mode
 
962
  */
 
963
  if (thd->in_sub_stmt)
 
964
  {
 
965
    my_error(ER_STORED_FUNCTION_PREVENTS_SWITCH_BINLOG_FORMAT, MYF(0));
 
966
    return 1;    
 
967
  }
842
968
  return sys_var_thd_enum::is_readonly();
843
969
}
844
970
 
845
971
 
846
972
void fix_binlog_format_after_update(THD *thd,
847
 
                                    enum_var_type type __attribute__((unused)))
 
973
                                    enum_var_type type __attribute__((__unused__)))
848
974
{
849
975
  thd->reset_current_stmt_binlog_row_based();
850
976
}
851
977
 
852
978
 
853
 
static void fix_max_binlog_size(THD *thd __attribute__((unused)),
854
 
                                enum_var_type type __attribute__((unused)))
 
979
static void fix_max_binlog_size(THD *thd __attribute__((__unused__)),
 
980
                                enum_var_type type __attribute__((__unused__)))
855
981
{
856
982
  mysql_bin_log.set_max_size(max_binlog_size);
 
983
#ifdef HAVE_REPLICATION
857
984
  if (!max_relay_log_size)
858
985
    active_mi->rli.relay_log.set_max_size(max_binlog_size);
 
986
#endif
859
987
  return;
860
988
}
861
989
 
862
 
static void fix_max_relay_log_size(THD *thd __attribute__((unused)),
863
 
                                   enum_var_type type __attribute__((unused)))
 
990
static void fix_max_relay_log_size(THD *thd __attribute__((__unused__)),
 
991
                                   enum_var_type type __attribute__((__unused__)))
864
992
{
 
993
#ifdef HAVE_REPLICATION
865
994
  active_mi->rli.relay_log.set_max_size(max_relay_log_size ?
866
995
                                        max_relay_log_size: max_binlog_size);
 
996
#endif
867
997
  return;
868
998
}
869
999
 
870
 
static void fix_max_connections(THD *thd __attribute__((unused)),
871
 
                                enum_var_type type __attribute__((unused)))
 
1000
static void fix_max_connections(THD *thd __attribute__((__unused__)),
 
1001
                                enum_var_type type __attribute__((__unused__)))
872
1002
{
873
1003
  resize_thr_alarm(max_connections +  10);
874
1004
}
892
1022
}
893
1023
 
894
1024
 
895
 
static void fix_server_id(THD *thd __attribute__((unused)),
896
 
                          enum_var_type type __attribute__((unused)))
 
1025
static void fix_server_id(THD *thd __attribute__((__unused__)),
 
1026
                          enum_var_type type __attribute__((__unused__)))
897
1027
{
898
1028
  server_id_supplied = 1;
899
1029
  thd->server_id= server_id;
912
1042
    else
913
1043
      llstr(val, buf);
914
1044
 
915
 
    push_warning_printf(thd, DRIZZLE_ERROR::WARN_LEVEL_WARN,
 
1045
    push_warning_printf(thd, MYSQL_ERROR::WARN_LEVEL_WARN,
916
1046
                        ER_TRUNCATED_WRONG_VALUE,
917
1047
                        ER(ER_TRUNCATED_WRONG_VALUE), name, buf);
918
1048
  }
929
1059
  return out;
930
1060
}
931
1061
 
932
 
static bool get_unsigned(THD *thd __attribute__((unused)), set_var *var)
 
1062
static bool get_unsigned(THD *thd __attribute__((__unused__)), set_var *var)
933
1063
{
934
1064
  if (var->value->unsigned_flag)
935
1065
    var->save_result.uint64_t_value= (uint64_t) var->value->val_int();
963
1093
    *value= (ulong) fix_unsigned(thd, tmp, option_limits);
964
1094
  else
965
1095
  {
966
 
    if (tmp > UINT32_MAX)
 
1096
#if SIZEOF_LONG < SIZEOF_LONG_LONG
 
1097
    /* Avoid overflows on 32 bit systems */
 
1098
    if (tmp > ULONG_MAX)
967
1099
    {
968
 
      tmp= UINT32_MAX;
 
1100
      tmp= ULONG_MAX;
969
1101
      throw_bounds_warning(thd, true, true, name,
970
1102
                           (int64_t) var->save_result.uint64_t_value);
971
1103
    }
 
1104
#endif
972
1105
    *value= (ulong) tmp;
973
1106
  }
974
1107
 
977
1110
}
978
1111
 
979
1112
 
980
 
void sys_var_long_ptr_global::set_default(THD *thd __attribute__((unused)), enum_var_type type __attribute__((unused)))
 
1113
void sys_var_long_ptr_global::set_default(THD *thd __attribute__((__unused__)), enum_var_type type __attribute__((__unused__)))
981
1114
{
982
1115
  bool not_used;
983
1116
  pthread_mutex_lock(guard);
1000
1133
}
1001
1134
 
1002
1135
 
1003
 
void sys_var_uint64_t_ptr::set_default(THD *thd __attribute__((unused)),
1004
 
                                        enum_var_type type __attribute__((unused)))
 
1136
void sys_var_uint64_t_ptr::set_default(THD *thd __attribute__((__unused__)),
 
1137
                                        enum_var_type type __attribute__((__unused__)))
1005
1138
{
1006
1139
  bool not_used;
1007
1140
  pthread_mutex_lock(&LOCK_global_system_variables);
1011
1144
}
1012
1145
 
1013
1146
 
1014
 
bool sys_var_bool_ptr::update(THD *thd __attribute__((unused)), set_var *var)
 
1147
bool sys_var_bool_ptr::update(THD *thd __attribute__((__unused__)), set_var *var)
1015
1148
{
1016
1149
  *value= (bool) var->save_result.ulong_value;
1017
1150
  return 0;
1018
1151
}
1019
1152
 
1020
1153
 
1021
 
void sys_var_bool_ptr::set_default(THD *thd __attribute__((unused)), enum_var_type type __attribute__((unused)))
 
1154
void sys_var_bool_ptr::set_default(THD *thd __attribute__((__unused__)), enum_var_type type __attribute__((__unused__)))
1022
1155
{
1023
1156
  *value= (bool) option_limits->def_value;
1024
1157
}
1025
1158
 
1026
1159
 
1027
 
bool sys_var_enum::update(THD *thd __attribute__((unused)), set_var *var)
 
1160
bool sys_var_enum::update(THD *thd __attribute__((__unused__)), set_var *var)
1028
1161
{
1029
1162
  *value= (uint) var->save_result.ulong_value;
1030
1163
  return 0;
1031
1164
}
1032
1165
 
1033
1166
 
1034
 
unsigned char *sys_var_enum::value_ptr(THD *thd __attribute__((unused)),
1035
 
                               enum_var_type type __attribute__((unused)),
1036
 
                               LEX_STRING *base __attribute__((unused)))
 
1167
uchar *sys_var_enum::value_ptr(THD *thd __attribute__((__unused__)),
 
1168
                               enum_var_type type __attribute__((__unused__)),
 
1169
                               LEX_STRING *base __attribute__((__unused__)))
1037
1170
{
1038
 
  return (unsigned char*) enum_names->type_names[*value];
 
1171
  return (uchar*) enum_names->type_names[*value];
1039
1172
}
1040
1173
 
1041
1174
 
1042
 
unsigned char *sys_var_enum_const::value_ptr(THD *thd __attribute__((unused)),
1043
 
                                     enum_var_type type __attribute__((unused)),
1044
 
                                     LEX_STRING *base __attribute__((unused)))
 
1175
uchar *sys_var_enum_const::value_ptr(THD *thd __attribute__((__unused__)),
 
1176
                                     enum_var_type type __attribute__((__unused__)),
 
1177
                                     LEX_STRING *base __attribute__((__unused__)))
1045
1178
{
1046
 
  return (unsigned char*) enum_names->type_names[global_system_variables.*offset];
 
1179
  return (uchar*) enum_names->type_names[global_system_variables.*offset];
1047
1180
}
1048
1181
 
1049
1182
bool sys_var_thd_ulong::check(THD *thd, set_var *var)
1065
1198
  
1066
1199
  if (option_limits)
1067
1200
    tmp= (ulong) fix_unsigned(thd, tmp, option_limits);
1068
 
  else if (tmp > UINT32_MAX)
 
1201
#if SIZEOF_LONG < SIZEOF_LONG_LONG
 
1202
  else if (tmp > ULONG_MAX)
1069
1203
  {
1070
 
    tmp= UINT32_MAX;
 
1204
    tmp= ULONG_MAX;
1071
1205
    throw_bounds_warning(thd, true, true, name, (int64_t) var->save_result.uint64_t_value);
1072
1206
  }
 
1207
#endif
1073
1208
  
1074
1209
  if (var->type == OPT_GLOBAL)
1075
1210
     global_system_variables.*offset= (ulong) tmp;
1095
1230
 }
1096
1231
 
1097
1232
 
1098
 
unsigned char *sys_var_thd_ulong::value_ptr(THD *thd, enum_var_type type,
1099
 
                                    LEX_STRING *base __attribute__((unused)))
 
1233
uchar *sys_var_thd_ulong::value_ptr(THD *thd, enum_var_type type,
 
1234
                                    LEX_STRING *base __attribute__((__unused__)))
1100
1235
{
1101
1236
  if (type == OPT_GLOBAL)
1102
 
    return (unsigned char*) &(global_system_variables.*offset);
1103
 
  return (unsigned char*) &(thd->variables.*offset);
 
1237
    return (uchar*) &(global_system_variables.*offset);
 
1238
  return (uchar*) &(thd->variables.*offset);
1104
1239
}
1105
1240
 
1106
1241
 
1144
1279
}
1145
1280
 
1146
1281
 
1147
 
unsigned char *sys_var_thd_ha_rows::value_ptr(THD *thd, enum_var_type type,
1148
 
                                      LEX_STRING *base __attribute__((unused)))
 
1282
uchar *sys_var_thd_ha_rows::value_ptr(THD *thd, enum_var_type type,
 
1283
                                      LEX_STRING *base __attribute__((__unused__)))
1149
1284
{
1150
1285
  if (type == OPT_GLOBAL)
1151
 
    return (unsigned char*) &(global_system_variables.*offset);
1152
 
  return (unsigned char*) &(thd->variables.*offset);
 
1286
    return (uchar*) &(global_system_variables.*offset);
 
1287
  return (uchar*) &(thd->variables.*offset);
1153
1288
}
1154
1289
 
1155
1290
bool sys_var_thd_uint64_t::check(THD *thd, set_var *var)
1195
1330
}
1196
1331
 
1197
1332
 
1198
 
unsigned char *sys_var_thd_uint64_t::value_ptr(THD *thd, enum_var_type type,
1199
 
                                        LEX_STRING *base __attribute__((unused)))
 
1333
uchar *sys_var_thd_uint64_t::value_ptr(THD *thd, enum_var_type type,
 
1334
                                        LEX_STRING *base __attribute__((__unused__)))
1200
1335
{
1201
1336
  if (type == OPT_GLOBAL)
1202
 
    return (unsigned char*) &(global_system_variables.*offset);
1203
 
  return (unsigned char*) &(thd->variables.*offset);
 
1337
    return (uchar*) &(global_system_variables.*offset);
 
1338
  return (uchar*) &(thd->variables.*offset);
1204
1339
}
1205
1340
 
1206
1341
 
1207
1342
bool sys_var_thd_bool::update(THD *thd,  set_var *var)
1208
1343
{
1209
1344
  if (var->type == OPT_GLOBAL)
1210
 
    global_system_variables.*offset= (bool) var->save_result.ulong_value;
 
1345
    global_system_variables.*offset= (my_bool) var->save_result.ulong_value;
1211
1346
  else
1212
 
    thd->variables.*offset= (bool) var->save_result.ulong_value;
 
1347
    thd->variables.*offset= (my_bool) var->save_result.ulong_value;
1213
1348
  return 0;
1214
1349
}
1215
1350
 
1217
1352
void sys_var_thd_bool::set_default(THD *thd,  enum_var_type type)
1218
1353
{
1219
1354
  if (type == OPT_GLOBAL)
1220
 
    global_system_variables.*offset= (bool) option_limits->def_value;
 
1355
    global_system_variables.*offset= (my_bool) option_limits->def_value;
1221
1356
  else
1222
1357
    thd->variables.*offset= global_system_variables.*offset;
1223
1358
}
1224
1359
 
1225
1360
 
1226
 
unsigned char *sys_var_thd_bool::value_ptr(THD *thd, enum_var_type type,
1227
 
                                   LEX_STRING *base __attribute__((unused)))
 
1361
uchar *sys_var_thd_bool::value_ptr(THD *thd, enum_var_type type,
 
1362
                                   LEX_STRING *base __attribute__((__unused__)))
1228
1363
{
1229
1364
  if (type == OPT_GLOBAL)
1230
 
    return (unsigned char*) &(global_system_variables.*offset);
1231
 
  return (unsigned char*) &(thd->variables.*offset);
 
1365
    return (uchar*) &(global_system_variables.*offset);
 
1366
  return (uchar*) &(thd->variables.*offset);
1232
1367
}
1233
1368
 
1234
1369
 
1235
 
bool sys_var::check_enum(THD *thd __attribute__((unused)),
 
1370
bool sys_var::check_enum(THD *thd __attribute__((__unused__)),
1236
1371
                         set_var *var, const TYPELIB *enum_names)
1237
1372
{
1238
1373
  char buff[STRING_BUFFER_USUAL_SIZE];
1269
1404
}
1270
1405
 
1271
1406
 
1272
 
bool sys_var::check_set(THD *thd __attribute__((unused)),
 
1407
bool sys_var::check_set(THD *thd __attribute__((__unused__)),
1273
1408
                        set_var *var, TYPELIB *enum_names)
1274
1409
{
1275
1410
  bool not_used;
1276
1411
  char buff[STRING_BUFFER_USUAL_SIZE], *error= 0;
1277
 
  uint32_t error_len= 0;
 
1412
  uint error_len= 0;
1278
1413
  String str(buff, sizeof(buff), system_charset_info), *res;
1279
1414
 
1280
1415
  if (var->value->result_type() == STRING_RESULT)
1281
1416
  {
1282
1417
    if (!(res= var->value->val_str(&str)))
1283
1418
    {
1284
 
      my_stpcpy(buff, "NULL");
 
1419
      strmov(buff, "NULL");
1285
1420
      goto err;
1286
1421
    }
1287
1422
 
1300
1435
                                            &not_used));
1301
1436
    if (error_len)
1302
1437
    {
1303
 
      strmake(buff, error, cmin(sizeof(buff) - 1, (ulong)error_len));
 
1438
      strmake(buff, error, min(sizeof(buff) - 1, error_len));
1304
1439
      goto err;
1305
1440
    }
1306
1441
  }
1320
1455
      For when the enum is made to contain 64 elements, as 1ULL<<64 is
1321
1456
      undefined, we guard with a "count<64" test.
1322
1457
    */
1323
 
    if (unlikely((tmp >= ((1UL) << enum_names->count)) &&
 
1458
    if (unlikely((tmp >= ((1ULL) << enum_names->count)) &&
1324
1459
                 (enum_names->count < 64)))
1325
1460
    {
1326
1461
      llstr(tmp, buff);
1360
1495
  switch (show_type()) {
1361
1496
  case SHOW_INT:
1362
1497
  {
1363
 
    uint32_t value;
 
1498
    uint value;
1364
1499
    pthread_mutex_lock(&LOCK_global_system_variables);
1365
1500
    value= *(uint*) value_ptr(thd, var_type, base);
1366
1501
    pthread_mutex_unlock(&LOCK_global_system_variables);
1401
1536
  }
1402
1537
  case SHOW_MY_BOOL:
1403
1538
  {
1404
 
    int32_t value;
 
1539
    int32 value;
1405
1540
    pthread_mutex_lock(&LOCK_global_system_variables);
1406
 
    value= *(bool*) value_ptr(thd, var_type, base);
 
1541
    value= *(my_bool*) value_ptr(thd, var_type, base);
1407
1542
    pthread_mutex_unlock(&LOCK_global_system_variables);
1408
1543
    return new Item_int(value,1);
1409
1544
  }
1414
1549
    char *str= *(char**) value_ptr(thd, var_type, base);
1415
1550
    if (str)
1416
1551
    {
1417
 
      uint32_t length= strlen(str);
 
1552
      uint length= strlen(str);
1418
1553
      tmp= new Item_string(thd->strmake(str, length), length,
1419
1554
                           system_charset_info, DERIVATION_SYSCONST);
1420
1555
    }
1468
1603
}
1469
1604
 
1470
1605
 
1471
 
unsigned char *sys_var_thd_enum::value_ptr(THD *thd, enum_var_type type,
1472
 
                                   LEX_STRING *base __attribute__((unused)))
 
1606
uchar *sys_var_thd_enum::value_ptr(THD *thd, enum_var_type type,
 
1607
                                   LEX_STRING *base __attribute__((__unused__)))
1473
1608
{
1474
1609
  ulong tmp= ((type == OPT_GLOBAL) ?
1475
1610
              global_system_variables.*offset :
1476
1611
              thd->variables.*offset);
1477
 
  return (unsigned char*) enum_names->type_names[tmp];
 
1612
  return (uchar*) enum_names->type_names[tmp];
1478
1613
}
1479
1614
 
1480
1615
bool sys_var_thd_bit::check(THD *thd, set_var *var)
1490
1625
}
1491
1626
 
1492
1627
 
1493
 
unsigned char *sys_var_thd_bit::value_ptr(THD *thd,
1494
 
                                  enum_var_type type __attribute__((unused)),
1495
 
                                  LEX_STRING *base __attribute__((unused)))
 
1628
uchar *sys_var_thd_bit::value_ptr(THD *thd,
 
1629
                                  enum_var_type type __attribute__((__unused__)),
 
1630
                                  LEX_STRING *base __attribute__((__unused__)))
1496
1631
{
1497
1632
  /*
1498
1633
    If reverse is 0 (default) return 1 if bit is set.
1499
1634
    If reverse is 1, return 0 if bit is set
1500
1635
  */
1501
 
  thd->sys_var_tmp.bool_value= ((thd->options & bit_flag) ?
 
1636
  thd->sys_var_tmp.my_bool_value= ((thd->options & bit_flag) ?
1502
1637
                                   !reverse : reverse);
1503
 
  return (unsigned char*) &thd->sys_var_tmp.bool_value;
 
1638
  return (uchar*) &thd->sys_var_tmp.my_bool_value;
1504
1639
}
1505
1640
 
1506
1641
 
1523
1658
    old= (thd->variables.*offset);
1524
1659
    (thd->variables.*offset)= new_value;
1525
1660
  }
1526
 
  free((char*) old);
 
1661
  my_free((char*) old, MYF(MY_ALLOW_ZERO_PTR));
1527
1662
  return;
1528
1663
}
1529
1664
 
1562
1697
    update is aborted
1563
1698
  */
1564
1699
  var->save_result.date_time_format= date_time_format_copy(thd, format);
1565
 
  free((char*) format);
 
1700
  my_free((char*) format, MYF(0));
1566
1701
  return var->save_result.date_time_format == 0;
1567
1702
}
1568
1703
 
1588
1723
}
1589
1724
 
1590
1725
 
1591
 
unsigned char *sys_var_thd_date_time_format::value_ptr(THD *thd, enum_var_type type,
1592
 
                                               LEX_STRING *base __attribute__((unused)))
 
1726
uchar *sys_var_thd_date_time_format::value_ptr(THD *thd, enum_var_type type,
 
1727
                                               LEX_STRING *base __attribute__((__unused__)))
1593
1728
{
1594
1729
  if (type == OPT_GLOBAL)
1595
1730
  {
1601
1736
    */
1602
1737
    res= thd->strmake((global_system_variables.*offset)->format.str,
1603
1738
                      (global_system_variables.*offset)->format.length);
1604
 
    return (unsigned char*) res;
 
1739
    return (uchar*) res;
1605
1740
  }
1606
 
  return (unsigned char*) (thd->variables.*offset)->format.str;
 
1741
  return (uchar*) (thd->variables.*offset)->format.str;
1607
1742
}
1608
1743
 
1609
1744
 
1613
1748
  const char *new_name;
1614
1749
} my_old_conv;
1615
1750
 
1616
 
bool sys_var_collation::check(THD *thd __attribute__((unused)),
 
1751
static my_old_conv old_conv[]= 
 
1752
{
 
1753
  {     "cp1251_koi8"           ,       "cp1251"        },
 
1754
  {     "cp1250_latin2"         ,       "cp1250"        },
 
1755
  {     "kam_latin2"            ,       "keybcs2"       },
 
1756
  {     "mac_latin2"            ,       "MacRoman"      },
 
1757
  {     "macce_latin2"          ,       "MacCE"         },
 
1758
  {     "pc2_latin2"            ,       "pclatin2"      },
 
1759
  {     "vga_latin2"            ,       "pclatin1"      },
 
1760
  {     "koi8_cp1251"           ,       "koi8r"         },
 
1761
  {     "win1251ukr_koi8_ukr"   ,       "win1251ukr"    },
 
1762
  {     "koi8_ukr_win1251ukr"   ,       "koi8u"         },
 
1763
  {     NULL                    ,       NULL            }
 
1764
};
 
1765
 
 
1766
CHARSET_INFO *get_old_charset_by_name(const char *name)
 
1767
{
 
1768
  my_old_conv *conv;
 
1769
 
 
1770
  for (conv= old_conv; conv->old_name; conv++)
 
1771
  {
 
1772
    if (!my_strcasecmp(&my_charset_latin1, name, conv->old_name))
 
1773
      return get_charset_by_csname(conv->new_name, MY_CS_PRIMARY, MYF(0));
 
1774
  }
 
1775
  return NULL;
 
1776
}
 
1777
 
 
1778
 
 
1779
bool sys_var_collation::check(THD *thd __attribute__((__unused__)),
1617
1780
                              set_var *var)
1618
1781
{
1619
 
  const CHARSET_INFO *tmp;
 
1782
  CHARSET_INFO *tmp;
1620
1783
 
1621
1784
  if (var->value->result_type() == STRING_RESULT)
1622
1785
  {
1648
1811
}
1649
1812
 
1650
1813
 
1651
 
bool sys_var_character_set::check(THD *thd __attribute__((unused)),
 
1814
bool sys_var_character_set::check(THD *thd __attribute__((__unused__)),
1652
1815
                                  set_var *var)
1653
1816
{
1654
 
  const CHARSET_INFO *tmp;
 
1817
  CHARSET_INFO *tmp;
1655
1818
 
1656
1819
  if (var->value->result_type() == STRING_RESULT)
1657
1820
  {
1666
1829
      }
1667
1830
      tmp= NULL;
1668
1831
    }
1669
 
    else if (!(tmp= get_charset_by_csname(res->c_ptr(),MY_CS_PRIMARY,MYF(0))))
 
1832
    else if (!(tmp=get_charset_by_csname(res->c_ptr(),MY_CS_PRIMARY,MYF(0))) &&
 
1833
             !(tmp=get_old_charset_by_name(res->c_ptr())))
1670
1834
    {
1671
1835
      my_error(ER_UNKNOWN_CHARACTER_SET, MYF(0), res->c_ptr());
1672
1836
      return 1;
1695
1859
}
1696
1860
 
1697
1861
 
1698
 
unsigned char *sys_var_character_set::value_ptr(THD *thd, enum_var_type type,
1699
 
                                        LEX_STRING *base __attribute__((unused)))
1700
 
{
1701
 
  const CHARSET_INFO * const cs= ci_ptr(thd,type)[0];
1702
 
  return cs ? (unsigned char*) cs->csname : (unsigned char*) NULL;
 
1862
uchar *sys_var_character_set::value_ptr(THD *thd, enum_var_type type,
 
1863
                                        LEX_STRING *base __attribute__((__unused__)))
 
1864
{
 
1865
  CHARSET_INFO *cs= ci_ptr(thd,type)[0];
 
1866
  return cs ? (uchar*) cs->csname : (uchar*) NULL;
 
1867
}
 
1868
 
 
1869
 
 
1870
void sys_var_character_set_sv::set_default(THD *thd, enum_var_type type)
 
1871
{
 
1872
  if (type == OPT_GLOBAL)
 
1873
    global_system_variables.*offset= *global_default;
 
1874
  else
 
1875
  {
 
1876
    thd->variables.*offset= global_system_variables.*offset;
 
1877
    thd->update_charset();
 
1878
  }
 
1879
}
 
1880
CHARSET_INFO **sys_var_character_set_sv::ci_ptr(THD *thd, enum_var_type type)
 
1881
{
 
1882
  if (type == OPT_GLOBAL)
 
1883
    return &(global_system_variables.*offset);
 
1884
  else
 
1885
    return &(thd->variables.*offset);
 
1886
}
 
1887
 
 
1888
 
 
1889
bool sys_var_character_set_client::check(THD *thd, set_var *var)
 
1890
{
 
1891
  if (sys_var_character_set_sv::check(thd, var))
 
1892
    return 1;
 
1893
  /* Currently, UCS-2 cannot be used as a client character set */
 
1894
  if (var->save_result.charset->mbminlen > 1)
 
1895
  {
 
1896
    my_error(ER_WRONG_VALUE_FOR_VAR, MYF(0), name, 
 
1897
             var->save_result.charset->csname);
 
1898
    return 1;
 
1899
  }
 
1900
  return 0;
 
1901
}
 
1902
 
 
1903
 
 
1904
CHARSET_INFO ** sys_var_character_set_database::ci_ptr(THD *thd,
 
1905
                                                       enum_var_type type)
 
1906
{
 
1907
  if (type == OPT_GLOBAL)
 
1908
    return &global_system_variables.collation_database;
 
1909
  else
 
1910
    return &thd->variables.collation_database;
 
1911
}
 
1912
 
 
1913
 
 
1914
void sys_var_character_set_database::set_default(THD *thd, enum_var_type type)
 
1915
{
 
1916
 if (type == OPT_GLOBAL)
 
1917
    global_system_variables.collation_database= default_charset_info;
 
1918
  else
 
1919
  {
 
1920
    thd->variables.collation_database= thd->db_charset;
 
1921
    thd->update_charset();
 
1922
  }
1703
1923
}
1704
1924
 
1705
1925
 
1728
1948
}
1729
1949
 
1730
1950
 
1731
 
unsigned char *sys_var_collation_sv::value_ptr(THD *thd, enum_var_type type,
1732
 
                                       LEX_STRING *base __attribute__((unused)))
 
1951
uchar *sys_var_collation_sv::value_ptr(THD *thd, enum_var_type type,
 
1952
                                       LEX_STRING *base __attribute__((__unused__)))
1733
1953
{
1734
 
  const CHARSET_INFO *cs= ((type == OPT_GLOBAL) ?
 
1954
  CHARSET_INFO *cs= ((type == OPT_GLOBAL) ?
1735
1955
                     global_system_variables.*offset : thd->variables.*offset);
1736
 
  return cs ? (unsigned char*) cs->name : (unsigned char*) "NULL";
 
1956
  return cs ? (uchar*) cs->name : (uchar*) "NULL";
1737
1957
}
1738
1958
 
1739
1959
 
1751
1971
}
1752
1972
 
1753
1973
 
1754
 
unsigned char *sys_var_key_cache_param::value_ptr(THD *thd __attribute__((unused)),
1755
 
                                          enum_var_type type __attribute__((unused)),
1756
 
                                          LEX_STRING *base __attribute__((unused)))
 
1974
uchar *sys_var_key_cache_param::value_ptr(THD *thd __attribute__((__unused__)),
 
1975
                                          enum_var_type type __attribute__((__unused__)),
 
1976
                                          LEX_STRING *base __attribute__((__unused__)))
1757
1977
{
1758
1978
  KEY_CACHE *key_cache= get_key_cache(base);
1759
1979
  if (!key_cache)
1760
1980
    key_cache= &zero_key_cache;
1761
 
  return (unsigned char*) key_cache + offset ;
 
1981
  return (uchar*) key_cache + offset ;
1762
1982
}
1763
1983
 
1764
1984
 
1800
2020
  {
1801
2021
    if (key_cache == dflt_key_cache)
1802
2022
    {
1803
 
      push_warning_printf(thd, DRIZZLE_ERROR::WARN_LEVEL_WARN,
 
2023
      push_warning_printf(thd, MYSQL_ERROR::WARN_LEVEL_WARN,
1804
2024
                          ER_WARN_CANT_DROP_DEFAULT_KEYCACHE,
1805
2025
                          ER(ER_WARN_CANT_DROP_DEFAULT_KEYCACHE));
1806
2026
      goto end;                                 // Ignore default key cache
1904
2124
}
1905
2125
 
1906
2126
 
1907
 
bool sys_var_log_state::update(THD *thd __attribute__((unused)), set_var *var)
 
2127
bool sys_var_log_state::update(THD *thd, set_var *var)
1908
2128
{
1909
2129
  bool res;
1910
2130
  pthread_mutex_lock(&LOCK_global_system_variables);
1911
2131
  if (!var->save_result.ulong_value)
 
2132
  {
 
2133
    logger.deactivate_log_handler(thd, log_type);
1912
2134
    res= false;
 
2135
  }
1913
2136
  else
1914
 
    res= true;
 
2137
    res= logger.activate_log_handler(thd, log_type);
1915
2138
  pthread_mutex_unlock(&LOCK_global_system_variables);
1916
2139
  return res;
1917
2140
}
1918
2141
 
1919
 
void sys_var_log_state::set_default(THD *thd __attribute__((unused)),
1920
 
                                    enum_var_type type __attribute__((unused)))
1921
 
{
1922
 
}
1923
 
 
1924
 
 
1925
 
bool update_sys_var_str_path(THD *thd __attribute__((unused)),
 
2142
void sys_var_log_state::set_default(THD *thd,
 
2143
                                    enum_var_type type __attribute__((__unused__)))
 
2144
{
 
2145
  pthread_mutex_lock(&LOCK_global_system_variables);
 
2146
  logger.deactivate_log_handler(thd, log_type);
 
2147
  pthread_mutex_unlock(&LOCK_global_system_variables);
 
2148
}
 
2149
 
 
2150
 
 
2151
static int  sys_check_log_path(THD *thd __attribute__((__unused__)),
 
2152
                               set_var *var)
 
2153
{
 
2154
  char path[FN_REFLEN], buff[FN_REFLEN];
 
2155
  struct stat f_stat;
 
2156
  String str(buff, sizeof(buff), system_charset_info), *res;
 
2157
  const char *log_file_str;
 
2158
  size_t path_length;
 
2159
 
 
2160
  if (!(res= var->value->val_str(&str)))
 
2161
    goto err;
 
2162
 
 
2163
  log_file_str= res->c_ptr();
 
2164
  bzero(&f_stat, sizeof(struct stat));
 
2165
 
 
2166
  path_length= unpack_filename(path, log_file_str);
 
2167
 
 
2168
  if (!path_length)
 
2169
  {
 
2170
    /* File name is empty. */
 
2171
 
 
2172
    goto err;
 
2173
  }
 
2174
 
 
2175
  if (!stat(path, &f_stat))
 
2176
  {
 
2177
    /*
 
2178
      A file system object exists. Check if argument is a file and we have
 
2179
      'write' permission.
 
2180
    */
 
2181
 
 
2182
    if (!MY_S_ISREG(f_stat.st_mode) ||
 
2183
        !(f_stat.st_mode & MY_S_IWRITE))
 
2184
      goto err;
 
2185
 
 
2186
    return 0;
 
2187
  }
 
2188
 
 
2189
  /* Get dirname of the file path. */
 
2190
  (void) dirname_part(path, log_file_str, &path_length);
 
2191
 
 
2192
  /* Dirname is empty if file path is relative. */
 
2193
  if (!path_length)
 
2194
    return 0;
 
2195
 
 
2196
  /*
 
2197
    Check if directory exists and we have permission to create file and
 
2198
    write to file.
 
2199
  */
 
2200
  if (my_access(path, (F_OK|W_OK)))
 
2201
    goto err;
 
2202
 
 
2203
  return 0;
 
2204
 
 
2205
err:
 
2206
  my_error(ER_WRONG_VALUE_FOR_VAR, MYF(0), var->var->name, 
 
2207
           res ? log_file_str : "NULL");
 
2208
  return 1;
 
2209
}
 
2210
 
 
2211
 
 
2212
bool update_sys_var_str_path(THD *thd __attribute__((__unused__)),
1926
2213
                             sys_var_str *var_str,
1927
2214
                             set_var *var, const char *log_ext,
1928
 
                             bool log_state, uint32_t log_type)
 
2215
                             bool log_state, uint log_type)
1929
2216
{
 
2217
  MYSQL_QUERY_LOG *file_log;
1930
2218
  char buff[FN_REFLEN];
1931
2219
  char *res= 0, *old_value=(char *)(var ? var->value->str_value.ptr() : 0);
1932
2220
  bool result= 0;
1933
 
  uint32_t str_length= (var ? var->value->str_value.length() : 0);
 
2221
  uint str_length= (var ? var->value->str_value.length() : 0);
1934
2222
 
1935
2223
  switch (log_type) {
 
2224
  case QUERY_LOG_SLOW:
 
2225
    file_log= logger.get_slow_log_file_handler();
 
2226
    break;
 
2227
  case QUERY_LOG_GENERAL:
 
2228
    file_log= logger.get_log_file_handler();
 
2229
    break;
1936
2230
  default:
1937
2231
    assert(0);                                  // Impossible
1938
2232
  }
1951
2245
  pthread_mutex_lock(&LOCK_global_system_variables);
1952
2246
  logger.lock_exclusive();
1953
2247
 
 
2248
  if (file_log && log_state)
 
2249
    file_log->close(0);
1954
2250
  old_value= var_str->value;
1955
2251
  var_str->value= res;
1956
2252
  var_str->value_length= str_length;
1957
 
  free(old_value);
1958
 
  if (log_state)
 
2253
  my_free(old_value, MYF(MY_ALLOW_ZERO_PTR));
 
2254
  if (file_log && log_state)
1959
2255
  {
1960
2256
    switch (log_type) {
 
2257
    case QUERY_LOG_SLOW:
 
2258
      file_log->open_slow_log(sys_var_slow_log_path.value);
 
2259
      break;
 
2260
    case QUERY_LOG_GENERAL:
 
2261
      file_log->open_query_log(sys_var_general_log_path.value);
 
2262
      break;
1961
2263
    default:
1962
2264
      assert(0);
1963
2265
    }
1971
2273
}
1972
2274
 
1973
2275
 
1974
 
bool sys_var_log_output::update(THD *thd __attribute__((unused)),
 
2276
static bool sys_update_general_log_path(THD *thd, set_var * var)
 
2277
{
 
2278
  return update_sys_var_str_path(thd, &sys_var_general_log_path,
 
2279
                                 var, ".log", opt_log, QUERY_LOG_GENERAL);
 
2280
}
 
2281
 
 
2282
 
 
2283
static void sys_default_general_log_path(THD *thd,
 
2284
                                         enum_var_type type __attribute__((__unused__)))
 
2285
{
 
2286
  (void) update_sys_var_str_path(thd, &sys_var_general_log_path,
 
2287
                                 0, ".log", opt_log, QUERY_LOG_GENERAL);
 
2288
}
 
2289
 
 
2290
 
 
2291
static bool sys_update_slow_log_path(THD *thd, set_var * var)
 
2292
{
 
2293
  return update_sys_var_str_path(thd, &sys_var_slow_log_path,
 
2294
                                 var, "-slow.log", opt_slow_log,
 
2295
                                 QUERY_LOG_SLOW);
 
2296
}
 
2297
 
 
2298
 
 
2299
static void sys_default_slow_log_path(THD *thd,
 
2300
                                      enum_var_type type __attribute__((__unused__)))
 
2301
{
 
2302
  (void) update_sys_var_str_path(thd, &sys_var_slow_log_path,
 
2303
                                 0, "-slow.log", opt_slow_log,
 
2304
                                 QUERY_LOG_SLOW);
 
2305
}
 
2306
 
 
2307
 
 
2308
bool sys_var_log_output::update(THD *thd __attribute__((__unused__)),
1975
2309
                                set_var *var)
1976
2310
{
1977
2311
  pthread_mutex_lock(&LOCK_global_system_variables);
1978
2312
  logger.lock_exclusive();
 
2313
  logger.init_slow_log(var->save_result.ulong_value);
 
2314
  logger.init_general_log(var->save_result.ulong_value);
1979
2315
  *value= var->save_result.ulong_value;
1980
2316
  logger.unlock();
1981
2317
  pthread_mutex_unlock(&LOCK_global_system_variables);
1983
2319
}
1984
2320
 
1985
2321
 
1986
 
void sys_var_log_output::set_default(THD *thd __attribute__((unused)),
1987
 
                                     enum_var_type type __attribute__((unused)))
 
2322
void sys_var_log_output::set_default(THD *thd __attribute__((__unused__)),
 
2323
                                     enum_var_type type __attribute__((__unused__)))
1988
2324
{
1989
2325
  pthread_mutex_lock(&LOCK_global_system_variables);
1990
2326
  logger.lock_exclusive();
 
2327
  logger.init_slow_log(LOG_FILE);
 
2328
  logger.init_general_log(LOG_FILE);
1991
2329
  *value= LOG_FILE;
1992
2330
  logger.unlock();
1993
2331
  pthread_mutex_unlock(&LOCK_global_system_variables);
1994
2332
}
1995
2333
 
1996
2334
 
1997
 
unsigned char *sys_var_log_output::value_ptr(THD *thd,
1998
 
                                     enum_var_type type __attribute__((unused)),
1999
 
                                     LEX_STRING *base __attribute__((unused)))
 
2335
uchar *sys_var_log_output::value_ptr(THD *thd,
 
2336
                                     enum_var_type type __attribute__((__unused__)),
 
2337
                                     LEX_STRING *base __attribute__((__unused__)))
2000
2338
{
2001
2339
  char buff[256];
2002
 
  String tmp(buff, sizeof(buff), &my_charset_utf8_general_ci);
 
2340
  String tmp(buff, sizeof(buff), &my_charset_latin1);
2003
2341
  ulong length;
2004
2342
  ulong val= *value;
2005
2343
 
2006
2344
  tmp.length(0);
2007
 
  for (uint32_t i= 0; val; val>>= 1, i++)
 
2345
  for (uint i= 0; val; val>>= 1, i++)
2008
2346
  {
2009
2347
    if (val & 1)
2010
2348
    {
2016
2354
 
2017
2355
  if ((length= tmp.length()))
2018
2356
    length--;
2019
 
  return (unsigned char*) thd->strmake(tmp.ptr(), length);
 
2357
  return (uchar*) thd->strmake(tmp.ptr(), length);
2020
2358
}
2021
2359
 
2022
2360
 
2024
2362
  Functions to handle SET NAMES and SET CHARACTER SET
2025
2363
*****************************************************************************/
2026
2364
 
2027
 
int set_var_collation_client::check(THD *thd __attribute__((unused)))
 
2365
int set_var_collation_client::check(THD *thd __attribute__((__unused__)))
2028
2366
{
2029
2367
  /* Currently, UCS-2 cannot be used as a client character set */
2030
2368
  if (character_set_client->mbminlen > 1)
2056
2394
 
2057
2395
 
2058
2396
void sys_var_timestamp::set_default(THD *thd,
2059
 
                                    enum_var_type type __attribute__((unused)))
 
2397
                                    enum_var_type type __attribute__((__unused__)))
2060
2398
{
2061
2399
  thd->user_time=0;
2062
2400
}
2063
2401
 
2064
2402
 
2065
 
unsigned char *sys_var_timestamp::value_ptr(THD *thd,
2066
 
                                    enum_var_type type __attribute__((unused)),
2067
 
                                    LEX_STRING *base __attribute__((unused)))
 
2403
uchar *sys_var_timestamp::value_ptr(THD *thd,
 
2404
                                    enum_var_type type __attribute__((__unused__)),
 
2405
                                    LEX_STRING *base __attribute__((__unused__)))
2068
2406
{
2069
2407
  thd->sys_var_tmp.long_value= (long) thd->start_time;
2070
 
  return (unsigned char*) &thd->sys_var_tmp.long_value;
 
2408
  return (uchar*) &thd->sys_var_tmp.long_value;
2071
2409
}
2072
2410
 
2073
2411
 
2079
2417
}
2080
2418
 
2081
2419
 
2082
 
unsigned char *sys_var_last_insert_id::value_ptr(THD *thd,
2083
 
                                         enum_var_type type __attribute__((unused)),
2084
 
                                         LEX_STRING *base __attribute__((unused)))
 
2420
uchar *sys_var_last_insert_id::value_ptr(THD *thd,
 
2421
                                         enum_var_type type __attribute__((__unused__)),
 
2422
                                         LEX_STRING *base __attribute__((__unused__)))
2085
2423
{
2086
2424
  /*
2087
2425
    this tmp var makes it robust againt change of type of
2089
2427
  */
2090
2428
  thd->sys_var_tmp.uint64_t_value= 
2091
2429
    thd->read_first_successful_insert_id_in_prev_stmt();
2092
 
  return (unsigned char*) &thd->sys_var_tmp.uint64_t_value;
 
2430
  return (uchar*) &thd->sys_var_tmp.uint64_t_value;
2093
2431
}
2094
2432
 
2095
2433
 
2100
2438
}
2101
2439
 
2102
2440
 
2103
 
unsigned char *sys_var_insert_id::value_ptr(THD *thd,
2104
 
                                    enum_var_type type __attribute__((unused)),
2105
 
                                    LEX_STRING *base __attribute__((unused)))
 
2441
uchar *sys_var_insert_id::value_ptr(THD *thd,
 
2442
                                    enum_var_type type __attribute__((__unused__)),
 
2443
                                    LEX_STRING *base __attribute__((__unused__)))
2106
2444
{
2107
2445
  thd->sys_var_tmp.uint64_t_value=
2108
2446
    thd->auto_inc_intervals_forced.minimum();
2109
 
  return (unsigned char*) &thd->sys_var_tmp.uint64_t_value;
 
2447
  return (uchar*) &thd->sys_var_tmp.uint64_t_value;
2110
2448
}
2111
2449
 
2112
2450
 
2126
2464
bool sys_var_thd_time_zone::check(THD *thd, set_var *var)
2127
2465
{
2128
2466
  char buff[MAX_TIME_ZONE_NAME_LENGTH];
2129
 
  String str(buff, sizeof(buff), &my_charset_utf8_general_ci);
 
2467
  String str(buff, sizeof(buff), &my_charset_latin1);
2130
2468
  String *res= var->value->val_str(&str);
2131
2469
 
2132
2470
  if (!(var->save_result.time_zone= my_tz_find(thd, res)))
2153
2491
}
2154
2492
 
2155
2493
 
2156
 
unsigned char *sys_var_thd_time_zone::value_ptr(THD *thd, enum_var_type type,
2157
 
                                        LEX_STRING *base __attribute__((unused)))
 
2494
uchar *sys_var_thd_time_zone::value_ptr(THD *thd, enum_var_type type,
 
2495
                                        LEX_STRING *base __attribute__((__unused__)))
2158
2496
{
2159
2497
  /* 
2160
2498
    We can use ptr() instead of c_ptr() here because String contaning
2161
2499
    time zone name is guaranteed to be zero ended.
2162
2500
  */
2163
2501
  if (type == OPT_GLOBAL)
2164
 
    return (unsigned char *)(global_system_variables.time_zone->get_name()->ptr());
 
2502
    return (uchar *)(global_system_variables.time_zone->get_name()->ptr());
2165
2503
  else
2166
2504
  {
2167
2505
    /*
2173
2511
      (binlog code stores session value only).
2174
2512
    */
2175
2513
    thd->time_zone_used= 1;
2176
 
    return (unsigned char *)(thd->variables.time_zone->get_name()->ptr());
 
2514
    return (uchar *)(thd->variables.time_zone->get_name()->ptr());
2177
2515
  }
2178
2516
}
2179
2517
 
2185
2523
 {
2186
2524
   if (default_tz_name)
2187
2525
   {
2188
 
     String str(default_tz_name, &my_charset_utf8_general_ci);
 
2526
     String str(default_tz_name, &my_charset_latin1);
2189
2527
     /*
2190
2528
       We are guaranteed to find this time zone since its existence
2191
2529
       is checked during start-up.
2216
2554
  }
2217
2555
}
2218
2556
 
2219
 
bool sys_var_max_user_conn::update(THD *thd __attribute__((unused)),
 
2557
bool sys_var_max_user_conn::update(THD *thd __attribute__((__unused__)),
2220
2558
                                   set_var *var)
2221
2559
{
2222
2560
  assert(var->type == OPT_GLOBAL);
2227
2565
}
2228
2566
 
2229
2567
 
2230
 
void sys_var_max_user_conn::set_default(THD *thd __attribute__((unused)),
2231
 
                                        enum_var_type type __attribute__((unused)))
 
2568
void sys_var_max_user_conn::set_default(THD *thd __attribute__((__unused__)),
 
2569
                                        enum_var_type type __attribute__((__unused__)))
2232
2570
{
2233
2571
  assert(type == OPT_GLOBAL);
2234
2572
  pthread_mutex_lock(&LOCK_global_system_variables);
2237
2575
}
2238
2576
 
2239
2577
 
2240
 
unsigned char *sys_var_max_user_conn::value_ptr(THD *thd, enum_var_type type,
2241
 
                                        LEX_STRING *base __attribute__((unused)))
 
2578
uchar *sys_var_max_user_conn::value_ptr(THD *thd, enum_var_type type,
 
2579
                                        LEX_STRING *base __attribute__((__unused__)))
2242
2580
{
2243
2581
  if (type != OPT_GLOBAL &&
2244
2582
      thd->user_connect && thd->user_connect->user_resources.user_conn)
2245
 
    return (unsigned char*) &(thd->user_connect->user_resources.user_conn);
2246
 
  return (unsigned char*) &(max_user_connections);
 
2583
    return (uchar*) &(thd->user_connect->user_resources.user_conn);
 
2584
  return (uchar*) &(max_user_connections);
2247
2585
}
2248
2586
 
2249
2587
 
2250
 
bool sys_var_thd_lc_time_names::check(THD *thd __attribute__((unused)),
 
2588
bool sys_var_thd_lc_time_names::check(THD *thd __attribute__((__unused__)),
2251
2589
                                      set_var *var)
2252
2590
{
2253
2591
  MY_LOCALE *locale_match;
2265
2603
  else // STRING_RESULT
2266
2604
  {
2267
2605
    char buff[6]; 
2268
 
    String str(buff, sizeof(buff), &my_charset_utf8_general_ci), *res;
 
2606
    String str(buff, sizeof(buff), &my_charset_latin1), *res;
2269
2607
    if (!(res=var->value->val_str(&str)))
2270
2608
    {
2271
2609
      my_error(ER_WRONG_VALUE_FOR_VAR, MYF(0), name, "NULL");
2295
2633
}
2296
2634
 
2297
2635
 
2298
 
unsigned char *sys_var_thd_lc_time_names::value_ptr(THD *thd,
 
2636
uchar *sys_var_thd_lc_time_names::value_ptr(THD *thd,
2299
2637
                                            enum_var_type type,
2300
 
                                            LEX_STRING *base __attribute__((unused)))
 
2638
                                            LEX_STRING *base __attribute__((__unused__)))
2301
2639
{
2302
2640
  return type == OPT_GLOBAL ?
2303
 
                 (unsigned char *) global_system_variables.lc_time_names->name :
2304
 
                 (unsigned char *) thd->variables.lc_time_names->name;
 
2641
                 (uchar *) global_system_variables.lc_time_names->name :
 
2642
                 (uchar *) thd->variables.lc_time_names->name;
2305
2643
}
2306
2644
 
2307
2645
 
2357
2695
}
2358
2696
 
2359
2697
 
2360
 
unsigned char *sys_var_microseconds::value_ptr(THD *thd, enum_var_type type,
2361
 
                                          LEX_STRING *base __attribute__((unused)))
 
2698
uchar *sys_var_microseconds::value_ptr(THD *thd, enum_var_type type,
 
2699
                                          LEX_STRING *base __attribute__((__unused__)))
2362
2700
{
2363
2701
  thd->tmp_double_value= (double) ((type == OPT_GLOBAL) ?
2364
2702
                                   global_system_variables.*offset :
2365
2703
                                   thd->variables.*offset) / 1000000.0;
2366
 
  return (unsigned char*) &thd->tmp_double_value;
 
2704
  return (uchar*) &thd->tmp_double_value;
2367
2705
}
2368
2706
 
2369
2707
 
2413
2751
  return 0;
2414
2752
}
2415
2753
 
2416
 
static int check_log_update(THD *thd __attribute__((unused)),
2417
 
                            set_var *var __attribute__((unused)))
2418
 
{
2419
 
  return 0;
2420
 
}
2421
 
 
2422
 
 
2423
 
static int check_pseudo_thread_id(THD *thd __attribute__((unused)),
 
2754
static int check_log_update(THD *thd __attribute__((__unused__)),
 
2755
                            set_var *var __attribute__((__unused__)))
 
2756
{
 
2757
  return 0;
 
2758
}
 
2759
 
 
2760
static bool set_log_update(THD *thd __attribute__((__unused__)),
 
2761
                           set_var *var __attribute__((__unused__)))
 
2762
{
 
2763
  /*
 
2764
    The update log is not supported anymore since 5.0.
 
2765
    See sql/mysqld.cc/, comments in function init_server_components() for an
 
2766
    explaination of the different warnings we send below
 
2767
  */
 
2768
 
 
2769
  if (opt_sql_bin_update)
 
2770
  {
 
2771
    push_warning(thd, MYSQL_ERROR::WARN_LEVEL_NOTE,
 
2772
                 ER_UPDATE_LOG_DEPRECATED_TRANSLATED,
 
2773
                 ER(ER_UPDATE_LOG_DEPRECATED_TRANSLATED));
 
2774
  }
 
2775
  else
 
2776
    push_warning(thd, MYSQL_ERROR::WARN_LEVEL_NOTE,
 
2777
                 ER_UPDATE_LOG_DEPRECATED_IGNORED,
 
2778
                 ER(ER_UPDATE_LOG_DEPRECATED_IGNORED));
 
2779
  set_option_bit(thd, var);
 
2780
  return 0;
 
2781
}
 
2782
 
 
2783
 
 
2784
static int check_pseudo_thread_id(THD *thd __attribute__((__unused__)),
2424
2785
                                  set_var *var)
2425
2786
{
2426
2787
  var->save_result.uint64_t_value= var->value->val_int();
2427
2788
  return 0;
2428
2789
}
2429
2790
 
2430
 
static unsigned char *get_warning_count(THD *thd)
 
2791
static uchar *get_warning_count(THD *thd)
2431
2792
{
2432
2793
  thd->sys_var_tmp.long_value=
2433
 
    (thd->warn_count[(uint) DRIZZLE_ERROR::WARN_LEVEL_NOTE] +
2434
 
     thd->warn_count[(uint) DRIZZLE_ERROR::WARN_LEVEL_ERROR] +
2435
 
     thd->warn_count[(uint) DRIZZLE_ERROR::WARN_LEVEL_WARN]);
2436
 
  return (unsigned char*) &thd->sys_var_tmp.long_value;
 
2794
    (thd->warn_count[(uint) MYSQL_ERROR::WARN_LEVEL_NOTE] +
 
2795
     thd->warn_count[(uint) MYSQL_ERROR::WARN_LEVEL_ERROR] +
 
2796
     thd->warn_count[(uint) MYSQL_ERROR::WARN_LEVEL_WARN]);
 
2797
  return (uchar*) &thd->sys_var_tmp.long_value;
2437
2798
}
2438
2799
 
2439
 
static unsigned char *get_error_count(THD *thd)
 
2800
static uchar *get_error_count(THD *thd)
2440
2801
{
2441
2802
  thd->sys_var_tmp.long_value= 
2442
 
    thd->warn_count[(uint) DRIZZLE_ERROR::WARN_LEVEL_ERROR];
2443
 
  return (unsigned char*) &thd->sys_var_tmp.long_value;
 
2803
    thd->warn_count[(uint) MYSQL_ERROR::WARN_LEVEL_ERROR];
 
2804
  return (uchar*) &thd->sys_var_tmp.long_value;
2444
2805
}
2445
2806
 
2446
2807
 
2458
2819
  @retval
2459
2820
    ptr         pointer to NUL-terminated string
2460
2821
*/
2461
 
static unsigned char *get_tmpdir(THD *thd __attribute__((unused)))
 
2822
static uchar *get_tmpdir(THD *thd __attribute__((__unused__)))
2462
2823
{
2463
2824
  if (opt_mysql_tmpdir)
2464
 
    return (unsigned char *)opt_mysql_tmpdir;
2465
 
  return (unsigned char*)mysql_tmpdir;
 
2825
    return (uchar *)opt_mysql_tmpdir;
 
2826
  return (uchar*)mysql_tmpdir;
2466
2827
}
2467
2828
 
2468
2829
/****************************************************************************
2487
2848
 
2488
2849
static struct my_option *find_option(struct my_option *opt, const char *name) 
2489
2850
{
2490
 
  uint32_t length=strlen(name);
 
2851
  uint length=strlen(name);
2491
2852
  for (; opt->name; opt++)
2492
2853
  {
2493
2854
    if (!getopt_compare_strings(opt->name, name, length) &&
2508
2869
  Return variable name and length for hashing of variables.
2509
2870
*/
2510
2871
 
2511
 
static unsigned char *get_sys_var_length(const sys_var *var, size_t *length,
2512
 
                                 bool first __attribute__((unused)))
 
2872
static uchar *get_sys_var_length(const sys_var *var, size_t *length,
 
2873
                                 my_bool first __attribute__((__unused__)))
2513
2874
{
2514
2875
  *length= var->name_length;
2515
 
  return (unsigned char*) var->name;
 
2876
  return (uchar*) var->name;
2516
2877
}
2517
2878
 
2518
2879
 
2540
2901
  {
2541
2902
    var->name_length= strlen(var->name);
2542
2903
    /* this fails if there is a conflicting variable name. see HASH_UNIQUE */
2543
 
    if (my_hash_insert(&system_variable_hash, (unsigned char*) var))
 
2904
    if (my_hash_insert(&system_variable_hash, (uchar*) var))
2544
2905
      goto error;
2545
2906
    if (long_options)
2546
2907
      var->option_limits= find_option(long_options, var->name);
2549
2910
 
2550
2911
error:
2551
2912
  for (; first != var; first= first->next)
2552
 
    hash_delete(&system_variable_hash, (unsigned char*) first);
 
2913
    hash_delete(&system_variable_hash, (uchar*) first);
2553
2914
  return 1;
2554
2915
}
2555
2916
 
2573
2934
  /* A write lock should be held on LOCK_system_variables_hash */
2574
2935
   
2575
2936
  for (sys_var *var= first; var; var= var->next)
2576
 
    result|= hash_delete(&system_variable_hash, (unsigned char*) var);
 
2937
    result|= hash_delete(&system_variable_hash, (uchar*) var);
2577
2938
 
2578
2939
  return result;
2579
2940
}
2625
2986
               (qsort_cmp) show_cmp);
2626
2987
    
2627
2988
    /* make last element empty */
2628
 
    memset(show, 0, sizeof(SHOW_VAR));
 
2989
    bzero(show, sizeof(SHOW_VAR));
2629
2990
  }
2630
2991
  return result;
2631
2992
}
2644
3005
 
2645
3006
int set_var_init()
2646
3007
{
2647
 
  uint32_t count= 0;
 
3008
  uint count= 0;
2648
3009
  
2649
3010
  for (sys_var *var=vars.first; var; var= var->next, count++) {};
2650
3011
 
2663
3024
  if (mysql_add_sys_var_chain(vars.first, my_long_options))
2664
3025
    goto error;
2665
3026
 
 
3027
  /*
 
3028
    Special cases
 
3029
    Needed because MySQL can't find the limits for a variable it it has
 
3030
    a different name than the command line option.
 
3031
    As these variables are deprecated, this code will disappear soon...
 
3032
  */
 
3033
  sys_sql_max_join_size.option_limits= sys_max_join_size.option_limits;
 
3034
 
2666
3035
  return(0);
2667
3036
 
2668
3037
error:
2690
3059
    0           SUCCESS
2691
3060
    otherwise   FAILURE
2692
3061
*/
2693
 
int mysql_append_static_vars(const SHOW_VAR *show_vars, uint32_t count)
 
3062
int mysql_append_static_vars(const SHOW_VAR *show_vars, uint count)
2694
3063
{
2695
3064
  for (; count > 0; count--, show_vars++)
2696
 
    if (insert_dynamic(&fixed_show_vars, (unsigned char*) show_vars))
 
3065
    if (insert_dynamic(&fixed_show_vars, (uchar*) show_vars))
2697
3066
      return 1;
2698
3067
  return 0;
2699
3068
}
2713
3082
    0           Unknown variable (error message is given)
2714
3083
*/
2715
3084
 
2716
 
sys_var *intern_find_sys_var(const char *str, uint32_t length, bool no_error)
 
3085
sys_var *intern_find_sys_var(const char *str, uint length, bool no_error)
2717
3086
{
2718
3087
  sys_var *var;
2719
3088
 
2722
3091
    A lock on LOCK_system_variable_hash should be held
2723
3092
  */
2724
3093
  var= (sys_var*) hash_search(&system_variable_hash,
2725
 
                              (unsigned char*) str, length ? length : strlen(str));
 
3094
                              (uchar*) str, length ? length : strlen(str));
2726
3095
  if (!(var || no_error))
2727
3096
    my_error(ER_UNKNOWN_SYSTEM_VARIABLE, MYF(0), (char*) str);
2728
3097
 
2881
3250
}
2882
3251
 
2883
3252
 
2884
 
int set_var_user::update(THD *thd __attribute__((unused)))
 
3253
int set_var_user::update(THD *thd __attribute__((__unused__)))
2885
3254
{
2886
3255
  if (user_var_item->update())
2887
3256
  {
2902
3271
{
2903
3272
  char buff[STRING_BUFFER_USUAL_SIZE];
2904
3273
  const char *value;
2905
 
  String str(buff, sizeof(buff), &my_charset_utf8_general_ci), *res;
 
3274
  String str(buff, sizeof(buff), &my_charset_latin1), *res;
2906
3275
 
2907
3276
  var->save_result.plugin= NULL;
2908
3277
  if (var->value->result_type() == STRING_RESULT)
2913
3282
        !(engine_name.str= (char *)res->ptr()) ||
2914
3283
        !(engine_name.length= res->length()) ||
2915
3284
        !(var->save_result.plugin= ha_resolve_by_name(thd, &engine_name)) ||
2916
 
        !(hton= plugin_data(var->save_result.plugin, handlerton *)))
 
3285
        !(hton= plugin_data(var->save_result.plugin, handlerton *)) ||
 
3286
        ha_checktype(thd, ha_legacy_type(hton), 1, 0) != hton)
2917
3287
    {
2918
3288
      value= res ? res->c_ptr() : "NULL";
2919
3289
      goto err;
2928
3298
}
2929
3299
 
2930
3300
 
2931
 
unsigned char *sys_var_thd_storage_engine::value_ptr(THD *thd, enum_var_type type,
2932
 
                                             LEX_STRING *base __attribute__((unused)))
 
3301
uchar *sys_var_thd_storage_engine::value_ptr(THD *thd, enum_var_type type,
 
3302
                                             LEX_STRING *base __attribute__((__unused__)))
2933
3303
{
2934
 
  unsigned char* result;
 
3304
  uchar* result;
2935
3305
  handlerton *hton;
2936
3306
  LEX_STRING *engine_name;
2937
3307
  plugin_ref plugin= thd->variables.*offset;
2939
3309
    plugin= my_plugin_lock(thd, &(global_system_variables.*offset));
2940
3310
  hton= plugin_data(plugin, handlerton*);
2941
3311
  engine_name= &hton2plugin[hton->slot]->name;
2942
 
  result= (unsigned char *) thd->strmake(engine_name->str, engine_name->length);
 
3312
  result= (uchar *) thd->strmake(engine_name->str, engine_name->length);
2943
3313
  if (type == OPT_GLOBAL)
2944
3314
    plugin_unlock(thd, plugin);
2945
3315
  return result;
2985
3355
symbolic_mode_representation(THD *thd, uint64_t val, LEX_STRING *rep)
2986
3356
{
2987
3357
  char buff[STRING_BUFFER_USUAL_SIZE*8];
2988
 
  String tmp(buff, sizeof(buff), &my_charset_utf8_general_ci);
 
3358
  String tmp(buff, sizeof(buff), &my_charset_latin1);
2989
3359
 
2990
3360
  tmp.length(0);
2991
3361
 
2992
 
  for (uint32_t i= 0; val; val>>= 1, i++)
 
3362
  for (uint i= 0; val; val>>= 1, i++)
2993
3363
  {
2994
3364
    if (val & 1)
2995
3365
    {
3010
3380
}
3011
3381
 
3012
3382
 
3013
 
unsigned char *sys_var_thd_optimizer_switch::value_ptr(THD *thd, enum_var_type type,
3014
 
                                               LEX_STRING *base __attribute__((unused)))
 
3383
uchar *sys_var_thd_optimizer_switch::value_ptr(THD *thd, enum_var_type type,
 
3384
                                               LEX_STRING *base __attribute__((__unused__)))
3015
3385
{
3016
3386
  LEX_STRING opts;
3017
3387
  uint64_t val= ((type == OPT_GLOBAL) ? global_system_variables.*offset :
3018
3388
                  thd->variables.*offset);
3019
3389
  (void) symbolic_mode_representation(thd, val, &opts);
3020
 
  return (unsigned char *) opts.str;
 
3390
  return (uchar *) opts.str;
3021
3391
}
3022
3392
 
3023
3393
 
3034
3404
  Named list handling
3035
3405
****************************************************************************/
3036
3406
 
3037
 
unsigned char* find_named(I_List<NAMED_LIST> *list, const char *name, uint32_t length,
 
3407
uchar* find_named(I_List<NAMED_LIST> *list, const char *name, uint length,
3038
3408
                NAMED_LIST **found)
3039
3409
{
3040
3410
  I_List_iterator<NAMED_LIST> it(*list);
3053
3423
 
3054
3424
 
3055
3425
void delete_elements(I_List<NAMED_LIST> *list,
3056
 
                     void (*free_element)(const char *name, unsigned char*))
 
3426
                     void (*free_element)(const char *name, uchar*))
3057
3427
{
3058
3428
  NAMED_LIST *element;
3059
3429
  while ((element= list->get()))
3067
3437
 
3068
3438
/* Key cache functions */
3069
3439
 
3070
 
static KEY_CACHE *create_key_cache(const char *name, uint32_t length)
 
3440
static KEY_CACHE *create_key_cache(const char *name, uint length)
3071
3441
{
3072
3442
  KEY_CACHE *key_cache;
3073
3443
  
3074
3444
  if ((key_cache= (KEY_CACHE*) my_malloc(sizeof(KEY_CACHE),
3075
3445
                                             MYF(MY_ZEROFILL | MY_WME))))
3076
3446
  {
3077
 
    if (!new NAMED_LIST(&key_caches, name, length, (unsigned char*) key_cache))
 
3447
    if (!new NAMED_LIST(&key_caches, name, length, (uchar*) key_cache))
3078
3448
    {
3079
 
      free((char*) key_cache);
 
3449
      my_free((char*) key_cache, MYF(0));
3080
3450
      key_cache= 0;
3081
3451
    }
3082
3452
    else
3096
3466
}
3097
3467
 
3098
3468
 
3099
 
KEY_CACHE *get_or_create_key_cache(const char *name, uint32_t length)
 
3469
KEY_CACHE *get_or_create_key_cache(const char *name, uint length)
3100
3470
{
3101
3471
  LEX_STRING key_cache_name;
3102
3472
  KEY_CACHE *key_cache;
3111
3481
}
3112
3482
 
3113
3483
 
3114
 
void free_key_cache(const char *name __attribute__((unused)),
 
3484
void free_key_cache(const char *name __attribute__((__unused__)),
3115
3485
                    KEY_CACHE *key_cache)
3116
3486
{
3117
3487
  ha_end_key_cache(key_cache);
3118
 
  free((char*) key_cache);
 
3488
  my_free((char*) key_cache, MYF(0));
3119
3489
}
3120
3490
 
3121
3491