~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to sql/set_var.cc

  • Committer: Monty Taylor
  • Date: 2008-07-05 18:10:38 UTC
  • mto: This revision was merged to the branch mainline in revision 63.
  • Revision ID: monty@inaugust.com-20080705181038-0ih0nnamu5qrut0y
Fixed prototypes. Cleaned define a little bit.

Show diffs side-by-side

added added

removed removed

Lines of Context:
42
42
 
43
43
  @note
44
44
    Be careful with var->save_result: sys_var::check() only updates
45
 
    uint64_t_value; so other members of the union are garbage then; to use
 
45
    ulonglong_value; so other members of the union are garbage then; to use
46
46
    them you must first assign a value to them (in specific ::check() for
47
47
    example).
48
48
*/
49
 
#include <drizzled/server_includes.h>
 
49
 
 
50
#ifdef USE_PRAGMA_IMPLEMENTATION
 
51
#pragma implementation                          // gcc: Class implementation
 
52
#endif
 
53
 
 
54
#include "mysql_priv.h"
 
55
#include <mysql.h>
 
56
#include "slave.h"
50
57
#include "rpl_mi.h"
51
 
#include <mysys/my_getopt.h>
52
 
#include <mysys/thr_alarm.h>
53
 
#include <storage/myisam/myisam.h>
54
 
#include <drizzled/drizzled_error_messages.h>
55
 
#include <libdrizzle/gettext.h>
 
58
#include <my_getopt.h>
 
59
#include <thr_alarm.h>
 
60
#include <myisam.h>
 
61
#include <my_dir.h>
56
62
 
57
 
extern const CHARSET_INFO *character_set_filesystem;
 
63
extern CHARSET_INFO *character_set_filesystem;
58
64
 
59
65
 
60
66
static DYNAMIC_ARRAY fixed_show_vars;
61
67
static HASH system_variable_hash;
62
68
 
63
 
const char *bool_type_names[]= { "OFF", "ON", NULL };
 
69
const char *bool_type_names[]= { "OFF", "ON", NullS };
64
70
TYPELIB bool_typelib=
65
71
{
66
72
  array_elements(bool_type_names)-1, "", bool_type_names, NULL
67
73
};
68
74
 
69
 
const char *delay_key_write_type_names[]= { "OFF", "ON", "ALL", NULL };
 
75
const char *delay_key_write_type_names[]= { "OFF", "ON", "ALL", NullS };
70
76
TYPELIB delay_key_write_typelib=
71
77
{
72
78
  array_elements(delay_key_write_type_names)-1, "",
74
80
};
75
81
 
76
82
const char *slave_exec_mode_names[]=
77
 
{ "STRICT", "IDEMPOTENT", NULL };
 
83
{ "STRICT", "IDEMPOTENT", NullS };
78
84
static const unsigned int slave_exec_mode_names_len[]=
79
85
{ sizeof("STRICT") - 1, sizeof("IDEMPOTENT") - 1, 0 };
80
86
TYPELIB slave_exec_mode_typelib=
90
96
static bool set_option_bit(THD *thd, set_var *var);
91
97
static bool set_option_autocommit(THD *thd, set_var *var);
92
98
static int  check_log_update(THD *thd, set_var *var);
 
99
static bool set_log_update(THD *thd, set_var *var);
93
100
static int  check_pseudo_thread_id(THD *thd, set_var *var);
 
101
void fix_binlog_format_after_update(THD *thd, enum_var_type type);
94
102
static void fix_low_priority_updates(THD *thd, enum_var_type type);
95
103
static int check_tx_isolation(THD *thd, set_var *var);
96
104
static void fix_tx_isolation(THD *thd, enum_var_type type);
107
115
static void fix_thd_mem_root(THD *thd, enum_var_type type);
108
116
static void fix_trans_mem_root(THD *thd, enum_var_type type);
109
117
static void fix_server_id(THD *thd, enum_var_type type);
110
 
static uint64_t fix_unsigned(THD *, uint64_t, const struct my_option *);
 
118
static ulonglong fix_unsigned(THD *, ulonglong, const struct my_option *);
111
119
static bool get_unsigned(THD *thd, set_var *var);
112
120
bool throw_bounds_warning(THD *thd, bool fixed, bool unsignd,
113
 
                          const char *name, int64_t val);
114
 
static KEY_CACHE *create_key_cache(const char *name, uint32_t length);
115
 
static unsigned char *get_error_count(THD *thd);
116
 
static unsigned char *get_warning_count(THD *thd);
117
 
static unsigned char *get_tmpdir(THD *thd);
 
121
                          const char *name, longlong val);
 
122
static KEY_CACHE *create_key_cache(const char *name, uint length);
 
123
static uchar *get_error_count(THD *thd);
 
124
static uchar *get_warning_count(THD *thd);
 
125
static uchar *get_tmpdir(THD *thd);
 
126
static int  sys_check_log_path(THD *thd,  set_var *var);
 
127
static bool sys_update_general_log_path(THD *thd, set_var * var);
 
128
static void sys_default_general_log_path(THD *thd, enum_var_type type);
 
129
static bool sys_update_slow_log_path(THD *thd, set_var * var);
 
130
static void sys_default_slow_log_path(THD *thd, enum_var_type type);
118
131
 
119
132
/*
120
133
  Variable definition list
144
157
                                            &SV::binlog_format);
145
158
static sys_var_thd_ulong        sys_bulk_insert_buff_size(&vars, "bulk_insert_buffer_size",
146
159
                                                  &SV::bulk_insert_buff_size);
 
160
static sys_var_character_set_sv
 
161
sys_character_set_server(&vars, "character_set_server",
 
162
                         &SV::collation_server, &default_charset_info, 0,
 
163
                         sys_var::SESSION_VARIABLE_IN_BINLOG);
 
164
sys_var_const_str       sys_charset_system(&vars, "character_set_system",
 
165
                                           (char *)my_charset_utf8_general_ci.name);
 
166
static sys_var_character_set_database
 
167
sys_character_set_database(&vars, "character_set_database",
 
168
                           sys_var::SESSION_VARIABLE_IN_BINLOG);
 
169
static sys_var_character_set_client
 
170
sys_character_set_client(&vars, "character_set_client",
 
171
                         &SV::character_set_client,
 
172
                         &default_charset_info,
 
173
                         sys_var::SESSION_VARIABLE_IN_BINLOG);
 
174
static sys_var_character_set_sv
 
175
sys_character_set_connection(&vars, "character_set_connection",
 
176
                             &SV::collation_connection,
 
177
                             &default_charset_info, 0,
 
178
                             sys_var::SESSION_VARIABLE_IN_BINLOG);
 
179
static sys_var_character_set_sv sys_character_set_results(&vars, "character_set_results",
 
180
                                        &SV::character_set_results,
 
181
                                        &default_charset_info, true);
 
182
static sys_var_character_set_sv sys_character_set_filesystem(&vars, "character_set_filesystem",
 
183
                                        &SV::character_set_filesystem,
 
184
                                        &character_set_filesystem);
147
185
static sys_var_thd_ulong        sys_completion_type(&vars, "completion_type",
148
186
                                         &SV::completion_type,
149
187
                                         check_completion_type,
160
198
sys_collation_server(&vars, "collation_server", &SV::collation_server,
161
199
                     &default_charset_info,
162
200
                     sys_var::SESSION_VARIABLE_IN_BINLOG);
 
201
static sys_var_long_ptr sys_concurrent_insert(&vars, "concurrent_insert",
 
202
                                              &myisam_concurrent_insert);
163
203
static sys_var_long_ptr sys_connect_timeout(&vars, "connect_timeout",
164
204
                                            &connect_timeout);
165
205
static sys_var_const_str       sys_datadir(&vars, "datadir", mysql_real_data_home);
 
206
#ifndef DBUG_OFF
 
207
static sys_var_thd_dbug        sys_dbug(&vars, "debug");
 
208
#endif
166
209
static sys_var_enum             sys_delay_key_write(&vars, "delay_key_write",
167
210
                                            &delay_key_write_options,
168
211
                                            &delay_key_write_typelib,
171
214
static sys_var_long_ptr sys_expire_logs_days(&vars, "expire_logs_days",
172
215
                                             &expire_logs_days);
173
216
static sys_var_bool_ptr sys_flush(&vars, "flush", &myisam_flush);
 
217
static sys_var_long_ptr sys_flush_time(&vars, "flush_time", &flush_time);
174
218
sys_var_str             sys_init_connect(&vars, "init_connect", 0,
175
219
                                         sys_update_init_connect,
176
220
                                         sys_default_init_connect,0);
193
237
                                                              param_age_threshold));
194
238
static sys_var_bool_ptr sys_local_infile(&vars, "local_infile",
195
239
                                         &opt_local_infile);
 
240
static sys_var_bool_ptr
 
241
  sys_log_queries_not_using_indexes(&vars, "log_queries_not_using_indexes",
 
242
                                    &opt_log_queries_not_using_indexes);
 
243
static sys_var_thd_ulong        sys_log_warnings(&vars, "log_warnings", &SV::log_warnings);
 
244
static sys_var_microseconds     sys_var_long_query_time(&vars, "long_query_time",
 
245
                                                        &SV::long_query_time);
196
246
static sys_var_thd_bool sys_low_priority_updates(&vars, "low_priority_updates",
197
247
                                                 &SV::low_priority_updates,
198
248
                                                 fix_low_priority_updates);
215
265
                                               &max_connect_errors);
216
266
static sys_var_thd_ulong        sys_max_error_count(&vars, "max_error_count",
217
267
                                            &SV::max_error_count);
218
 
static sys_var_thd_uint64_t     sys_max_heap_table_size(&vars, "max_heap_table_size",
 
268
static sys_var_thd_ulonglong    sys_max_heap_table_size(&vars, "max_heap_table_size",
219
269
                                                &SV::max_heap_table_size);
220
270
static sys_var_thd_ulong sys_pseudo_thread_id(&vars, "pseudo_thread_id",
221
271
                                              &SV::pseudo_thread_id,
228
278
                                              &SV::max_seeks_for_key);
229
279
static sys_var_thd_ulong   sys_max_length_for_sort_data(&vars, "max_length_for_sort_data",
230
280
                                                 &SV::max_length_for_sort_data);
 
281
#ifndef TO_BE_DELETED   /* Alias for max_join_size */
 
282
static sys_var_thd_ha_rows      sys_sql_max_join_size(&vars, "sql_max_join_size",
 
283
                                              &SV::max_join_size,
 
284
                                              fix_max_join_size);
 
285
#endif
231
286
static sys_var_long_ptr sys_max_relay_log_size(&vars, "max_relay_log_size",
232
287
                                               &max_relay_log_size,
233
288
                                               fix_max_relay_log_size);
240
295
                                                 &max_write_lock_count);
241
296
static sys_var_thd_ulong       sys_min_examined_row_limit(&vars, "min_examined_row_limit",
242
297
                                                          &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);
 
298
static sys_var_long_ptr sys_myisam_data_pointer_size(&vars, "myisam_data_pointer_size",
 
299
                                                    &myisam_data_pointer_size);
 
300
static sys_var_thd_ulonglong    sys_myisam_max_sort_file_size(&vars, "myisam_max_sort_file_size", &SV::myisam_max_sort_file_size, fix_myisam_max_sort_file_size, 1);
244
301
static sys_var_thd_ulong       sys_myisam_repair_threads(&vars, "myisam_repair_threads", &SV::myisam_repair_threads);
245
302
static sys_var_thd_ulong        sys_myisam_sort_buffer_size(&vars, "myisam_sort_buffer_size", &SV::myisam_sort_buff_size);
246
303
 
265
322
/* these two cannot be static */
266
323
sys_var_thd_bool                sys_old_alter_table(&vars, "old_alter_table",
267
324
                                            &SV::old_alter_table);
 
325
sys_var_thd_bool                sys_old_passwords(&vars, "old_passwords", &SV::old_passwords);
268
326
static sys_var_thd_ulong        sys_optimizer_prune_level(&vars, "optimizer_prune_level",
269
327
                                                  &SV::optimizer_prune_level);
270
328
static sys_var_thd_ulong        sys_optimizer_search_depth(&vars, "optimizer_search_depth",
271
329
                                                   &SV::optimizer_search_depth);
272
330
 
273
 
const char *optimizer_use_mrr_names[] = {"auto", "force", "disable", NULL};
 
331
const char *optimizer_use_mrr_names[] = {"auto", "force", "disable", NullS};
274
332
TYPELIB optimizer_use_mrr_typelib= {
275
333
  array_elements(optimizer_use_mrr_names) - 1, "",
276
334
  optimizer_use_mrr_names, NULL
290
348
                                               &SV::read_rnd_buff_size);
291
349
static sys_var_thd_ulong        sys_div_precincrement(&vars, "div_precision_increment",
292
350
                                              &SV::div_precincrement);
 
351
static sys_var_long_ptr sys_rpl_recovery_rank(&vars, "rpl_recovery_rank",
 
352
                                              &rpl_recovery_rank);
293
353
 
294
354
static sys_var_thd_ulong        sys_range_alloc_block_size(&vars, "range_alloc_block_size",
295
355
                                                   &SV::range_alloc_block_size);
307
367
                                                &SV::trans_prealloc_size,
308
368
                                                0, fix_trans_mem_root);
309
369
 
 
370
static sys_var_bool_ptr sys_secure_auth(&vars, "secure_auth", &opt_secure_auth);
310
371
static sys_var_const_str_ptr sys_secure_file_priv(&vars, "secure_file_priv",
311
372
                                             &opt_secure_file_priv);
312
373
static sys_var_long_ptr sys_server_id(&vars, "server_id", &server_id, fix_server_id);
313
374
static sys_var_bool_ptr sys_slave_compressed_protocol(&vars, "slave_compressed_protocol",
314
375
                                                      &opt_slave_compressed_protocol);
 
376
#ifdef HAVE_REPLICATION
315
377
static sys_var_bool_ptr         sys_slave_allow_batching(&vars, "slave_allow_batching",
316
378
                                                         &slave_allow_batching);
317
379
static sys_var_set_slave_mode slave_exec_mode(&vars,
319
381
                                              &slave_exec_mode_options,
320
382
                                              &slave_exec_mode_typelib,
321
383
                                              0);
 
384
#endif
322
385
static sys_var_long_ptr sys_slow_launch_time(&vars, "slow_launch_time",
323
386
                                             &slow_launch_time);
324
387
static sys_var_thd_ulong        sys_sort_buffer(&vars, "sort_buffer_size",
331
394
*/
332
395
static sys_var_thd_optimizer_switch   sys_optimizer_switch(&vars, "optimizer_switch",
333
396
                                     &SV::optimizer_switch);
 
397
static sys_var_const_str        sys_ssl_ca(&vars, "ssl_ca", NULL);
 
398
static sys_var_const_str        sys_ssl_capath(&vars, "ssl_capath", NULL);
 
399
static sys_var_const_str        sys_ssl_cert(&vars, "ssl_cert", NULL);
 
400
static sys_var_const_str        sys_ssl_cipher(&vars, "ssl_cipher", NULL);
 
401
static sys_var_const_str        sys_ssl_key(&vars, "ssl_key", NULL);
334
402
 
335
403
static sys_var_thd_storage_engine sys_storage_engine(&vars, "storage_engine",
336
404
                                       &SV::table_plugin);
 
405
static sys_var_bool_ptr sys_sync_frm(&vars, "sync_frm", &opt_sync_frm);
337
406
static sys_var_const_str        sys_system_time_zone(&vars, "system_time_zone",
338
407
                                             system_time_zone);
339
408
static sys_var_long_ptr sys_table_def_size(&vars, "table_definition_cache",
351
420
                                         &tx_isolation_typelib,
352
421
                                         fix_tx_isolation,
353
422
                                         check_tx_isolation);
354
 
static sys_var_thd_uint64_t     sys_tmp_table_size(&vars, "tmp_table_size",
 
423
static sys_var_thd_ulonglong    sys_tmp_table_size(&vars, "tmp_table_size",
355
424
                                           &SV::tmp_table_size);
356
 
static sys_var_bool_ptr  sys_timed_mutexes(&vars, "timed_mutexes", &timed_mutexes);
 
425
static sys_var_bool_ptr  sys_timed_mutexes(&vars, "timed_mutexes",
 
426
                                    &timed_mutexes);
357
427
static sys_var_const_str        sys_version(&vars, "version", server_version);
358
428
static sys_var_const_str        sys_version_comment(&vars, "version_comment",
359
 
                                            DRIZZLE_COMPILATION_COMMENT);
 
429
                                            MYSQL_COMPILATION_COMMENT);
360
430
static sys_var_const_str        sys_version_compile_machine(&vars, "version_compile_machine",
361
431
                                                    MACHINE_TYPE);
362
432
static sys_var_const_str        sys_version_compile_os(&vars, "version_compile_os",
373
443
 
374
444
static sys_var_thd_date_time_format sys_time_format(&vars, "time_format",
375
445
                                             &SV::time_format,
376
 
                                             DRIZZLE_TIMESTAMP_TIME);
 
446
                                             MYSQL_TIMESTAMP_TIME);
377
447
static sys_var_thd_date_time_format sys_date_format(&vars, "date_format",
378
448
                                             &SV::date_format,
379
 
                                             DRIZZLE_TIMESTAMP_DATE);
 
449
                                             MYSQL_TIMESTAMP_DATE);
380
450
static sys_var_thd_date_time_format sys_datetime_format(&vars, "datetime_format",
381
451
                                                 &SV::datetime_format,
382
 
                                                 DRIZZLE_TIMESTAMP_DATETIME);
 
452
                                                 MYSQL_TIMESTAMP_DATETIME);
383
453
 
384
454
/* Variables that are bits in THD */
385
455
 
398
468
static sys_var_thd_bit  sys_big_selects(&vars, "sql_big_selects", 0,
399
469
                                        set_option_bit,
400
470
                                        OPTION_BIG_SELECTS);
 
471
static sys_var_thd_bit  sys_log_off(&vars, "sql_log_off",
 
472
                                    check_log_update,
 
473
                                    set_option_bit,
 
474
                                    OPTION_LOG_OFF);
 
475
static sys_var_thd_bit  sys_log_update(&vars, "sql_log_update",
 
476
                                       check_log_update,
 
477
                                       set_log_update,
 
478
                                       OPTION_BIN_LOG);
401
479
static sys_var_thd_bit  sys_log_binlog(&vars, "sql_log_bin",
402
480
                                       check_log_update,
403
481
                                       set_option_bit,
408
486
static sys_var_thd_bit  sys_sql_notes(&vars, "sql_notes", 0,
409
487
                                         set_option_bit,
410
488
                                         OPTION_SQL_NOTES);
 
489
static sys_var_thd_bit  sys_auto_is_null(&vars, "sql_auto_is_null", 0,
 
490
                                         set_option_bit,
 
491
                                         OPTION_AUTO_IS_NULL, 0,
 
492
                                         sys_var::SESSION_VARIABLE_IN_BINLOG);
411
493
static sys_var_thd_bit  sys_safe_updates(&vars, "sql_safe_updates", 0,
412
494
                                         set_option_bit,
413
495
                                         OPTION_SAFE_UPDATES);
495
577
static sys_var_const_str_ptr    sys_repl_report_user(&vars, "report_user", &report_user);
496
578
static sys_var_const_str_ptr    sys_repl_report_password(&vars, "report_password", &report_password);
497
579
 
498
 
static unsigned char *slave_get_report_port(THD *thd)
 
580
static uchar *slave_get_report_port(THD *thd)
499
581
{
500
582
  thd->sys_var_tmp.long_value= report_port;
501
 
  return (unsigned char*) &thd->sys_var_tmp.long_value;
 
583
  return (uchar*) &thd->sys_var_tmp.long_value;
502
584
}
503
585
 
504
586
static sys_var_readonly    sys_repl_report_port(&vars, "report_port", OPT_GLOBAL, SHOW_INT, slave_get_report_port);
508
590
/* Read only variables */
509
591
 
510
592
static sys_var_have_variable sys_have_compress(&vars, "have_compress", &have_compress);
 
593
static sys_var_have_variable sys_have_crypt(&vars, "have_crypt", &have_crypt);
 
594
static sys_var_have_plugin sys_have_csv(&vars, "have_csv", C_STRING_WITH_LEN("csv"), MYSQL_STORAGE_ENGINE_PLUGIN);
 
595
static sys_var_have_variable sys_have_dlopen(&vars, "have_dynamic_loading", &have_dlopen);
 
596
static sys_var_have_plugin sys_have_innodb(&vars, "have_innodb", C_STRING_WITH_LEN("innodb"), MYSQL_STORAGE_ENGINE_PLUGIN);
511
597
static sys_var_have_variable sys_have_symlink(&vars, "have_symlink", &have_symlink);
 
598
/* Global read-only variable describing server license */
 
599
static sys_var_const_str        sys_license(&vars, "license", STRINGIFY_ARG(LICENSE));
 
600
/* Global variables which enable|disable logging */
 
601
static sys_var_log_state sys_var_general_log(&vars, "general_log", &opt_log,
 
602
                                      QUERY_LOG_GENERAL);
 
603
/* Synonym of "general_log" for consistency with SHOW VARIABLES output */
 
604
static sys_var_log_state sys_var_log(&vars, "log", &opt_log,
 
605
                                      QUERY_LOG_GENERAL);
 
606
static sys_var_log_state sys_var_slow_query_log(&vars, "slow_query_log", &opt_slow_log,
 
607
                                         QUERY_LOG_SLOW);
 
608
/* Synonym of "slow_query_log" for consistency with SHOW VARIABLES output */
 
609
static sys_var_log_state sys_var_log_slow(&vars, "log_slow_queries",
 
610
                                          &opt_slow_log, QUERY_LOG_SLOW);
 
611
sys_var_str sys_var_general_log_path(&vars, "general_log_file", sys_check_log_path,
 
612
                                     sys_update_general_log_path,
 
613
                                     sys_default_general_log_path,
 
614
                                     opt_logname);
 
615
sys_var_str sys_var_slow_log_path(&vars, "slow_query_log_file", sys_check_log_path,
 
616
                                  sys_update_slow_log_path, 
 
617
                                  sys_default_slow_log_path,
 
618
                                  opt_slow_logname);
 
619
static sys_var_log_output sys_var_log_output_state(&vars, "log_output", &log_output_options,
 
620
                                            &log_output_typelib, 0);
 
621
 
 
622
 
512
623
/*
513
624
  Additional variables (not derived from sys_var class, not accessible as
514
625
  @@varname in SELECT or SET). Sorted in alphabetical order to facilitate
519
630
#define FIXED_VARS_SIZE (sizeof(fixed_vars) / sizeof(SHOW_VAR))
520
631
static SHOW_VAR fixed_vars[]= {
521
632
  {"back_log",                (char*) &back_log,                    SHOW_LONG},
 
633
  {"character_sets_dir",      mysql_charsets_dir,                   SHOW_CHAR},
522
634
  {"init_file",               (char*) &opt_init_file,               SHOW_CHAR_PTR},
523
635
  {"language",                language,                             SHOW_CHAR},
524
636
#ifdef HAVE_MLOCKALL
526
638
#endif
527
639
  {"log_bin",                 (char*) &opt_bin_log,                 SHOW_BOOL},
528
640
  {"log_error",               (char*) log_error_file,               SHOW_CHAR},
 
641
  {"lower_case_file_system",  (char*) &lower_case_file_system,      SHOW_MY_BOOL},
 
642
  {"lower_case_table_names",  (char*) &lower_case_table_names,      SHOW_INT},
529
643
  {"myisam_recover_options",  (char*) &myisam_recover_options_str,  SHOW_CHAR_PTR},
530
644
  {"open_files_limit",        (char*) &open_files_limit,            SHOW_LONG},
531
645
  {"pid_file",                (char*) pidfile_name,                 SHOW_CHAR},
532
646
  {"plugin_dir",              (char*) opt_plugin_dir,               SHOW_CHAR},
533
647
  {"port",                    (char*) &mysqld_port,                 SHOW_INT},
534
648
  {"protocol_version",        (char*) &protocol_version,            SHOW_INT},
 
649
  {"skip_external_locking",   (char*) &my_disable_locking,          SHOW_MY_BOOL},
 
650
  {"skip_networking",         (char*) &opt_disable_networking,      SHOW_BOOL},
 
651
  {"skip_show_database",      (char*) &opt_skip_show_db,            SHOW_BOOL},
535
652
  {"thread_stack",            (char*) &my_thread_stack_size,        SHOW_LONG},
536
653
};
537
654
 
538
655
 
539
 
bool sys_var::check(THD *thd __attribute__((unused)), set_var *var)
 
656
bool sys_var::check(THD *thd, set_var *var)
540
657
{
541
 
  var->save_result.uint64_t_value= var->value->val_int();
 
658
  var->save_result.ulonglong_value= var->value->val_int();
542
659
  return 0;
543
660
}
544
661
 
571
688
                        set_var *var)
572
689
{
573
690
  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);
 
691
  uint new_length= (var ? var->value->str_value.length() : 0);
575
692
  if (!old_value)
576
693
    old_value= (char*) "";
577
694
  if (!(res= my_strndup(old_value, new_length, MYF(0))))
585
702
  var_str->value= res;
586
703
  var_str->value_length= new_length;
587
704
  rw_unlock(var_mutex);
588
 
  free(old_value);
 
705
  my_free(old_value, MYF(MY_ALLOW_ZERO_PTR));
589
706
  return 0;
590
707
}
591
708
 
592
709
 
593
 
static bool sys_update_init_connect(THD *thd __attribute__((unused)), set_var *var)
 
710
static bool sys_update_init_connect(THD *thd, set_var *var)
594
711
{
595
712
  return update_sys_var_str(&sys_init_connect, &LOCK_sys_init_connect, var);
596
713
}
597
714
 
598
715
 
599
 
static void sys_default_init_connect(THD* thd __attribute__((unused)),
600
 
                                     enum_var_type type __attribute__((unused)))
 
716
static void sys_default_init_connect(THD* thd, enum_var_type type)
601
717
{
602
718
  update_sys_var_str(&sys_init_connect, &LOCK_sys_init_connect, 0);
603
719
}
604
720
 
605
721
 
606
 
static bool sys_update_init_slave(THD *thd __attribute__((unused)),
607
 
                                  set_var *var)
 
722
static bool sys_update_init_slave(THD *thd, set_var *var)
608
723
{
609
724
  return update_sys_var_str(&sys_init_slave, &LOCK_sys_init_slave, var);
610
725
}
611
726
 
612
727
 
613
 
static void sys_default_init_slave(THD* thd __attribute__((unused)),
614
 
                                   enum_var_type type __attribute__((unused)))
 
728
static void sys_default_init_slave(THD* thd, enum_var_type type)
615
729
{
616
730
  update_sys_var_str(&sys_init_slave, &LOCK_sys_init_slave, 0);
617
731
}
635
749
 
636
750
 
637
751
static void
638
 
fix_myisam_max_sort_file_size(THD *thd __attribute__((unused)),
639
 
                              enum_var_type type __attribute__((unused)))
 
752
fix_myisam_max_sort_file_size(THD *thd, enum_var_type type)
640
753
{
641
754
  myisam_max_temp_length=
642
755
    (my_off_t) global_system_variables.myisam_max_sort_file_size;
686
799
static void fix_completion_type(THD *thd __attribute__((unused)),
687
800
                                enum_var_type type __attribute__((unused))) {}
688
801
 
689
 
static int check_completion_type(THD *thd __attribute__((unused)),
690
 
                                 set_var *var)
 
802
static int check_completion_type(THD *thd, set_var *var)
691
803
{
692
 
  int64_t val= var->value->val_int();
 
804
  longlong val= var->value->val_int();
693
805
  if (val < 0 || val > 2)
694
806
  {
695
807
    char buf[64];
704
816
  If we are changing the thread variable, we have to copy it to NET too
705
817
*/
706
818
 
 
819
#ifdef HAVE_REPLICATION
707
820
static void fix_net_read_timeout(THD *thd, enum_var_type type)
708
821
{
709
822
  if (type != OPT_GLOBAL)
722
835
  if (type != OPT_GLOBAL)
723
836
    thd->net.retry_count=thd->variables.net_retry_count;
724
837
}
725
 
 
726
 
 
727
 
extern void fix_delay_key_write(THD *thd __attribute__((unused)),
728
 
                                enum_var_type type __attribute__((unused)))
 
838
#else /* HAVE_REPLICATION */
 
839
static void fix_net_read_timeout(THD *thd __attribute__((unused)),
 
840
                                 enum_var_type type __attribute__((unused)))
 
841
{}
 
842
static void fix_net_write_timeout(THD *thd __attribute__((unused)),
 
843
                                  enum_var_type type __attribute__((unused)))
 
844
{}
 
845
static void fix_net_retry_count(THD *thd __attribute__((unused)),
 
846
                                enum_var_type type __attribute__((unused)))
 
847
{}
 
848
#endif /* HAVE_REPLICATION */
 
849
 
 
850
 
 
851
extern void fix_delay_key_write(THD *thd, enum_var_type type)
729
852
{
730
853
  switch ((enum_delay_key_write) delay_key_write_options) {
731
854
  case DELAY_KEY_WRITE_NONE:
741
864
  }
742
865
}
743
866
 
744
 
bool sys_var_set::update(THD *thd __attribute__((unused)),
745
 
                         set_var *var)
 
867
bool sys_var_set::update(THD *thd, set_var *var)
746
868
{
747
869
  *value= var->save_result.ulong_value;
748
870
  return 0;
749
871
}
750
872
 
751
 
unsigned char *sys_var_set::value_ptr(THD *thd,
752
 
                              enum_var_type type __attribute__((unused)),
753
 
                              LEX_STRING *base __attribute__((unused)))
 
873
uchar *sys_var_set::value_ptr(THD *thd, enum_var_type type,
 
874
                              LEX_STRING *base)
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, enum_var_type type)
778
898
{
779
899
  slave_exec_mode_options= 0;
780
900
  bit_do_set(slave_exec_mode_options, SLAVE_EXEC_MODE_STRICT);
802
922
  return rc;
803
923
}
804
924
 
805
 
void fix_slave_exec_mode(enum_var_type type __attribute__((unused)))
 
925
void fix_slave_exec_mode(enum_var_type type)
806
926
{
 
927
  DBUG_ENTER("fix_slave_exec_mode");
 
928
  compile_time_assert(sizeof(slave_exec_mode_options) * CHAR_BIT
 
929
                      > SLAVE_EXEC_MODE_LAST_BIT - 1);
807
930
  if (bit_is_set(slave_exec_mode_options, SLAVE_EXEC_MODE_STRICT) == 1 &&
808
931
      bit_is_set(slave_exec_mode_options, SLAVE_EXEC_MODE_IDEMPOTENT) == 1)
809
932
  {
810
 
    sql_print_error(_("Ambiguous slave modes combination."
811
 
                    " STRICT will be used"));
 
933
    sql_print_error("Ambiguous slave modes combination."
 
934
                    " STRICT will be used");
812
935
    bit_do_clear(slave_exec_mode_options, SLAVE_EXEC_MODE_IDEMPOTENT);
813
936
  }
814
937
  if (bit_is_set(slave_exec_mode_options, SLAVE_EXEC_MODE_IDEMPOTENT) == 0)
838
961
    my_error(ER_TEMP_TABLE_PREVENTS_SWITCH_OUT_OF_RBR, MYF(0));
839
962
    return 1;
840
963
  }
841
 
  
 
964
  /*
 
965
    if in a stored function/trigger, it's too late to change mode
 
966
  */
 
967
  if (thd->in_sub_stmt)
 
968
  {
 
969
    my_error(ER_STORED_FUNCTION_PREVENTS_SWITCH_BINLOG_FORMAT, MYF(0));
 
970
    return 1;    
 
971
  }
842
972
  return sys_var_thd_enum::is_readonly();
843
973
}
844
974
 
845
975
 
846
 
void fix_binlog_format_after_update(THD *thd,
847
 
                                    enum_var_type type __attribute__((unused)))
 
976
void fix_binlog_format_after_update(THD *thd, enum_var_type type)
848
977
{
849
978
  thd->reset_current_stmt_binlog_row_based();
850
979
}
851
980
 
852
981
 
853
 
static void fix_max_binlog_size(THD *thd __attribute__((unused)),
854
 
                                enum_var_type type __attribute__((unused)))
 
982
static void fix_max_binlog_size(THD *thd, enum_var_type type)
855
983
{
 
984
  DBUG_ENTER("fix_max_binlog_size");
 
985
  DBUG_PRINT("info",("max_binlog_size=%lu max_relay_log_size=%lu",
 
986
                     max_binlog_size, max_relay_log_size));
856
987
  mysql_bin_log.set_max_size(max_binlog_size);
 
988
#ifdef HAVE_REPLICATION
857
989
  if (!max_relay_log_size)
858
990
    active_mi->rli.relay_log.set_max_size(max_binlog_size);
859
 
  return;
 
991
#endif
 
992
  DBUG_VOID_RETURN;
860
993
}
861
994
 
862
 
static void fix_max_relay_log_size(THD *thd __attribute__((unused)),
863
 
                                   enum_var_type type __attribute__((unused)))
 
995
static void fix_max_relay_log_size(THD *thd, enum_var_type type)
864
996
{
 
997
  DBUG_ENTER("fix_max_relay_log_size");
 
998
  DBUG_PRINT("info",("max_binlog_size=%lu max_relay_log_size=%lu",
 
999
                     max_binlog_size, max_relay_log_size));
 
1000
#ifdef HAVE_REPLICATION
865
1001
  active_mi->rli.relay_log.set_max_size(max_relay_log_size ?
866
1002
                                        max_relay_log_size: max_binlog_size);
867
 
  return;
 
1003
#endif
 
1004
  DBUG_VOID_RETURN;
868
1005
}
869
1006
 
870
 
static void fix_max_connections(THD *thd __attribute__((unused)),
871
 
                                enum_var_type type __attribute__((unused)))
 
1007
static void fix_max_connections(THD *thd, enum_var_type type)
872
1008
{
873
1009
  resize_thr_alarm(max_connections +  10);
874
1010
}
892
1028
}
893
1029
 
894
1030
 
895
 
static void fix_server_id(THD *thd __attribute__((unused)),
896
 
                          enum_var_type type __attribute__((unused)))
 
1031
static void fix_server_id(THD *thd, enum_var_type type)
897
1032
{
898
1033
  server_id_supplied = 1;
899
1034
  thd->server_id= server_id;
901
1036
 
902
1037
 
903
1038
bool throw_bounds_warning(THD *thd, bool fixed, bool unsignd,
904
 
                          const char *name, int64_t val)
 
1039
                          const char *name, longlong val)
905
1040
{
906
1041
  if (fixed)
907
1042
  {
908
1043
    char buf[22];
909
1044
 
910
1045
    if (unsignd)
911
 
      ullstr((uint64_t) val, buf);
 
1046
      ullstr((ulonglong) val, buf);
912
1047
    else
913
1048
      llstr(val, buf);
914
1049
 
915
 
    push_warning_printf(thd, DRIZZLE_ERROR::WARN_LEVEL_WARN,
 
1050
    push_warning_printf(thd, MYSQL_ERROR::WARN_LEVEL_WARN,
916
1051
                        ER_TRUNCATED_WRONG_VALUE,
917
1052
                        ER(ER_TRUNCATED_WRONG_VALUE), name, buf);
918
1053
  }
919
 
  return false;
 
1054
  return FALSE;
920
1055
}
921
1056
 
922
 
static uint64_t fix_unsigned(THD *thd, uint64_t num,
 
1057
static ulonglong fix_unsigned(THD *thd, ulonglong num,
923
1058
                              const struct my_option *option_limits)
924
1059
{
925
 
  bool fixed= false;
926
 
  uint64_t out= getopt_ull_limit_value(num, option_limits, &fixed);
 
1060
  my_bool fixed= FALSE;
 
1061
  ulonglong out= getopt_ull_limit_value(num, option_limits, &fixed);
927
1062
 
928
 
  throw_bounds_warning(thd, fixed, true, option_limits->name, (int64_t) num);
 
1063
  throw_bounds_warning(thd, fixed, TRUE, option_limits->name, (longlong) num);
929
1064
  return out;
930
1065
}
931
1066
 
932
 
static bool get_unsigned(THD *thd __attribute__((unused)), set_var *var)
 
1067
static bool get_unsigned(THD *thd, set_var *var)
933
1068
{
934
1069
  if (var->value->unsigned_flag)
935
 
    var->save_result.uint64_t_value= (uint64_t) var->value->val_int();
 
1070
    var->save_result.ulonglong_value= (ulonglong) var->value->val_int();
936
1071
  else
937
1072
  {
938
 
    int64_t v= var->value->val_int();
939
 
    var->save_result.uint64_t_value= (uint64_t) ((v < 0) ? 0 : v);
 
1073
    longlong v= var->value->val_int();
 
1074
    var->save_result.ulonglong_value= (ulonglong) ((v < 0) ? 0 : v);
940
1075
  }
941
1076
  return 0;
942
1077
}
957
1092
 
958
1093
bool sys_var_long_ptr_global::update(THD *thd, set_var *var)
959
1094
{
960
 
  uint64_t tmp= var->save_result.uint64_t_value;
 
1095
  ulonglong tmp= var->save_result.ulonglong_value;
961
1096
  pthread_mutex_lock(guard);
962
1097
  if (option_limits)
963
1098
    *value= (ulong) fix_unsigned(thd, tmp, option_limits);
964
1099
  else
965
1100
  {
966
 
    if (tmp > UINT32_MAX)
 
1101
#if SIZEOF_LONG < SIZEOF_LONG_LONG
 
1102
    /* Avoid overflows on 32 bit systems */
 
1103
    if (tmp > ULONG_MAX)
967
1104
    {
968
 
      tmp= UINT32_MAX;
969
 
      throw_bounds_warning(thd, true, true, name,
970
 
                           (int64_t) var->save_result.uint64_t_value);
 
1105
      tmp= ULONG_MAX;
 
1106
      throw_bounds_warning(thd, TRUE, TRUE, name,
 
1107
                           (longlong) var->save_result.ulonglong_value);
971
1108
    }
 
1109
#endif
972
1110
    *value= (ulong) tmp;
973
1111
  }
974
1112
 
977
1115
}
978
1116
 
979
1117
 
980
 
void sys_var_long_ptr_global::set_default(THD *thd __attribute__((unused)), enum_var_type type __attribute__((unused)))
 
1118
void sys_var_long_ptr_global::set_default(THD *thd, enum_var_type type)
981
1119
{
982
 
  bool not_used;
 
1120
  my_bool not_used;
983
1121
  pthread_mutex_lock(guard);
984
1122
  *value= (ulong) getopt_ull_limit_value((ulong) option_limits->def_value,
985
1123
                                         option_limits, &not_used);
987
1125
}
988
1126
 
989
1127
 
990
 
bool sys_var_uint64_t_ptr::update(THD *thd, set_var *var)
 
1128
bool sys_var_ulonglong_ptr::update(THD *thd, set_var *var)
991
1129
{
992
 
  uint64_t tmp= var->save_result.uint64_t_value;
 
1130
  ulonglong tmp= var->save_result.ulonglong_value;
993
1131
  pthread_mutex_lock(&LOCK_global_system_variables);
994
1132
  if (option_limits)
995
 
    *value= (uint64_t) fix_unsigned(thd, tmp, option_limits);
 
1133
    *value= (ulonglong) fix_unsigned(thd, tmp, option_limits);
996
1134
  else
997
 
    *value= (uint64_t) tmp;
 
1135
    *value= (ulonglong) tmp;
998
1136
  pthread_mutex_unlock(&LOCK_global_system_variables);
999
1137
  return 0;
1000
1138
}
1001
1139
 
1002
1140
 
1003
 
void sys_var_uint64_t_ptr::set_default(THD *thd __attribute__((unused)),
1004
 
                                        enum_var_type type __attribute__((unused)))
 
1141
void sys_var_ulonglong_ptr::set_default(THD *thd, enum_var_type type)
1005
1142
{
1006
 
  bool not_used;
 
1143
  my_bool not_used;
1007
1144
  pthread_mutex_lock(&LOCK_global_system_variables);
1008
 
  *value= getopt_ull_limit_value((uint64_t) option_limits->def_value,
 
1145
  *value= getopt_ull_limit_value((ulonglong) option_limits->def_value,
1009
1146
                                 option_limits, &not_used);
1010
1147
  pthread_mutex_unlock(&LOCK_global_system_variables);
1011
1148
}
1012
1149
 
1013
1150
 
1014
 
bool sys_var_bool_ptr::update(THD *thd __attribute__((unused)), set_var *var)
 
1151
bool sys_var_bool_ptr::update(THD *thd, set_var *var)
1015
1152
{
1016
 
  *value= (bool) var->save_result.ulong_value;
 
1153
  *value= (my_bool) var->save_result.ulong_value;
1017
1154
  return 0;
1018
1155
}
1019
1156
 
1020
1157
 
1021
 
void sys_var_bool_ptr::set_default(THD *thd __attribute__((unused)), enum_var_type type __attribute__((unused)))
 
1158
void sys_var_bool_ptr::set_default(THD *thd, enum_var_type type)
1022
1159
{
1023
 
  *value= (bool) option_limits->def_value;
 
1160
  *value= (my_bool) option_limits->def_value;
1024
1161
}
1025
1162
 
1026
1163
 
1027
 
bool sys_var_enum::update(THD *thd __attribute__((unused)), set_var *var)
 
1164
bool sys_var_enum::update(THD *thd, set_var *var)
1028
1165
{
1029
1166
  *value= (uint) var->save_result.ulong_value;
1030
1167
  return 0;
1031
1168
}
1032
1169
 
1033
1170
 
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)))
 
1171
uchar *sys_var_enum::value_ptr(THD *thd, enum_var_type type, LEX_STRING *base)
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, enum_var_type type,
 
1178
                                     LEX_STRING *base)
1045
1179
{
1046
 
  return (unsigned char*) enum_names->type_names[global_system_variables.*offset];
 
1180
  return (uchar*) enum_names->type_names[global_system_variables.*offset];
1047
1181
}
1048
1182
 
1049
1183
bool sys_var_thd_ulong::check(THD *thd, set_var *var)
1054
1188
 
1055
1189
bool sys_var_thd_ulong::update(THD *thd, set_var *var)
1056
1190
{
1057
 
  uint64_t tmp= var->save_result.uint64_t_value;
1058
 
  
 
1191
  ulonglong tmp= var->save_result.ulonglong_value;
 
1192
 
1059
1193
  /* Don't use bigger value than given with --maximum-variable-name=.. */
1060
1194
  if ((ulong) tmp > max_system_variables.*offset)
1061
1195
  {
1062
 
    throw_bounds_warning(thd, true, true, name, (int64_t) tmp);
 
1196
    throw_bounds_warning(thd, TRUE, TRUE, name, (longlong) tmp);
1063
1197
    tmp= max_system_variables.*offset;
1064
1198
  }
1065
 
  
 
1199
 
1066
1200
  if (option_limits)
1067
1201
    tmp= (ulong) fix_unsigned(thd, tmp, option_limits);
1068
 
  else if (tmp > UINT32_MAX)
 
1202
#if SIZEOF_LONG < SIZEOF_LONG_LONG
 
1203
  else if (tmp > ULONG_MAX)
1069
1204
  {
1070
 
    tmp= UINT32_MAX;
1071
 
    throw_bounds_warning(thd, true, true, name, (int64_t) var->save_result.uint64_t_value);
 
1205
    tmp= ULONG_MAX;
 
1206
    throw_bounds_warning(thd, TRUE, TRUE, name, (longlong) var->save_result.ulonglong_value);
1072
1207
  }
1073
 
  
 
1208
#endif
 
1209
 
1074
1210
  if (var->type == OPT_GLOBAL)
1075
 
     global_system_variables.*offset= (ulong) tmp;
1076
 
   else
1077
 
     thd->variables.*offset= (ulong) tmp;
1078
 
 
1079
 
   return 0;
1080
 
 }
1081
 
 
1082
 
 
1083
 
 void sys_var_thd_ulong::set_default(THD *thd, enum_var_type type)
1084
 
 {
1085
 
   if (type == OPT_GLOBAL)
1086
 
   {
1087
 
     bool not_used;
1088
 
     /* We will not come here if option_limits is not set */
1089
 
     global_system_variables.*offset=
1090
 
       (ulong) getopt_ull_limit_value((ulong) option_limits->def_value,
1091
 
                                      option_limits, &not_used);
1092
 
   }
1093
 
   else
1094
 
     thd->variables.*offset= global_system_variables.*offset;
1095
 
 }
1096
 
 
1097
 
 
1098
 
unsigned char *sys_var_thd_ulong::value_ptr(THD *thd, enum_var_type type,
1099
 
                                    LEX_STRING *base __attribute__((unused)))
1100
 
{
1101
 
  if (type == OPT_GLOBAL)
1102
 
    return (unsigned char*) &(global_system_variables.*offset);
1103
 
  return (unsigned char*) &(thd->variables.*offset);
 
1211
    global_system_variables.*offset= (ulong) tmp;
 
1212
  else
 
1213
    thd->variables.*offset= (ulong) tmp;
 
1214
 
 
1215
  return 0;
 
1216
}
 
1217
 
 
1218
 
 
1219
void sys_var_thd_ulong::set_default(THD *thd, enum_var_type type)
 
1220
{
 
1221
  if (type == OPT_GLOBAL)
 
1222
  {
 
1223
    my_bool not_used;
 
1224
    /* We will not come here if option_limits is not set */
 
1225
    global_system_variables.*offset=
 
1226
      (ulong) getopt_ull_limit_value((ulong) option_limits->def_value,
 
1227
                                     option_limits, &not_used);
 
1228
  }
 
1229
  else
 
1230
    thd->variables.*offset= global_system_variables.*offset;
 
1231
}
 
1232
 
 
1233
 
 
1234
uchar *sys_var_thd_ulong::value_ptr(THD *thd, enum_var_type type,
 
1235
                                   LEX_STRING *base)
 
1236
{
 
1237
  if (type == OPT_GLOBAL)
 
1238
    return (uchar*) &(global_system_variables.*offset);
 
1239
  return (uchar*) &(thd->variables.*offset);
1104
1240
}
1105
1241
 
1106
1242
 
1107
1243
bool sys_var_thd_ha_rows::update(THD *thd, set_var *var)
1108
1244
{
1109
 
  uint64_t tmp= var->save_result.uint64_t_value;
 
1245
  ulonglong tmp= var->save_result.ulonglong_value;
1110
1246
 
1111
1247
  /* Don't use bigger value than given with --maximum-variable-name=.. */
1112
1248
  if ((ha_rows) tmp > max_system_variables.*offset)
1131
1267
{
1132
1268
  if (type == OPT_GLOBAL)
1133
1269
  {
1134
 
    bool not_used;
 
1270
    my_bool not_used;
1135
1271
    /* We will not come here if option_limits is not set */
1136
1272
    pthread_mutex_lock(&LOCK_global_system_variables);
1137
1273
    global_system_variables.*offset=
1144
1280
}
1145
1281
 
1146
1282
 
1147
 
unsigned char *sys_var_thd_ha_rows::value_ptr(THD *thd, enum_var_type type,
1148
 
                                      LEX_STRING *base __attribute__((unused)))
 
1283
uchar *sys_var_thd_ha_rows::value_ptr(THD *thd, enum_var_type type,
 
1284
                                     LEX_STRING *base)
1149
1285
{
1150
1286
  if (type == OPT_GLOBAL)
1151
 
    return (unsigned char*) &(global_system_variables.*offset);
1152
 
  return (unsigned char*) &(thd->variables.*offset);
 
1287
    return (uchar*) &(global_system_variables.*offset);
 
1288
  return (uchar*) &(thd->variables.*offset);
1153
1289
}
1154
1290
 
1155
 
bool sys_var_thd_uint64_t::check(THD *thd, set_var *var)
 
1291
bool sys_var_thd_ulonglong::check(THD *thd, set_var *var)
1156
1292
{
1157
1293
  return get_unsigned(thd, var);
1158
1294
}
1159
1295
 
1160
 
bool sys_var_thd_uint64_t::update(THD *thd,  set_var *var)
 
1296
bool sys_var_thd_ulonglong::update(THD *thd,  set_var *var)
1161
1297
{
1162
 
  uint64_t tmp= var->save_result.uint64_t_value;
 
1298
  ulonglong tmp= var->save_result.ulonglong_value;
1163
1299
 
1164
1300
  if (tmp > max_system_variables.*offset)
1165
1301
    tmp= max_system_variables.*offset;
1170
1306
  {
1171
1307
    /* Lock is needed to make things safe on 32 bit systems */
1172
1308
    pthread_mutex_lock(&LOCK_global_system_variables);
1173
 
    global_system_variables.*offset= (uint64_t) tmp;
 
1309
    global_system_variables.*offset= (ulonglong) tmp;
1174
1310
    pthread_mutex_unlock(&LOCK_global_system_variables);
1175
1311
  }
1176
1312
  else
1177
 
    thd->variables.*offset= (uint64_t) tmp;
 
1313
    thd->variables.*offset= (ulonglong) tmp;
1178
1314
  return 0;
1179
1315
}
1180
1316
 
1181
1317
 
1182
 
void sys_var_thd_uint64_t::set_default(THD *thd, enum_var_type type)
 
1318
void sys_var_thd_ulonglong::set_default(THD *thd, enum_var_type type)
1183
1319
{
1184
1320
  if (type == OPT_GLOBAL)
1185
1321
  {
1186
 
    bool not_used;
 
1322
    my_bool not_used;
1187
1323
    pthread_mutex_lock(&LOCK_global_system_variables);
1188
1324
    global_system_variables.*offset=
1189
 
      getopt_ull_limit_value((uint64_t) option_limits->def_value,
 
1325
      getopt_ull_limit_value((ulonglong) option_limits->def_value,
1190
1326
                             option_limits, &not_used);
1191
1327
    pthread_mutex_unlock(&LOCK_global_system_variables);
1192
1328
  }
1195
1331
}
1196
1332
 
1197
1333
 
1198
 
unsigned char *sys_var_thd_uint64_t::value_ptr(THD *thd, enum_var_type type,
1199
 
                                        LEX_STRING *base __attribute__((unused)))
 
1334
uchar *sys_var_thd_ulonglong::value_ptr(THD *thd, enum_var_type type,
 
1335
                                       LEX_STRING *base)
1200
1336
{
1201
1337
  if (type == OPT_GLOBAL)
1202
 
    return (unsigned char*) &(global_system_variables.*offset);
1203
 
  return (unsigned char*) &(thd->variables.*offset);
 
1338
    return (uchar*) &(global_system_variables.*offset);
 
1339
  return (uchar*) &(thd->variables.*offset);
1204
1340
}
1205
1341
 
1206
1342
 
1207
1343
bool sys_var_thd_bool::update(THD *thd,  set_var *var)
1208
1344
{
1209
1345
  if (var->type == OPT_GLOBAL)
1210
 
    global_system_variables.*offset= (bool) var->save_result.ulong_value;
 
1346
    global_system_variables.*offset= (my_bool) var->save_result.ulong_value;
1211
1347
  else
1212
 
    thd->variables.*offset= (bool) var->save_result.ulong_value;
 
1348
    thd->variables.*offset= (my_bool) var->save_result.ulong_value;
1213
1349
  return 0;
1214
1350
}
1215
1351
 
1217
1353
void sys_var_thd_bool::set_default(THD *thd,  enum_var_type type)
1218
1354
{
1219
1355
  if (type == OPT_GLOBAL)
1220
 
    global_system_variables.*offset= (bool) option_limits->def_value;
 
1356
    global_system_variables.*offset= (my_bool) option_limits->def_value;
1221
1357
  else
1222
1358
    thd->variables.*offset= global_system_variables.*offset;
1223
1359
}
1224
1360
 
1225
1361
 
1226
 
unsigned char *sys_var_thd_bool::value_ptr(THD *thd, enum_var_type type,
1227
 
                                   LEX_STRING *base __attribute__((unused)))
 
1362
uchar *sys_var_thd_bool::value_ptr(THD *thd, enum_var_type type,
 
1363
                                  LEX_STRING *base)
1228
1364
{
1229
1365
  if (type == OPT_GLOBAL)
1230
 
    return (unsigned char*) &(global_system_variables.*offset);
1231
 
  return (unsigned char*) &(thd->variables.*offset);
 
1366
    return (uchar*) &(global_system_variables.*offset);
 
1367
  return (uchar*) &(thd->variables.*offset);
1232
1368
}
1233
1369
 
1234
1370
 
1235
 
bool sys_var::check_enum(THD *thd __attribute__((unused)),
1236
 
                         set_var *var, const TYPELIB *enum_names)
 
1371
bool sys_var::check_enum(THD *thd, set_var *var, const TYPELIB *enum_names)
1237
1372
{
1238
1373
  char buff[STRING_BUFFER_USUAL_SIZE];
1239
1374
  const char *value;
1252
1387
  }
1253
1388
  else
1254
1389
  {
1255
 
    uint64_t tmp=var->value->val_int();
 
1390
    ulonglong tmp=var->value->val_int();
1256
1391
    if (tmp >= enum_names->count)
1257
1392
    {
1258
1393
      llstr(tmp,buff);
1269
1404
}
1270
1405
 
1271
1406
 
1272
 
bool sys_var::check_set(THD *thd __attribute__((unused)),
1273
 
                        set_var *var, TYPELIB *enum_names)
 
1407
bool sys_var::check_set(THD *thd, set_var *var, TYPELIB *enum_names)
1274
1408
{
1275
1409
  bool not_used;
1276
1410
  char buff[STRING_BUFFER_USUAL_SIZE], *error= 0;
1277
 
  uint32_t error_len= 0;
 
1411
  uint error_len= 0;
1278
1412
  String str(buff, sizeof(buff), system_charset_info), *res;
1279
1413
 
1280
1414
  if (var->value->result_type() == STRING_RESULT)
1281
1415
  {
1282
1416
    if (!(res= var->value->val_str(&str)))
1283
1417
    {
1284
 
      my_stpcpy(buff, "NULL");
 
1418
      strmov(buff, "NULL");
1285
1419
      goto err;
1286
1420
    }
1287
1421
 
1300
1434
                                            &not_used));
1301
1435
    if (error_len)
1302
1436
    {
1303
 
      strmake(buff, error, cmin(sizeof(buff) - 1, (ulong)error_len));
 
1437
      strmake(buff, error, min(sizeof(buff) - 1, error_len));
1304
1438
      goto err;
1305
1439
    }
1306
1440
  }
1307
1441
  else
1308
1442
  {
1309
 
    uint64_t tmp= var->value->val_int();
 
1443
    ulonglong tmp= var->value->val_int();
1310
1444
 
1311
1445
    if (!m_allow_empty_value &&
1312
1446
        tmp == 0)
1320
1454
      For when the enum is made to contain 64 elements, as 1ULL<<64 is
1321
1455
      undefined, we guard with a "count<64" test.
1322
1456
    */
1323
 
    if (unlikely((tmp >= ((1UL) << enum_names->count)) &&
 
1457
    if (unlikely((tmp >= ((ULL(1)) << enum_names->count)) &&
1324
1458
                 (enum_names->count < 64)))
1325
1459
    {
1326
1460
      llstr(tmp, buff);
1360
1494
  switch (show_type()) {
1361
1495
  case SHOW_INT:
1362
1496
  {
1363
 
    uint32_t value;
 
1497
    uint value;
1364
1498
    pthread_mutex_lock(&LOCK_global_system_variables);
1365
1499
    value= *(uint*) value_ptr(thd, var_type, base);
1366
1500
    pthread_mutex_unlock(&LOCK_global_system_variables);
1367
 
    return new Item_uint((uint64_t) value);
 
1501
    return new Item_uint((ulonglong) value);
1368
1502
  }
1369
1503
  case SHOW_LONG:
1370
1504
  {
1372
1506
    pthread_mutex_lock(&LOCK_global_system_variables);
1373
1507
    value= *(ulong*) value_ptr(thd, var_type, base);
1374
1508
    pthread_mutex_unlock(&LOCK_global_system_variables);
1375
 
    return new Item_uint((uint64_t) value);
 
1509
    return new Item_uint((ulonglong) value);
1376
1510
  }
1377
1511
  case SHOW_LONGLONG:
1378
1512
  {
1379
 
    int64_t value;
 
1513
    longlong value;
1380
1514
    pthread_mutex_lock(&LOCK_global_system_variables);
1381
 
    value= *(int64_t*) value_ptr(thd, var_type, base);
 
1515
    value= *(longlong*) value_ptr(thd, var_type, base);
1382
1516
    pthread_mutex_unlock(&LOCK_global_system_variables);
1383
1517
    return new Item_int(value);
1384
1518
  }
1397
1531
    pthread_mutex_lock(&LOCK_global_system_variables);
1398
1532
    value= *(ha_rows*) value_ptr(thd, var_type, base);
1399
1533
    pthread_mutex_unlock(&LOCK_global_system_variables);
1400
 
    return new Item_int((uint64_t) value);
 
1534
    return new Item_int((ulonglong) value);
1401
1535
  }
1402
1536
  case SHOW_MY_BOOL:
1403
1537
  {
1404
 
    int32_t value;
 
1538
    int32 value;
1405
1539
    pthread_mutex_lock(&LOCK_global_system_variables);
1406
 
    value= *(bool*) value_ptr(thd, var_type, base);
 
1540
    value= *(my_bool*) value_ptr(thd, var_type, base);
1407
1541
    pthread_mutex_unlock(&LOCK_global_system_variables);
1408
1542
    return new Item_int(value,1);
1409
1543
  }
1414
1548
    char *str= *(char**) value_ptr(thd, var_type, base);
1415
1549
    if (str)
1416
1550
    {
1417
 
      uint32_t length= strlen(str);
 
1551
      uint length= strlen(str);
1418
1552
      tmp= new Item_string(thd->strmake(str, length), length,
1419
1553
                           system_charset_info, DERIVATION_SYSCONST);
1420
1554
    }
1468
1602
}
1469
1603
 
1470
1604
 
1471
 
unsigned char *sys_var_thd_enum::value_ptr(THD *thd, enum_var_type type,
1472
 
                                   LEX_STRING *base __attribute__((unused)))
 
1605
uchar *sys_var_thd_enum::value_ptr(THD *thd, enum_var_type type,
 
1606
                                  LEX_STRING *base)
1473
1607
{
1474
1608
  ulong tmp= ((type == OPT_GLOBAL) ?
1475
1609
              global_system_variables.*offset :
1476
1610
              thd->variables.*offset);
1477
 
  return (unsigned char*) enum_names->type_names[tmp];
 
1611
  return (uchar*) enum_names->type_names[tmp];
1478
1612
}
1479
1613
 
1480
1614
bool sys_var_thd_bit::check(THD *thd, set_var *var)
1490
1624
}
1491
1625
 
1492
1626
 
1493
 
unsigned char *sys_var_thd_bit::value_ptr(THD *thd,
1494
 
                                  enum_var_type type __attribute__((unused)),
1495
 
                                  LEX_STRING *base __attribute__((unused)))
 
1627
uchar *sys_var_thd_bit::value_ptr(THD *thd, enum_var_type type,
 
1628
                                 LEX_STRING *base)
1496
1629
{
1497
1630
  /*
1498
1631
    If reverse is 0 (default) return 1 if bit is set.
1499
1632
    If reverse is 1, return 0 if bit is set
1500
1633
  */
1501
 
  thd->sys_var_tmp.bool_value= ((thd->options & bit_flag) ?
 
1634
  thd->sys_var_tmp.my_bool_value= ((thd->options & bit_flag) ?
1502
1635
                                   !reverse : reverse);
1503
 
  return (unsigned char*) &thd->sys_var_tmp.bool_value;
 
1636
  return (uchar*) &thd->sys_var_tmp.my_bool_value;
1504
1637
}
1505
1638
 
1506
1639
 
1510
1643
                                           DATE_TIME_FORMAT *new_value)
1511
1644
{
1512
1645
  DATE_TIME_FORMAT *old;
 
1646
  DBUG_ENTER("sys_var_date_time_format::update2");
 
1647
  DBUG_DUMP("positions", (uchar*) new_value->positions,
 
1648
            sizeof(new_value->positions));
1513
1649
 
1514
1650
  if (type == OPT_GLOBAL)
1515
1651
  {
1523
1659
    old= (thd->variables.*offset);
1524
1660
    (thd->variables.*offset)= new_value;
1525
1661
  }
1526
 
  free((char*) old);
1527
 
  return;
 
1662
  my_free((char*) old, MYF(MY_ALLOW_ZERO_PTR));
 
1663
  DBUG_VOID_RETURN;
1528
1664
}
1529
1665
 
1530
1666
 
1562
1698
    update is aborted
1563
1699
  */
1564
1700
  var->save_result.date_time_format= date_time_format_copy(thd, format);
1565
 
  free((char*) format);
 
1701
  my_free((char*) format, MYF(0));
1566
1702
  return var->save_result.date_time_format == 0;
1567
1703
}
1568
1704
 
1588
1724
}
1589
1725
 
1590
1726
 
1591
 
unsigned char *sys_var_thd_date_time_format::value_ptr(THD *thd, enum_var_type type,
1592
 
                                               LEX_STRING *base __attribute__((unused)))
 
1727
uchar *sys_var_thd_date_time_format::value_ptr(THD *thd, enum_var_type type,
 
1728
                                              LEX_STRING *base)
1593
1729
{
1594
1730
  if (type == OPT_GLOBAL)
1595
1731
  {
1601
1737
    */
1602
1738
    res= thd->strmake((global_system_variables.*offset)->format.str,
1603
1739
                      (global_system_variables.*offset)->format.length);
1604
 
    return (unsigned char*) res;
 
1740
    return (uchar*) res;
1605
1741
  }
1606
 
  return (unsigned char*) (thd->variables.*offset)->format.str;
 
1742
  return (uchar*) (thd->variables.*offset)->format.str;
1607
1743
}
1608
1744
 
1609
1745
 
1613
1749
  const char *new_name;
1614
1750
} my_old_conv;
1615
1751
 
1616
 
bool sys_var_collation::check(THD *thd __attribute__((unused)),
1617
 
                              set_var *var)
1618
 
{
1619
 
  const CHARSET_INFO *tmp;
 
1752
static my_old_conv old_conv[]= 
 
1753
{
 
1754
  {     "cp1251_koi8"           ,       "cp1251"        },
 
1755
  {     "cp1250_latin2"         ,       "cp1250"        },
 
1756
  {     "kam_latin2"            ,       "keybcs2"       },
 
1757
  {     "mac_latin2"            ,       "MacRoman"      },
 
1758
  {     "macce_latin2"          ,       "MacCE"         },
 
1759
  {     "pc2_latin2"            ,       "pclatin2"      },
 
1760
  {     "vga_latin2"            ,       "pclatin1"      },
 
1761
  {     "koi8_cp1251"           ,       "koi8r"         },
 
1762
  {     "win1251ukr_koi8_ukr"   ,       "win1251ukr"    },
 
1763
  {     "koi8_ukr_win1251ukr"   ,       "koi8u"         },
 
1764
  {     NULL                    ,       NULL            }
 
1765
};
 
1766
 
 
1767
CHARSET_INFO *get_old_charset_by_name(const char *name)
 
1768
{
 
1769
  my_old_conv *conv;
 
1770
 
 
1771
  for (conv= old_conv; conv->old_name; conv++)
 
1772
  {
 
1773
    if (!my_strcasecmp(&my_charset_latin1, name, conv->old_name))
 
1774
      return get_charset_by_csname(conv->new_name, MY_CS_PRIMARY, MYF(0));
 
1775
  }
 
1776
  return NULL;
 
1777
}
 
1778
 
 
1779
 
 
1780
bool sys_var_collation::check(THD *thd, set_var *var)
 
1781
{
 
1782
  CHARSET_INFO *tmp;
1620
1783
 
1621
1784
  if (var->value->result_type() == STRING_RESULT)
1622
1785
  {
1648
1811
}
1649
1812
 
1650
1813
 
1651
 
bool sys_var_character_set::check(THD *thd __attribute__((unused)),
1652
 
                                  set_var *var)
 
1814
bool sys_var_character_set::check(THD *thd, set_var *var)
1653
1815
{
1654
 
  const CHARSET_INFO *tmp;
 
1816
  CHARSET_INFO *tmp;
1655
1817
 
1656
1818
  if (var->value->result_type() == STRING_RESULT)
1657
1819
  {
1666
1828
      }
1667
1829
      tmp= NULL;
1668
1830
    }
1669
 
    else if (!(tmp= get_charset_by_csname(res->c_ptr(),MY_CS_PRIMARY,MYF(0))))
 
1831
    else if (!(tmp=get_charset_by_csname(res->c_ptr(),MY_CS_PRIMARY,MYF(0))) &&
 
1832
             !(tmp=get_old_charset_by_name(res->c_ptr())))
1670
1833
    {
1671
1834
      my_error(ER_UNKNOWN_CHARACTER_SET, MYF(0), res->c_ptr());
1672
1835
      return 1;
1695
1858
}
1696
1859
 
1697
1860
 
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;
 
1861
uchar *sys_var_character_set::value_ptr(THD *thd, enum_var_type type,
 
1862
                                       LEX_STRING *base)
 
1863
{
 
1864
  CHARSET_INFO *cs= ci_ptr(thd,type)[0];
 
1865
  return cs ? (uchar*) cs->csname : (uchar*) NULL;
 
1866
}
 
1867
 
 
1868
 
 
1869
void sys_var_character_set_sv::set_default(THD *thd, enum_var_type type)
 
1870
{
 
1871
  if (type == OPT_GLOBAL)
 
1872
    global_system_variables.*offset= *global_default;
 
1873
  else
 
1874
  {
 
1875
    thd->variables.*offset= global_system_variables.*offset;
 
1876
    thd->update_charset();
 
1877
  }
 
1878
}
 
1879
CHARSET_INFO **sys_var_character_set_sv::ci_ptr(THD *thd, enum_var_type type)
 
1880
{
 
1881
  if (type == OPT_GLOBAL)
 
1882
    return &(global_system_variables.*offset);
 
1883
  else
 
1884
    return &(thd->variables.*offset);
 
1885
}
 
1886
 
 
1887
 
 
1888
bool sys_var_character_set_client::check(THD *thd, set_var *var)
 
1889
{
 
1890
  if (sys_var_character_set_sv::check(thd, var))
 
1891
    return 1;
 
1892
  /* Currently, UCS-2 cannot be used as a client character set */
 
1893
  if (var->save_result.charset->mbminlen > 1)
 
1894
  {
 
1895
    my_error(ER_WRONG_VALUE_FOR_VAR, MYF(0), name, 
 
1896
             var->save_result.charset->csname);
 
1897
    return 1;
 
1898
  }
 
1899
  return 0;
 
1900
}
 
1901
 
 
1902
 
 
1903
CHARSET_INFO ** sys_var_character_set_database::ci_ptr(THD *thd,
 
1904
                                                       enum_var_type type)
 
1905
{
 
1906
  if (type == OPT_GLOBAL)
 
1907
    return &global_system_variables.collation_database;
 
1908
  else
 
1909
    return &thd->variables.collation_database;
 
1910
}
 
1911
 
 
1912
 
 
1913
void sys_var_character_set_database::set_default(THD *thd, enum_var_type type)
 
1914
{
 
1915
 if (type == OPT_GLOBAL)
 
1916
    global_system_variables.collation_database= default_charset_info;
 
1917
  else
 
1918
  {
 
1919
    thd->variables.collation_database= thd->db_charset;
 
1920
    thd->update_charset();
 
1921
  }
1703
1922
}
1704
1923
 
1705
1924
 
1728
1947
}
1729
1948
 
1730
1949
 
1731
 
unsigned char *sys_var_collation_sv::value_ptr(THD *thd, enum_var_type type,
1732
 
                                       LEX_STRING *base __attribute__((unused)))
 
1950
uchar *sys_var_collation_sv::value_ptr(THD *thd, enum_var_type type,
 
1951
                                       LEX_STRING *base)
1733
1952
{
1734
 
  const CHARSET_INFO *cs= ((type == OPT_GLOBAL) ?
 
1953
  CHARSET_INFO *cs= ((type == OPT_GLOBAL) ?
1735
1954
                     global_system_variables.*offset : thd->variables.*offset);
1736
 
  return cs ? (unsigned char*) cs->name : (unsigned char*) "NULL";
 
1955
  return cs ? (uchar*) cs->name : (uchar*) "NULL";
1737
1956
}
1738
1957
 
1739
1958
 
1751
1970
}
1752
1971
 
1753
1972
 
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)))
 
1973
uchar *sys_var_key_cache_param::value_ptr(THD *thd, enum_var_type type,
 
1974
                                         LEX_STRING *base)
1757
1975
{
1758
1976
  KEY_CACHE *key_cache= get_key_cache(base);
1759
1977
  if (!key_cache)
1760
1978
    key_cache= &zero_key_cache;
1761
 
  return (unsigned char*) key_cache + offset ;
 
1979
  return (uchar*) key_cache + offset ;
1762
1980
}
1763
1981
 
1764
1982
 
1765
1983
bool sys_var_key_buffer_size::update(THD *thd, set_var *var)
1766
1984
{
1767
 
  uint64_t tmp= var->save_result.uint64_t_value;
 
1985
  ulonglong tmp= var->save_result.ulonglong_value;
1768
1986
  LEX_STRING *base_name= &var->base;
1769
1987
  KEY_CACHE *key_cache;
1770
1988
  bool error= 0;
1800
2018
  {
1801
2019
    if (key_cache == dflt_key_cache)
1802
2020
    {
1803
 
      push_warning_printf(thd, DRIZZLE_ERROR::WARN_LEVEL_WARN,
 
2021
      push_warning_printf(thd, MYSQL_ERROR::WARN_LEVEL_WARN,
1804
2022
                          ER_WARN_CANT_DROP_DEFAULT_KEYCACHE,
1805
2023
                          ER(ER_WARN_CANT_DROP_DEFAULT_KEYCACHE));
1806
2024
      goto end;                                 // Ignore default key cache
1829
2047
  }
1830
2048
 
1831
2049
  key_cache->param_buff_size=
1832
 
    (uint64_t) fix_unsigned(thd, tmp, option_limits);
 
2050
    (ulonglong) fix_unsigned(thd, tmp, option_limits);
1833
2051
 
1834
2052
  /* If key cache didn't existed initialize it, else resize it */
1835
2053
  key_cache->in_init= 1;
1904
2122
}
1905
2123
 
1906
2124
 
1907
 
bool sys_var_log_state::update(THD *thd __attribute__((unused)), set_var *var)
 
2125
bool sys_var_log_state::update(THD *thd, set_var *var)
1908
2126
{
1909
2127
  bool res;
1910
2128
  pthread_mutex_lock(&LOCK_global_system_variables);
1911
2129
  if (!var->save_result.ulong_value)
 
2130
  {
 
2131
    logger.deactivate_log_handler(thd, log_type);
1912
2132
    res= false;
 
2133
  }
1913
2134
  else
1914
 
    res= true;
 
2135
    res= logger.activate_log_handler(thd, log_type);
1915
2136
  pthread_mutex_unlock(&LOCK_global_system_variables);
1916
2137
  return res;
1917
2138
}
1918
2139
 
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)),
1926
 
                             sys_var_str *var_str,
1927
 
                             set_var *var, const char *log_ext,
1928
 
                             bool log_state, uint32_t log_type)
1929
 
{
 
2140
void sys_var_log_state::set_default(THD *thd, enum_var_type type)
 
2141
{
 
2142
  pthread_mutex_lock(&LOCK_global_system_variables);
 
2143
  logger.deactivate_log_handler(thd, log_type);
 
2144
  pthread_mutex_unlock(&LOCK_global_system_variables);
 
2145
}
 
2146
 
 
2147
 
 
2148
static int  sys_check_log_path(THD *thd,  set_var *var)
 
2149
{
 
2150
  char path[FN_REFLEN], buff[FN_REFLEN];
 
2151
  struct stat f_stat;
 
2152
  String str(buff, sizeof(buff), system_charset_info), *res;
 
2153
  const char *log_file_str;
 
2154
  size_t path_length;
 
2155
 
 
2156
  if (!(res= var->value->val_str(&str)))
 
2157
    goto err;
 
2158
 
 
2159
  log_file_str= res->c_ptr();
 
2160
  bzero(&f_stat, sizeof(struct stat));
 
2161
 
 
2162
  path_length= unpack_filename(path, log_file_str);
 
2163
 
 
2164
  if (!path_length)
 
2165
  {
 
2166
    /* File name is empty. */
 
2167
 
 
2168
    goto err;
 
2169
  }
 
2170
 
 
2171
  if (!stat(path, &f_stat))
 
2172
  {
 
2173
    /*
 
2174
      A file system object exists. Check if argument is a file and we have
 
2175
      'write' permission.
 
2176
    */
 
2177
 
 
2178
    if (!MY_S_ISREG(f_stat.st_mode) ||
 
2179
        !(f_stat.st_mode & MY_S_IWRITE))
 
2180
      goto err;
 
2181
 
 
2182
    return 0;
 
2183
  }
 
2184
 
 
2185
  /* Get dirname of the file path. */
 
2186
  (void) dirname_part(path, log_file_str, &path_length);
 
2187
 
 
2188
  /* Dirname is empty if file path is relative. */
 
2189
  if (!path_length)
 
2190
    return 0;
 
2191
 
 
2192
  /*
 
2193
    Check if directory exists and we have permission to create file and
 
2194
    write to file.
 
2195
  */
 
2196
  if (my_access(path, (F_OK|W_OK)))
 
2197
    goto err;
 
2198
 
 
2199
  return 0;
 
2200
 
 
2201
err:
 
2202
  my_error(ER_WRONG_VALUE_FOR_VAR, MYF(0), var->var->name, 
 
2203
           res ? log_file_str : "NULL");
 
2204
  return 1;
 
2205
}
 
2206
 
 
2207
 
 
2208
bool update_sys_var_str_path(THD *thd, sys_var_str *var_str,
 
2209
                             set_var *var, const char *log_ext,
 
2210
                             bool log_state, uint log_type)
 
2211
{
 
2212
  MYSQL_QUERY_LOG *file_log;
1930
2213
  char buff[FN_REFLEN];
1931
2214
  char *res= 0, *old_value=(char *)(var ? var->value->str_value.ptr() : 0);
1932
2215
  bool result= 0;
1933
 
  uint32_t str_length= (var ? var->value->str_value.length() : 0);
 
2216
  uint str_length= (var ? var->value->str_value.length() : 0);
1934
2217
 
1935
2218
  switch (log_type) {
 
2219
  case QUERY_LOG_SLOW:
 
2220
    file_log= logger.get_slow_log_file_handler();
 
2221
    break;
 
2222
  case QUERY_LOG_GENERAL:
 
2223
    file_log= logger.get_log_file_handler();
 
2224
    break;
1936
2225
  default:
1937
2226
    assert(0);                                  // Impossible
1938
2227
  }
1951
2240
  pthread_mutex_lock(&LOCK_global_system_variables);
1952
2241
  logger.lock_exclusive();
1953
2242
 
 
2243
  if (file_log && log_state)
 
2244
    file_log->close(0);
1954
2245
  old_value= var_str->value;
1955
2246
  var_str->value= res;
1956
2247
  var_str->value_length= str_length;
1957
 
  free(old_value);
1958
 
  if (log_state)
 
2248
  my_free(old_value, MYF(MY_ALLOW_ZERO_PTR));
 
2249
  if (file_log && log_state)
1959
2250
  {
1960
2251
    switch (log_type) {
 
2252
    case QUERY_LOG_SLOW:
 
2253
      file_log->open_slow_log(sys_var_slow_log_path.value);
 
2254
      break;
 
2255
    case QUERY_LOG_GENERAL:
 
2256
      file_log->open_query_log(sys_var_general_log_path.value);
 
2257
      break;
1961
2258
    default:
1962
 
      assert(0);
 
2259
      DBUG_ASSERT(0);
1963
2260
    }
1964
2261
  }
1965
2262
 
1971
2268
}
1972
2269
 
1973
2270
 
1974
 
bool sys_var_log_output::update(THD *thd __attribute__((unused)),
1975
 
                                set_var *var)
 
2271
static bool sys_update_general_log_path(THD *thd, set_var * var)
 
2272
{
 
2273
  return update_sys_var_str_path(thd, &sys_var_general_log_path, 
 
2274
                                 var, ".log", opt_log, QUERY_LOG_GENERAL);
 
2275
}
 
2276
 
 
2277
 
 
2278
static void sys_default_general_log_path(THD *thd, enum_var_type type)
 
2279
{
 
2280
  (void) update_sys_var_str_path(thd, &sys_var_general_log_path,
 
2281
                                 0, ".log", opt_log, QUERY_LOG_GENERAL);
 
2282
}
 
2283
 
 
2284
 
 
2285
static bool sys_update_slow_log_path(THD *thd, set_var * var)
 
2286
{
 
2287
  return update_sys_var_str_path(thd, &sys_var_slow_log_path,
 
2288
                                 var, "-slow.log", opt_slow_log,
 
2289
                                 QUERY_LOG_SLOW);
 
2290
}
 
2291
 
 
2292
 
 
2293
static void sys_default_slow_log_path(THD *thd, enum_var_type type)
 
2294
{
 
2295
  (void) update_sys_var_str_path(thd, &sys_var_slow_log_path,
 
2296
                                 0, "-slow.log", opt_slow_log,
 
2297
                                 QUERY_LOG_SLOW);
 
2298
}
 
2299
 
 
2300
 
 
2301
bool sys_var_log_output::update(THD *thd, set_var *var)
1976
2302
{
1977
2303
  pthread_mutex_lock(&LOCK_global_system_variables);
1978
2304
  logger.lock_exclusive();
 
2305
  logger.init_slow_log(var->save_result.ulong_value);
 
2306
  logger.init_general_log(var->save_result.ulong_value);
1979
2307
  *value= var->save_result.ulong_value;
1980
2308
  logger.unlock();
1981
2309
  pthread_mutex_unlock(&LOCK_global_system_variables);
1983
2311
}
1984
2312
 
1985
2313
 
1986
 
void sys_var_log_output::set_default(THD *thd __attribute__((unused)),
1987
 
                                     enum_var_type type __attribute__((unused)))
 
2314
void sys_var_log_output::set_default(THD *thd, enum_var_type type)
1988
2315
{
1989
2316
  pthread_mutex_lock(&LOCK_global_system_variables);
1990
2317
  logger.lock_exclusive();
 
2318
  logger.init_slow_log(LOG_FILE);
 
2319
  logger.init_general_log(LOG_FILE);
1991
2320
  *value= LOG_FILE;
1992
2321
  logger.unlock();
1993
2322
  pthread_mutex_unlock(&LOCK_global_system_variables);
1994
2323
}
1995
2324
 
1996
2325
 
1997
 
unsigned char *sys_var_log_output::value_ptr(THD *thd,
1998
 
                                     enum_var_type type __attribute__((unused)),
1999
 
                                     LEX_STRING *base __attribute__((unused)))
 
2326
uchar *sys_var_log_output::value_ptr(THD *thd, enum_var_type type,
 
2327
                                    LEX_STRING *base)
2000
2328
{
2001
2329
  char buff[256];
2002
 
  String tmp(buff, sizeof(buff), &my_charset_utf8_general_ci);
 
2330
  String tmp(buff, sizeof(buff), &my_charset_latin1);
2003
2331
  ulong length;
2004
2332
  ulong val= *value;
2005
2333
 
2006
2334
  tmp.length(0);
2007
 
  for (uint32_t i= 0; val; val>>= 1, i++)
 
2335
  for (uint i= 0; val; val>>= 1, i++)
2008
2336
  {
2009
2337
    if (val & 1)
2010
2338
    {
2016
2344
 
2017
2345
  if ((length= tmp.length()))
2018
2346
    length--;
2019
 
  return (unsigned char*) thd->strmake(tmp.ptr(), length);
 
2347
  return (uchar*) thd->strmake(tmp.ptr(), length);
2020
2348
}
2021
2349
 
2022
2350
 
2024
2352
  Functions to handle SET NAMES and SET CHARACTER SET
2025
2353
*****************************************************************************/
2026
2354
 
2027
 
int set_var_collation_client::check(THD *thd __attribute__((unused)))
 
2355
int set_var_collation_client::check(THD *thd)
2028
2356
{
2029
2357
  /* Currently, UCS-2 cannot be used as a client character set */
2030
2358
  if (character_set_client->mbminlen > 1)
2050
2378
 
2051
2379
bool sys_var_timestamp::update(THD *thd,  set_var *var)
2052
2380
{
2053
 
  thd->set_time((time_t) var->save_result.uint64_t_value);
 
2381
  thd->set_time((time_t) var->save_result.ulonglong_value);
2054
2382
  return 0;
2055
2383
}
2056
2384
 
2057
2385
 
2058
 
void sys_var_timestamp::set_default(THD *thd,
2059
 
                                    enum_var_type type __attribute__((unused)))
 
2386
void sys_var_timestamp::set_default(THD *thd, enum_var_type type)
2060
2387
{
2061
2388
  thd->user_time=0;
2062
2389
}
2063
2390
 
2064
2391
 
2065
 
unsigned char *sys_var_timestamp::value_ptr(THD *thd,
2066
 
                                    enum_var_type type __attribute__((unused)),
2067
 
                                    LEX_STRING *base __attribute__((unused)))
 
2392
uchar *sys_var_timestamp::value_ptr(THD *thd, enum_var_type type,
 
2393
                                   LEX_STRING *base)
2068
2394
{
2069
2395
  thd->sys_var_tmp.long_value= (long) thd->start_time;
2070
 
  return (unsigned char*) &thd->sys_var_tmp.long_value;
 
2396
  return (uchar*) &thd->sys_var_tmp.long_value;
2071
2397
}
2072
2398
 
2073
2399
 
2074
2400
bool sys_var_last_insert_id::update(THD *thd, set_var *var)
2075
2401
{
2076
 
  thd->first_successful_insert_id_in_prev_stmt=
2077
 
    var->save_result.uint64_t_value;
 
2402
  thd->first_successful_insert_id_in_prev_stmt= 
 
2403
    var->save_result.ulonglong_value;
2078
2404
  return 0;
2079
2405
}
2080
2406
 
2081
2407
 
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)))
 
2408
uchar *sys_var_last_insert_id::value_ptr(THD *thd, enum_var_type type,
 
2409
                                        LEX_STRING *base)
2085
2410
{
2086
2411
  /*
2087
 
    this tmp var makes it robust againt change of type of
 
2412
    this tmp var makes it robust againt change of type of 
2088
2413
    read_first_successful_insert_id_in_prev_stmt().
2089
2414
  */
2090
 
  thd->sys_var_tmp.uint64_t_value= 
 
2415
  thd->sys_var_tmp.ulonglong_value= 
2091
2416
    thd->read_first_successful_insert_id_in_prev_stmt();
2092
 
  return (unsigned char*) &thd->sys_var_tmp.uint64_t_value;
 
2417
  return (uchar*) &thd->sys_var_tmp.ulonglong_value;
2093
2418
}
2094
2419
 
2095
2420
 
2096
2421
bool sys_var_insert_id::update(THD *thd, set_var *var)
2097
2422
{
2098
 
  thd->force_one_auto_inc_interval(var->save_result.uint64_t_value);
 
2423
  thd->force_one_auto_inc_interval(var->save_result.ulonglong_value);
2099
2424
  return 0;
2100
2425
}
2101
2426
 
2102
2427
 
2103
 
unsigned char *sys_var_insert_id::value_ptr(THD *thd,
2104
 
                                    enum_var_type type __attribute__((unused)),
2105
 
                                    LEX_STRING *base __attribute__((unused)))
 
2428
uchar *sys_var_insert_id::value_ptr(THD *thd, enum_var_type type,
 
2429
                                   LEX_STRING *base)
2106
2430
{
2107
 
  thd->sys_var_tmp.uint64_t_value=
 
2431
  thd->sys_var_tmp.ulonglong_value= 
2108
2432
    thd->auto_inc_intervals_forced.minimum();
2109
 
  return (unsigned char*) &thd->sys_var_tmp.uint64_t_value;
 
2433
  return (uchar*) &thd->sys_var_tmp.ulonglong_value;
2110
2434
}
2111
2435
 
2112
2436
 
2113
2437
bool sys_var_rand_seed1::update(THD *thd, set_var *var)
2114
2438
{
2115
 
  thd->rand.seed1= (ulong) var->save_result.uint64_t_value;
 
2439
  thd->rand.seed1= (ulong) var->save_result.ulonglong_value;
2116
2440
  return 0;
2117
2441
}
2118
2442
 
2119
2443
bool sys_var_rand_seed2::update(THD *thd, set_var *var)
2120
2444
{
2121
 
  thd->rand.seed2= (ulong) var->save_result.uint64_t_value;
 
2445
  thd->rand.seed2= (ulong) var->save_result.ulonglong_value;
2122
2446
  return 0;
2123
2447
}
2124
2448
 
2126
2450
bool sys_var_thd_time_zone::check(THD *thd, set_var *var)
2127
2451
{
2128
2452
  char buff[MAX_TIME_ZONE_NAME_LENGTH];
2129
 
  String str(buff, sizeof(buff), &my_charset_utf8_general_ci);
 
2453
  String str(buff, sizeof(buff), &my_charset_latin1);
2130
2454
  String *res= var->value->val_str(&str);
2131
2455
 
2132
2456
  if (!(var->save_result.time_zone= my_tz_find(thd, res)))
2153
2477
}
2154
2478
 
2155
2479
 
2156
 
unsigned char *sys_var_thd_time_zone::value_ptr(THD *thd, enum_var_type type,
2157
 
                                        LEX_STRING *base __attribute__((unused)))
 
2480
uchar *sys_var_thd_time_zone::value_ptr(THD *thd, enum_var_type type,
 
2481
                                       LEX_STRING *base)
2158
2482
{
2159
2483
  /* 
2160
2484
    We can use ptr() instead of c_ptr() here because String contaning
2161
2485
    time zone name is guaranteed to be zero ended.
2162
2486
  */
2163
2487
  if (type == OPT_GLOBAL)
2164
 
    return (unsigned char *)(global_system_variables.time_zone->get_name()->ptr());
 
2488
    return (uchar *)(global_system_variables.time_zone->get_name()->ptr());
2165
2489
  else
2166
2490
  {
2167
2491
    /*
2173
2497
      (binlog code stores session value only).
2174
2498
    */
2175
2499
    thd->time_zone_used= 1;
2176
 
    return (unsigned char *)(thd->variables.time_zone->get_name()->ptr());
 
2500
    return (uchar *)(thd->variables.time_zone->get_name()->ptr());
2177
2501
  }
2178
2502
}
2179
2503
 
2185
2509
 {
2186
2510
   if (default_tz_name)
2187
2511
   {
2188
 
     String str(default_tz_name, &my_charset_utf8_general_ci);
 
2512
     String str(default_tz_name, &my_charset_latin1);
2189
2513
     /*
2190
2514
       We are guaranteed to find this time zone since its existence
2191
2515
       is checked during start-up.
2212
2536
      May be we should have a separate error message for this?
2213
2537
    */
2214
2538
    my_error(ER_GLOBAL_VARIABLE, MYF(0), name);
2215
 
    return true;
 
2539
    return TRUE;
2216
2540
  }
2217
2541
}
2218
2542
 
2219
 
bool sys_var_max_user_conn::update(THD *thd __attribute__((unused)),
2220
 
                                   set_var *var)
 
2543
bool sys_var_max_user_conn::update(THD *thd, set_var *var)
2221
2544
{
2222
 
  assert(var->type == OPT_GLOBAL);
 
2545
  DBUG_ASSERT(var->type == OPT_GLOBAL);
2223
2546
  pthread_mutex_lock(&LOCK_global_system_variables);
2224
 
  max_user_connections= (uint)var->save_result.uint64_t_value;
 
2547
  max_user_connections= (uint)var->save_result.ulonglong_value;
2225
2548
  pthread_mutex_unlock(&LOCK_global_system_variables);
2226
2549
  return 0;
2227
2550
}
2228
2551
 
2229
2552
 
2230
 
void sys_var_max_user_conn::set_default(THD *thd __attribute__((unused)),
2231
 
                                        enum_var_type type __attribute__((unused)))
 
2553
void sys_var_max_user_conn::set_default(THD *thd, enum_var_type type)
2232
2554
{
2233
 
  assert(type == OPT_GLOBAL);
 
2555
  DBUG_ASSERT(type == OPT_GLOBAL);
2234
2556
  pthread_mutex_lock(&LOCK_global_system_variables);
2235
2557
  max_user_connections= (ulong) option_limits->def_value;
2236
2558
  pthread_mutex_unlock(&LOCK_global_system_variables);
2237
2559
}
2238
2560
 
2239
2561
 
2240
 
unsigned char *sys_var_max_user_conn::value_ptr(THD *thd, enum_var_type type,
2241
 
                                        LEX_STRING *base __attribute__((unused)))
 
2562
uchar *sys_var_max_user_conn::value_ptr(THD *thd, enum_var_type type,
 
2563
                                       LEX_STRING *base)
2242
2564
{
2243
2565
  if (type != OPT_GLOBAL &&
2244
2566
      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);
 
2567
    return (uchar*) &(thd->user_connect->user_resources.user_conn);
 
2568
  return (uchar*) &(max_user_connections);
2247
2569
}
2248
2570
 
2249
2571
 
2250
 
bool sys_var_thd_lc_time_names::check(THD *thd __attribute__((unused)),
2251
 
                                      set_var *var)
 
2572
bool sys_var_thd_lc_time_names::check(THD *thd, set_var *var)
2252
2573
{
2253
2574
  MY_LOCALE *locale_match;
2254
2575
 
2265
2586
  else // STRING_RESULT
2266
2587
  {
2267
2588
    char buff[6]; 
2268
 
    String str(buff, sizeof(buff), &my_charset_utf8_general_ci), *res;
 
2589
    String str(buff, sizeof(buff), &my_charset_latin1), *res;
2269
2590
    if (!(res=var->value->val_str(&str)))
2270
2591
    {
2271
2592
      my_error(ER_WRONG_VALUE_FOR_VAR, MYF(0), name, "NULL");
2295
2616
}
2296
2617
 
2297
2618
 
2298
 
unsigned char *sys_var_thd_lc_time_names::value_ptr(THD *thd,
2299
 
                                            enum_var_type type,
2300
 
                                            LEX_STRING *base __attribute__((unused)))
 
2619
uchar *sys_var_thd_lc_time_names::value_ptr(THD *thd, enum_var_type type,
 
2620
                                          LEX_STRING *base)
2301
2621
{
2302
2622
  return type == OPT_GLOBAL ?
2303
 
                 (unsigned char *) global_system_variables.lc_time_names->name :
2304
 
                 (unsigned char *) thd->variables.lc_time_names->name;
 
2623
                 (uchar *) global_system_variables.lc_time_names->name :
 
2624
                 (uchar *) thd->variables.lc_time_names->name;
2305
2625
}
2306
2626
 
2307
2627
 
2318
2638
 
2319
2639
  NOTES
2320
2640
    The argument to long query time is in seconds in decimal
2321
 
    which is converted to uint64_t integer holding microseconds for storage.
 
2641
    which is converted to ulonglong integer holding microseconds for storage.
2322
2642
    This is used for handling long_query_time
2323
2643
*/
2324
2644
 
2325
2645
bool sys_var_microseconds::update(THD *thd, set_var *var)
2326
2646
{
2327
2647
  double num= var->value->val_real();
2328
 
  int64_t microseconds;
 
2648
  longlong microseconds;
2329
2649
  if (num > (double) option_limits->max_value)
2330
2650
    num= (double) option_limits->max_value;
2331
2651
  if (num < (double) option_limits->min_value)
2332
2652
    num= (double) option_limits->min_value;
2333
 
  microseconds= (int64_t) (num * 1000000.0 + 0.5);
 
2653
  microseconds= (longlong) (num * 1000000.0 + 0.5);
2334
2654
  if (var->type == OPT_GLOBAL)
2335
2655
  {
2336
2656
    pthread_mutex_lock(&LOCK_global_system_variables);
2345
2665
 
2346
2666
void sys_var_microseconds::set_default(THD *thd, enum_var_type type)
2347
2667
{
2348
 
  int64_t microseconds= (int64_t) (option_limits->def_value * 1000000.0);
 
2668
  longlong microseconds= (longlong) (option_limits->def_value * 1000000.0);
2349
2669
  if (type == OPT_GLOBAL)
2350
2670
  {
2351
2671
    pthread_mutex_lock(&LOCK_global_system_variables);
2357
2677
}
2358
2678
 
2359
2679
 
2360
 
unsigned char *sys_var_microseconds::value_ptr(THD *thd, enum_var_type type,
2361
 
                                          LEX_STRING *base __attribute__((unused)))
 
2680
uchar *sys_var_microseconds::value_ptr(THD *thd, enum_var_type type,
 
2681
                                          LEX_STRING *base)
2362
2682
{
2363
2683
  thd->tmp_double_value= (double) ((type == OPT_GLOBAL) ?
2364
2684
                                   global_system_variables.*offset :
2365
2685
                                   thd->variables.*offset) / 1000000.0;
2366
 
  return (unsigned char*) &thd->tmp_double_value;
 
2686
  return (uchar*) &thd->tmp_double_value;
2367
2687
}
2368
2688
 
2369
2689
 
2386
2706
{
2387
2707
  /* The test is negative as the flag we use is NOT autocommit */
2388
2708
 
2389
 
  uint64_t org_options= thd->options;
 
2709
  ulonglong org_options= thd->options;
2390
2710
 
2391
2711
  if (var->save_result.ulong_value != 0)
2392
2712
    thd->options&= ~((sys_var_thd_bit*) var->var)->bit_flag;
2398
2718
    if ((org_options & OPTION_NOT_AUTOCOMMIT))
2399
2719
    {
2400
2720
      /* We changed to auto_commit mode */
2401
 
      thd->options&= ~(uint64_t) (OPTION_BEGIN | OPTION_KEEP_LOG);
2402
 
      thd->transaction.all.modified_non_trans_table= false;
 
2721
      thd->options&= ~(ulonglong) (OPTION_BEGIN | OPTION_KEEP_LOG);
 
2722
      thd->transaction.all.modified_non_trans_table= FALSE;
2403
2723
      thd->server_status|= SERVER_STATUS_AUTOCOMMIT;
2404
2724
      if (ha_commit(thd))
2405
2725
        return 1;
2406
2726
    }
2407
2727
    else
2408
2728
    {
2409
 
      thd->transaction.all.modified_non_trans_table= false;
 
2729
      thd->transaction.all.modified_non_trans_table= FALSE;
2410
2730
      thd->server_status&= ~SERVER_STATUS_AUTOCOMMIT;
2411
2731
    }
2412
2732
  }
2413
2733
  return 0;
2414
2734
}
2415
2735
 
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)),
2424
 
                                  set_var *var)
2425
 
{
2426
 
  var->save_result.uint64_t_value= var->value->val_int();
2427
 
  return 0;
2428
 
}
2429
 
 
2430
 
static unsigned char *get_warning_count(THD *thd)
 
2736
static int check_log_update(THD *thd, set_var *var)
 
2737
{
 
2738
  return 0;
 
2739
}
 
2740
 
 
2741
static bool set_log_update(THD *thd, set_var *var)
 
2742
{
 
2743
  /*
 
2744
    The update log is not supported anymore since 5.0.
 
2745
    See sql/mysqld.cc/, comments in function init_server_components() for an
 
2746
    explaination of the different warnings we send below
 
2747
  */
 
2748
 
 
2749
  if (opt_sql_bin_update)
 
2750
  {
 
2751
    push_warning(thd, MYSQL_ERROR::WARN_LEVEL_NOTE,
 
2752
                 ER_UPDATE_LOG_DEPRECATED_TRANSLATED,
 
2753
                 ER(ER_UPDATE_LOG_DEPRECATED_TRANSLATED));
 
2754
  }
 
2755
  else
 
2756
    push_warning(thd, MYSQL_ERROR::WARN_LEVEL_NOTE,
 
2757
                 ER_UPDATE_LOG_DEPRECATED_IGNORED,
 
2758
                 ER(ER_UPDATE_LOG_DEPRECATED_IGNORED));
 
2759
  set_option_bit(thd, var);
 
2760
  return 0;
 
2761
}
 
2762
 
 
2763
 
 
2764
static int check_pseudo_thread_id(THD *thd, set_var *var)
 
2765
{
 
2766
  var->save_result.ulonglong_value= var->value->val_int();
 
2767
  return 0;
 
2768
}
 
2769
 
 
2770
static uchar *get_warning_count(THD *thd)
2431
2771
{
2432
2772
  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;
 
2773
    (thd->warn_count[(uint) MYSQL_ERROR::WARN_LEVEL_NOTE] +
 
2774
     thd->warn_count[(uint) MYSQL_ERROR::WARN_LEVEL_ERROR] +
 
2775
     thd->warn_count[(uint) MYSQL_ERROR::WARN_LEVEL_WARN]);
 
2776
  return (uchar*) &thd->sys_var_tmp.long_value;
2437
2777
}
2438
2778
 
2439
 
static unsigned char *get_error_count(THD *thd)
 
2779
static uchar *get_error_count(THD *thd)
2440
2780
{
2441
2781
  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;
 
2782
    thd->warn_count[(uint) MYSQL_ERROR::WARN_LEVEL_ERROR];
 
2783
  return (uchar*) &thd->sys_var_tmp.long_value;
2444
2784
}
2445
2785
 
2446
2786
 
2458
2798
  @retval
2459
2799
    ptr         pointer to NUL-terminated string
2460
2800
*/
2461
 
static unsigned char *get_tmpdir(THD *thd __attribute__((unused)))
 
2801
static uchar *get_tmpdir(THD *thd)
2462
2802
{
2463
2803
  if (opt_mysql_tmpdir)
2464
 
    return (unsigned char *)opt_mysql_tmpdir;
2465
 
  return (unsigned char*)mysql_tmpdir;
 
2804
    return (uchar *)opt_mysql_tmpdir;
 
2805
  return (uchar*)mysql_tmpdir;
2466
2806
}
2467
2807
 
2468
2808
/****************************************************************************
2487
2827
 
2488
2828
static struct my_option *find_option(struct my_option *opt, const char *name) 
2489
2829
{
2490
 
  uint32_t length=strlen(name);
 
2830
  uint length=strlen(name);
2491
2831
  for (; opt->name; opt++)
2492
2832
  {
2493
2833
    if (!getopt_compare_strings(opt->name, name, length) &&
2508
2848
  Return variable name and length for hashing of variables.
2509
2849
*/
2510
2850
 
2511
 
static unsigned char *get_sys_var_length(const sys_var *var, size_t *length,
2512
 
                                 bool first __attribute__((unused)))
 
2851
static uchar *get_sys_var_length(const sys_var *var, size_t *length,
 
2852
                                 my_bool first)
2513
2853
{
2514
2854
  *length= var->name_length;
2515
 
  return (unsigned char*) var->name;
 
2855
  return (uchar*) var->name;
2516
2856
}
2517
2857
 
2518
2858
 
2540
2880
  {
2541
2881
    var->name_length= strlen(var->name);
2542
2882
    /* this fails if there is a conflicting variable name. see HASH_UNIQUE */
2543
 
    if (my_hash_insert(&system_variable_hash, (unsigned char*) var))
 
2883
    if (my_hash_insert(&system_variable_hash, (uchar*) var))
2544
2884
      goto error;
2545
2885
    if (long_options)
2546
2886
      var->option_limits= find_option(long_options, var->name);
2549
2889
 
2550
2890
error:
2551
2891
  for (; first != var; first= first->next)
2552
 
    hash_delete(&system_variable_hash, (unsigned char*) first);
 
2892
    hash_delete(&system_variable_hash, (uchar*) first);
2553
2893
  return 1;
2554
2894
}
2555
2895
 
2573
2913
  /* A write lock should be held on LOCK_system_variables_hash */
2574
2914
   
2575
2915
  for (sys_var *var= first; var; var= var->next)
2576
 
    result|= hash_delete(&system_variable_hash, (unsigned char*) var);
 
2916
    result|= hash_delete(&system_variable_hash, (uchar*) var);
2577
2917
 
2578
2918
  return result;
2579
2919
}
2625
2965
               (qsort_cmp) show_cmp);
2626
2966
    
2627
2967
    /* make last element empty */
2628
 
    memset(show, 0, sizeof(SHOW_VAR));
 
2968
    bzero(show, sizeof(SHOW_VAR));
2629
2969
  }
2630
2970
  return result;
2631
2971
}
2644
2984
 
2645
2985
int set_var_init()
2646
2986
{
2647
 
  uint32_t count= 0;
 
2987
  uint count= 0;
 
2988
  DBUG_ENTER("set_var_init");
2648
2989
  
2649
2990
  for (sys_var *var=vars.first; var; var= var->next, count++) {};
2650
2991
 
2663
3004
  if (mysql_add_sys_var_chain(vars.first, my_long_options))
2664
3005
    goto error;
2665
3006
 
2666
 
  return(0);
 
3007
  /*
 
3008
    Special cases
 
3009
    Needed because MySQL can't find the limits for a variable it it has
 
3010
    a different name than the command line option.
 
3011
    As these variables are deprecated, this code will disappear soon...
 
3012
  */
 
3013
  sys_sql_max_join_size.option_limits= sys_max_join_size.option_limits;
 
3014
 
 
3015
  DBUG_RETURN(0);
2667
3016
 
2668
3017
error:
2669
3018
  fprintf(stderr, "failed to initialize system variables");
2670
 
  return(1);
 
3019
  DBUG_RETURN(1);
2671
3020
}
2672
3021
 
2673
3022
 
2690
3039
    0           SUCCESS
2691
3040
    otherwise   FAILURE
2692
3041
*/
2693
 
int mysql_append_static_vars(const SHOW_VAR *show_vars, uint32_t count)
 
3042
int mysql_append_static_vars(const SHOW_VAR *show_vars, uint count)
2694
3043
{
2695
3044
  for (; count > 0; count--, show_vars++)
2696
 
    if (insert_dynamic(&fixed_show_vars, (unsigned char*) show_vars))
 
3045
    if (insert_dynamic(&fixed_show_vars, (uchar*) show_vars))
2697
3046
      return 1;
2698
3047
  return 0;
2699
3048
}
2713
3062
    0           Unknown variable (error message is given)
2714
3063
*/
2715
3064
 
2716
 
sys_var *intern_find_sys_var(const char *str, uint32_t length, bool no_error)
 
3065
sys_var *intern_find_sys_var(const char *str, uint length, bool no_error)
2717
3066
{
2718
3067
  sys_var *var;
2719
3068
 
2722
3071
    A lock on LOCK_system_variable_hash should be held
2723
3072
  */
2724
3073
  var= (sys_var*) hash_search(&system_variable_hash,
2725
 
                              (unsigned char*) str, length ? length : strlen(str));
 
3074
                              (uchar*) str, length ? length : strlen(str));
2726
3075
  if (!(var || no_error))
2727
3076
    my_error(ER_UNKNOWN_SYSTEM_VARIABLE, MYF(0), (char*) str);
2728
3077
 
2754
3103
{
2755
3104
  int error;
2756
3105
  List_iterator_fast<set_var_base> it(*var_list);
 
3106
  DBUG_ENTER("sql_set_variables");
2757
3107
 
2758
3108
  set_var_base *var;
2759
3109
  while ((var=it++))
2770
3120
 
2771
3121
err:
2772
3122
  free_underlaid_joins(thd, &thd->lex->select_lex);
2773
 
  return(error);
 
3123
  DBUG_RETURN(error);
2774
3124
}
2775
3125
 
2776
3126
 
2881
3231
}
2882
3232
 
2883
3233
 
2884
 
int set_var_user::update(THD *thd __attribute__((unused)))
 
3234
int set_var_user::update(THD *thd)
2885
3235
{
2886
3236
  if (user_var_item->update())
2887
3237
  {
2902
3252
{
2903
3253
  char buff[STRING_BUFFER_USUAL_SIZE];
2904
3254
  const char *value;
2905
 
  String str(buff, sizeof(buff), &my_charset_utf8_general_ci), *res;
 
3255
  String str(buff, sizeof(buff), &my_charset_latin1), *res;
2906
3256
 
2907
3257
  var->save_result.plugin= NULL;
2908
3258
  if (var->value->result_type() == STRING_RESULT)
2913
3263
        !(engine_name.str= (char *)res->ptr()) ||
2914
3264
        !(engine_name.length= res->length()) ||
2915
3265
        !(var->save_result.plugin= ha_resolve_by_name(thd, &engine_name)) ||
2916
 
        !(hton= plugin_data(var->save_result.plugin, handlerton *)))
 
3266
        !(hton= plugin_data(var->save_result.plugin, handlerton *)) ||
 
3267
        ha_checktype(thd, ha_legacy_type(hton), 1, 0) != hton)
2917
3268
    {
2918
3269
      value= res ? res->c_ptr() : "NULL";
2919
3270
      goto err;
2928
3279
}
2929
3280
 
2930
3281
 
2931
 
unsigned char *sys_var_thd_storage_engine::value_ptr(THD *thd, enum_var_type type,
2932
 
                                             LEX_STRING *base __attribute__((unused)))
 
3282
uchar *sys_var_thd_storage_engine::value_ptr(THD *thd, enum_var_type type,
 
3283
                                            LEX_STRING *base)
2933
3284
{
2934
 
  unsigned char* result;
 
3285
  uchar* result;
2935
3286
  handlerton *hton;
2936
3287
  LEX_STRING *engine_name;
2937
3288
  plugin_ref plugin= thd->variables.*offset;
2939
3290
    plugin= my_plugin_lock(thd, &(global_system_variables.*offset));
2940
3291
  hton= plugin_data(plugin, handlerton*);
2941
3292
  engine_name= &hton2plugin[hton->slot]->name;
2942
 
  result= (unsigned char *) thd->strmake(engine_name->str, engine_name->length);
 
3293
  result= (uchar *) thd->strmake(engine_name->str, engine_name->length);
2943
3294
  if (type == OPT_GLOBAL)
2944
3295
    plugin_unlock(thd, plugin);
2945
3296
  return result;
2959
3310
    value= &(thd->variables.*offset);
2960
3311
    new_value= my_plugin_lock(NULL, &(global_system_variables.*offset));
2961
3312
  }
2962
 
  assert(new_value);
 
3313
  DBUG_ASSERT(new_value);
2963
3314
  old_value= *value;
2964
3315
  *value= new_value;
2965
3316
  plugin_unlock(NULL, old_value);
2982
3333
 
2983
3334
bool
2984
3335
sys_var_thd_optimizer_switch::
2985
 
symbolic_mode_representation(THD *thd, uint64_t val, LEX_STRING *rep)
 
3336
symbolic_mode_representation(THD *thd, ulonglong val, LEX_STRING *rep)
2986
3337
{
2987
3338
  char buff[STRING_BUFFER_USUAL_SIZE*8];
2988
 
  String tmp(buff, sizeof(buff), &my_charset_utf8_general_ci);
 
3339
  String tmp(buff, sizeof(buff), &my_charset_latin1);
2989
3340
 
2990
3341
  tmp.length(0);
2991
3342
 
2992
 
  for (uint32_t i= 0; val; val>>= 1, i++)
 
3343
  for (uint i= 0; val; val>>= 1, i++)
2993
3344
  {
2994
3345
    if (val & 1)
2995
3346
    {
3010
3361
}
3011
3362
 
3012
3363
 
3013
 
unsigned char *sys_var_thd_optimizer_switch::value_ptr(THD *thd, enum_var_type type,
3014
 
                                               LEX_STRING *base __attribute__((unused)))
 
3364
uchar *sys_var_thd_optimizer_switch::value_ptr(THD *thd, enum_var_type type,
 
3365
                                               LEX_STRING *base)
3015
3366
{
3016
3367
  LEX_STRING opts;
3017
 
  uint64_t val= ((type == OPT_GLOBAL) ? global_system_variables.*offset :
 
3368
  ulonglong val= ((type == OPT_GLOBAL) ? global_system_variables.*offset :
3018
3369
                  thd->variables.*offset);
3019
3370
  (void) symbolic_mode_representation(thd, val, &opts);
3020
 
  return (unsigned char *) opts.str;
 
3371
  return (uchar *) opts.str;
3021
3372
}
3022
3373
 
3023
3374
 
3034
3385
  Named list handling
3035
3386
****************************************************************************/
3036
3387
 
3037
 
unsigned char* find_named(I_List<NAMED_LIST> *list, const char *name, uint32_t length,
 
3388
uchar* find_named(I_List<NAMED_LIST> *list, const char *name, uint length,
3038
3389
                NAMED_LIST **found)
3039
3390
{
3040
3391
  I_List_iterator<NAMED_LIST> it(*list);
3053
3404
 
3054
3405
 
3055
3406
void delete_elements(I_List<NAMED_LIST> *list,
3056
 
                     void (*free_element)(const char *name, unsigned char*))
 
3407
                     void (*free_element)(const char *name, uchar*))
3057
3408
{
3058
3409
  NAMED_LIST *element;
 
3410
  DBUG_ENTER("delete_elements");
3059
3411
  while ((element= list->get()))
3060
3412
  {
3061
3413
    (*free_element)(element->name, element->data);
3062
3414
    delete element;
3063
3415
  }
3064
 
  return;
 
3416
  DBUG_VOID_RETURN;
3065
3417
}
3066
3418
 
3067
3419
 
3068
3420
/* Key cache functions */
3069
3421
 
3070
 
static KEY_CACHE *create_key_cache(const char *name, uint32_t length)
 
3422
static KEY_CACHE *create_key_cache(const char *name, uint length)
3071
3423
{
3072
3424
  KEY_CACHE *key_cache;
 
3425
  DBUG_ENTER("create_key_cache");
 
3426
  DBUG_PRINT("enter",("name: %.*s", length, name));
3073
3427
  
3074
3428
  if ((key_cache= (KEY_CACHE*) my_malloc(sizeof(KEY_CACHE),
3075
3429
                                             MYF(MY_ZEROFILL | MY_WME))))
3076
3430
  {
3077
 
    if (!new NAMED_LIST(&key_caches, name, length, (unsigned char*) key_cache))
 
3431
    if (!new NAMED_LIST(&key_caches, name, length, (uchar*) key_cache))
3078
3432
    {
3079
 
      free((char*) key_cache);
 
3433
      my_free((char*) key_cache, MYF(0));
3080
3434
      key_cache= 0;
3081
3435
    }
3082
3436
    else
3092
3446
      key_cache->param_age_threshold=  dflt_key_cache_var.param_age_threshold;
3093
3447
    }
3094
3448
  }
3095
 
  return(key_cache);
 
3449
  DBUG_RETURN(key_cache);
3096
3450
}
3097
3451
 
3098
3452
 
3099
 
KEY_CACHE *get_or_create_key_cache(const char *name, uint32_t length)
 
3453
KEY_CACHE *get_or_create_key_cache(const char *name, uint length)
3100
3454
{
3101
3455
  LEX_STRING key_cache_name;
3102
3456
  KEY_CACHE *key_cache;
3111
3465
}
3112
3466
 
3113
3467
 
3114
 
void free_key_cache(const char *name __attribute__((unused)),
3115
 
                    KEY_CACHE *key_cache)
 
3468
void free_key_cache(const char *name, KEY_CACHE *key_cache)
3116
3469
{
3117
3470
  ha_end_key_cache(key_cache);
3118
 
  free((char*) key_cache);
 
3471
  my_free((char*) key_cache, MYF(0));
3119
3472
}
3120
3473
 
3121
3474
 
3137
3490
{
3138
3491
  bool result;
3139
3492
 
 
3493
  DBUG_ENTER("sys_var_opt_readonly::update");
 
3494
 
3140
3495
  /* Prevent self dead-lock */
3141
3496
  if (thd->locked_tables || thd->active_transaction())
3142
3497
  {
3143
3498
    my_error(ER_LOCK_OR_ACTIVE_TRANSACTION, MYF(0));
3144
 
    return(true);
 
3499
    DBUG_RETURN(true);
3145
3500
  }
3146
3501
 
3147
3502
  if (thd->global_read_lock)
3153
3508
      - SET GLOBAL READ_ONLY = 1
3154
3509
    */
3155
3510
    result= sys_var_bool_ptr::update(thd, var);
3156
 
    return(result);
 
3511
    DBUG_RETURN(result);
3157
3512
  }
3158
3513
 
3159
3514
  /*
3168
3523
  */
3169
3524
 
3170
3525
  if (lock_global_read_lock(thd))
3171
 
    return(true);
 
3526
    DBUG_RETURN(true);
3172
3527
 
3173
3528
  /*
3174
3529
    This call will be blocked by any connection holding a READ or WRITE lock.
3179
3534
    can cause to wait on a read lock, it's required for the client application
3180
3535
    to unlock everything, and acceptable for the server to wait on all locks.
3181
3536
  */
3182
 
  if ((result= close_cached_tables(thd, NULL, false, true, true)) == true)
 
3537
  if ((result= close_cached_tables(thd, NULL, FALSE, TRUE, TRUE)) == true)
3183
3538
    goto end_with_read_lock;
3184
3539
 
3185
3540
  if ((result= make_global_read_lock_block_commit(thd)) == true)
3191
3546
end_with_read_lock:
3192
3547
  /* Release the lock */
3193
3548
  unlock_global_read_lock(thd);
3194
 
  return(result);
 
3549
  DBUG_RETURN(result);
 
3550
}
 
3551
 
 
3552
bool sys_var_thd_dbug::update(THD *thd, set_var *var)
 
3553
{
 
3554
  if (var->type == OPT_GLOBAL)
 
3555
  {
 
3556
    DBUG_SET_INITIAL(var ? var->value->str_value.c_ptr() : "");
 
3557
  }
 
3558
  else
 
3559
  {
 
3560
    DBUG_SET(var ? var->value->str_value.c_ptr() : "");
 
3561
  }
 
3562
 
 
3563
  return 0;
 
3564
}
 
3565
 
 
3566
 
 
3567
uchar *sys_var_thd_dbug::value_ptr(THD *thd, enum_var_type type, LEX_STRING *b)
 
3568
{
 
3569
  char buf[256];
 
3570
  if (type == OPT_GLOBAL)
 
3571
  {
 
3572
    DBUG_EXPLAIN_INITIAL(buf, sizeof(buf));
 
3573
  }
 
3574
  else
 
3575
  {
 
3576
    DBUG_EXPLAIN(buf, sizeof(buf));
 
3577
  }
 
3578
  return (uchar*) thd->strdup(buf);
3195
3579
}
3196
3580
 
3197
3581
/****************************************************************************