set_var.cc 54.2 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
/* Copyright (C) 2000 MySQL AB & MySQL Finland AB & TCX DataKonsult AB

   This program is free software; you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
   the Free Software Foundation; either version 2 of the License, or
   (at your option) any later version.

   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License for more details.

   You should have received a copy of the GNU General Public License
   along with this program; if not, write to the Free Software
   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */

/*
  Handling of MySQL SQL variables

  To add a new variable, one has to do the following:

  - If the variable is thread specific, add it to 'system_variables' struct.
    If not, add it to mysqld.cc and an declaration in 'mysql_priv.h'
24 25
  - Don't forget to initialize new fields in global_system_variables and
     max_system_variables!
26 27 28
  - Use one of the 'sys_var... classes from set_var.h or write a specific
    one for the variable type.
  - Define it in the 'variable definition list' in this file.
29 30 31
  - If the variable should be changeable or one should be able to access it
    with @@variable_name, it should be added to the 'list of all variables'
    list in this file.
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
  - If the variable should be changed from the command line, add a definition
    of it in the my_option structure list in mysqld.dcc
  - If the variable should show up in 'show variables' add it to the
    init_vars[] struct in this file

  TODO:
    - Add full support for the variable character_set (for 4.1)

    - When updating myisam_delay_key_write, we should do a 'flush tables'
      of all MyISAM tables to ensure that they are reopen with the
      new attribute.
*/

#ifdef __GNUC__
#pragma implementation				// gcc: Class implementation
#endif

#include "mysql_priv.h"
50
#include <mysql.h>
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68
#include "slave.h"
#include "sql_acl.h"
#include <my_getopt.h>
#include <myisam.h>
#ifdef HAVE_BERKELEY_DB
#include "ha_berkeley.h"
#endif
#ifdef HAVE_INNOBASE_DB
#include "ha_innodb.h"
#endif

static HASH system_variable_hash;
const char *bool_type_names[]= { "OFF", "ON", NullS };
TYPELIB bool_typelib=
{
  array_elements(bool_type_names)-1, "", bool_type_names
};

69 70 71 72 73 74
const char *delay_key_write_type_names[]= { "OFF", "ON", "ALL", NullS };
TYPELIB delay_key_write_typelib=
{
  array_elements(delay_key_write_type_names)-1, "", delay_key_write_type_names
};

75 76 77 78 79 80 81 82 83 84
static bool sys_check_charset(THD *thd, set_var *var);
static bool sys_update_charset(THD *thd, set_var *var);
static void sys_set_default_charset(THD *thd, enum_var_type type);
static bool set_option_bit(THD *thd, set_var *var);
static bool set_option_autocommit(THD *thd, set_var *var);
static bool set_log_update(THD *thd, set_var *var);
static void fix_low_priority_updates(THD *thd, enum_var_type type);
static void fix_tx_isolation(THD *thd, enum_var_type type);
static void fix_net_read_timeout(THD *thd, enum_var_type type);
static void fix_net_write_timeout(THD *thd, enum_var_type type);
85
static void fix_net_retry_count(THD *thd, enum_var_type type);
86 87
static void fix_max_join_size(THD *thd, enum_var_type type);
static void fix_query_cache_size(THD *thd, enum_var_type type);
88
static void fix_query_cache_min_res_unit(THD *thd, enum_var_type type);
89
static void fix_key_buffer_size(THD *thd, enum_var_type type);
90 91
static byte *get_error_count(THD *thd);
static byte *get_warning_count(THD *thd);
92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107

/*
  Variable definition list

  These are variables that can be set from the command line, in
  alphabetic order
*/

sys_var_long_ptr	sys_binlog_cache_size("binlog_cache_size",
					      &binlog_cache_size);
sys_var_thd_ulong	sys_bulk_insert_buff_size("bulk_insert_buffer_size",
						  &SV::bulk_insert_buff_size);
sys_var_str		sys_charset("character_set",
				    sys_check_charset,
				    sys_update_charset,
				    sys_set_default_charset);
108 109 110 111
sys_var_str		sys_charset_system("character_set_system",
				    sys_check_charset,
				    sys_update_charset,
				    sys_set_default_charset);
112 113 114
sys_var_collation_client sys_collation_client("collation_client");
sys_var_collation_connection sys_collation_connection("collation_connection");
sys_var_collation_results sys_collation_results("collation_results");
115 116 117 118
sys_var_bool_ptr	sys_concurrent_insert("concurrent_insert",
					      &myisam_concurrent_insert);
sys_var_long_ptr	sys_connect_timeout("connect_timeout",
					    &connect_timeout);
119 120 121 122
sys_var_enum		sys_delay_key_write("delay_key_write",
					    &delay_key_write_options,
					    &delay_key_write_typelib,
					    fix_delay_key_write);
123 124 125 126 127 128
sys_var_long_ptr	sys_delayed_insert_limit("delayed_insert_limit",
						 &delayed_insert_limit);
sys_var_long_ptr	sys_delayed_insert_timeout("delayed_insert_timeout",
						   &delayed_insert_timeout);
sys_var_long_ptr	sys_delayed_queue_size("delayed_queue_size",
					       &delayed_queue_size);
129 130
sys_var_long_ptr	sys_expire_logs_days("expire_logs_days",
					     &expire_logs_days);
131 132 133 134 135 136
sys_var_bool_ptr	sys_flush("flush", &myisam_flush);
sys_var_long_ptr	sys_flush_time("flush_time", &flush_time);
sys_var_thd_ulong	sys_interactive_timeout("interactive_timeout",
						&SV::net_interactive_timeout);
sys_var_thd_ulong	sys_join_buffer_size("join_buffer_size",
					     &SV::join_buff_size);
137
sys_var_ulonglong_ptr	sys_key_buffer_size("key_buffer_size",
138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164
					    &keybuff_size,
					    fix_key_buffer_size);
sys_var_bool_ptr	sys_local_infile("local_infile",
					 &opt_local_infile);
sys_var_thd_bool	sys_log_warnings("log_warnings", &SV::log_warnings);
sys_var_thd_ulong	sys_long_query_time("long_query_time",
					     &SV::long_query_time);
sys_var_thd_bool	sys_low_priority_updates("low_priority_updates",
						 &SV::low_priority_updates,
						 fix_low_priority_updates);
#ifndef TO_BE_DELETED	/* Alias for the low_priority_updates */
sys_var_thd_bool	sys_sql_low_priority_updates("sql_low_priority_updates",
						     &SV::low_priority_updates,
						     fix_low_priority_updates);
#endif
sys_var_thd_ulong	sys_max_allowed_packet("max_allowed_packet",
					       &SV::max_allowed_packet);
sys_var_long_ptr	sys_max_binlog_cache_size("max_binlog_cache_size",
						  &max_binlog_cache_size);
sys_var_long_ptr	sys_max_binlog_size("max_binlog_size",
					    &max_binlog_size);
sys_var_long_ptr	sys_max_connections("max_connections",
					    &max_connections);
sys_var_long_ptr	sys_max_connect_errors("max_connect_errors",
					       &max_connect_errors);
sys_var_long_ptr	sys_max_delayed_threads("max_delayed_threads",
						&max_insert_delayed_threads);
165 166
sys_var_thd_ulong	sys_max_error_count("max_error_count",
					    &SV::max_error_count);
167 168
sys_var_thd_ulong	sys_max_heap_table_size("max_heap_table_size",
						&SV::max_heap_table_size);
169 170
sys_var_thd_ulong       sys_pseudo_thread_id("pseudo_thread_id",
					     &SV::pseudo_thread_id);
171
sys_var_thd_ha_rows	sys_max_join_size("max_join_size",
172 173
					  &SV::max_join_size,
					  fix_max_join_size);
igor@hundin.mysql.fi's avatar
igor@hundin.mysql.fi committed
174 175
sys_var_thd_ulong   sys_max_length_for_sort_data("max_length_for_sort_data",
                        &SV::max_length_for_sort_data);
176
#ifndef TO_BE_DELETED	/* Alias for max_join_size */
177
sys_var_thd_ha_rows	sys_sql_max_join_size("sql_max_join_size",
178 179 180
					      &SV::max_join_size,
					      fix_max_join_size);
#endif
181 182
sys_var_thd_ulong	sys_max_prep_stmt_count("max_prepared_statements",
						&SV::max_prep_stmt_count);
183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201
sys_var_thd_ulong	sys_max_sort_length("max_sort_length",
					    &SV::max_sort_length);
sys_var_long_ptr	sys_max_user_connections("max_user_connections",
						 &max_user_connections);
sys_var_thd_ulong	sys_max_tmp_tables("max_tmp_tables",
					   &SV::max_tmp_tables);
sys_var_long_ptr	sys_max_write_lock_count("max_write_lock_count",
						 &max_write_lock_count);
sys_var_thd_ulonglong	sys_myisam_max_extra_sort_file_size("myisam_max_extra_sort_file_size", &SV::myisam_max_extra_sort_file_size);
sys_var_thd_ulonglong	sys_myisam_max_sort_file_size("myisam_max_sort_file_size", &SV::myisam_max_sort_file_size);
sys_var_thd_ulong	sys_myisam_sort_buffer_size("myisam_sort_buffer_size", &SV::myisam_sort_buff_size);
sys_var_thd_ulong	sys_net_buffer_length("net_buffer_length",
					      &SV::net_buffer_length);
sys_var_thd_ulong	sys_net_read_timeout("net_read_timeout",
					     &SV::net_read_timeout,
					     fix_net_read_timeout);
sys_var_thd_ulong	sys_net_write_timeout("net_write_timeout",
					      &SV::net_write_timeout,
					      fix_net_write_timeout);
202 203 204
sys_var_thd_ulong	sys_net_retry_count("net_retry_count",
					    &SV::net_retry_count,
					    fix_net_retry_count);
205
sys_var_thd_bool	sys_new_mode("new", &SV::new_mode);
206 207 208 209
sys_var_thd_ulong	sys_read_buff_size("read_buffer_size",
					   &SV::read_buff_size);
sys_var_thd_ulong	sys_read_rnd_buff_size("read_rnd_buffer_size",
					       &SV::read_rnd_buff_size);
210 211 212 213
#ifdef HAVE_REPLICATION
sys_var_bool_ptr	sys_relay_log_purge("relay_log_purge",
                                            &relay_log_purge);
#endif
214 215 216 217 218 219 220 221
sys_var_long_ptr	sys_rpl_recovery_rank("rpl_recovery_rank",
					      &rpl_recovery_rank);
sys_var_long_ptr	sys_query_cache_size("query_cache_size",
					     &query_cache_size,
					     fix_query_cache_size);
#ifdef HAVE_QUERY_CACHE
sys_var_long_ptr	sys_query_cache_limit("query_cache_limit",
					      &query_cache.query_cache_limit);
222 223 224
sys_var_long_ptr        sys_query_cache_min_res_unit("query_cache_min_res_unit",
						     &query_cache_min_res_unit,
						     fix_query_cache_min_res_unit);
225 226 227 228 229
sys_var_thd_enum	sys_query_cache_type("query_cache_type",
					     &SV::query_cache_type,
					     &query_cache_type_typelib);
#endif /* HAVE_QUERY_CACHE */
sys_var_long_ptr	sys_server_id("server_id",&server_id);
230 231
sys_var_bool_ptr	sys_slave_compressed_protocol("slave_compressed_protocol",
						      &opt_slave_compressed_protocol);
hf@deer.mysql.r18.ru's avatar
SCRUM  
hf@deer.mysql.r18.ru committed
232
#ifdef HAVE_REPLICATION
233 234
sys_var_long_ptr	sys_slave_net_timeout("slave_net_timeout",
					      &slave_net_timeout);
235
#endif
236 237 238 239
sys_var_long_ptr	sys_slow_launch_time("slow_launch_time",
					     &slow_launch_time);
sys_var_thd_ulong	sys_sort_buffer("sort_buffer_size",
					&SV::sortbuff_size);
240 241 242 243
sys_var_thd_sql_mode    sys_sql_mode("sql_mode",
                                     &SV::sql_mode);
sys_var_thd_enum        sys_table_type("table_type", &SV::table_type,
                                       &ha_table_typelib);
244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298
sys_var_long_ptr	sys_table_cache_size("table_cache",
					     &table_cache_size);
sys_var_long_ptr	sys_thread_cache_size("thread_cache_size",
					      &thread_cache_size);
sys_var_thd_enum	sys_tx_isolation("tx_isolation",
					 &SV::tx_isolation,
					 &tx_isolation_typelib,
					 fix_tx_isolation);
sys_var_thd_ulong	sys_tmp_table_size("tmp_table_size",
					   &SV::tmp_table_size);
sys_var_thd_ulong	sys_net_wait_timeout("wait_timeout",
					     &SV::net_wait_timeout);
/*
  Variables that are bits in THD
*/

static sys_var_thd_bit	sys_autocommit("autocommit",
				       set_option_autocommit,
				       OPTION_NOT_AUTOCOMMIT,
				       1);
static sys_var_thd_bit	sys_big_tables("big_tables",
				       set_option_bit,
				       OPTION_BIG_TABLES);
#ifndef TO_BE_DELETED	/* Alias for big_tables */
static sys_var_thd_bit	sys_sql_big_tables("sql_big_tables",
					   set_option_bit,
					   OPTION_BIG_TABLES);
#endif
static sys_var_thd_bit	sys_big_selects("sql_big_selects",
					set_option_bit,
					OPTION_BIG_TABLES);
static sys_var_thd_bit	sys_log_off("sql_log_off",
				    set_option_bit,
				    OPTION_LOG_OFF);
static sys_var_thd_bit	sys_log_update("sql_log_update",
				       set_log_update,
				       OPTION_UPDATE_LOG);
static sys_var_thd_bit	sys_log_binlog("sql_log_bin",
					set_log_update,
					OPTION_BIN_LOG);
static sys_var_thd_bit	sys_sql_warnings("sql_warnings",
					 set_option_bit,
					 OPTION_WARNINGS);
static sys_var_thd_bit	sys_auto_is_null("sql_auto_is_null",
					 set_option_bit,
					 OPTION_AUTO_IS_NULL);
static sys_var_thd_bit	sys_safe_updates("sql_safe_updates",
					 set_option_bit,
					 OPTION_SAFE_UPDATES);
static sys_var_thd_bit	sys_buffer_results("sql_buffer_result",
					   set_option_bit,
					   OPTION_BUFFER_RESULT);
static sys_var_thd_bit	sys_quote_show_create("sql_quote_show_create",
					      set_option_bit,
					      OPTION_QUOTE_SHOW_CREATE);
299 300 301 302 303 304 305 306 307
static sys_var_thd_bit	sys_foreign_key_checks("foreign_key_checks",
					       set_option_bit,
					       OPTION_NO_FOREIGN_KEY_CHECKS,
					       1);
static sys_var_thd_bit	sys_unique_checks("unique_checks",
					  set_option_bit,
					  OPTION_RELAXED_UNIQUE_CHECKS,
					  1);

308 309 310

/* Local state variables */

311
static sys_var_thd_ha_rows	sys_select_limit("sql_select_limit",
312 313 314 315 316
						 &SV::select_limit);
static sys_var_timestamp	sys_timestamp("timestamp");
static sys_var_last_insert_id	sys_last_insert_id("last_insert_id");
static sys_var_last_insert_id	sys_identity("identity");
static sys_var_insert_id	sys_insert_id("insert_id");
317 318 319 320 321 322 323 324 325
static sys_var_readonly		sys_error_count("error_count",
						OPT_SESSION,
						SHOW_LONG,
						get_error_count);
static sys_var_readonly		sys_warning_count("warning_count",
						  OPT_SESSION,
						  SHOW_LONG,
						  get_warning_count);

326
/* alias for last_insert_id() to be compatible with Sybase */
hf@deer.mysql.r18.ru's avatar
SCRUM  
hf@deer.mysql.r18.ru committed
327
#ifdef HAVE_REPLICATION
328
static sys_var_slave_skip_counter sys_slave_skip_counter("sql_slave_skip_counter");
329
#endif
330 331
static sys_var_rand_seed1	sys_rand_seed1("rand_seed1");
static sys_var_rand_seed2	sys_rand_seed2("rand_seed2");
332

333 334
static sys_var_thd_ulong        sys_default_week_format("default_week_format",
					                &SV::default_week_format);
335

336 337 338
sys_var_thd_ulong               sys_group_concat_max_len("group_concat_max_len",
                                                         &SV::group_concat_max_len);

339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355
/*
  List of all variables for initialisation and storage in hash
  This is sorted in alphabetical order to make it easy to add new variables

  If the variable is not in this list, it can't be changed with
  SET variable_name=
*/

sys_var *sys_variables[]=
{
  &sys_auto_is_null,
  &sys_autocommit,
  &sys_big_tables,
  &sys_big_selects,
  &sys_binlog_cache_size,
  &sys_buffer_results,
  &sys_bulk_insert_buff_size,
356 357 358
  &sys_collation_client,
  &sys_collation_connection,
  &sys_collation_results,
359 360
  &sys_concurrent_insert,
  &sys_connect_timeout,
361
  &sys_default_week_format,
362 363 364 365
  &sys_delay_key_write,
  &sys_delayed_insert_limit,
  &sys_delayed_insert_timeout,
  &sys_delayed_queue_size,
366
  &sys_error_count,
367
  &sys_expire_logs_days,
368 369
  &sys_flush,
  &sys_flush_time,
370
  &sys_foreign_key_checks,
371
  &sys_group_concat_max_len,
372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390
  &sys_identity,
  &sys_insert_id,
  &sys_interactive_timeout,
  &sys_join_buffer_size,
  &sys_key_buffer_size,
  &sys_last_insert_id,
  &sys_local_infile,
  &sys_log_binlog,
  &sys_log_off,
  &sys_log_update,
  &sys_log_warnings,
  &sys_long_query_time,
  &sys_low_priority_updates,
  &sys_max_allowed_packet,
  &sys_max_binlog_cache_size,
  &sys_max_binlog_size,
  &sys_max_connect_errors,
  &sys_max_connections,
  &sys_max_delayed_threads,
391
  &sys_max_error_count,
392 393
  &sys_max_heap_table_size,
  &sys_max_join_size,
igor@hundin.mysql.fi's avatar
igor@hundin.mysql.fi committed
394
  &sys_max_length_for_sort_data,
395
  &sys_max_prep_stmt_count,
396 397 398 399 400 401 402 403 404
  &sys_max_sort_length,
  &sys_max_tmp_tables,
  &sys_max_user_connections,
  &sys_max_write_lock_count,
  &sys_myisam_max_extra_sort_file_size,
  &sys_myisam_max_sort_file_size,
  &sys_myisam_sort_buffer_size,
  &sys_net_buffer_length,
  &sys_net_read_timeout,
405
  &sys_net_retry_count,
406 407
  &sys_net_wait_timeout,
  &sys_net_write_timeout,
408
  &sys_new_mode,
409
  &sys_pseudo_thread_id,
410 411 412
  &sys_query_cache_size,
#ifdef HAVE_QUERY_CACHE
  &sys_query_cache_limit,
413
  &sys_query_cache_min_res_unit,
414
  &sys_query_cache_type,
415
#endif /* HAVE_QUERY_CACHE */
416
  &sys_quote_show_create,
417 418
  &sys_rand_seed1,
  &sys_rand_seed2,
419 420
  &sys_read_buff_size,
  &sys_read_rnd_buff_size,
421 422 423
#ifdef HAVE_REPLICATION
  &sys_relay_log_purge,
#endif
424 425 426 427
  &sys_rpl_recovery_rank,
  &sys_safe_updates,
  &sys_select_limit,
  &sys_server_id,
hf@deer.mysql.r18.ru's avatar
SCRUM  
hf@deer.mysql.r18.ru committed
428
#ifdef HAVE_REPLICATION
429
  &sys_slave_compressed_protocol,
430 431
  &sys_slave_net_timeout,
  &sys_slave_skip_counter,
432
#endif
433 434 435 436 437
  &sys_slow_launch_time,
  &sys_sort_buffer,
  &sys_sql_big_tables,
  &sys_sql_low_priority_updates,
  &sys_sql_max_join_size,
438
  &sys_sql_mode,
439 440 441 442 443 444 445
  &sys_sql_warnings,
  &sys_table_cache_size,
  &sys_table_type,
  &sys_thread_cache_size,
  &sys_timestamp,
  &sys_tmp_table_size,
  &sys_tx_isolation,
446 447
  &sys_unique_checks,
  &sys_warning_count
448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469
};


/*
  Variables shown by SHOW variables in alphabetical order
*/

struct show_var_st init_vars[]= {
  {"back_log",                (char*) &back_log,                    SHOW_LONG},
  {"basedir",                 mysql_home,                           SHOW_CHAR},
#ifdef HAVE_BERKELEY_DB
  {"bdb_cache_size",          (char*) &berkeley_cache_size,         SHOW_LONG},
  {"bdb_log_buffer_size",     (char*) &berkeley_log_buffer_size,    SHOW_LONG},
  {"bdb_home",                (char*) &berkeley_home,               SHOW_CHAR_PTR},
  {"bdb_max_lock",            (char*) &berkeley_max_lock,	    SHOW_LONG},
  {"bdb_logdir",              (char*) &berkeley_logdir,             SHOW_CHAR_PTR},
  {"bdb_shared_data",	      (char*) &berkeley_shared_data,	    SHOW_BOOL},
  {"bdb_tmpdir",              (char*) &berkeley_tmpdir,             SHOW_CHAR_PTR},
  {"bdb_version",             (char*) DB_VERSION_STRING,            SHOW_CHAR},
#endif
  {sys_binlog_cache_size.name,(char*) &sys_binlog_cache_size,	    SHOW_SYS},
  {sys_bulk_insert_buff_size.name,(char*) &sys_bulk_insert_buff_size,SHOW_SYS},
470 471
  {sys_charset.name, 	      (char*) &sys_charset,		    SHOW_SYS},
  {sys_charset_system.name,   (char*) &sys_charset_system,          SHOW_SYS},
472 473 474
  {sys_collation_client.name, (char*) &sys_collation_client,	    SHOW_SYS},
  {sys_collation_connection.name,(char*) &sys_collation_connection, SHOW_SYS},
  {sys_collation_results.name, (char*) &sys_collation_results,	    SHOW_SYS},
475 476 477
  {sys_concurrent_insert.name,(char*) &sys_concurrent_insert,       SHOW_SYS},
  {sys_connect_timeout.name,  (char*) &sys_connect_timeout,         SHOW_SYS},
  {"datadir",                 mysql_real_data_home,                 SHOW_CHAR},
478
  {"default_week_format",     (char*) &sys_default_week_format,     SHOW_SYS},
479 480 481 482
  {sys_delay_key_write.name,  (char*) &sys_delay_key_write,         SHOW_SYS},
  {sys_delayed_insert_limit.name, (char*) &sys_delayed_insert_limit,SHOW_SYS},
  {sys_delayed_insert_timeout.name, (char*) &sys_delayed_insert_timeout, SHOW_SYS},
  {sys_delayed_queue_size.name,(char*) &sys_delayed_queue_size,     SHOW_SYS},
483
  {sys_expire_logs_days.name, (char*) &sys_expire_logs_days,        SHOW_SYS},
484 485
  {sys_flush.name,             (char*) &sys_flush,                  SHOW_SYS},
  {sys_flush_time.name,        (char*) &sys_flush_time,             SHOW_SYS},
486
  {"ft_boolean_syntax",       (char*) ft_boolean_syntax,	    SHOW_CHAR},
487 488 489
  {"ft_min_word_len",         (char*) &ft_min_word_len,             SHOW_LONG},
  {"ft_max_word_len",         (char*) &ft_max_word_len,             SHOW_LONG},
  {"ft_max_word_len_for_sort",(char*) &ft_max_word_len_for_sort,    SHOW_LONG},
490
  {"ft_stopword_file",        (char*) &ft_stopword_file,            SHOW_CHAR_PTR},
491
  {"have_bdb",		      (char*) &have_berkeley_db,	    SHOW_HAVE},
monty@mashka.mysql.fi's avatar
monty@mashka.mysql.fi committed
492
  {"have_crypt",	      (char*) &have_crypt,		    SHOW_HAVE},
493
  {"have_compress",	      (char*) &have_compress,		    SHOW_HAVE},
494 495 496 497 498 499 500 501 502 503
  {"have_innodb",	      (char*) &have_innodb,		    SHOW_HAVE},
  {"have_isam",	      	      (char*) &have_isam,		    SHOW_HAVE},
  {"have_raid",		      (char*) &have_raid,		    SHOW_HAVE},
  {"have_symlink",            (char*) &have_symlink,         	    SHOW_HAVE},
  {"have_openssl",	      (char*) &have_openssl,		    SHOW_HAVE},
  {"have_query_cache",        (char*) &have_query_cache,            SHOW_HAVE},
  {"init_file",               (char*) &opt_init_file,               SHOW_CHAR_PTR},
#ifdef HAVE_INNOBASE_DB
  {"innodb_additional_mem_pool_size", (char*) &innobase_additional_mem_pool_size, SHOW_LONG },
  {"innodb_buffer_pool_size", (char*) &innobase_buffer_pool_size, SHOW_LONG },
504
  {"innodb_buffer_pool_awe_mem_mb", (char*) &innobase_buffer_pool_awe_mem_mb, SHOW_LONG },
505 506 507 508 509
  {"innodb_data_file_path", (char*) &innobase_data_file_path,	    SHOW_CHAR_PTR},
  {"innodb_data_home_dir",  (char*) &innobase_data_home_dir,	    SHOW_CHAR_PTR},
  {"innodb_file_io_threads", (char*) &innobase_file_io_threads, SHOW_LONG },
  {"innodb_force_recovery", (char*) &innobase_force_recovery, SHOW_LONG },
  {"innodb_thread_concurrency", (char*) &innobase_thread_concurrency, SHOW_LONG },
heikki@hundin.mysql.fi's avatar
heikki@hundin.mysql.fi committed
510
  {"innodb_flush_log_at_trx_commit", (char*) &innobase_flush_log_at_trx_commit, SHOW_INT},
511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533
  {"innodb_fast_shutdown", (char*) &innobase_fast_shutdown, SHOW_MY_BOOL},
  {"innodb_flush_method",    (char*) &innobase_unix_file_flush_method, SHOW_CHAR_PTR},
  {"innodb_lock_wait_timeout", (char*) &innobase_lock_wait_timeout, SHOW_LONG },
  {"innodb_log_arch_dir",   (char*) &innobase_log_arch_dir, 	    SHOW_CHAR_PTR},
  {"innodb_log_archive",    (char*) &innobase_log_archive, 	    SHOW_MY_BOOL},
  {"innodb_log_buffer_size", (char*) &innobase_log_buffer_size, SHOW_LONG },
  {"innodb_log_file_size", (char*) &innobase_log_file_size, SHOW_LONG},
  {"innodb_log_files_in_group", (char*) &innobase_log_files_in_group,	SHOW_LONG},
  {"innodb_log_group_home_dir", (char*) &innobase_log_group_home_dir, SHOW_CHAR_PTR},
  {"innodb_mirrored_log_groups", (char*) &innobase_mirrored_log_groups, SHOW_LONG},
#endif
  {sys_interactive_timeout.name,(char*) &sys_interactive_timeout,   SHOW_SYS},
  {sys_join_buffer_size.name,   (char*) &sys_join_buffer_size,	    SHOW_SYS},
  {sys_key_buffer_size.name,	(char*) &sys_key_buffer_size,	    SHOW_SYS},
  {"language",                language,                             SHOW_CHAR},
  {"large_files_support",     (char*) &opt_large_files,             SHOW_BOOL},	
  {sys_local_infile.name,     (char*) &sys_local_infile,	    SHOW_SYS},
#ifdef HAVE_MLOCKALL
  {"locked_in_memory",	      (char*) &locked_in_memory,	    SHOW_BOOL},
#endif
  {"log",                     (char*) &opt_log,                     SHOW_BOOL},
  {"log_update",              (char*) &opt_update_log,              SHOW_BOOL},
  {"log_bin",                 (char*) &opt_bin_log,                 SHOW_BOOL},
hf@deer.mysql.r18.ru's avatar
SCRUM  
hf@deer.mysql.r18.ru committed
534
#ifdef HAVE_REPLICATION
535
  {"log_slave_updates",       (char*) &opt_log_slave_updates,       SHOW_MY_BOOL},
536
#endif
537 538 539 540 541 542 543 544 545 546
  {"log_slow_queries",        (char*) &opt_slow_log,                SHOW_BOOL},
  {sys_log_warnings.name,     (char*) &sys_log_warnings,	    SHOW_SYS},
  {sys_long_query_time.name,  (char*) &sys_long_query_time, 	    SHOW_SYS},
  {sys_low_priority_updates.name, (char*) &sys_low_priority_updates, SHOW_SYS},
  {"lower_case_table_names",  (char*) &lower_case_table_names,      SHOW_MY_BOOL},
  {sys_max_allowed_packet.name,(char*) &sys_max_allowed_packet,	    SHOW_SYS},
  {sys_max_binlog_cache_size.name,(char*) &sys_max_binlog_cache_size, SHOW_SYS},
  {sys_max_binlog_size.name,    (char*) &sys_max_binlog_size,	    SHOW_SYS},
  {sys_max_connections.name,    (char*) &sys_max_connections,	    SHOW_SYS},
  {sys_max_connect_errors.name, (char*) &sys_max_connect_errors,    SHOW_SYS},
547
  {sys_max_error_count.name,	(char*) &sys_max_error_count,	    SHOW_SYS},
548 549 550
  {sys_max_delayed_threads.name,(char*) &sys_max_delayed_threads,   SHOW_SYS},
  {sys_max_heap_table_size.name,(char*) &sys_max_heap_table_size,   SHOW_SYS},
  {sys_max_join_size.name,	(char*) &sys_max_join_size,	    SHOW_SYS},
igor@hundin.mysql.fi's avatar
igor@hundin.mysql.fi committed
551 552 553
  {sys_max_length_for_sort_data.name,
   (char*) &sys_max_length_for_sort_data,
   SHOW_SYS},
554
  {sys_max_prep_stmt_count.name,(char*) &sys_max_prep_stmt_count,   SHOW_SYS},
555 556 557 558 559 560 561 562 563 564 565 566 567
  {sys_max_sort_length.name,	(char*) &sys_max_sort_length,	    SHOW_SYS},
  {sys_max_user_connections.name,(char*) &sys_max_user_connections, SHOW_SYS},
  {sys_max_tmp_tables.name,	(char*) &sys_max_tmp_tables,   	    SHOW_SYS},
  {sys_max_write_lock_count.name, (char*) &sys_max_write_lock_count,SHOW_SYS},
  {sys_myisam_max_extra_sort_file_size.name,
   (char*) &sys_myisam_max_extra_sort_file_size,
   SHOW_SYS},
  {sys_myisam_max_sort_file_size.name,
   (char*) &sys_myisam_max_sort_file_size,
   SHOW_SYS},
  {"myisam_recover_options",  (char*) &myisam_recover_options_str,  SHOW_CHAR_PTR},
  {sys_myisam_sort_buffer_size.name, (char*) &sys_myisam_sort_buffer_size, SHOW_SYS},
#ifdef __NT__
568
  {"named_pipe",	      (char*) &opt_enable_named_pipe,       SHOW_MY_BOOL},
569 570 571
#endif
  {sys_net_buffer_length.name,(char*) &sys_net_buffer_length,       SHOW_SYS},
  {sys_net_read_timeout.name, (char*) &sys_net_read_timeout,        SHOW_SYS},
572
  {sys_net_retry_count.name,  (char*) &sys_net_retry_count,	    SHOW_SYS},
573
  {sys_net_write_timeout.name,(char*) &sys_net_write_timeout,       SHOW_SYS},
574
  {sys_new_mode.name,         (char*) &sys_new_mode,                SHOW_SYS},
575 576
  {"open_files_limit",	      (char*) &open_files_limit,	    SHOW_LONG},
  {"pid_file",                (char*) pidfile_name,                 SHOW_CHAR},
577
  {"log_error",               (char*) log_error_file,               SHOW_CHAR},
578 579
  {"port",                    (char*) &mysql_port,                  SHOW_INT},
  {"protocol_version",        (char*) &protocol_version,            SHOW_INT},
580
  {sys_pseudo_thread_id.name, (char*) &sys_pseudo_thread_id,        SHOW_SYS},
581 582
  {sys_read_buff_size.name,   (char*) &sys_read_buff_size,	    SHOW_SYS},
  {sys_read_rnd_buff_size.name,(char*) &sys_read_rnd_buff_size,	    SHOW_SYS},
583 584 585
#ifdef HAVE_REPLICATION
  {sys_relay_log_purge.name,  (char*) &sys_relay_log_purge,         SHOW_SYS},
#endif
586
  {sys_rpl_recovery_rank.name,(char*) &sys_rpl_recovery_rank,       SHOW_SYS},
587
#ifdef HAVE_QUERY_CACHE
588
  {sys_query_cache_limit.name,(char*) &sys_query_cache_limit,	    SHOW_SYS},
589 590
  {sys_query_cache_min_res_unit.name, (char*) &sys_query_cache_min_res_unit,
   SHOW_SYS},
591 592 593
  {sys_query_cache_size.name, (char*) &sys_query_cache_size,	    SHOW_SYS},
  {sys_query_cache_type.name, (char*) &sys_query_cache_type,        SHOW_SYS},
#endif /* HAVE_QUERY_CACHE */
594 595 596 597
#ifdef HAVE_SMEM
  {"shared_memory",           (char*) &opt_enable_shared_memory,    SHOW_MY_BOOL},
  {"shared_memory_base_name", (char*) &shared_memory_base_name,     SHOW_CHAR_PTR},
#endif
598
  {sys_server_id.name,	      (char*) &sys_server_id,		    SHOW_SYS},
hf@deer.mysql.r18.ru's avatar
SCRUM  
hf@deer.mysql.r18.ru committed
599
#ifdef HAVE_REPLICATION
600
  {sys_slave_net_timeout.name,(char*) &sys_slave_net_timeout,	    SHOW_SYS},
601
#endif
602
  {"skip_external_locking",   (char*) &my_disable_locking,          SHOW_MY_BOOL},
603 604 605
  {"skip_networking",         (char*) &opt_disable_networking,      SHOW_BOOL},
  {"skip_show_database",      (char*) &opt_skip_show_db,            SHOW_BOOL},
  {sys_slow_launch_time.name, (char*) &sys_slow_launch_time,        SHOW_SYS},
606
#ifdef HAVE_SYS_UN_H
607
  {"socket",                  (char*) &mysql_unix_port,             SHOW_CHAR_PTR},
608
#endif
609
  {sys_sort_buffer.name,      (char*) &sys_sort_buffer, 	    SHOW_SYS},
610
  {sys_sql_mode.name,         (char*) &sys_sql_mode,                SHOW_SYS},
611 612 613 614 615 616 617 618 619 620 621 622
  {"table_cache",             (char*) &table_cache_size,            SHOW_LONG},
  {sys_table_type.name,	      (char*) &sys_table_type,	            SHOW_SYS},
  {sys_thread_cache_size.name,(char*) &sys_thread_cache_size,       SHOW_SYS},
#ifdef HAVE_THR_SETCONCURRENCY
  {"thread_concurrency",      (char*) &concurrency,                 SHOW_LONG},
#endif
  {"thread_stack",            (char*) &thread_stack,                SHOW_LONG},
  {sys_tx_isolation.name,     (char*) &sys_tx_isolation,	    SHOW_SYS},
#ifdef HAVE_TZNAME
  {"timezone",                time_zone,                            SHOW_CHAR},
#endif
  {sys_tmp_table_size.name,   (char*) &sys_tmp_table_size,	    SHOW_SYS},
623
  {"tmpdir",                  (char*) &opt_mysql_tmpdir,            SHOW_CHAR_PTR},
624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675
  {"version",                 server_version,                       SHOW_CHAR},
  {sys_net_wait_timeout.name, (char*) &sys_net_wait_timeout,	    SHOW_SYS},
  {NullS, NullS, SHOW_LONG}
};

/*
  Functions to check and update variables
*/

/*
  The following 3 functions need to be changed in 4.1 when we allow
  one to change character sets
*/

static bool sys_check_charset(THD *thd, set_var *var)
{
  return 0;
}


static bool sys_update_charset(THD *thd, set_var *var)
{
  return 0;
}


static void sys_set_default_charset(THD *thd, enum_var_type type)
{
}


/*
  If one sets the LOW_PRIORIY UPDATES flag, we also must change the
  used lock type
*/

static void fix_low_priority_updates(THD *thd, enum_var_type type)
{
  if (type != OPT_GLOBAL)
    thd->update_lock_default= (thd->variables.low_priority_updates ?
			       TL_WRITE_LOW_PRIORITY : TL_WRITE);
}


/*
  Set the OPTION_BIG_SELECTS flag if max_join_size == HA_POS_ERROR
*/

static void fix_max_join_size(THD *thd, enum_var_type type)
{
  if (type != OPT_GLOBAL)
  {
676
    if (thd->variables.max_join_size == HA_POS_ERROR)
677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700
      thd->options|= OPTION_BIG_SELECTS;
    else
      thd->options&= ~OPTION_BIG_SELECTS;
  }
}
  

/*
  If one doesn't use the SESSION modifier, the isolation level
  is only active for the next command
*/

static void fix_tx_isolation(THD *thd, enum_var_type type)
{
  if (type == OPT_SESSION)
    thd->session_tx_isolation= ((enum_tx_isolation)
				thd->variables.tx_isolation);
}


/*
  If we are changing the thread variable, we have to copy it to NET too
*/

hf@deer.mysql.r18.ru's avatar
SCRUM  
hf@deer.mysql.r18.ru committed
701
#ifdef HAVE_REPLICATION
702 703 704 705 706 707 708 709 710 711 712 713 714
static void fix_net_read_timeout(THD *thd, enum_var_type type)
{
  if (type != OPT_GLOBAL)
    thd->net.read_timeout=thd->variables.net_read_timeout;
}


static void fix_net_write_timeout(THD *thd, enum_var_type type)
{
  if (type != OPT_GLOBAL)
    thd->net.write_timeout=thd->variables.net_write_timeout;
}

715 716 717 718 719
static void fix_net_retry_count(THD *thd, enum_var_type type)
{
  if (type != OPT_GLOBAL)
    thd->net.retry_count=thd->variables.net_retry_count;
}
hf@deer.mysql.r18.ru's avatar
SCRUM  
hf@deer.mysql.r18.ru committed
720 721 722
#else /* HAVE_REPLICATION */
static void fix_net_read_timeout(THD *thd __attribute__(unused),
				 enum_var_type type __attribute__(unused))
723
{}
hf@deer.mysql.r18.ru's avatar
SCRUM  
hf@deer.mysql.r18.ru committed
724 725
static void fix_net_write_timeout(THD *thd __attribute__(unused),
				  enum_var_type type __attribute__(unused))
726
{}
hf@deer.mysql.r18.ru's avatar
SCRUM  
hf@deer.mysql.r18.ru committed
727 728
static void fix_net_retry_count(THD *thd __attribute__(unused),
				enum_var_type type __attribute__(unused))
729
{}
hf@deer.mysql.r18.ru's avatar
SCRUM  
hf@deer.mysql.r18.ru committed
730
#endif /* HAVE_REPLICATION */
731

732 733 734 735 736 737 738 739 740

static void fix_query_cache_size(THD *thd, enum_var_type type)
{
#ifdef HAVE_QUERY_CACHE
  query_cache.resize(query_cache_size);
#endif
}


741 742 743 744 745 746 747 748 749
#ifdef HAVE_QUERY_CACHE
static void fix_query_cache_min_res_unit(THD *thd, enum_var_type type)
{
  query_cache_min_res_unit= 
    query_cache.set_min_res_unit(query_cache_min_res_unit);
}
#endif


750 751 752 753 754 755
static void fix_key_buffer_size(THD *thd, enum_var_type type)
{
  ha_resize_key_cache();
}


756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772
void fix_delay_key_write(THD *thd, enum_var_type type)
{
  switch ((enum_delay_key_write) delay_key_write_options) {
  case DELAY_KEY_WRITE_NONE:
    myisam_delay_key_write=0;
    break;
  case DELAY_KEY_WRITE_ON:
    myisam_delay_key_write=1;
    break;
  case DELAY_KEY_WRITE_ALL:
    myisam_delay_key_write=1;
    ha_open_options|= HA_OPEN_DELAY_KEY_WRITE;
    break;
  }
}


773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789
bool sys_var_long_ptr::update(THD *thd, set_var *var)
{
  ulonglong tmp= var->value->val_int();
  if (option_limits)
    *value= (ulong) getopt_ull_limit_value(tmp, option_limits);
  else
    *value= (ulong) tmp;
  return 0;
}


void sys_var_long_ptr::set_default(THD *thd, enum_var_type type)
{
  *value= (ulong) option_limits->def_value;
}


790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806
bool sys_var_ulonglong_ptr::update(THD *thd, set_var *var)
{
  ulonglong tmp= var->value->val_int();
  if (option_limits)
    *value= (ulonglong) getopt_ull_limit_value(tmp, option_limits);
  else
    *value= (ulonglong) tmp;
  return 0;
}


void sys_var_ulonglong_ptr::set_default(THD *thd, enum_var_type type)
{
  *value= (ulonglong) option_limits->def_value;
}


807 808 809 810 811 812 813 814 815 816 817 818 819
bool sys_var_bool_ptr::update(THD *thd, set_var *var)
{
  *value= (my_bool) var->save_result.ulong_value;
  return 0;
}


void sys_var_bool_ptr::set_default(THD *thd, enum_var_type type)
{
  *value= (my_bool) option_limits->def_value;
}


820 821 822 823 824 825 826 827 828 829 830 831 832
bool sys_var_enum::update(THD *thd, set_var *var)
{
  *value= (uint) var->save_result.ulong_value;
  return 0;
}


byte *sys_var_enum::value_ptr(THD *thd, enum_var_type type)
{
  return (byte*) enum_names->type_names[*value];
}


833 834 835 836 837 838 839 840 841 842 843
bool sys_var_thd_ulong::update(THD *thd, set_var *var)
{
  ulonglong tmp= var->value->val_int();

  /* Don't use bigger value than given with --maximum-variable-name=.. */
  if ((ulong) tmp > max_system_variables.*offset)
    tmp= max_system_variables.*offset;

  if (option_limits)
    tmp= (ulong) getopt_ull_limit_value(tmp, option_limits);
  if (var->type == OPT_GLOBAL)
844
    global_system_variables.*offset= (ulong) tmp;
845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870
  else
    thd->variables.*offset= (ulong) tmp;
  return 0;
}


void sys_var_thd_ulong::set_default(THD *thd, enum_var_type type)
{
  if (type == OPT_GLOBAL)
  {
    /* We will not come here if option_limits is not set */
    global_system_variables.*offset= (ulong) option_limits->def_value;
  }
  else
    thd->variables.*offset= global_system_variables.*offset;
}


byte *sys_var_thd_ulong::value_ptr(THD *thd, enum_var_type type)
{
  if (type == OPT_GLOBAL)
    return (byte*) &(global_system_variables.*offset);
  return (byte*) &(thd->variables.*offset);
}


871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915
bool sys_var_thd_ha_rows::update(THD *thd, set_var *var)
{
  ulonglong tmp= var->value->val_int();

  /* Don't use bigger value than given with --maximum-variable-name=.. */
  if ((ha_rows) tmp > max_system_variables.*offset)
    tmp= max_system_variables.*offset;

  if (option_limits)
    tmp= (ha_rows) getopt_ull_limit_value(tmp, option_limits);
  if (var->type == OPT_GLOBAL)
  {
    /* Lock is needed to make things safe on 32 bit systems */
    pthread_mutex_lock(&LOCK_global_system_variables);    
    global_system_variables.*offset= (ha_rows) tmp;
    pthread_mutex_unlock(&LOCK_global_system_variables);
  }
  else
    thd->variables.*offset= (ha_rows) tmp;
  return 0;
}


void sys_var_thd_ha_rows::set_default(THD *thd, enum_var_type type)
{
  if (type == OPT_GLOBAL)
  {
    /* We will not come here if option_limits is not set */
    pthread_mutex_lock(&LOCK_global_system_variables);
    global_system_variables.*offset= (ha_rows) option_limits->def_value;
    pthread_mutex_unlock(&LOCK_global_system_variables);
  }
  else
    thd->variables.*offset= global_system_variables.*offset;
}


byte *sys_var_thd_ha_rows::value_ptr(THD *thd, enum_var_type type)
{
  if (type == OPT_GLOBAL)
    return (byte*) &(global_system_variables.*offset);
  return (byte*) &(thd->variables.*offset);
}


916 917 918
bool sys_var_thd_ulonglong::update(THD *thd,  set_var *var)
{
  if (var->type == OPT_GLOBAL)
919 920 921
  {
    /* Lock is needed to make things safe on 32 bit systems */
    pthread_mutex_lock(&LOCK_global_system_variables);
922
    global_system_variables.*offset= var->value->val_int();
923 924
    pthread_mutex_unlock(&LOCK_global_system_variables);
  }
925 926 927 928 929 930 931 932 933
  else
    thd->variables.*offset= var->value->val_int();
  return 0;
}


void sys_var_thd_ulonglong::set_default(THD *thd, enum_var_type type)
{
  if (type == OPT_GLOBAL)
934 935
  {
    pthread_mutex_lock(&LOCK_global_system_variables);
936
    global_system_variables.*offset= (ulonglong) option_limits->def_value;
937 938
    pthread_mutex_unlock(&LOCK_global_system_variables);
  }
939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981
  else
    thd->variables.*offset= global_system_variables.*offset;
}


byte *sys_var_thd_ulonglong::value_ptr(THD *thd, enum_var_type type)
{
  if (type == OPT_GLOBAL)
    return (byte*) &(global_system_variables.*offset);
  return (byte*) &(thd->variables.*offset);
}


bool sys_var_thd_bool::update(THD *thd,  set_var *var)
{
  if (var->type == OPT_GLOBAL)
    global_system_variables.*offset= (my_bool) var->save_result.ulong_value;
  else
    thd->variables.*offset= (my_bool) var->save_result.ulong_value;
  return 0;
}


void sys_var_thd_bool::set_default(THD *thd,  enum_var_type type)
{
  if (type == OPT_GLOBAL)
    global_system_variables.*offset= (my_bool) option_limits->def_value;
  else
    thd->variables.*offset= global_system_variables.*offset;
}


byte *sys_var_thd_bool::value_ptr(THD *thd, enum_var_type type)
{
  if (type == OPT_GLOBAL)
    return (byte*) &(global_system_variables.*offset);
  return (byte*) &(thd->variables.*offset);
}


bool sys_var::check_enum(THD *thd, set_var *var, TYPELIB *enum_names)
{
  char buff[80], *value;
982
  String str(buff, sizeof(buff), system_charset_info), *res;
983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012

  if (var->value->result_type() == STRING_RESULT)
  {
    if (!(res=var->value->val_str(&str)) ||
	((long) (var->save_result.ulong_value=
		 (ulong) find_type(res->c_ptr(), enum_names, 3)-1))
	< 0)
    {
      value=res->c_ptr();
      goto err;
    }
  }
  else
  {
    ulonglong tmp=var->value->val_int();
    if (tmp >= enum_names->count)
    {
      llstr(tmp,buff);
      value=buff;				// Wrong value is here
      goto err;
    }
    var->save_result.ulong_value= (ulong) tmp;	// Save for update
  }
  return 0;

err:
  my_error(ER_WRONG_VALUE_FOR_VAR, MYF(0), name, value);
  return 1;
}

1013 1014 1015 1016


bool sys_var::check_set(THD *thd, set_var *var, TYPELIB *enum_names)
{
1017
  bool not_used;
1018
  char buff[80], *error= 0;
1019 1020 1021 1022 1023 1024 1025
  uint error_len= 0;
  String str(buff, sizeof(buff), system_charset_info), *res;

  if (var->value->result_type() == STRING_RESULT)
  {
    if (!(res= var->value->val_str(&str)))
      goto err;
1026
    var->save_result.ulong_value= (ulong)
1027
      find_set(enum_names, res->c_ptr(), res->length(), &error, &error_len, &not_used);
1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051
    if (error_len)
    {
      strmake(buff, error, min(sizeof(buff), error_len));
      goto err;
    }
  }
  else
  {
    ulonglong tmp= var->value->val_int();
    if (tmp >= enum_names->count)
    {
      llstr(tmp, buff);
      goto err;
    }
    var->save_result.ulong_value= (ulong) tmp;  // Save for update
  }
  return 0;

err:
  my_error(ER_WRONG_VALUE_FOR_VAR, MYF(0), name, buff);
  return 1;
}


1052 1053 1054 1055 1056 1057 1058
/*
  Return an Item for a variable.  Used with @@[global.]variable_name

  If type is not given, return local value if exists, else global

  We have to use netprintf() instead of my_error() here as this is
  called on the parsing stage.
1059 1060 1061 1062

  TODO:
    With prepared statements/stored procedures this has to be fixed
    to create an item that gets the current value at fix_fields() stage.
1063 1064 1065 1066 1067 1068 1069 1070
*/

Item *sys_var::item(THD *thd, enum_var_type var_type)
{
  if (check_type(var_type))
  {
    if (var_type != OPT_DEFAULT)
    {
1071
      net_printf(thd,
1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083
		 var_type == OPT_GLOBAL ? ER_LOCAL_VARIABLE :
		 ER_GLOBAL_VARIABLE, name);
      return 0;
    }
    /* As there was no local variable, return the global value */
    var_type= OPT_GLOBAL;
  }
  switch (type()) {
  case SHOW_LONG:
    return new Item_uint((int32) *(ulong*) value_ptr(thd, var_type));
  case SHOW_LONGLONG:
    return new Item_int(*(longlong*) value_ptr(thd, var_type));
1084 1085
  case SHOW_HA_ROWS:
    return new Item_int((longlong) *(ha_rows*) value_ptr(thd, var_type));
1086 1087 1088 1089 1090
  case SHOW_MY_BOOL:
    return new Item_int((int32) *(my_bool*) value_ptr(thd, var_type),1);
  case SHOW_CHAR:
  {
    char *str= (char*) value_ptr(thd, var_type);
1091
    return new Item_string(str, strlen(str), system_charset_info);
1092 1093
  }
  default:
1094
    net_printf(thd, ER_VAR_CANT_BE_READ, name);
1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127
  }
  return 0;
}


bool sys_var_thd_enum::update(THD *thd, set_var *var)
{
  if (var->type == OPT_GLOBAL)
    global_system_variables.*offset= var->save_result.ulong_value;
  else
    thd->variables.*offset= var->save_result.ulong_value;
  return 0;
}


void sys_var_thd_enum::set_default(THD *thd, enum_var_type type)
{
  if (type == OPT_GLOBAL)
    global_system_variables.*offset= (ulong) option_limits->def_value;
  else
    thd->variables.*offset= global_system_variables.*offset;
}


byte *sys_var_thd_enum::value_ptr(THD *thd, enum_var_type type)
{
  ulong tmp= ((type == OPT_GLOBAL) ?
	      global_system_variables.*offset :
	      thd->variables.*offset);
  return (byte*) enum_names->type_names[tmp];
}


1128 1129 1130 1131
byte *sys_var_thd_sql_mode::value_ptr(THD *thd, enum_var_type type)
{
  ulong val;
  char buff[256];
1132
  String tmp(buff, sizeof(buff), &my_charset_latin1);
1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147
  my_bool found= 0;

  tmp.length(0);
  val= ((type == OPT_GLOBAL) ? global_system_variables.*offset :
        thd->variables.*offset);
  for (uint i= 0; val; val>>= 1, i++)
  {
    if (val & 1)
    {
      tmp.append(enum_names->type_names[i]);
      tmp.append(',');
    }
  }
  if (tmp.length())
    tmp.length(tmp.length() - 1);
1148
  return (byte*) thd->strmake(tmp.ptr(), tmp.length());
1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161
}


void sys_var_thd_sql_mode::set_default(THD *thd, enum_var_type type)
{
  if (type == OPT_GLOBAL)
    global_system_variables.*offset= 0;
  else
    thd->variables.*offset= global_system_variables.*offset;
}



1162 1163
bool sys_var_thd_bit::update(THD *thd, set_var *var)
{
1164
  int res= (*update_func)(thd, var);
1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181
  thd->lex.select_lex.options=thd->options;
  return res;
}


byte *sys_var_thd_bit::value_ptr(THD *thd, enum_var_type type)
{
  /*
    If reverse is 0 (default) return 1 if bit is set.
    If reverse is 1, return 0 if bit is set
  */
  thd->sys_var_tmp.my_bool_value= ((thd->options & bit_flag) ?
				   !reverse : reverse);
  return (byte*) &thd->sys_var_tmp.my_bool_value;
}


1182 1183
typedef struct old_names_map_st
{
1184 1185 1186
  const char *old_name;
  const char *new_name;
} my_old_conv;
1187

1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201
static my_old_conv old_conv[]= 
{
	{	"cp1251_koi8"		,	"cp1251"	},
	{	"cp1250_latin2"		,	"cp1250"	},
	{	"kam_latin2"		,	"keybcs2"	},
	{	"mac_latin2"		,	"MacRoman"	},
	{	"macce_latin2"		,	"MacCE"		},
	{	"pc2_latin2"		,	"pclatin2"	},
	{	"vga_latin2"		,	"pclatin1"	},
	{	"koi8_cp1251"		,	"koi8r"		},
	{	"win1251ukr_koi8_ukr"	,	"win1251ukr"	},
	{	"koi8_ukr_win1251ukr"	,	"koi8u"		},
	{	NULL			,	NULL		}
};
1202

1203
CHARSET_INFO *get_old_charset_by_name(const char *name)
1204
{
1205 1206 1207
  my_old_conv *c;
 
  for (c= old_conv; c->old_name; c++)
1208
  {
1209 1210
    if (!my_strcasecmp(&my_charset_latin1,name,c->old_name))
      return get_charset_by_name(c->new_name,MYF(0));
1211
  }
1212
  return NULL;
1213 1214
}

1215
bool sys_var_collation::check(THD *thd, set_var *var)
bar@bar.mysql.r18.ru's avatar
bar@bar.mysql.r18.ru committed
1216 1217 1218 1219 1220 1221 1222 1223
{
  CHARSET_INFO *tmp;
  char buff[80];
  String str(buff,sizeof(buff), system_charset_info), *res;

  if (!(res=var->value->val_str(&str)))
    res= &empty_string;

1224 1225
  if (!(tmp=get_charset_by_name(res->c_ptr(),MYF(0))) &&
      !(tmp=get_old_charset_by_name(res->c_ptr())))
bar@bar.mysql.r18.ru's avatar
bar@bar.mysql.r18.ru committed
1226 1227 1228 1229 1230 1231 1232 1233
  {
    my_error(ER_UNKNOWN_CHARACTER_SET, MYF(0), res->c_ptr());
    return 1;
  }
  var->save_result.charset= tmp;	// Save for update
  return 0;
}

1234
bool sys_var_collation_client::update(THD *thd, set_var *var)
bar@bar.mysql.r18.ru's avatar
bar@bar.mysql.r18.ru committed
1235 1236
{
  if (var->type == OPT_GLOBAL)
1237
    global_system_variables.collation_client= var->save_result.charset;
bar@bar.mysql.r18.ru's avatar
bar@bar.mysql.r18.ru committed
1238
  else
1239
    thd->variables.collation_client= var->save_result.charset;
bar@bar.mysql.r18.ru's avatar
bar@bar.mysql.r18.ru committed
1240 1241 1242
  return 0;
}

1243
byte *sys_var_collation_client::value_ptr(THD *thd, enum_var_type type)
bar@bar.mysql.r18.ru's avatar
bar@bar.mysql.r18.ru committed
1244 1245
{
  CHARSET_INFO *cs= ((type == OPT_GLOBAL) ?
1246 1247
		  global_system_variables.collation_client :
		  thd->variables.collation_client);
1248
  return cs ? (byte*) cs->name : (byte*) "";
bar@bar.mysql.r18.ru's avatar
bar@bar.mysql.r18.ru committed
1249 1250
}

1251
void sys_var_collation_client::set_default(THD *thd, enum_var_type type)
1252 1253
{
 if (type == OPT_GLOBAL)
1254
   global_system_variables.collation_client= default_charset_info;
1255
 else
1256
   thd->variables.collation_client= global_system_variables.collation_client;
1257
}
bar@bar.mysql.r18.ru's avatar
bar@bar.mysql.r18.ru committed
1258

1259

1260
bool sys_var_collation_connection::update(THD *thd, set_var *var)
1261 1262
{
  if (var->type == OPT_GLOBAL)
1263
    global_system_variables.collation_connection= var->save_result.charset;
1264
  else
1265
    thd->variables.collation_connection= var->save_result.charset;
1266 1267 1268
  return 0;
}

1269
byte *sys_var_collation_connection::value_ptr(THD *thd, enum_var_type type)
1270 1271
{
  CHARSET_INFO *cs= ((type == OPT_GLOBAL) ?
1272 1273
		  global_system_variables.collation_connection :
		  thd->variables.collation_connection);
1274 1275 1276
  return cs ? (byte*) cs->name : (byte*) "";
}

1277
void sys_var_collation_connection::set_default(THD *thd, enum_var_type type)
1278 1279
{
 if (type == OPT_GLOBAL)
1280
   global_system_variables.collation_connection= default_charset_info;
1281
 else
1282
   thd->variables.collation_connection= global_system_variables.collation_connection;
1283 1284
}

1285
bool sys_var_collation_results::update(THD *thd, set_var *var)
1286 1287
{
  if (var->type == OPT_GLOBAL)
1288
    global_system_variables.collation_results= var->save_result.charset;
1289
  else
1290
    thd->variables.collation_results= var->save_result.charset;
1291 1292 1293
  return 0;
}

1294
byte *sys_var_collation_results::value_ptr(THD *thd, enum_var_type type)
1295 1296
{
  CHARSET_INFO *cs= ((type == OPT_GLOBAL) ?
1297 1298
		  global_system_variables.collation_results :
		  thd->variables.collation_results);
1299 1300 1301
  return cs ? (byte*) cs->name : (byte*) "";
}

1302
void sys_var_collation_results::set_default(THD *thd, enum_var_type type)
1303 1304
{
 if (type == OPT_GLOBAL)
1305
   global_system_variables.collation_results= default_charset_info;
1306
 else
1307
   thd->variables.collation_results= global_system_variables.collation_results;
1308 1309
}

1310 1311 1312 1313 1314

/*****************************************************************************
  Functions to handle SET NAMES and SET CHARACTER SET
*****************************************************************************/

1315
int set_var_collation_client::check(THD *thd)
1316 1317 1318 1319
{
  return 0;
}

1320
int set_var_collation_client::update(THD *thd)
1321
{
1322 1323 1324
  thd->variables.collation_client= collation_client;
  thd->variables.collation_connection= collation_connection;
  thd->variables.collation_results= collation_results;
1325 1326 1327 1328 1329 1330 1331
  thd->protocol_simple.init(thd);
  thd->protocol_prep.init(thd);
  return 0;
}

/****************************************************************************/

1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378
bool sys_var_timestamp::update(THD *thd,  set_var *var)
{
  thd->set_time((time_t) var->value->val_int());
  return 0;
}


void sys_var_timestamp::set_default(THD *thd, enum_var_type type)
{
  thd->user_time=0;
}


byte *sys_var_timestamp::value_ptr(THD *thd, enum_var_type type)
{
  thd->sys_var_tmp.long_value= (long) thd->start_time;
  return (byte*) &thd->sys_var_tmp.long_value;
}


bool sys_var_last_insert_id::update(THD *thd, set_var *var)
{
  thd->insert_id(var->value->val_int());
  return 0;
}


byte *sys_var_last_insert_id::value_ptr(THD *thd, enum_var_type type)
{
  thd->sys_var_tmp.long_value= (long) thd->insert_id();
  return (byte*) &thd->last_insert_id;
}


bool sys_var_insert_id::update(THD *thd, set_var *var)
{
  thd->next_insert_id=var->value->val_int();
  return 0;
}


byte *sys_var_insert_id::value_ptr(THD *thd, enum_var_type type)
{
  return (byte*) &thd->current_insert_id;
}


hf@deer.mysql.r18.ru's avatar
SCRUM  
hf@deer.mysql.r18.ru committed
1379
#ifdef HAVE_REPLICATION
1380 1381
bool sys_var_slave_skip_counter::check(THD *thd, set_var *var)
{
1382
  int result= 0;
1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407
  LOCK_ACTIVE_MI;
  pthread_mutex_lock(&active_mi->rli.run_lock);
  if (active_mi->rli.slave_running)
  {
    my_error(ER_SLAVE_MUST_STOP, MYF(0));
    result=1;
  }
  pthread_mutex_unlock(&active_mi->rli.run_lock);
  UNLOCK_ACTIVE_MI;
  return result;
}


bool sys_var_slave_skip_counter::update(THD *thd, set_var *var)
{
  LOCK_ACTIVE_MI;
  pthread_mutex_lock(&active_mi->rli.run_lock);
  /*
    The following test should normally never be true as we test this
    in the check function;  To be safe against multiple
    SQL_SLAVE_SKIP_COUNTER request, we do the check anyway
  */
  if (!active_mi->rli.slave_running)
  {
    pthread_mutex_lock(&active_mi->rli.data_lock);
1408
    active_mi->rli.slave_skip_counter= (ulong) var->value->val_int();
1409 1410 1411 1412 1413 1414
    pthread_mutex_unlock(&active_mi->rli.data_lock);
  }
  pthread_mutex_unlock(&active_mi->rli.run_lock);
  UNLOCK_ACTIVE_MI;
  return 0;
}
hf@deer.mysql.r18.ru's avatar
SCRUM  
hf@deer.mysql.r18.ru committed
1415
#endif /* HAVE_REPLICATION */
1416

1417 1418
bool sys_var_rand_seed1::update(THD *thd, set_var *var)
{
1419
  thd->rand.seed1= (ulong) var->value->val_int();
1420 1421 1422 1423 1424
  return 0;
}

bool sys_var_rand_seed2::update(THD *thd, set_var *var)
{
1425
  thd->rand.seed2= (ulong) var->value->val_int();
1426 1427 1428 1429
  return 0;
}


1430 1431 1432 1433 1434 1435
/*
  Functions to update thd->options bits
*/

static bool set_option_bit(THD *thd, set_var *var)
{
1436 1437 1438
  sys_var_thd_bit *sys_var= ((sys_var_thd_bit*) var->var);
  if ((var->save_result.ulong_value != 0) == sys_var->reverse)
    thd->options&= ~sys_var->bit_flag;
1439
  else
1440
    thd->options|= sys_var->bit_flag;
1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484
  return 0;
}


static bool set_option_autocommit(THD *thd, set_var *var)
{
  /* The test is negative as the flag we use is NOT autocommit */

  ulong org_options=thd->options;

  if (var->save_result.ulong_value != 0)
    thd->options&= ~((sys_var_thd_bit*) var->var)->bit_flag;
  else
    thd->options|= ((sys_var_thd_bit*) var->var)->bit_flag;

  if ((org_options ^ thd->options) & OPTION_NOT_AUTOCOMMIT)
  {
    if ((org_options & OPTION_NOT_AUTOCOMMIT))
    {
      /* We changed to auto_commit mode */
      thd->options&= ~(ulong) (OPTION_BEGIN | OPTION_STATUS_NO_TRANS_UPDATE);
      thd->server_status|= SERVER_STATUS_AUTOCOMMIT;
      if (ha_commit(thd))
	return 1;
    }
    else
    {
      thd->options&= ~(ulong) (OPTION_STATUS_NO_TRANS_UPDATE);
      thd->server_status&= ~SERVER_STATUS_AUTOCOMMIT;
    }
  }
  return 0;
}


static bool set_log_update(THD *thd, set_var *var)
{
  if (opt_sql_bin_update)
    ((sys_var_thd_bit*) var->var)->bit_flag|= (OPTION_BIN_LOG |
					       OPTION_UPDATE_LOG);
  set_option_bit(thd, var);
  return 0;
}

1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499
static byte *get_warning_count(THD *thd)
{
  thd->sys_var_tmp.long_value=
    (thd->warn_count[(uint) MYSQL_ERROR::WARN_LEVEL_NOTE] +
     thd->warn_count[(uint) MYSQL_ERROR::WARN_LEVEL_WARN]);
  return (byte*) &thd->sys_var_tmp.long_value;
}

static byte *get_error_count(THD *thd)
{
  thd->sys_var_tmp.long_value= 
    thd->warn_count[(uint) MYSQL_ERROR::WARN_LEVEL_ERROR];
  return (byte*) &thd->sys_var_tmp.long_value;
}

1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560

/****************************************************************************
  Main handling of variables:
  - Initialisation
  - Searching during parsing
  - Update loop
****************************************************************************/

/*
  Find variable name in option my_getopt structure used for command line args

  SYNOPSIS
    find_option()
    opt		option structure array to search in
    name	variable name

  RETURN VALUES
    0		Error
    ptr		pointer to option structure
*/

static struct my_option *find_option(struct my_option *opt, const char *name) 
{
  uint length=strlen(name);
  for (; opt->name; opt++)
  {
    if (!getopt_compare_strings(opt->name, name, length) &&
	!opt->name[length])
    {
      /*
	Only accept the option if one can set values through it.
	If not, there is no default value or limits in the option.
      */
      return (opt->value) ? opt : 0;
    }
  }
  return 0;
}


/*
  Return variable name and length for hashing of variables
*/

static byte *get_sys_var_length(const sys_var *var, uint *length,
				my_bool first)
{
  *length= var->name_length;
  return (byte*) var->name;
}


/*
  Initialises sys variables and put them in system_variable_hash
*/


void set_var_init()
{
  extern struct my_option my_long_options[];	// From mysqld

1561 1562
  hash_init(&system_variable_hash, system_charset_info,
	    array_elements(sys_variables),0,0,
1563
	    (hash_get_key) get_sys_var_length,0,0);
1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605
  sys_var **var, **end;
  for (var= sys_variables, end= sys_variables+array_elements(sys_variables) ;
       var < end;
       var++)
  {
    (*var)->name_length= strlen((*var)->name);
    (*var)->option_limits= find_option(my_long_options, (*var)->name);
    hash_insert(&system_variable_hash, (byte*) *var);
  }
  /*
    Special cases
    Needed because MySQL can't find the limits for a variable it it has
    a different name than the command line option.
    As these variables are deprecated, this code will disappear soon...
  */
  sys_sql_max_join_size.option_limits= sys_max_join_size.option_limits;
}


void set_var_free()
{
  hash_free(&system_variable_hash);
}


/*
  Find a user set-table variable

  SYNOPSIS
    find_sys_var()
    str		Name of system variable to find
    length	Length of variable.  zero means that we should use strlen()
		on the variable

  NOTE
    We have to use net_printf() as this is called during the parsing stage

  RETURN VALUES
    pointer	pointer to variable definitions
    0		Unknown variable (error message is given)
*/

1606
sys_var *find_sys_var(const char *str, uint length)
1607
{
1608 1609
  sys_var *var= (sys_var*) hash_search(&system_variable_hash,
				       (byte*) str,
1610 1611 1612
				       length ? length :
				       strlen(str));
  if (!var)
1613
    net_printf(current_thd, ER_UNKNOWN_SYSTEM_VARIABLE, (char*) str);
1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635
  return var;
}


/*
  Execute update of all variables

  SYNOPSIS

  sql_set
    THD		Thread id
    set_var	List of variables to update

  DESCRIPTION
    First run a check of all variables that all updates will go ok.
    If yes, then execute all updates, returning an error if any one failed.

    This should ensure that in all normal cases none all or variables are
    updated

    RETURN VALUE
    0	ok
1636 1637
    1	ERROR, message sent (normally no variables was updated)
    -1  ERROR, message not sent
1638 1639
*/

1640
int sql_set_variables(THD *thd, List<set_var_base> *var_list)
1641
{
1642
  int error= 0;
1643 1644 1645 1646 1647
  List_iterator<set_var_base> it(*var_list);

  set_var_base *var;
  while ((var=it++))
  {
1648 1649
    if ((error=var->check(thd)))
      return error;
1650 1651 1652
  }
  it.rewind();
  while ((var=it++))
1653
    error|= var->update(thd);			// Returns 0, -1 or 1
1654 1655 1656 1657 1658 1659 1660 1661
  return error;
}


/*****************************************************************************
  Functions to handle SET mysql_internal_variable=const_expr
*****************************************************************************/

1662
int set_var::check(THD *thd)
1663 1664 1665 1666 1667 1668
{
  if (var->check_type(type))
  {
    my_error(type == OPT_GLOBAL ? ER_LOCAL_VARIABLE : ER_GLOBAL_VARIABLE,
	     MYF(0),
	     var->name);
1669
    return -1;
1670 1671 1672 1673 1674 1675 1676 1677 1678 1679
  }
  if ((type == OPT_GLOBAL && check_global_access(thd, SUPER_ACL)))
    return 1;

  /* value is a NULL pointer if we are using SET ... = DEFAULT */
  if (!value)
  {
    if (var->check_default(type))
    {
      my_error(ER_NO_DEFAULT, MYF(0), var->name);
1680
      return -1;
1681 1682 1683 1684
    }
    return 0;
  }

1685
  if (value->fix_fields(thd, 0, &value) || value->check_cols(1))
1686
    return -1;
1687 1688 1689
  if (var->check_update_type(value->result_type()))
  {
    my_error(ER_WRONG_TYPE_FOR_VAR, MYF(0), var->name);
1690
    return -1;
1691
  }    
1692
  return var->check(thd, this) ? -1 : 0;
1693 1694 1695
}


1696
int set_var::update(THD *thd)
1697 1698 1699 1700
{
  if (!value)
    var->set_default(thd, type);
  else if (var->update(thd, this))
1701
    return -1;				// should never happen
1702 1703 1704 1705 1706 1707 1708 1709 1710 1711
  if (var->after_update)
    (*var->after_update)(thd, type);
  return 0;
}


/*****************************************************************************
  Functions to handle SET @user_variable=const_expr
*****************************************************************************/

1712
int set_var_user::check(THD *thd)
1713
{
monty@mashka.mysql.fi's avatar
monty@mashka.mysql.fi committed
1714
  return user_var_item->fix_fields(thd,0, (Item**) 0) ? -1 : 0;
1715 1716 1717
}


1718
int set_var_user::update(THD *thd)
1719 1720 1721 1722
{
  if (user_var_item->update())
  {
    /* Give an error if it's not given already */
1723 1724
    my_error(ER_SET_CONSTANTS_ONLY, MYF(0));
    return -1;
1725 1726 1727 1728 1729 1730 1731 1732 1733
  }
  return 0;
}


/*****************************************************************************
  Functions to handle SET PASSWORD
*****************************************************************************/

1734
int set_var_password::check(THD *thd)
1735 1736 1737
{
  if (!user->host.str)
    user->host.str= (char*) thd->host_or_ip;
1738 1739
  /* Returns 1 as the function sends error to client */
  return check_change_password(thd, user->host.str, user->user.str) ? 1 : 0;
1740 1741
}

1742
int set_var_password::update(THD *thd)
1743
{
1744 1745 1746
  /* Returns 1 as the function sends error to client */
  return (change_password(thd, user->host.str, user->user.str, password) ?
	  1 : 0);
1747 1748
}

1749 1750 1751 1752




1753 1754 1755 1756 1757 1758 1759 1760
/****************************************************************************
  Used templates
****************************************************************************/

#ifdef __GNUC__
template class List<set_var_base>;
template class List_iterator<set_var_base>;
#endif