~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to server/set_var.cc

  • Committer: Brian Aker
  • Date: 2008-07-13 21:20:24 UTC
  • Revision ID: brian@tangent.org-20080713212024-o6263c1vha7yxdeu
More bool removal. More cow bell!

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