~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/set_var.cc

  • Committer: Andy Lester
  • Date: 2008-08-09 05:13:22 UTC
  • mto: (266.1.29 use-replace-funcs)
  • mto: This revision was merged to the branch mainline in revision 287.
  • Revision ID: andy@petdance.com-20080809051322-dzas70no2mv6c9i5
removed incorrect comment

Show diffs side-by-side

added added

removed removed

Lines of Context:
52
52
#include <mysys/thr_alarm.h>
53
53
#include <storage/myisam/myisam.h>
54
54
#include <drizzled/drizzled_error_messages.h>
55
 
#include <libdrizzle/gettext.h>
56
55
 
57
56
extern const CHARSET_INFO *character_set_filesystem;
58
57
 
60
59
static DYNAMIC_ARRAY fixed_show_vars;
61
60
static HASH system_variable_hash;
62
61
 
63
 
const char *bool_type_names[]= { "OFF", "ON", NULL };
 
62
const char *bool_type_names[]= { "OFF", "ON", NullS };
64
63
TYPELIB bool_typelib=
65
64
{
66
65
  array_elements(bool_type_names)-1, "", bool_type_names, NULL
67
66
};
68
67
 
69
 
const char *delay_key_write_type_names[]= { "OFF", "ON", "ALL", NULL };
 
68
const char *delay_key_write_type_names[]= { "OFF", "ON", "ALL", NullS };
70
69
TYPELIB delay_key_write_typelib=
71
70
{
72
71
  array_elements(delay_key_write_type_names)-1, "",
74
73
};
75
74
 
76
75
const char *slave_exec_mode_names[]=
77
 
{ "STRICT", "IDEMPOTENT", NULL };
 
76
{ "STRICT", "IDEMPOTENT", NullS };
78
77
static const unsigned int slave_exec_mode_names_len[]=
79
78
{ sizeof("STRICT") - 1, sizeof("IDEMPOTENT") - 1, 0 };
80
79
TYPELIB slave_exec_mode_typelib=
90
89
static bool set_option_bit(THD *thd, set_var *var);
91
90
static bool set_option_autocommit(THD *thd, set_var *var);
92
91
static int  check_log_update(THD *thd, set_var *var);
 
92
static bool set_log_update(THD *thd, set_var *var);
93
93
static int  check_pseudo_thread_id(THD *thd, set_var *var);
94
94
static void fix_low_priority_updates(THD *thd, enum_var_type type);
95
95
static int check_tx_isolation(THD *thd, set_var *var);
111
111
static bool get_unsigned(THD *thd, set_var *var);
112
112
bool throw_bounds_warning(THD *thd, bool fixed, bool unsignd,
113
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);
 
114
static KEY_CACHE *create_key_cache(const char *name, uint length);
 
115
static uchar *get_error_count(THD *thd);
 
116
static uchar *get_warning_count(THD *thd);
 
117
static uchar *get_tmpdir(THD *thd);
 
118
static int  sys_check_log_path(THD *thd,  set_var *var);
 
119
static bool sys_update_general_log_path(THD *thd, set_var * var);
 
120
static void sys_default_general_log_path(THD *thd, enum_var_type type);
 
121
static bool sys_update_slow_log_path(THD *thd, set_var * var);
 
122
static void sys_default_slow_log_path(THD *thd, enum_var_type type);
118
123
 
119
124
/*
120
125
  Variable definition list
144
149
                                            &SV::binlog_format);
145
150
static sys_var_thd_ulong        sys_bulk_insert_buff_size(&vars, "bulk_insert_buffer_size",
146
151
                                                  &SV::bulk_insert_buff_size);
 
152
static sys_var_character_set_sv
 
153
sys_character_set_server(&vars, "character_set_server",
 
154
                         &SV::collation_server, &default_charset_info, 0,
 
155
                         sys_var::SESSION_VARIABLE_IN_BINLOG);
 
156
sys_var_const_str       sys_charset_system(&vars, "character_set_system",
 
157
                                           (char *)my_charset_utf8_general_ci.name);
 
158
static sys_var_character_set_database
 
159
sys_character_set_database(&vars, "character_set_database",
 
160
                           sys_var::SESSION_VARIABLE_IN_BINLOG);
 
161
static sys_var_character_set_client
 
162
sys_character_set_client(&vars, "character_set_client",
 
163
                         &SV::character_set_client,
 
164
                         &default_charset_info,
 
165
                         sys_var::SESSION_VARIABLE_IN_BINLOG);
 
166
static sys_var_character_set_sv
 
167
sys_character_set_connection(&vars, "character_set_connection",
 
168
                             &SV::collation_connection,
 
169
                             &default_charset_info, 0,
 
170
                             sys_var::SESSION_VARIABLE_IN_BINLOG);
 
171
static sys_var_character_set_sv sys_character_set_results(&vars, "character_set_results",
 
172
                                        &SV::character_set_results,
 
173
                                        &default_charset_info, true);
 
174
static sys_var_character_set_sv sys_character_set_filesystem(&vars, "character_set_filesystem",
 
175
                                        &SV::character_set_filesystem,
 
176
                                        &character_set_filesystem);
147
177
static sys_var_thd_ulong        sys_completion_type(&vars, "completion_type",
148
178
                                         &SV::completion_type,
149
179
                                         check_completion_type,
160
190
sys_collation_server(&vars, "collation_server", &SV::collation_server,
161
191
                     &default_charset_info,
162
192
                     sys_var::SESSION_VARIABLE_IN_BINLOG);
 
193
static sys_var_long_ptr sys_concurrent_insert(&vars, "concurrent_insert",
 
194
                                              &myisam_concurrent_insert);
163
195
static sys_var_long_ptr sys_connect_timeout(&vars, "connect_timeout",
164
196
                                            &connect_timeout);
165
197
static sys_var_const_str       sys_datadir(&vars, "datadir", mysql_real_data_home);
193
225
                                                              param_age_threshold));
194
226
static sys_var_bool_ptr sys_local_infile(&vars, "local_infile",
195
227
                                         &opt_local_infile);
 
228
static sys_var_bool_ptr
 
229
  sys_log_queries_not_using_indexes(&vars, "log_queries_not_using_indexes",
 
230
                                    &opt_log_queries_not_using_indexes);
 
231
static sys_var_thd_ulong        sys_log_warnings(&vars, "log_warnings", &SV::log_warnings);
 
232
static sys_var_microseconds     sys_var_long_query_time(&vars, "long_query_time",
 
233
                                                        &SV::long_query_time);
196
234
static sys_var_thd_bool sys_low_priority_updates(&vars, "low_priority_updates",
197
235
                                                 &SV::low_priority_updates,
198
236
                                                 fix_low_priority_updates);
240
278
                                                 &max_write_lock_count);
241
279
static sys_var_thd_ulong       sys_min_examined_row_limit(&vars, "min_examined_row_limit",
242
280
                                                          &SV::min_examined_row_limit);
 
281
static sys_var_long_ptr sys_myisam_data_pointer_size(&vars, "myisam_data_pointer_size",
 
282
                                                    &myisam_data_pointer_size);
243
283
static sys_var_thd_uint64_t     sys_myisam_max_sort_file_size(&vars, "myisam_max_sort_file_size", &SV::myisam_max_sort_file_size, fix_myisam_max_sort_file_size, 1);
244
284
static sys_var_thd_ulong       sys_myisam_repair_threads(&vars, "myisam_repair_threads", &SV::myisam_repair_threads);
245
285
static sys_var_thd_ulong        sys_myisam_sort_buffer_size(&vars, "myisam_sort_buffer_size", &SV::myisam_sort_buff_size);
270
310
static sys_var_thd_ulong        sys_optimizer_search_depth(&vars, "optimizer_search_depth",
271
311
                                                   &SV::optimizer_search_depth);
272
312
 
273
 
const char *optimizer_use_mrr_names[] = {"auto", "force", "disable", NULL};
 
313
const char *optimizer_use_mrr_names[] = {"auto", "force", "disable", NullS};
274
314
TYPELIB optimizer_use_mrr_typelib= {
275
315
  array_elements(optimizer_use_mrr_names) - 1, "",
276
316
  optimizer_use_mrr_names, NULL
290
330
                                               &SV::read_rnd_buff_size);
291
331
static sys_var_thd_ulong        sys_div_precincrement(&vars, "div_precision_increment",
292
332
                                              &SV::div_precincrement);
 
333
static sys_var_long_ptr sys_rpl_recovery_rank(&vars, "rpl_recovery_rank",
 
334
                                              &rpl_recovery_rank);
293
335
 
294
336
static sys_var_thd_ulong        sys_range_alloc_block_size(&vars, "range_alloc_block_size",
295
337
                                                   &SV::range_alloc_block_size);
307
349
                                                &SV::trans_prealloc_size,
308
350
                                                0, fix_trans_mem_root);
309
351
 
 
352
static sys_var_bool_ptr sys_secure_auth(&vars, "secure_auth", &opt_secure_auth);
310
353
static sys_var_const_str_ptr sys_secure_file_priv(&vars, "secure_file_priv",
311
354
                                             &opt_secure_file_priv);
312
355
static sys_var_long_ptr sys_server_id(&vars, "server_id", &server_id, fix_server_id);
313
356
static sys_var_bool_ptr sys_slave_compressed_protocol(&vars, "slave_compressed_protocol",
314
357
                                                      &opt_slave_compressed_protocol);
 
358
#ifdef HAVE_REPLICATION
315
359
static sys_var_bool_ptr         sys_slave_allow_batching(&vars, "slave_allow_batching",
316
360
                                                         &slave_allow_batching);
317
361
static sys_var_set_slave_mode slave_exec_mode(&vars,
319
363
                                              &slave_exec_mode_options,
320
364
                                              &slave_exec_mode_typelib,
321
365
                                              0);
 
366
#endif
322
367
static sys_var_long_ptr sys_slow_launch_time(&vars, "slow_launch_time",
323
368
                                             &slow_launch_time);
324
369
static sys_var_thd_ulong        sys_sort_buffer(&vars, "sort_buffer_size",
331
376
*/
332
377
static sys_var_thd_optimizer_switch   sys_optimizer_switch(&vars, "optimizer_switch",
333
378
                                     &SV::optimizer_switch);
 
379
static sys_var_const_str        sys_ssl_ca(&vars, "ssl_ca", NULL);
 
380
static sys_var_const_str        sys_ssl_capath(&vars, "ssl_capath", NULL);
 
381
static sys_var_const_str        sys_ssl_cert(&vars, "ssl_cert", NULL);
 
382
static sys_var_const_str        sys_ssl_cipher(&vars, "ssl_cipher", NULL);
 
383
static sys_var_const_str        sys_ssl_key(&vars, "ssl_key", NULL);
334
384
 
335
385
static sys_var_thd_storage_engine sys_storage_engine(&vars, "storage_engine",
336
386
                                       &SV::table_plugin);
 
387
static sys_var_bool_ptr sys_sync_frm(&vars, "sync_frm", &opt_sync_frm);
337
388
static sys_var_const_str        sys_system_time_zone(&vars, "system_time_zone",
338
389
                                             system_time_zone);
339
390
static sys_var_long_ptr sys_table_def_size(&vars, "table_definition_cache",
356
407
static sys_var_bool_ptr  sys_timed_mutexes(&vars, "timed_mutexes", &timed_mutexes);
357
408
static sys_var_const_str        sys_version(&vars, "version", server_version);
358
409
static sys_var_const_str        sys_version_comment(&vars, "version_comment",
359
 
                                            DRIZZLE_COMPILATION_COMMENT);
 
410
                                            MYSQL_COMPILATION_COMMENT);
360
411
static sys_var_const_str        sys_version_compile_machine(&vars, "version_compile_machine",
361
412
                                                    MACHINE_TYPE);
362
413
static sys_var_const_str        sys_version_compile_os(&vars, "version_compile_os",
398
449
static sys_var_thd_bit  sys_big_selects(&vars, "sql_big_selects", 0,
399
450
                                        set_option_bit,
400
451
                                        OPTION_BIG_SELECTS);
 
452
static sys_var_thd_bit  sys_log_off(&vars, "sql_log_off",
 
453
                                    check_log_update,
 
454
                                    set_option_bit,
 
455
                                    OPTION_LOG_OFF);
 
456
static sys_var_thd_bit  sys_log_update(&vars, "sql_log_update",
 
457
                                       check_log_update,
 
458
                                       set_log_update,
 
459
                                       OPTION_BIN_LOG);
401
460
static sys_var_thd_bit  sys_log_binlog(&vars, "sql_log_bin",
402
461
                                       check_log_update,
403
462
                                       set_option_bit,
408
467
static sys_var_thd_bit  sys_sql_notes(&vars, "sql_notes", 0,
409
468
                                         set_option_bit,
410
469
                                         OPTION_SQL_NOTES);
 
470
static sys_var_thd_bit  sys_auto_is_null(&vars, "sql_auto_is_null", 0,
 
471
                                         set_option_bit,
 
472
                                         OPTION_AUTO_IS_NULL, 0,
 
473
                                         sys_var::SESSION_VARIABLE_IN_BINLOG);
411
474
static sys_var_thd_bit  sys_safe_updates(&vars, "sql_safe_updates", 0,
412
475
                                         set_option_bit,
413
476
                                         OPTION_SAFE_UPDATES);
495
558
static sys_var_const_str_ptr    sys_repl_report_user(&vars, "report_user", &report_user);
496
559
static sys_var_const_str_ptr    sys_repl_report_password(&vars, "report_password", &report_password);
497
560
 
498
 
static unsigned char *slave_get_report_port(THD *thd)
 
561
static uchar *slave_get_report_port(THD *thd)
499
562
{
500
563
  thd->sys_var_tmp.long_value= report_port;
501
 
  return (unsigned char*) &thd->sys_var_tmp.long_value;
 
564
  return (uchar*) &thd->sys_var_tmp.long_value;
502
565
}
503
566
 
504
567
static sys_var_readonly    sys_repl_report_port(&vars, "report_port", OPT_GLOBAL, SHOW_INT, slave_get_report_port);
509
572
 
510
573
static sys_var_have_variable sys_have_compress(&vars, "have_compress", &have_compress);
511
574
static sys_var_have_variable sys_have_symlink(&vars, "have_symlink", &have_symlink);
 
575
/* Global variables which enable|disable logging */
 
576
static sys_var_log_state sys_var_general_log(&vars, "general_log", &opt_log,
 
577
                                      QUERY_LOG_GENERAL);
 
578
/* Synonym of "general_log" for consistency with SHOW VARIABLES output */
 
579
static sys_var_log_state sys_var_log(&vars, "log", &opt_log, QUERY_LOG_GENERAL);
 
580
static sys_var_log_state sys_var_slow_query_log(&vars, "slow_query_log", &opt_slow_log,
 
581
                                         QUERY_LOG_SLOW);
 
582
/* Synonym of "slow_query_log" for consistency with SHOW VARIABLES output */
 
583
static sys_var_log_state sys_var_log_slow(&vars, "log_slow_queries",
 
584
                                          &opt_slow_log, QUERY_LOG_SLOW);
 
585
sys_var_str sys_var_general_log_path(&vars, "general_log_file", sys_check_log_path,
 
586
                                     sys_update_general_log_path,
 
587
                                     sys_default_general_log_path,
 
588
                                     opt_logname);
 
589
sys_var_str sys_var_slow_log_path(&vars, "slow_query_log_file", sys_check_log_path,
 
590
                                  sys_update_slow_log_path, 
 
591
                                  sys_default_slow_log_path,
 
592
                                  opt_slow_logname);
 
593
static sys_var_log_output sys_var_log_output_state(&vars, "log_output", &log_output_options,
 
594
                                            &log_output_typelib, 0);
 
595
 
 
596
 
512
597
/*
513
598
  Additional variables (not derived from sys_var class, not accessible as
514
599
  @@varname in SELECT or SET). Sorted in alphabetical order to facilitate
519
604
#define FIXED_VARS_SIZE (sizeof(fixed_vars) / sizeof(SHOW_VAR))
520
605
static SHOW_VAR fixed_vars[]= {
521
606
  {"back_log",                (char*) &back_log,                    SHOW_LONG},
 
607
  {"character_sets_dir",      mysql_charsets_dir,                   SHOW_CHAR},
522
608
  {"init_file",               (char*) &opt_init_file,               SHOW_CHAR_PTR},
523
609
  {"language",                language,                             SHOW_CHAR},
524
610
#ifdef HAVE_MLOCKALL
571
657
                        set_var *var)
572
658
{
573
659
  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);
 
660
  uint new_length= (var ? var->value->str_value.length() : 0);
575
661
  if (!old_value)
576
662
    old_value= (char*) "";
577
663
  if (!(res= my_strndup(old_value, new_length, MYF(0))))
585
671
  var_str->value= res;
586
672
  var_str->value_length= new_length;
587
673
  rw_unlock(var_mutex);
588
 
  free(old_value);
 
674
  my_free(old_value, MYF(MY_ALLOW_ZERO_PTR));
589
675
  return 0;
590
676
}
591
677
 
704
790
  If we are changing the thread variable, we have to copy it to NET too
705
791
*/
706
792
 
 
793
#ifdef HAVE_REPLICATION
707
794
static void fix_net_read_timeout(THD *thd, enum_var_type type)
708
795
{
709
796
  if (type != OPT_GLOBAL)
722
809
  if (type != OPT_GLOBAL)
723
810
    thd->net.retry_count=thd->variables.net_retry_count;
724
811
}
 
812
#else /* HAVE_REPLICATION */
 
813
static void fix_net_read_timeout(THD *thd __attribute__((unused)),
 
814
                                 enum_var_type type __attribute__((unused)))
 
815
{}
 
816
static void fix_net_write_timeout(THD *thd __attribute__((unused)),
 
817
                                  enum_var_type type __attribute__((unused)))
 
818
{}
 
819
static void fix_net_retry_count(THD *thd __attribute__((unused)),
 
820
                                enum_var_type type __attribute__((unused)))
 
821
{}
 
822
#endif /* HAVE_REPLICATION */
725
823
 
726
824
 
727
825
extern void fix_delay_key_write(THD *thd __attribute__((unused)),
748
846
  return 0;
749
847
}
750
848
 
751
 
unsigned char *sys_var_set::value_ptr(THD *thd,
 
849
uchar *sys_var_set::value_ptr(THD *thd,
752
850
                              enum_var_type type __attribute__((unused)),
753
851
                              LEX_STRING *base __attribute__((unused)))
754
852
{
755
853
  char buff[256];
756
 
  String tmp(buff, sizeof(buff), &my_charset_utf8_general_ci);
 
854
  String tmp(buff, sizeof(buff), &my_charset_latin1);
757
855
  ulong length;
758
856
  ulong val= *value;
759
857
 
760
858
  tmp.length(0);
761
 
  for (uint32_t i= 0; val; val>>= 1, i++)
 
859
  for (uint i= 0; val; val>>= 1, i++)
762
860
  {
763
861
    if (val & 1)
764
862
    {
770
868
 
771
869
  if ((length= tmp.length()))
772
870
    length--;
773
 
  return (unsigned char*) thd->strmake(tmp.ptr(), length);
 
871
  return (uchar*) thd->strmake(tmp.ptr(), length);
774
872
}
775
873
 
776
874
void sys_var_set_slave_mode::set_default(THD *thd __attribute__((unused)),
807
905
  if (bit_is_set(slave_exec_mode_options, SLAVE_EXEC_MODE_STRICT) == 1 &&
808
906
      bit_is_set(slave_exec_mode_options, SLAVE_EXEC_MODE_IDEMPOTENT) == 1)
809
907
  {
810
 
    sql_print_error(_("Ambiguous slave modes combination."
811
 
                    " STRICT will be used"));
 
908
    sql_print_error("Ambiguous slave modes combination."
 
909
                    " STRICT will be used");
812
910
    bit_do_clear(slave_exec_mode_options, SLAVE_EXEC_MODE_IDEMPOTENT);
813
911
  }
814
912
  if (bit_is_set(slave_exec_mode_options, SLAVE_EXEC_MODE_IDEMPOTENT) == 0)
838
936
    my_error(ER_TEMP_TABLE_PREVENTS_SWITCH_OUT_OF_RBR, MYF(0));
839
937
    return 1;
840
938
  }
841
 
  
 
939
  /*
 
940
    if in a stored function/trigger, it's too late to change mode
 
941
  */
 
942
  if (thd->in_sub_stmt)
 
943
  {
 
944
    my_error(ER_STORED_FUNCTION_PREVENTS_SWITCH_BINLOG_FORMAT, MYF(0));
 
945
    return 1;    
 
946
  }
842
947
  return sys_var_thd_enum::is_readonly();
843
948
}
844
949
 
854
959
                                enum_var_type type __attribute__((unused)))
855
960
{
856
961
  mysql_bin_log.set_max_size(max_binlog_size);
 
962
#ifdef HAVE_REPLICATION
857
963
  if (!max_relay_log_size)
858
964
    active_mi->rli.relay_log.set_max_size(max_binlog_size);
 
965
#endif
859
966
  return;
860
967
}
861
968
 
862
969
static void fix_max_relay_log_size(THD *thd __attribute__((unused)),
863
970
                                   enum_var_type type __attribute__((unused)))
864
971
{
 
972
#ifdef HAVE_REPLICATION
865
973
  active_mi->rli.relay_log.set_max_size(max_relay_log_size ?
866
974
                                        max_relay_log_size: max_binlog_size);
 
975
#endif
867
976
  return;
868
977
}
869
978
 
963
1072
    *value= (ulong) fix_unsigned(thd, tmp, option_limits);
964
1073
  else
965
1074
  {
966
 
    if (tmp > UINT32_MAX)
 
1075
#if SIZEOF_LONG < SIZEOF_LONG_LONG
 
1076
    /* Avoid overflows on 32 bit systems */
 
1077
    if (tmp > ULONG_MAX)
967
1078
    {
968
 
      tmp= UINT32_MAX;
 
1079
      tmp= ULONG_MAX;
969
1080
      throw_bounds_warning(thd, true, true, name,
970
1081
                           (int64_t) var->save_result.uint64_t_value);
971
1082
    }
 
1083
#endif
972
1084
    *value= (ulong) tmp;
973
1085
  }
974
1086
 
1031
1143
}
1032
1144
 
1033
1145
 
1034
 
unsigned char *sys_var_enum::value_ptr(THD *thd __attribute__((unused)),
 
1146
uchar *sys_var_enum::value_ptr(THD *thd __attribute__((unused)),
1035
1147
                               enum_var_type type __attribute__((unused)),
1036
1148
                               LEX_STRING *base __attribute__((unused)))
1037
1149
{
1038
 
  return (unsigned char*) enum_names->type_names[*value];
 
1150
  return (uchar*) enum_names->type_names[*value];
1039
1151
}
1040
1152
 
1041
1153
 
1042
 
unsigned char *sys_var_enum_const::value_ptr(THD *thd __attribute__((unused)),
 
1154
uchar *sys_var_enum_const::value_ptr(THD *thd __attribute__((unused)),
1043
1155
                                     enum_var_type type __attribute__((unused)),
1044
1156
                                     LEX_STRING *base __attribute__((unused)))
1045
1157
{
1046
 
  return (unsigned char*) enum_names->type_names[global_system_variables.*offset];
 
1158
  return (uchar*) enum_names->type_names[global_system_variables.*offset];
1047
1159
}
1048
1160
 
1049
1161
bool sys_var_thd_ulong::check(THD *thd, set_var *var)
1065
1177
  
1066
1178
  if (option_limits)
1067
1179
    tmp= (ulong) fix_unsigned(thd, tmp, option_limits);
1068
 
  else if (tmp > UINT32_MAX)
 
1180
#if SIZEOF_LONG < SIZEOF_LONG_LONG
 
1181
  else if (tmp > ULONG_MAX)
1069
1182
  {
1070
 
    tmp= UINT32_MAX;
 
1183
    tmp= ULONG_MAX;
1071
1184
    throw_bounds_warning(thd, true, true, name, (int64_t) var->save_result.uint64_t_value);
1072
1185
  }
 
1186
#endif
1073
1187
  
1074
1188
  if (var->type == OPT_GLOBAL)
1075
1189
     global_system_variables.*offset= (ulong) tmp;
1095
1209
 }
1096
1210
 
1097
1211
 
1098
 
unsigned char *sys_var_thd_ulong::value_ptr(THD *thd, enum_var_type type,
 
1212
uchar *sys_var_thd_ulong::value_ptr(THD *thd, enum_var_type type,
1099
1213
                                    LEX_STRING *base __attribute__((unused)))
1100
1214
{
1101
1215
  if (type == OPT_GLOBAL)
1102
 
    return (unsigned char*) &(global_system_variables.*offset);
1103
 
  return (unsigned char*) &(thd->variables.*offset);
 
1216
    return (uchar*) &(global_system_variables.*offset);
 
1217
  return (uchar*) &(thd->variables.*offset);
1104
1218
}
1105
1219
 
1106
1220
 
1144
1258
}
1145
1259
 
1146
1260
 
1147
 
unsigned char *sys_var_thd_ha_rows::value_ptr(THD *thd, enum_var_type type,
 
1261
uchar *sys_var_thd_ha_rows::value_ptr(THD *thd, enum_var_type type,
1148
1262
                                      LEX_STRING *base __attribute__((unused)))
1149
1263
{
1150
1264
  if (type == OPT_GLOBAL)
1151
 
    return (unsigned char*) &(global_system_variables.*offset);
1152
 
  return (unsigned char*) &(thd->variables.*offset);
 
1265
    return (uchar*) &(global_system_variables.*offset);
 
1266
  return (uchar*) &(thd->variables.*offset);
1153
1267
}
1154
1268
 
1155
1269
bool sys_var_thd_uint64_t::check(THD *thd, set_var *var)
1195
1309
}
1196
1310
 
1197
1311
 
1198
 
unsigned char *sys_var_thd_uint64_t::value_ptr(THD *thd, enum_var_type type,
 
1312
uchar *sys_var_thd_uint64_t::value_ptr(THD *thd, enum_var_type type,
1199
1313
                                        LEX_STRING *base __attribute__((unused)))
1200
1314
{
1201
1315
  if (type == OPT_GLOBAL)
1202
 
    return (unsigned char*) &(global_system_variables.*offset);
1203
 
  return (unsigned char*) &(thd->variables.*offset);
 
1316
    return (uchar*) &(global_system_variables.*offset);
 
1317
  return (uchar*) &(thd->variables.*offset);
1204
1318
}
1205
1319
 
1206
1320
 
1223
1337
}
1224
1338
 
1225
1339
 
1226
 
unsigned char *sys_var_thd_bool::value_ptr(THD *thd, enum_var_type type,
 
1340
uchar *sys_var_thd_bool::value_ptr(THD *thd, enum_var_type type,
1227
1341
                                   LEX_STRING *base __attribute__((unused)))
1228
1342
{
1229
1343
  if (type == OPT_GLOBAL)
1230
 
    return (unsigned char*) &(global_system_variables.*offset);
1231
 
  return (unsigned char*) &(thd->variables.*offset);
 
1344
    return (uchar*) &(global_system_variables.*offset);
 
1345
  return (uchar*) &(thd->variables.*offset);
1232
1346
}
1233
1347
 
1234
1348
 
1274
1388
{
1275
1389
  bool not_used;
1276
1390
  char buff[STRING_BUFFER_USUAL_SIZE], *error= 0;
1277
 
  uint32_t error_len= 0;
 
1391
  uint error_len= 0;
1278
1392
  String str(buff, sizeof(buff), system_charset_info), *res;
1279
1393
 
1280
1394
  if (var->value->result_type() == STRING_RESULT)
1281
1395
  {
1282
1396
    if (!(res= var->value->val_str(&str)))
1283
1397
    {
1284
 
      my_stpcpy(buff, "NULL");
 
1398
      strmov(buff, "NULL");
1285
1399
      goto err;
1286
1400
    }
1287
1401
 
1300
1414
                                            &not_used));
1301
1415
    if (error_len)
1302
1416
    {
1303
 
      strmake(buff, error, cmin(sizeof(buff) - 1, (ulong)error_len));
 
1417
      strmake(buff, error, min(sizeof(buff) - 1, error_len));
1304
1418
      goto err;
1305
1419
    }
1306
1420
  }
1320
1434
      For when the enum is made to contain 64 elements, as 1ULL<<64 is
1321
1435
      undefined, we guard with a "count<64" test.
1322
1436
    */
1323
 
    if (unlikely((tmp >= ((1UL) << enum_names->count)) &&
 
1437
    if (unlikely((tmp >= ((1ULL) << enum_names->count)) &&
1324
1438
                 (enum_names->count < 64)))
1325
1439
    {
1326
1440
      llstr(tmp, buff);
1360
1474
  switch (show_type()) {
1361
1475
  case SHOW_INT:
1362
1476
  {
1363
 
    uint32_t value;
 
1477
    uint value;
1364
1478
    pthread_mutex_lock(&LOCK_global_system_variables);
1365
1479
    value= *(uint*) value_ptr(thd, var_type, base);
1366
1480
    pthread_mutex_unlock(&LOCK_global_system_variables);
1414
1528
    char *str= *(char**) value_ptr(thd, var_type, base);
1415
1529
    if (str)
1416
1530
    {
1417
 
      uint32_t length= strlen(str);
 
1531
      uint length= strlen(str);
1418
1532
      tmp= new Item_string(thd->strmake(str, length), length,
1419
1533
                           system_charset_info, DERIVATION_SYSCONST);
1420
1534
    }
1468
1582
}
1469
1583
 
1470
1584
 
1471
 
unsigned char *sys_var_thd_enum::value_ptr(THD *thd, enum_var_type type,
 
1585
uchar *sys_var_thd_enum::value_ptr(THD *thd, enum_var_type type,
1472
1586
                                   LEX_STRING *base __attribute__((unused)))
1473
1587
{
1474
1588
  ulong tmp= ((type == OPT_GLOBAL) ?
1475
1589
              global_system_variables.*offset :
1476
1590
              thd->variables.*offset);
1477
 
  return (unsigned char*) enum_names->type_names[tmp];
 
1591
  return (uchar*) enum_names->type_names[tmp];
1478
1592
}
1479
1593
 
1480
1594
bool sys_var_thd_bit::check(THD *thd, set_var *var)
1490
1604
}
1491
1605
 
1492
1606
 
1493
 
unsigned char *sys_var_thd_bit::value_ptr(THD *thd,
 
1607
uchar *sys_var_thd_bit::value_ptr(THD *thd,
1494
1608
                                  enum_var_type type __attribute__((unused)),
1495
1609
                                  LEX_STRING *base __attribute__((unused)))
1496
1610
{
1500
1614
  */
1501
1615
  thd->sys_var_tmp.bool_value= ((thd->options & bit_flag) ?
1502
1616
                                   !reverse : reverse);
1503
 
  return (unsigned char*) &thd->sys_var_tmp.bool_value;
 
1617
  return (uchar*) &thd->sys_var_tmp.bool_value;
1504
1618
}
1505
1619
 
1506
1620
 
1523
1637
    old= (thd->variables.*offset);
1524
1638
    (thd->variables.*offset)= new_value;
1525
1639
  }
1526
 
  free((char*) old);
 
1640
  my_free((char*) old, MYF(MY_ALLOW_ZERO_PTR));
1527
1641
  return;
1528
1642
}
1529
1643
 
1562
1676
    update is aborted
1563
1677
  */
1564
1678
  var->save_result.date_time_format= date_time_format_copy(thd, format);
1565
 
  free((char*) format);
 
1679
  my_free((char*) format, MYF(0));
1566
1680
  return var->save_result.date_time_format == 0;
1567
1681
}
1568
1682
 
1588
1702
}
1589
1703
 
1590
1704
 
1591
 
unsigned char *sys_var_thd_date_time_format::value_ptr(THD *thd, enum_var_type type,
 
1705
uchar *sys_var_thd_date_time_format::value_ptr(THD *thd, enum_var_type type,
1592
1706
                                               LEX_STRING *base __attribute__((unused)))
1593
1707
{
1594
1708
  if (type == OPT_GLOBAL)
1601
1715
    */
1602
1716
    res= thd->strmake((global_system_variables.*offset)->format.str,
1603
1717
                      (global_system_variables.*offset)->format.length);
1604
 
    return (unsigned char*) res;
 
1718
    return (uchar*) res;
1605
1719
  }
1606
 
  return (unsigned char*) (thd->variables.*offset)->format.str;
 
1720
  return (uchar*) (thd->variables.*offset)->format.str;
1607
1721
}
1608
1722
 
1609
1723
 
1613
1727
  const char *new_name;
1614
1728
} my_old_conv;
1615
1729
 
 
1730
static my_old_conv old_conv[]= 
 
1731
{
 
1732
  {     "cp1251_koi8"           ,       "cp1251"        },
 
1733
  {     "cp1250_latin2"         ,       "cp1250"        },
 
1734
  {     "kam_latin2"            ,       "keybcs2"       },
 
1735
  {     "mac_latin2"            ,       "MacRoman"      },
 
1736
  {     "macce_latin2"          ,       "MacCE"         },
 
1737
  {     "pc2_latin2"            ,       "pclatin2"      },
 
1738
  {     "vga_latin2"            ,       "pclatin1"      },
 
1739
  {     "koi8_cp1251"           ,       "koi8r"         },
 
1740
  {     "win1251ukr_koi8_ukr"   ,       "win1251ukr"    },
 
1741
  {     "koi8_ukr_win1251ukr"   ,       "koi8u"         },
 
1742
  {     NULL                    ,       NULL            }
 
1743
};
 
1744
 
 
1745
const CHARSET_INFO *get_old_charset_by_name(const char *name)
 
1746
{
 
1747
  my_old_conv *conv;
 
1748
 
 
1749
  for (conv= old_conv; conv->old_name; conv++)
 
1750
  {
 
1751
    if (!my_strcasecmp(&my_charset_latin1, name, conv->old_name))
 
1752
      return get_charset_by_csname(conv->new_name, MY_CS_PRIMARY, MYF(0));
 
1753
  }
 
1754
  return NULL;
 
1755
}
 
1756
 
 
1757
 
1616
1758
bool sys_var_collation::check(THD *thd __attribute__((unused)),
1617
1759
                              set_var *var)
1618
1760
{
1666
1808
      }
1667
1809
      tmp= NULL;
1668
1810
    }
1669
 
    else if (!(tmp= get_charset_by_csname(res->c_ptr(),MY_CS_PRIMARY,MYF(0))))
 
1811
    else if (!(tmp=get_charset_by_csname(res->c_ptr(),MY_CS_PRIMARY,MYF(0))) &&
 
1812
             !(tmp=get_old_charset_by_name(res->c_ptr())))
1670
1813
    {
1671
1814
      my_error(ER_UNKNOWN_CHARACTER_SET, MYF(0), res->c_ptr());
1672
1815
      return 1;
1695
1838
}
1696
1839
 
1697
1840
 
1698
 
unsigned char *sys_var_character_set::value_ptr(THD *thd, enum_var_type type,
 
1841
uchar *sys_var_character_set::value_ptr(THD *thd, enum_var_type type,
1699
1842
                                        LEX_STRING *base __attribute__((unused)))
1700
1843
{
1701
1844
  const CHARSET_INFO * const cs= ci_ptr(thd,type)[0];
1702
 
  return cs ? (unsigned char*) cs->csname : (unsigned char*) NULL;
 
1845
  return cs ? (uchar*) cs->csname : (uchar*) NULL;
 
1846
}
 
1847
 
 
1848
 
 
1849
void sys_var_character_set_sv::set_default(THD *thd, enum_var_type type)
 
1850
{
 
1851
  if (type == OPT_GLOBAL)
 
1852
    global_system_variables.*offset= *global_default;
 
1853
  else
 
1854
  {
 
1855
    thd->variables.*offset= global_system_variables.*offset;
 
1856
    thd->update_charset();
 
1857
  }
 
1858
}
 
1859
const CHARSET_INFO **sys_var_character_set_sv::ci_ptr(THD *thd, enum_var_type type)
 
1860
{
 
1861
  if (type == OPT_GLOBAL)
 
1862
    return &(global_system_variables.*offset);
 
1863
  else
 
1864
    return &(thd->variables.*offset);
 
1865
}
 
1866
 
 
1867
 
 
1868
bool sys_var_character_set_client::check(THD *thd, set_var *var)
 
1869
{
 
1870
  if (sys_var_character_set_sv::check(thd, var))
 
1871
    return 1;
 
1872
  /* Currently, UCS-2 cannot be used as a client character set */
 
1873
  if (var->save_result.charset->mbminlen > 1)
 
1874
  {
 
1875
    my_error(ER_WRONG_VALUE_FOR_VAR, MYF(0), name, 
 
1876
             var->save_result.charset->csname);
 
1877
    return 1;
 
1878
  }
 
1879
  return 0;
 
1880
}
 
1881
 
 
1882
 
 
1883
const CHARSET_INFO ** sys_var_character_set_database::ci_ptr(THD *thd,
 
1884
                                                       enum_var_type type)
 
1885
{
 
1886
  if (type == OPT_GLOBAL)
 
1887
    return &global_system_variables.collation_database;
 
1888
  else
 
1889
    return &thd->variables.collation_database;
 
1890
}
 
1891
 
 
1892
 
 
1893
void sys_var_character_set_database::set_default(THD *thd, enum_var_type type)
 
1894
{
 
1895
 if (type == OPT_GLOBAL)
 
1896
    global_system_variables.collation_database= default_charset_info;
 
1897
  else
 
1898
  {
 
1899
    thd->variables.collation_database= thd->db_charset;
 
1900
    thd->update_charset();
 
1901
  }
1703
1902
}
1704
1903
 
1705
1904
 
1728
1927
}
1729
1928
 
1730
1929
 
1731
 
unsigned char *sys_var_collation_sv::value_ptr(THD *thd, enum_var_type type,
 
1930
uchar *sys_var_collation_sv::value_ptr(THD *thd, enum_var_type type,
1732
1931
                                       LEX_STRING *base __attribute__((unused)))
1733
1932
{
1734
1933
  const CHARSET_INFO *cs= ((type == OPT_GLOBAL) ?
1735
1934
                     global_system_variables.*offset : thd->variables.*offset);
1736
 
  return cs ? (unsigned char*) cs->name : (unsigned char*) "NULL";
 
1935
  return cs ? (uchar*) cs->name : (uchar*) "NULL";
1737
1936
}
1738
1937
 
1739
1938
 
1751
1950
}
1752
1951
 
1753
1952
 
1754
 
unsigned char *sys_var_key_cache_param::value_ptr(THD *thd __attribute__((unused)),
 
1953
uchar *sys_var_key_cache_param::value_ptr(THD *thd __attribute__((unused)),
1755
1954
                                          enum_var_type type __attribute__((unused)),
1756
1955
                                          LEX_STRING *base __attribute__((unused)))
1757
1956
{
1758
1957
  KEY_CACHE *key_cache= get_key_cache(base);
1759
1958
  if (!key_cache)
1760
1959
    key_cache= &zero_key_cache;
1761
 
  return (unsigned char*) key_cache + offset ;
 
1960
  return (uchar*) key_cache + offset ;
1762
1961
}
1763
1962
 
1764
1963
 
1904
2103
}
1905
2104
 
1906
2105
 
1907
 
bool sys_var_log_state::update(THD *thd __attribute__((unused)), set_var *var)
 
2106
bool sys_var_log_state::update(THD *thd, set_var *var)
1908
2107
{
1909
2108
  bool res;
1910
2109
  pthread_mutex_lock(&LOCK_global_system_variables);
1911
2110
  if (!var->save_result.ulong_value)
 
2111
  {
 
2112
    logger.deactivate_log_handler(thd, log_type);
1912
2113
    res= false;
 
2114
  }
1913
2115
  else
1914
 
    res= true;
 
2116
    res= logger.activate_log_handler(thd, log_type);
1915
2117
  pthread_mutex_unlock(&LOCK_global_system_variables);
1916
2118
  return res;
1917
2119
}
1918
2120
 
1919
 
void sys_var_log_state::set_default(THD *thd __attribute__((unused)),
 
2121
void sys_var_log_state::set_default(THD *thd,
1920
2122
                                    enum_var_type type __attribute__((unused)))
1921
2123
{
 
2124
  pthread_mutex_lock(&LOCK_global_system_variables);
 
2125
  logger.deactivate_log_handler(thd, log_type);
 
2126
  pthread_mutex_unlock(&LOCK_global_system_variables);
 
2127
}
 
2128
 
 
2129
 
 
2130
static int  sys_check_log_path(THD *thd __attribute__((unused)),
 
2131
                               set_var *var)
 
2132
{
 
2133
  char path[FN_REFLEN], buff[FN_REFLEN];
 
2134
  struct stat f_stat;
 
2135
  String str(buff, sizeof(buff), system_charset_info), *res;
 
2136
  const char *log_file_str;
 
2137
  size_t path_length;
 
2138
 
 
2139
  if (!(res= var->value->val_str(&str)))
 
2140
    goto err;
 
2141
 
 
2142
  log_file_str= res->c_ptr();
 
2143
  memset(&f_stat, 0, sizeof(struct stat));
 
2144
 
 
2145
  path_length= unpack_filename(path, log_file_str);
 
2146
 
 
2147
  if (!path_length)
 
2148
  {
 
2149
    /* File name is empty. */
 
2150
 
 
2151
    goto err;
 
2152
  }
 
2153
 
 
2154
  if (!stat(path, &f_stat))
 
2155
  {
 
2156
    /*
 
2157
      A file system object exists. Check if argument is a file and we have
 
2158
      'write' permission.
 
2159
    */
 
2160
 
 
2161
    if (!S_ISREG(f_stat.st_mode) ||
 
2162
        !(f_stat.st_mode & S_IWRITE))
 
2163
      goto err;
 
2164
 
 
2165
    return 0;
 
2166
  }
 
2167
 
 
2168
  /* Get dirname of the file path. */
 
2169
  (void) dirname_part(path, log_file_str, &path_length);
 
2170
 
 
2171
  /* Dirname is empty if file path is relative. */
 
2172
  if (!path_length)
 
2173
    return 0;
 
2174
 
 
2175
  /*
 
2176
    Check if directory exists and we have permission to create file and
 
2177
    write to file.
 
2178
  */
 
2179
  if (my_access(path, (F_OK|W_OK)))
 
2180
    goto err;
 
2181
 
 
2182
  return 0;
 
2183
 
 
2184
err:
 
2185
  my_error(ER_WRONG_VALUE_FOR_VAR, MYF(0), var->var->name, 
 
2186
           res ? log_file_str : "NULL");
 
2187
  return 1;
1922
2188
}
1923
2189
 
1924
2190
 
1925
2191
bool update_sys_var_str_path(THD *thd __attribute__((unused)),
1926
2192
                             sys_var_str *var_str,
1927
2193
                             set_var *var, const char *log_ext,
1928
 
                             bool log_state, uint32_t log_type)
 
2194
                             bool log_state, uint log_type)
1929
2195
{
 
2196
  MYSQL_QUERY_LOG *file_log;
1930
2197
  char buff[FN_REFLEN];
1931
2198
  char *res= 0, *old_value=(char *)(var ? var->value->str_value.ptr() : 0);
1932
2199
  bool result= 0;
1933
 
  uint32_t str_length= (var ? var->value->str_value.length() : 0);
 
2200
  uint str_length= (var ? var->value->str_value.length() : 0);
1934
2201
 
1935
2202
  switch (log_type) {
 
2203
  case QUERY_LOG_SLOW:
 
2204
    file_log= logger.get_slow_log_file_handler();
 
2205
    break;
 
2206
  case QUERY_LOG_GENERAL:
 
2207
    file_log= logger.get_log_file_handler();
 
2208
    break;
1936
2209
  default:
1937
2210
    assert(0);                                  // Impossible
1938
2211
  }
1951
2224
  pthread_mutex_lock(&LOCK_global_system_variables);
1952
2225
  logger.lock_exclusive();
1953
2226
 
 
2227
  if (file_log && log_state)
 
2228
    file_log->close(0);
1954
2229
  old_value= var_str->value;
1955
2230
  var_str->value= res;
1956
2231
  var_str->value_length= str_length;
1957
 
  free(old_value);
1958
 
  if (log_state)
 
2232
  my_free(old_value, MYF(MY_ALLOW_ZERO_PTR));
 
2233
  if (file_log && log_state)
1959
2234
  {
1960
2235
    switch (log_type) {
 
2236
    case QUERY_LOG_SLOW:
 
2237
      file_log->open_slow_log(sys_var_slow_log_path.value);
 
2238
      break;
 
2239
    case QUERY_LOG_GENERAL:
 
2240
      file_log->open_query_log(sys_var_general_log_path.value);
 
2241
      break;
1961
2242
    default:
1962
2243
      assert(0);
1963
2244
    }
1971
2252
}
1972
2253
 
1973
2254
 
 
2255
static bool sys_update_general_log_path(THD *thd, set_var * var)
 
2256
{
 
2257
  return update_sys_var_str_path(thd, &sys_var_general_log_path,
 
2258
                                 var, ".log", opt_log, QUERY_LOG_GENERAL);
 
2259
}
 
2260
 
 
2261
 
 
2262
static void sys_default_general_log_path(THD *thd,
 
2263
                                         enum_var_type type __attribute__((unused)))
 
2264
{
 
2265
  (void) update_sys_var_str_path(thd, &sys_var_general_log_path,
 
2266
                                 0, ".log", opt_log, QUERY_LOG_GENERAL);
 
2267
}
 
2268
 
 
2269
 
 
2270
static bool sys_update_slow_log_path(THD *thd, set_var * var)
 
2271
{
 
2272
  return update_sys_var_str_path(thd, &sys_var_slow_log_path,
 
2273
                                 var, "-slow.log", opt_slow_log,
 
2274
                                 QUERY_LOG_SLOW);
 
2275
}
 
2276
 
 
2277
 
 
2278
static void sys_default_slow_log_path(THD *thd,
 
2279
                                      enum_var_type type __attribute__((unused)))
 
2280
{
 
2281
  (void) update_sys_var_str_path(thd, &sys_var_slow_log_path,
 
2282
                                 0, "-slow.log", opt_slow_log,
 
2283
                                 QUERY_LOG_SLOW);
 
2284
}
 
2285
 
 
2286
 
1974
2287
bool sys_var_log_output::update(THD *thd __attribute__((unused)),
1975
2288
                                set_var *var)
1976
2289
{
1977
2290
  pthread_mutex_lock(&LOCK_global_system_variables);
1978
2291
  logger.lock_exclusive();
 
2292
  logger.init_slow_log(var->save_result.ulong_value);
 
2293
  logger.init_general_log(var->save_result.ulong_value);
1979
2294
  *value= var->save_result.ulong_value;
1980
2295
  logger.unlock();
1981
2296
  pthread_mutex_unlock(&LOCK_global_system_variables);
1988
2303
{
1989
2304
  pthread_mutex_lock(&LOCK_global_system_variables);
1990
2305
  logger.lock_exclusive();
 
2306
  logger.init_slow_log(LOG_FILE);
 
2307
  logger.init_general_log(LOG_FILE);
1991
2308
  *value= LOG_FILE;
1992
2309
  logger.unlock();
1993
2310
  pthread_mutex_unlock(&LOCK_global_system_variables);
1994
2311
}
1995
2312
 
1996
2313
 
1997
 
unsigned char *sys_var_log_output::value_ptr(THD *thd,
 
2314
uchar *sys_var_log_output::value_ptr(THD *thd,
1998
2315
                                     enum_var_type type __attribute__((unused)),
1999
2316
                                     LEX_STRING *base __attribute__((unused)))
2000
2317
{
2001
2318
  char buff[256];
2002
 
  String tmp(buff, sizeof(buff), &my_charset_utf8_general_ci);
 
2319
  String tmp(buff, sizeof(buff), &my_charset_latin1);
2003
2320
  ulong length;
2004
2321
  ulong val= *value;
2005
2322
 
2006
2323
  tmp.length(0);
2007
 
  for (uint32_t i= 0; val; val>>= 1, i++)
 
2324
  for (uint i= 0; val; val>>= 1, i++)
2008
2325
  {
2009
2326
    if (val & 1)
2010
2327
    {
2016
2333
 
2017
2334
  if ((length= tmp.length()))
2018
2335
    length--;
2019
 
  return (unsigned char*) thd->strmake(tmp.ptr(), length);
 
2336
  return (uchar*) thd->strmake(tmp.ptr(), length);
2020
2337
}
2021
2338
 
2022
2339
 
2062
2379
}
2063
2380
 
2064
2381
 
2065
 
unsigned char *sys_var_timestamp::value_ptr(THD *thd,
 
2382
uchar *sys_var_timestamp::value_ptr(THD *thd,
2066
2383
                                    enum_var_type type __attribute__((unused)),
2067
2384
                                    LEX_STRING *base __attribute__((unused)))
2068
2385
{
2069
2386
  thd->sys_var_tmp.long_value= (long) thd->start_time;
2070
 
  return (unsigned char*) &thd->sys_var_tmp.long_value;
 
2387
  return (uchar*) &thd->sys_var_tmp.long_value;
2071
2388
}
2072
2389
 
2073
2390
 
2079
2396
}
2080
2397
 
2081
2398
 
2082
 
unsigned char *sys_var_last_insert_id::value_ptr(THD *thd,
 
2399
uchar *sys_var_last_insert_id::value_ptr(THD *thd,
2083
2400
                                         enum_var_type type __attribute__((unused)),
2084
2401
                                         LEX_STRING *base __attribute__((unused)))
2085
2402
{
2089
2406
  */
2090
2407
  thd->sys_var_tmp.uint64_t_value= 
2091
2408
    thd->read_first_successful_insert_id_in_prev_stmt();
2092
 
  return (unsigned char*) &thd->sys_var_tmp.uint64_t_value;
 
2409
  return (uchar*) &thd->sys_var_tmp.uint64_t_value;
2093
2410
}
2094
2411
 
2095
2412
 
2100
2417
}
2101
2418
 
2102
2419
 
2103
 
unsigned char *sys_var_insert_id::value_ptr(THD *thd,
 
2420
uchar *sys_var_insert_id::value_ptr(THD *thd,
2104
2421
                                    enum_var_type type __attribute__((unused)),
2105
2422
                                    LEX_STRING *base __attribute__((unused)))
2106
2423
{
2107
2424
  thd->sys_var_tmp.uint64_t_value=
2108
2425
    thd->auto_inc_intervals_forced.minimum();
2109
 
  return (unsigned char*) &thd->sys_var_tmp.uint64_t_value;
 
2426
  return (uchar*) &thd->sys_var_tmp.uint64_t_value;
2110
2427
}
2111
2428
 
2112
2429
 
2126
2443
bool sys_var_thd_time_zone::check(THD *thd, set_var *var)
2127
2444
{
2128
2445
  char buff[MAX_TIME_ZONE_NAME_LENGTH];
2129
 
  String str(buff, sizeof(buff), &my_charset_utf8_general_ci);
 
2446
  String str(buff, sizeof(buff), &my_charset_latin1);
2130
2447
  String *res= var->value->val_str(&str);
2131
2448
 
2132
2449
  if (!(var->save_result.time_zone= my_tz_find(thd, res)))
2153
2470
}
2154
2471
 
2155
2472
 
2156
 
unsigned char *sys_var_thd_time_zone::value_ptr(THD *thd, enum_var_type type,
 
2473
uchar *sys_var_thd_time_zone::value_ptr(THD *thd, enum_var_type type,
2157
2474
                                        LEX_STRING *base __attribute__((unused)))
2158
2475
{
2159
2476
  /* 
2161
2478
    time zone name is guaranteed to be zero ended.
2162
2479
  */
2163
2480
  if (type == OPT_GLOBAL)
2164
 
    return (unsigned char *)(global_system_variables.time_zone->get_name()->ptr());
 
2481
    return (uchar *)(global_system_variables.time_zone->get_name()->ptr());
2165
2482
  else
2166
2483
  {
2167
2484
    /*
2173
2490
      (binlog code stores session value only).
2174
2491
    */
2175
2492
    thd->time_zone_used= 1;
2176
 
    return (unsigned char *)(thd->variables.time_zone->get_name()->ptr());
 
2493
    return (uchar *)(thd->variables.time_zone->get_name()->ptr());
2177
2494
  }
2178
2495
}
2179
2496
 
2185
2502
 {
2186
2503
   if (default_tz_name)
2187
2504
   {
2188
 
     String str(default_tz_name, &my_charset_utf8_general_ci);
 
2505
     String str(default_tz_name, &my_charset_latin1);
2189
2506
     /*
2190
2507
       We are guaranteed to find this time zone since its existence
2191
2508
       is checked during start-up.
2237
2554
}
2238
2555
 
2239
2556
 
2240
 
unsigned char *sys_var_max_user_conn::value_ptr(THD *thd, enum_var_type type,
 
2557
uchar *sys_var_max_user_conn::value_ptr(THD *thd, enum_var_type type,
2241
2558
                                        LEX_STRING *base __attribute__((unused)))
2242
2559
{
2243
2560
  if (type != OPT_GLOBAL &&
2244
2561
      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);
 
2562
    return (uchar*) &(thd->user_connect->user_resources.user_conn);
 
2563
  return (uchar*) &(max_user_connections);
2247
2564
}
2248
2565
 
2249
2566
 
2265
2582
  else // STRING_RESULT
2266
2583
  {
2267
2584
    char buff[6]; 
2268
 
    String str(buff, sizeof(buff), &my_charset_utf8_general_ci), *res;
 
2585
    String str(buff, sizeof(buff), &my_charset_latin1), *res;
2269
2586
    if (!(res=var->value->val_str(&str)))
2270
2587
    {
2271
2588
      my_error(ER_WRONG_VALUE_FOR_VAR, MYF(0), name, "NULL");
2295
2612
}
2296
2613
 
2297
2614
 
2298
 
unsigned char *sys_var_thd_lc_time_names::value_ptr(THD *thd,
 
2615
uchar *sys_var_thd_lc_time_names::value_ptr(THD *thd,
2299
2616
                                            enum_var_type type,
2300
2617
                                            LEX_STRING *base __attribute__((unused)))
2301
2618
{
2302
2619
  return type == OPT_GLOBAL ?
2303
 
                 (unsigned char *) global_system_variables.lc_time_names->name :
2304
 
                 (unsigned char *) thd->variables.lc_time_names->name;
 
2620
                 (uchar *) global_system_variables.lc_time_names->name :
 
2621
                 (uchar *) thd->variables.lc_time_names->name;
2305
2622
}
2306
2623
 
2307
2624
 
2357
2674
}
2358
2675
 
2359
2676
 
2360
 
unsigned char *sys_var_microseconds::value_ptr(THD *thd, enum_var_type type,
 
2677
uchar *sys_var_microseconds::value_ptr(THD *thd, enum_var_type type,
2361
2678
                                          LEX_STRING *base __attribute__((unused)))
2362
2679
{
2363
2680
  thd->tmp_double_value= (double) ((type == OPT_GLOBAL) ?
2364
2681
                                   global_system_variables.*offset :
2365
2682
                                   thd->variables.*offset) / 1000000.0;
2366
 
  return (unsigned char*) &thd->tmp_double_value;
 
2683
  return (uchar*) &thd->tmp_double_value;
2367
2684
}
2368
2685
 
2369
2686
 
2419
2736
  return 0;
2420
2737
}
2421
2738
 
 
2739
static bool set_log_update(THD *thd __attribute__((unused)),
 
2740
                           set_var *var __attribute__((unused)))
 
2741
{
 
2742
  /*
 
2743
    The update log is not supported anymore since 5.0.
 
2744
    See sql/mysqld.cc/, comments in function init_server_components() for an
 
2745
    explaination of the different warnings we send below
 
2746
  */
 
2747
 
 
2748
  if (opt_sql_bin_update)
 
2749
  {
 
2750
    push_warning(thd, DRIZZLE_ERROR::WARN_LEVEL_NOTE,
 
2751
                 ER_UPDATE_LOG_DEPRECATED_TRANSLATED,
 
2752
                 ER(ER_UPDATE_LOG_DEPRECATED_TRANSLATED));
 
2753
  }
 
2754
  else
 
2755
    push_warning(thd, DRIZZLE_ERROR::WARN_LEVEL_NOTE,
 
2756
                 ER_UPDATE_LOG_DEPRECATED_IGNORED,
 
2757
                 ER(ER_UPDATE_LOG_DEPRECATED_IGNORED));
 
2758
  set_option_bit(thd, var);
 
2759
  return 0;
 
2760
}
 
2761
 
2422
2762
 
2423
2763
static int check_pseudo_thread_id(THD *thd __attribute__((unused)),
2424
2764
                                  set_var *var)
2427
2767
  return 0;
2428
2768
}
2429
2769
 
2430
 
static unsigned char *get_warning_count(THD *thd)
 
2770
static uchar *get_warning_count(THD *thd)
2431
2771
{
2432
2772
  thd->sys_var_tmp.long_value=
2433
2773
    (thd->warn_count[(uint) DRIZZLE_ERROR::WARN_LEVEL_NOTE] +
2434
2774
     thd->warn_count[(uint) DRIZZLE_ERROR::WARN_LEVEL_ERROR] +
2435
2775
     thd->warn_count[(uint) DRIZZLE_ERROR::WARN_LEVEL_WARN]);
2436
 
  return (unsigned char*) &thd->sys_var_tmp.long_value;
 
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
2782
    thd->warn_count[(uint) DRIZZLE_ERROR::WARN_LEVEL_ERROR];
2443
 
  return (unsigned char*) &thd->sys_var_tmp.long_value;
 
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 __attribute__((unused)))
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,
 
2851
static uchar *get_sys_var_length(const sys_var *var, size_t *length,
2512
2852
                                 bool first __attribute__((unused)))
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
}
2644
2984
 
2645
2985
int set_var_init()
2646
2986
{
2647
 
  uint32_t count= 0;
 
2987
  uint count= 0;
2648
2988
  
2649
2989
  for (sys_var *var=vars.first; var; var= var->next, count++) {};
2650
2990
 
2690
3030
    0           SUCCESS
2691
3031
    otherwise   FAILURE
2692
3032
*/
2693
 
int mysql_append_static_vars(const SHOW_VAR *show_vars, uint32_t count)
 
3033
int mysql_append_static_vars(const SHOW_VAR *show_vars, uint count)
2694
3034
{
2695
3035
  for (; count > 0; count--, show_vars++)
2696
 
    if (insert_dynamic(&fixed_show_vars, (unsigned char*) show_vars))
 
3036
    if (insert_dynamic(&fixed_show_vars, (uchar*) show_vars))
2697
3037
      return 1;
2698
3038
  return 0;
2699
3039
}
2713
3053
    0           Unknown variable (error message is given)
2714
3054
*/
2715
3055
 
2716
 
sys_var *intern_find_sys_var(const char *str, uint32_t length, bool no_error)
 
3056
sys_var *intern_find_sys_var(const char *str, uint length, bool no_error)
2717
3057
{
2718
3058
  sys_var *var;
2719
3059
 
2722
3062
    A lock on LOCK_system_variable_hash should be held
2723
3063
  */
2724
3064
  var= (sys_var*) hash_search(&system_variable_hash,
2725
 
                              (unsigned char*) str, length ? length : strlen(str));
 
3065
                              (uchar*) str, length ? length : strlen(str));
2726
3066
  if (!(var || no_error))
2727
3067
    my_error(ER_UNKNOWN_SYSTEM_VARIABLE, MYF(0), (char*) str);
2728
3068
 
2902
3242
{
2903
3243
  char buff[STRING_BUFFER_USUAL_SIZE];
2904
3244
  const char *value;
2905
 
  String str(buff, sizeof(buff), &my_charset_utf8_general_ci), *res;
 
3245
  String str(buff, sizeof(buff), &my_charset_latin1), *res;
2906
3246
 
2907
3247
  var->save_result.plugin= NULL;
2908
3248
  if (var->value->result_type() == STRING_RESULT)
2913
3253
        !(engine_name.str= (char *)res->ptr()) ||
2914
3254
        !(engine_name.length= res->length()) ||
2915
3255
        !(var->save_result.plugin= ha_resolve_by_name(thd, &engine_name)) ||
2916
 
        !(hton= plugin_data(var->save_result.plugin, handlerton *)))
 
3256
        !(hton= plugin_data(var->save_result.plugin, handlerton *)) ||
 
3257
        ha_checktype(thd, ha_legacy_type(hton), 1, 0) != hton)
2917
3258
    {
2918
3259
      value= res ? res->c_ptr() : "NULL";
2919
3260
      goto err;
2928
3269
}
2929
3270
 
2930
3271
 
2931
 
unsigned char *sys_var_thd_storage_engine::value_ptr(THD *thd, enum_var_type type,
 
3272
uchar *sys_var_thd_storage_engine::value_ptr(THD *thd, enum_var_type type,
2932
3273
                                             LEX_STRING *base __attribute__((unused)))
2933
3274
{
2934
 
  unsigned char* result;
 
3275
  uchar* result;
2935
3276
  handlerton *hton;
2936
3277
  LEX_STRING *engine_name;
2937
3278
  plugin_ref plugin= thd->variables.*offset;
2939
3280
    plugin= my_plugin_lock(thd, &(global_system_variables.*offset));
2940
3281
  hton= plugin_data(plugin, handlerton*);
2941
3282
  engine_name= &hton2plugin[hton->slot]->name;
2942
 
  result= (unsigned char *) thd->strmake(engine_name->str, engine_name->length);
 
3283
  result= (uchar *) thd->strmake(engine_name->str, engine_name->length);
2943
3284
  if (type == OPT_GLOBAL)
2944
3285
    plugin_unlock(thd, plugin);
2945
3286
  return result;
2985
3326
symbolic_mode_representation(THD *thd, uint64_t val, LEX_STRING *rep)
2986
3327
{
2987
3328
  char buff[STRING_BUFFER_USUAL_SIZE*8];
2988
 
  String tmp(buff, sizeof(buff), &my_charset_utf8_general_ci);
 
3329
  String tmp(buff, sizeof(buff), &my_charset_latin1);
2989
3330
 
2990
3331
  tmp.length(0);
2991
3332
 
2992
 
  for (uint32_t i= 0; val; val>>= 1, i++)
 
3333
  for (uint i= 0; val; val>>= 1, i++)
2993
3334
  {
2994
3335
    if (val & 1)
2995
3336
    {
3010
3351
}
3011
3352
 
3012
3353
 
3013
 
unsigned char *sys_var_thd_optimizer_switch::value_ptr(THD *thd, enum_var_type type,
 
3354
uchar *sys_var_thd_optimizer_switch::value_ptr(THD *thd, enum_var_type type,
3014
3355
                                               LEX_STRING *base __attribute__((unused)))
3015
3356
{
3016
3357
  LEX_STRING opts;
3017
3358
  uint64_t val= ((type == OPT_GLOBAL) ? global_system_variables.*offset :
3018
3359
                  thd->variables.*offset);
3019
3360
  (void) symbolic_mode_representation(thd, val, &opts);
3020
 
  return (unsigned char *) opts.str;
 
3361
  return (uchar *) opts.str;
3021
3362
}
3022
3363
 
3023
3364
 
3034
3375
  Named list handling
3035
3376
****************************************************************************/
3036
3377
 
3037
 
unsigned char* find_named(I_List<NAMED_LIST> *list, const char *name, uint32_t length,
 
3378
uchar* find_named(I_List<NAMED_LIST> *list, const char *name, uint length,
3038
3379
                NAMED_LIST **found)
3039
3380
{
3040
3381
  I_List_iterator<NAMED_LIST> it(*list);
3053
3394
 
3054
3395
 
3055
3396
void delete_elements(I_List<NAMED_LIST> *list,
3056
 
                     void (*free_element)(const char *name, unsigned char*))
 
3397
                     void (*free_element)(const char *name, uchar*))
3057
3398
{
3058
3399
  NAMED_LIST *element;
3059
3400
  while ((element= list->get()))
3067
3408
 
3068
3409
/* Key cache functions */
3069
3410
 
3070
 
static KEY_CACHE *create_key_cache(const char *name, uint32_t length)
 
3411
static KEY_CACHE *create_key_cache(const char *name, uint length)
3071
3412
{
3072
3413
  KEY_CACHE *key_cache;
3073
3414
  
3074
3415
  if ((key_cache= (KEY_CACHE*) my_malloc(sizeof(KEY_CACHE),
3075
3416
                                             MYF(MY_ZEROFILL | MY_WME))))
3076
3417
  {
3077
 
    if (!new NAMED_LIST(&key_caches, name, length, (unsigned char*) key_cache))
 
3418
    if (!new NAMED_LIST(&key_caches, name, length, (uchar*) key_cache))
3078
3419
    {
3079
 
      free((char*) key_cache);
 
3420
      my_free((char*) key_cache, MYF(0));
3080
3421
      key_cache= 0;
3081
3422
    }
3082
3423
    else
3096
3437
}
3097
3438
 
3098
3439
 
3099
 
KEY_CACHE *get_or_create_key_cache(const char *name, uint32_t length)
 
3440
KEY_CACHE *get_or_create_key_cache(const char *name, uint length)
3100
3441
{
3101
3442
  LEX_STRING key_cache_name;
3102
3443
  KEY_CACHE *key_cache;
3115
3456
                    KEY_CACHE *key_cache)
3116
3457
{
3117
3458
  ha_end_key_cache(key_cache);
3118
 
  free((char*) key_cache);
 
3459
  my_free((char*) key_cache, MYF(0));
3119
3460
}
3120
3461
 
3121
3462