~drizzle-trunk/drizzle/development

520.4.14 by Monty Taylor
Removed korr.h and tztime.h from common_includes. Also removed the HAVE_DTRACE block and stuck it in autoconf.
1
/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
 *  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
3
 *
4
 *  Copyright (C) 2008 Sun Microsystems
5
 *
6
 *  This program is free software; you can redistribute it and/or modify
7
 *  it under the terms of the GNU General Public License as published by
8
 *  the Free Software Foundation; version 2 of the License.
9
 *
10
 *  This program is distributed in the hope that it will be useful,
11
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 *  GNU General Public License for more details.
14
 *
15
 *  You should have received a copy of the GNU General Public License
16
 *  along with this program; if not, write to the Free Software
17
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
18
 */
1 by brian
clean slate
19
20
/**
21
  @file
22
23
  @brief
24
  Handling of MySQL SQL variables
25
26
  @details
27
  To add a new variable, one has to do the following:
28
29
  - Use one of the 'sys_var... classes from set_var.h or write a specific
30
    one for the variable type.
31
  - Define it in the 'variable definition list' in this file.
32
  - If the variable is thread specific, add it to 'system_variables' struct.
33
    If not, add it to mysqld.cc and an declaration in 'mysql_priv.h'
34
  - If the variable should be changed from the command line, add a definition
35
    of it in the my_option structure list in mysqld.cc
36
  - Don't forget to initialize new fields in global_system_variables and
37
    max_system_variables!
38
39
  @todo
40
    Add full support for the variable character_set (for 4.1)
41
42
  @todo
43
    When updating myisam_delay_key_write, we should do a 'flush tables'
44
    of all MyISAM tables to ensure that they are reopen with the
45
    new attribute.
46
47
  @note
48
    Be careful with var->save_result: sys_var::check() only updates
151 by Brian Aker
Ulonglong to uint64_t
49
    uint64_t_value; so other members of the union are garbage then; to use
1 by brian
clean slate
50
    them you must first assign a value to them (in specific ::check() for
51
    example).
52
*/
520.4.14 by Monty Taylor
Removed korr.h and tztime.h from common_includes. Also removed the HAVE_DTRACE block and stuck it in autoconf.
53
243.1.17 by Jay Pipes
FINAL PHASE removal of mysql_priv.h (Bye, bye my friend.)
54
#include <drizzled/server_includes.h>
212.5.21 by Monty Taylor
Moved my_getopt.h
55
#include <mysys/my_getopt.h>
992.1.25 by Monty Taylor
Moved myisam to new plugin system.
56
#include <plugin/myisam/myisam.h>
549 by Monty Taylor
Took gettext.h out of header files.
57
#include <drizzled/error.h>
538 by Monty Taylor
Moved gettext.h into drizzled in anticipation of the new client lib.
58
#include <drizzled/gettext.h>
520.4.14 by Monty Taylor
Removed korr.h and tztime.h from common_includes. Also removed the HAVE_DTRACE block and stuck it in autoconf.
59
#include <drizzled/tztime.h>
520.6.7 by Monty Taylor
Moved a bunch of crap out of common_includes.
60
#include <drizzled/data_home.h>
584.1.15 by Monty Taylor
The mega-patch from hell. Renamed sql_class to session (since that's what it is) and removed it and field and table from common_includes.
61
#include <drizzled/set_var.h>
62
#include <drizzled/session.h>
63
#include <drizzled/sql_base.h>
670.2.4 by Monty Taylor
Removed more stuff from the headers.
64
#include <drizzled/lock.h>
642.1.16 by Lee
header file clean up
65
#include <drizzled/item/uint.h>
642.1.20 by Lee
header file clean up
66
#include <drizzled/item/null.h>
670.1.22 by Monty Taylor
Merged from Lee.
67
#include <drizzled/item/float.h>
1 by brian
clean slate
68
873.2.16 by Monty Taylor
Replaced HASH with std::map - avoid utf8 hashing on every sys_var lookup.
69
#include <map>
70
#include <algorithm>
71
72
using namespace std;
73
264.2.6 by Andrey Hristov
Constify the usage of CHARSET_INFO almost to the last place in the code.
74
extern const CHARSET_INFO *character_set_filesystem;
584.1.15 by Monty Taylor
The mega-patch from hell. Renamed sql_class to session (since that's what it is) and removed it and field and table from common_includes.
75
extern I_List<NAMED_LIST> key_caches;
629.2.7 by Monty Taylor
Fixed a couple of memory buffer size issues.
76
extern size_t my_thread_stack_size;
1 by brian
clean slate
77
78
static DYNAMIC_ARRAY fixed_show_vars;
873.2.16 by Monty Taylor
Replaced HASH with std::map - avoid utf8 hashing on every sys_var lookup.
79
static map<const string, sys_var *> system_variable_hash;
670.2.4 by Monty Taylor
Removed more stuff from the headers.
80
extern char *opt_drizzle_tmpdir;
1 by brian
clean slate
81
461 by Monty Taylor
Removed NullS. bu-bye.
82
const char *bool_type_names[]= { "OFF", "ON", NULL };
1 by brian
clean slate
83
TYPELIB bool_typelib=
84
{
85
  array_elements(bool_type_names)-1, "", bool_type_names, NULL
86
};
87
461 by Monty Taylor
Removed NullS. bu-bye.
88
const char *delay_key_write_type_names[]= { "OFF", "ON", "ALL", NULL };
1 by brian
clean slate
89
TYPELIB delay_key_write_typelib=
90
{
91
  array_elements(delay_key_write_type_names)-1, "",
92
  delay_key_write_type_names, NULL
93
};
94
520.1.22 by Brian Aker
Second pass of thd cleanup
95
static bool set_option_bit(Session *session, set_var *var);
96
static bool set_option_autocommit(Session *session, set_var *var);
97
static int  check_pseudo_thread_id(Session *session, set_var *var);
98
static int check_tx_isolation(Session *session, set_var *var);
99
static void fix_tx_isolation(Session *session, enum_var_type type);
100
static int check_completion_type(Session *session, set_var *var);
101
static void fix_completion_type(Session *session, enum_var_type type);
102
static void fix_net_read_timeout(Session *session, enum_var_type type);
103
static void fix_net_write_timeout(Session *session, enum_var_type type);
104
static void fix_net_retry_count(Session *session, enum_var_type type);
105
static void fix_max_join_size(Session *session, enum_var_type type);
106
static void fix_session_mem_root(Session *session, enum_var_type type);
107
static void fix_trans_mem_root(Session *session, enum_var_type type);
108
static void fix_server_id(Session *session, enum_var_type type);
520.1.21 by Brian Aker
THD -> Session rename
109
static uint64_t fix_unsigned(Session *, uint64_t, const struct my_option *);
910.4.10 by Stewart Smith
fix system variables for correct endian architectures.
110
static bool get_unsigned32(Session *session, set_var *var);
111
static bool get_unsigned64(Session *session, set_var *var);
520.1.22 by Brian Aker
Second pass of thd cleanup
112
bool throw_bounds_warning(Session *session, bool fixed, bool unsignd,
152 by Brian Aker
longlong replacement
113
                          const char *name, int64_t val);
482 by Brian Aker
Remove uint.
114
static KEY_CACHE *create_key_cache(const char *name, uint32_t length);
520.1.22 by Brian Aker
Second pass of thd cleanup
115
static unsigned char *get_error_count(Session *session);
116
static unsigned char *get_warning_count(Session *session);
117
static unsigned char *get_tmpdir(Session *session);
1 by brian
clean slate
118
119
/*
120
  Variable definition list
121
122
  These are variables that can be set from the command line, in
123
  alphabetic order.
124
125
  The variables are linked into the list. A variable is added to
126
  it in the constructor (see sys_var class for details).
127
*/
128
129
static sys_var_chain vars = { NULL, NULL };
130
819.1.1 by Toru Maesaka
Removed the 16bit limitation of auto_increment_(increment|offset) system variables
131
static sys_var_session_uint64_t
1 by brian
clean slate
132
sys_auto_increment_increment(&vars, "auto_increment_increment",
133
                             &SV::auto_increment_increment, NULL, NULL,
134
                             sys_var::SESSION_VARIABLE_IN_BINLOG);
819.1.1 by Toru Maesaka
Removed the 16bit limitation of auto_increment_(increment|offset) system variables
135
static sys_var_session_uint64_t
1 by brian
clean slate
136
sys_auto_increment_offset(&vars, "auto_increment_offset",
137
                          &SV::auto_increment_offset, NULL, NULL,
138
                          sys_var::SESSION_VARIABLE_IN_BINLOG);
139
575.4.1 by ysano
Rename mysql to drizzle.
140
static sys_var_const_str       sys_basedir(&vars, "basedir", drizzle_home);
619 by Brian Aker
Removed ulong methods from vars.
141
static sys_var_session_uint64_t	sys_bulk_insert_buff_size(&vars, "bulk_insert_buffer_size",
142
                                                          &SV::bulk_insert_buff_size);
143
static sys_var_session_uint32_t	sys_completion_type(&vars, "completion_type",
144
                                                    &SV::completion_type,
145
                                                    check_completion_type,
146
                                                    fix_completion_type);
1 by brian
clean slate
147
static sys_var_collation_sv
148
sys_collation_database(&vars, "collation_database", &SV::collation_database,
149
                       &default_charset_info,
150
                       sys_var::SESSION_VARIABLE_IN_BINLOG);
151
static sys_var_collation_sv
152
sys_collation_server(&vars, "collation_server", &SV::collation_server,
153
                     &default_charset_info,
154
                     sys_var::SESSION_VARIABLE_IN_BINLOG);
892.2.3 by Monty Taylor
Fixed fixes.
155
static sys_var_uint32_t_ptr	sys_connect_timeout(&vars, "connect_timeout",
156
                                                &connect_timeout);
575.4.1 by ysano
Rename mysql to drizzle.
157
static sys_var_const_str       sys_datadir(&vars, "datadir", drizzle_real_data_home);
1 by brian
clean slate
158
static sys_var_enum		sys_delay_key_write(&vars, "delay_key_write",
159
					    &delay_key_write_options,
160
					    &delay_key_write_typelib,
161
					    fix_delay_key_write);
162
163
static sys_var_bool_ptr	sys_flush(&vars, "flush", &myisam_flush);
616 by Brian Aker
ulong fixes.
164
static sys_var_session_uint64_t	sys_join_buffer_size(&vars, "join_buffer_size",
165
                                                     &SV::join_buff_size);
1 by brian
clean slate
166
static sys_var_key_buffer_size	sys_key_buffer_size(&vars, "key_buffer_size");
910.4.18 by Stewart Smith
fix alignment of variables (incl key cache). fixes SIGBUS on SPARC64
167
static sys_var_key_cache_uint32_t  sys_key_cache_block_size(&vars, "key_cache_block_size",
616 by Brian Aker
ulong fixes.
168
                                                        offsetof(KEY_CACHE,
169
                                                                 param_block_size));
910.4.18 by Stewart Smith
fix alignment of variables (incl key cache). fixes SIGBUS on SPARC64
170
static sys_var_key_cache_uint32_t	sys_key_cache_division_limit(&vars, "key_cache_division_limit",
616 by Brian Aker
ulong fixes.
171
                                                           offsetof(KEY_CACHE,
172
                                                                    param_division_limit));
910.4.18 by Stewart Smith
fix alignment of variables (incl key cache). fixes SIGBUS on SPARC64
173
static sys_var_key_cache_uint32_t  sys_key_cache_age_threshold(&vars, "key_cache_age_threshold",
616 by Brian Aker
ulong fixes.
174
                                                           offsetof(KEY_CACHE,
175
                                                                    param_age_threshold));
176
static sys_var_session_uint32_t	sys_max_allowed_packet(&vars, "max_allowed_packet",
177
                                                       &SV::max_allowed_packet);
910.4.10 by Stewart Smith
fix system variables for correct endian architectures.
178
static sys_var_uint64_t_ptr	sys_max_connect_errors(&vars, "max_connect_errors",
616 by Brian Aker
ulong fixes.
179
                                               &max_connect_errors);
180
static sys_var_session_uint64_t	sys_max_error_count(&vars, "max_error_count",
181
                                                  &SV::max_error_count);
520.1.22 by Brian Aker
Second pass of thd cleanup
182
static sys_var_session_uint64_t	sys_max_heap_table_size(&vars, "max_heap_table_size",
616 by Brian Aker
ulong fixes.
183
                                                        &SV::max_heap_table_size);
555 by Monty
Fixed 32-bit issues.
184
static sys_var_session_uint64_t sys_pseudo_thread_id(&vars, "pseudo_thread_id",
1 by brian
clean slate
185
                                              &SV::pseudo_thread_id,
555 by Monty
Fixed 32-bit issues.
186
                                              0, check_pseudo_thread_id,
1 by brian
clean slate
187
                                              sys_var::SESSION_VARIABLE_IN_BINLOG);
520.1.22 by Brian Aker
Second pass of thd cleanup
188
static sys_var_session_ha_rows	sys_max_join_size(&vars, "max_join_size",
617 by Brian Aker
ulong fixes
189
                                                  &SV::max_join_size,
190
                                                  fix_max_join_size);
191
static sys_var_session_uint64_t	sys_max_seeks_for_key(&vars, "max_seeks_for_key",
615 by Brian Aker
Added 32bit system variable support
192
                                                      &SV::max_seeks_for_key);
193
static sys_var_session_uint64_t   sys_max_length_for_sort_data(&vars, "max_length_for_sort_data",
194
                                                               &SV::max_length_for_sort_data);
910.4.4 by Stewart Smith
max_sort_length should be size_t everywhere. Causing numerous failures on SPARC and PowerPC due to strang value being retrieved in filesort. Basically, anything with filesort fails without this patch.
195
static sys_var_session_size_t	sys_max_sort_length(&vars, "max_sort_length",
615 by Brian Aker
Added 32bit system variable support
196
                                                    &SV::max_sort_length);
197
static sys_var_session_uint64_t	sys_max_tmp_tables(&vars, "max_tmp_tables",
198
                                                   &SV::max_tmp_tables);
910.4.10 by Stewart Smith
fix system variables for correct endian architectures.
199
static sys_var_uint64_t_ptr	sys_max_write_lock_count(&vars, "max_write_lock_count",
622.1.1 by Brian Aker
32bit fixes around vars
200
                                                 &max_write_lock_count);
619 by Brian Aker
Removed ulong methods from vars.
201
static sys_var_session_uint64_t sys_min_examined_row_limit(&vars, "min_examined_row_limit",
202
                                                           &SV::min_examined_row_limit);
1 by brian
clean slate
203
520.1.22 by Brian Aker
Second pass of thd cleanup
204
static sys_var_session_enum         sys_myisam_stats_method(&vars, "myisam_stats_method",
617 by Brian Aker
ulong fixes
205
                                                            &SV::myisam_stats_method,
206
                                                            &myisam_stats_method_typelib,
207
                                                            NULL);
616 by Brian Aker
ulong fixes.
208
static sys_var_session_uint32_t	sys_net_buffer_length(&vars, "net_buffer_length",
209
                                                      &SV::net_buffer_length);
210
static sys_var_session_uint32_t	sys_net_read_timeout(&vars, "net_read_timeout",
211
                                                     &SV::net_read_timeout,
212
                                                     0, fix_net_read_timeout);
213
static sys_var_session_uint32_t	sys_net_write_timeout(&vars, "net_write_timeout",
214
                                                      &SV::net_write_timeout,
215
                                                      0, fix_net_write_timeout);
216
static sys_var_session_uint32_t	sys_net_retry_count(&vars, "net_retry_count",
217
                                                    &SV::net_retry_count,
218
                                                    0, fix_net_retry_count);
1 by brian
clean slate
219
/* these two cannot be static */
619 by Brian Aker
Removed ulong methods from vars.
220
static sys_var_session_bool sys_optimizer_prune_level(&vars, "optimizer_prune_level",
221
                                                      &SV::optimizer_prune_level);
222
static sys_var_session_uint32_t sys_optimizer_search_depth(&vars, "optimizer_search_depth",
223
                                                           &SV::optimizer_search_depth);
1 by brian
clean slate
224
461 by Monty Taylor
Removed NullS. bu-bye.
225
const char *optimizer_use_mrr_names[] = {"auto", "force", "disable", NULL};
1 by brian
clean slate
226
TYPELIB optimizer_use_mrr_typelib= {
227
  array_elements(optimizer_use_mrr_names) - 1, "",
228
  optimizer_use_mrr_names, NULL
229
};
230
617 by Brian Aker
ulong fixes
231
static sys_var_session_enum sys_optimizer_use_mrr(&vars, "optimizer_use_mrr",
232
                                                  &SV::optimizer_use_mrr,
233
                                                  &optimizer_use_mrr_typelib,
234
                                                  NULL);
1 by brian
clean slate
235
619 by Brian Aker
Removed ulong methods from vars.
236
static sys_var_session_uint64_t sys_preload_buff_size(&vars, "preload_buffer_size",
237
                                                      &SV::preload_buff_size);
238
static sys_var_session_uint32_t sys_read_buff_size(&vars, "read_buffer_size",
239
                                                   &SV::read_buff_size);
240
static sys_var_session_uint32_t	sys_read_rnd_buff_size(&vars, "read_rnd_buffer_size",
241
                                                       &SV::read_rnd_buff_size);
242
static sys_var_session_uint32_t	sys_div_precincrement(&vars, "div_precision_increment",
243
                                                      &SV::div_precincrement);
1 by brian
clean slate
244
629.4.1 by Monty Taylor
First step in support size_t sys_var stuff.
245
static sys_var_session_size_t	sys_range_alloc_block_size(&vars, "range_alloc_block_size",
615 by Brian Aker
Added 32bit system variable support
246
                                                           &SV::range_alloc_block_size);
247
static sys_var_session_uint32_t	sys_query_alloc_block_size(&vars, "query_alloc_block_size",
248
                                                           &SV::query_alloc_block_size,
617 by Brian Aker
ulong fixes
249
                                                           false, fix_session_mem_root);
615 by Brian Aker
Added 32bit system variable support
250
static sys_var_session_uint32_t	sys_query_prealloc_size(&vars, "query_prealloc_size",
251
                                                        &SV::query_prealloc_size,
617 by Brian Aker
ulong fixes
252
                                                        false, fix_session_mem_root);
253
static sys_var_readonly sys_tmpdir(&vars, "tmpdir", OPT_GLOBAL, SHOW_CHAR, get_tmpdir);
615 by Brian Aker
Added 32bit system variable support
254
static sys_var_session_uint32_t	sys_trans_alloc_block_size(&vars, "transaction_alloc_block_size",
255
                                                           &SV::trans_alloc_block_size,
617 by Brian Aker
ulong fixes
256
                                                           false, fix_trans_mem_root);
615 by Brian Aker
Added 32bit system variable support
257
static sys_var_session_uint32_t	sys_trans_prealloc_size(&vars, "transaction_prealloc_size",
258
                                                        &SV::trans_prealloc_size,
617 by Brian Aker
ulong fixes
259
                                                        false, fix_trans_mem_root);
1 by brian
clean slate
260
261
static sys_var_const_str_ptr sys_secure_file_priv(&vars, "secure_file_priv",
262
                                             &opt_secure_file_priv);
520.4.14 by Monty Taylor
Removed korr.h and tztime.h from common_includes. Also removed the HAVE_DTRACE block and stuck it in autoconf.
263
static sys_var_uint32_t_ptr  sys_server_id(&vars, "server_id", &server_id,
264
                                           fix_server_id);
265
629.4.1 by Monty Taylor
First step in support size_t sys_var stuff.
266
static sys_var_session_size_t	sys_sort_buffer(&vars, "sort_buffer_size",
619 by Brian Aker
Removed ulong methods from vars.
267
                                                &SV::sortbuff_size);
1 by brian
clean slate
268
/*
269
  sql_mode should *not* have binlog_mode=SESSION_VARIABLE_IN_BINLOG:
270
  even though it is written to the binlog, the slave ignores the
271
  MODE_NO_DIR_IN_CREATE variable, so slave's value differs from
272
  master's (see log_event.cc: Query_log_event::do_apply_event()).
273
*/
520.1.22 by Brian Aker
Second pass of thd cleanup
274
static sys_var_session_optimizer_switch   sys_optimizer_switch(&vars, "optimizer_switch",
617 by Brian Aker
ulong fixes
275
                                                               &SV::optimizer_switch);
1 by brian
clean slate
276
520.1.22 by Brian Aker
Second pass of thd cleanup
277
static sys_var_session_storage_engine sys_storage_engine(&vars, "storage_engine",
971.1.21 by Monty Taylor
Store StorageEngine in system variables, rather than storage engine plugin.
278
				       &SV::storage_engine);
1 by brian
clean slate
279
static sys_var_const_str	sys_system_time_zone(&vars, "system_time_zone",
280
                                             system_time_zone);
910.4.10 by Stewart Smith
fix system variables for correct endian architectures.
281
static sys_var_uint64_t_ptr	sys_table_def_size(&vars, "table_definition_cache",
1 by brian
clean slate
282
                                           &table_def_size);
910.4.10 by Stewart Smith
fix system variables for correct endian architectures.
283
static sys_var_uint64_t_ptr	sys_table_cache_size(&vars, "table_open_cache",
1 by brian
clean slate
284
					     &table_cache_size);
910.4.10 by Stewart Smith
fix system variables for correct endian architectures.
285
static sys_var_uint64_t_ptr	sys_table_lock_wait_timeout(&vars, "table_lock_wait_timeout",
1 by brian
clean slate
286
                                                    &table_lock_wait_timeout);
520.1.22 by Brian Aker
Second pass of thd cleanup
287
static sys_var_session_enum	sys_tx_isolation(&vars, "tx_isolation",
617 by Brian Aker
ulong fixes
288
                                             &SV::tx_isolation,
289
                                             &tx_isolation_typelib,
290
                                             fix_tx_isolation,
291
                                             check_tx_isolation);
520.1.22 by Brian Aker
Second pass of thd cleanup
292
static sys_var_session_uint64_t	sys_tmp_table_size(&vars, "tmp_table_size",
1 by brian
clean slate
293
					   &SV::tmp_table_size);
147 by Brian Aker
More my_bool conversion. This time the set_var class.
294
static sys_var_bool_ptr  sys_timed_mutexes(&vars, "timed_mutexes", &timed_mutexes);
1 by brian
clean slate
295
static sys_var_const_str	sys_version(&vars, "version", server_version);
296
static sys_var_const_str	sys_version_comment(&vars, "version_comment",
546 by Monty Taylor
Cleaned up version.h. (And by cleaned, I mean removed)
297
                                            COMPILATION_COMMENT);
1 by brian
clean slate
298
static sys_var_const_str	sys_version_compile_machine(&vars, "version_compile_machine",
299
                                                    MACHINE_TYPE);
300
static sys_var_const_str	sys_version_compile_os(&vars, "version_compile_os",
301
                                               SYSTEM_TYPE);
616 by Brian Aker
ulong fixes.
302
static sys_var_session_uint32_t	sys_net_wait_timeout(&vars, "wait_timeout",
303
                                                     &SV::net_wait_timeout);
1 by brian
clean slate
304
305
/* Condition pushdown to storage engine */
520.1.22 by Brian Aker
Second pass of thd cleanup
306
static sys_var_session_bool
1 by brian
clean slate
307
sys_engine_condition_pushdown(&vars, "engine_condition_pushdown",
308
			      &SV::engine_condition_pushdown);
309
520.1.21 by Brian Aker
THD -> Session rename
310
/* Variables that are bits in Session */
1 by brian
clean slate
311
520.1.22 by Brian Aker
Second pass of thd cleanup
312
sys_var_session_bit sys_autocommit(&vars, "autocommit", 0,
1 by brian
clean slate
313
                               set_option_autocommit,
314
                               OPTION_NOT_AUTOCOMMIT,
315
                               1);
520.1.22 by Brian Aker
Second pass of thd cleanup
316
static sys_var_session_bit	sys_big_selects(&vars, "sql_big_selects", 0,
1 by brian
clean slate
317
					set_option_bit,
318
					OPTION_BIG_SELECTS);
520.1.22 by Brian Aker
Second pass of thd cleanup
319
static sys_var_session_bit	sys_sql_warnings(&vars, "sql_warnings", 0,
1 by brian
clean slate
320
					 set_option_bit,
321
					 OPTION_WARNINGS);
520.1.22 by Brian Aker
Second pass of thd cleanup
322
static sys_var_session_bit	sys_sql_notes(&vars, "sql_notes", 0,
1 by brian
clean slate
323
					 set_option_bit,
324
					 OPTION_SQL_NOTES);
520.1.22 by Brian Aker
Second pass of thd cleanup
325
static sys_var_session_bit	sys_safe_updates(&vars, "sql_safe_updates", 0,
1 by brian
clean slate
326
					 set_option_bit,
327
					 OPTION_SAFE_UPDATES);
520.1.22 by Brian Aker
Second pass of thd cleanup
328
static sys_var_session_bit	sys_buffer_results(&vars, "sql_buffer_result", 0,
1 by brian
clean slate
329
					   set_option_bit,
330
					   OPTION_BUFFER_RESULT);
520.1.22 by Brian Aker
Second pass of thd cleanup
331
static sys_var_session_bit	sys_foreign_key_checks(&vars, "foreign_key_checks", 0,
1 by brian
clean slate
332
					       set_option_bit,
333
					       OPTION_NO_FOREIGN_KEY_CHECKS,
334
                                               1, sys_var::SESSION_VARIABLE_IN_BINLOG);
520.1.22 by Brian Aker
Second pass of thd cleanup
335
static sys_var_session_bit	sys_unique_checks(&vars, "unique_checks", 0,
1 by brian
clean slate
336
					  set_option_bit,
337
					  OPTION_RELAXED_UNIQUE_CHECKS,
338
                                          1,
339
                                          sys_var::SESSION_VARIABLE_IN_BINLOG);
340
/* Local state variables */
341
520.1.22 by Brian Aker
Second pass of thd cleanup
342
static sys_var_session_ha_rows	sys_select_limit(&vars, "sql_select_limit",
1 by brian
clean slate
343
						 &SV::select_limit);
344
static sys_var_timestamp sys_timestamp(&vars, "timestamp",
345
                                       sys_var::SESSION_VARIABLE_IN_BINLOG);
346
static sys_var_last_insert_id
347
sys_last_insert_id(&vars, "last_insert_id",
348
                   sys_var::SESSION_VARIABLE_IN_BINLOG);
349
/*
350
  identity is an alias for last_insert_id(), so that we are compatible
351
  with Sybase
352
*/
353
static sys_var_last_insert_id
354
sys_identity(&vars, "identity", sys_var::SESSION_VARIABLE_IN_BINLOG);
355
520.1.22 by Brian Aker
Second pass of thd cleanup
356
static sys_var_session_lc_time_names
1 by brian
clean slate
357
sys_lc_time_names(&vars, "lc_time_names", sys_var::SESSION_VARIABLE_IN_BINLOG);
358
359
/*
360
  insert_id should *not* be marked as written to the binlog (i.e., it
361
  should *not* have binlog_status==SESSION_VARIABLE_IN_BINLOG),
362
  because we want any statement that refers to insert_id explicitly to
363
  be unsafe.  (By "explicitly", we mean using @@session.insert_id,
364
  whereas insert_id is used "implicitly" when NULL value is inserted
365
  into an auto_increment column).
366
367
  We want statements referring explicitly to @@session.insert_id to be
368
  unsafe, because insert_id is modified internally by the slave sql
369
  thread when NULL values are inserted in an AUTO_INCREMENT column.
370
  This modification interfers with the value of the
371
  @@session.insert_id variable if @@session.insert_id is referred
372
  explicitly by an insert statement (as is seen by executing "SET
373
  @@session.insert_id=0; CREATE TABLE t (a INT, b INT KEY
374
  AUTO_INCREMENT); INSERT INTO t(a) VALUES (@@session.insert_id);" in
375
  statement-based logging mode: t will be different on master and
376
  slave).
377
*/
626 by Brian Aker
More of the same (ulong/64)
378
static sys_var_readonly sys_error_count(&vars, "error_count",
379
                                        OPT_SESSION,
937.2.3 by Stewart Smith
yet another 4/8byte long issue with variables. Fix up warning and error count to use uint32_t instead.
380
                                        SHOW_INT,
626 by Brian Aker
More of the same (ulong/64)
381
                                        get_error_count);
382
static sys_var_readonly sys_warning_count(&vars, "warning_count",
383
                                          OPT_SESSION,
937.2.3 by Stewart Smith
yet another 4/8byte long issue with variables. Fix up warning and error count to use uint32_t instead.
384
                                          SHOW_INT,
626 by Brian Aker
More of the same (ulong/64)
385
                                          get_warning_count);
1 by brian
clean slate
386
617 by Brian Aker
ulong fixes
387
sys_var_session_uint64_t sys_group_concat_max_len(&vars, "group_concat_max_len",
388
                                                  &SV::group_concat_max_len);
1 by brian
clean slate
389
520.1.22 by Brian Aker
Second pass of thd cleanup
390
sys_var_session_time_zone sys_time_zone(&vars, "time_zone",
1 by brian
clean slate
391
                                    sys_var::SESSION_VARIABLE_IN_BINLOG);
392
393
/* Global read-only variable containing hostname */
394
static sys_var_const_str        sys_hostname(&vars, "hostname", glob_hostname);
395
660.1.3 by Eric Herman
removed trailing whitespace with simple script:
396
sys_var_session_bool  sys_keep_files_on_create(&vars, "keep_files_on_create",
1 by brian
clean slate
397
                                           &SV::keep_files_on_create);
398
/* Read only variables */
399
400
static sys_var_have_variable sys_have_symlink(&vars, "have_symlink", &have_symlink);
401
/*
402
  Additional variables (not derived from sys_var class, not accessible as
403
  @@varname in SELECT or SET). Sorted in alphabetical order to facilitate
404
  maintenance - SHOW VARIABLES will sort its output.
405
  TODO: remove this list completely
406
*/
407
408
#define FIXED_VARS_SIZE (sizeof(fixed_vars) / sizeof(SHOW_VAR))
409
static SHOW_VAR fixed_vars[]= {
626 by Brian Aker
More of the same (ulong/64)
410
  {"back_log",                (char*) &back_log,                    SHOW_INT},
1 by brian
clean slate
411
  {"language",                language,                             SHOW_CHAR},
412
#ifdef HAVE_MLOCKALL
413
  {"locked_in_memory",	      (char*) &locked_in_memory,	    SHOW_MY_BOOL},
414
#endif
415
  {"myisam_recover_options",  (char*) &myisam_recover_options_str,  SHOW_CHAR_PTR},
416
  {"pid_file",                (char*) pidfile_name,                 SHOW_CHAR},
417
  {"plugin_dir",              (char*) opt_plugin_dir,               SHOW_CHAR},
574.2.1 by ysano
Rename mysql to drizzle.
418
  {"port",                    (char*) &drizzled_port,               SHOW_INT},
1 by brian
clean slate
419
  {"protocol_version",        (char*) &protocol_version,            SHOW_INT},
626 by Brian Aker
More of the same (ulong/64)
420
  {"thread_stack",            (char*) &my_thread_stack_size,        SHOW_INT},
1 by brian
clean slate
421
};
422
575.1.2 by Monty Taylor
Changed a bunch of __attribute__((unused)) to removing the parameter name instead.
423
bool sys_var::check(Session *, set_var *var)
1 by brian
clean slate
424
{
151 by Brian Aker
Ulonglong to uint64_t
425
  var->save_result.uint64_t_value= var->value->val_int();
1 by brian
clean slate
426
  return 0;
427
}
428
520.1.22 by Brian Aker
Second pass of thd cleanup
429
bool sys_var_str::check(Session *session, set_var *var)
1 by brian
clean slate
430
{
431
  int res;
432
  if (!check_func)
433
    return 0;
434
520.1.22 by Brian Aker
Second pass of thd cleanup
435
  if ((res=(*check_func)(session, var)) < 0)
1 by brian
clean slate
436
    my_error(ER_WRONG_VALUE_FOR_VAR, MYF(0),
437
             name, var->value->str_value.ptr());
438
  return res;
439
}
440
441
/*
442
  Functions to check and update variables
443
*/
444
445
446
/**
447
  Set the OPTION_BIG_SELECTS flag if max_join_size == HA_POS_ERROR.
448
*/
449
520.1.22 by Brian Aker
Second pass of thd cleanup
450
static void fix_max_join_size(Session *session, enum_var_type type)
1 by brian
clean slate
451
{
452
  if (type != OPT_GLOBAL)
453
  {
520.1.22 by Brian Aker
Second pass of thd cleanup
454
    if (session->variables.max_join_size == HA_POS_ERROR)
455
      session->options|= OPTION_BIG_SELECTS;
1 by brian
clean slate
456
    else
520.1.22 by Brian Aker
Second pass of thd cleanup
457
      session->options&= ~OPTION_BIG_SELECTS;
1 by brian
clean slate
458
  }
459
}
460
461
462
/**
463
  Can't change the 'next' tx_isolation while we are already in
464
  a transaction
465
*/
520.1.22 by Brian Aker
Second pass of thd cleanup
466
static int check_tx_isolation(Session *session, set_var *var)
1 by brian
clean slate
467
{
520.1.22 by Brian Aker
Second pass of thd cleanup
468
  if (var->type == OPT_DEFAULT && (session->server_status & SERVER_STATUS_IN_TRANS))
1 by brian
clean slate
469
  {
470
    my_error(ER_CANT_CHANGE_TX_ISOLATION, MYF(0));
471
    return 1;
472
  }
473
  return 0;
474
}
475
476
/*
477
  If one doesn't use the SESSION modifier, the isolation level
478
  is only active for the next command.
479
*/
520.1.22 by Brian Aker
Second pass of thd cleanup
480
static void fix_tx_isolation(Session *session, enum_var_type type)
1 by brian
clean slate
481
{
482
  if (type == OPT_SESSION)
520.1.22 by Brian Aker
Second pass of thd cleanup
483
    session->session_tx_isolation= ((enum_tx_isolation)
575.1.2 by Monty Taylor
Changed a bunch of __attribute__((unused)) to removing the parameter name instead.
484
                                    session->variables.tx_isolation);
1 by brian
clean slate
485
}
486
575.1.2 by Monty Taylor
Changed a bunch of __attribute__((unused)) to removing the parameter name instead.
487
static void fix_completion_type(Session *, enum_var_type) {}
1 by brian
clean slate
488
575.1.2 by Monty Taylor
Changed a bunch of __attribute__((unused)) to removing the parameter name instead.
489
static int check_completion_type(Session *, set_var *var)
1 by brian
clean slate
490
{
152 by Brian Aker
longlong replacement
491
  int64_t val= var->value->val_int();
1 by brian
clean slate
492
  if (val < 0 || val > 2)
493
  {
494
    char buf[64];
495
    my_error(ER_WRONG_VALUE_FOR_VAR, MYF(0), var->var->name, llstr(val, buf));
496
    return 1;
497
  }
498
  return 0;
499
}
500
501
502
/*
971.3.5 by Eric Day
Moved more drizzleclient/NET specific code to Protocol class.
503
  If we are changing the thread variable, we have to copy it to Protocol too
1 by brian
clean slate
504
*/
505
520.1.22 by Brian Aker
Second pass of thd cleanup
506
static void fix_net_read_timeout(Session *session, enum_var_type type)
507
{
508
  if (type != OPT_GLOBAL)
971.3.19 by Eric Day
Finished first pass at Protocol cleanup, still some things to remove but they are a bit more involved.
509
    session->protocol->setReadTimeout(session->variables.net_read_timeout);
520.1.22 by Brian Aker
Second pass of thd cleanup
510
}
511
512
513
static void fix_net_write_timeout(Session *session, enum_var_type type)
514
{
515
  if (type != OPT_GLOBAL)
971.3.19 by Eric Day
Finished first pass at Protocol cleanup, still some things to remove but they are a bit more involved.
516
    session->protocol->setWriteTimeout(session->variables.net_write_timeout);
520.1.22 by Brian Aker
Second pass of thd cleanup
517
}
518
519
static void fix_net_retry_count(Session *session, enum_var_type type)
520
{
521
  if (type != OPT_GLOBAL)
971.3.19 by Eric Day
Finished first pass at Protocol cleanup, still some things to remove but they are a bit more involved.
522
    session->protocol->setRetryCount(session->variables.net_retry_count);
520.1.22 by Brian Aker
Second pass of thd cleanup
523
}
524
525
575.1.2 by Monty Taylor
Changed a bunch of __attribute__((unused)) to removing the parameter name instead.
526
extern void fix_delay_key_write(Session *, enum_var_type)
1 by brian
clean slate
527
{
528
  switch ((enum_delay_key_write) delay_key_write_options) {
529
  case DELAY_KEY_WRITE_NONE:
530
    myisam_delay_key_write=0;
531
    break;
532
  case DELAY_KEY_WRITE_ON:
533
    myisam_delay_key_write=1;
534
    break;
535
  case DELAY_KEY_WRITE_ALL:
536
    myisam_delay_key_write=1;
537
    ha_open_options|= HA_OPEN_DELAY_KEY_WRITE;
538
    break;
539
  }
540
}
541
542
520.1.22 by Brian Aker
Second pass of thd cleanup
543
static void fix_session_mem_root(Session *session, enum_var_type type)
544
{
545
  if (type != OPT_GLOBAL)
546
    reset_root_defaults(session->mem_root,
547
                        session->variables.query_alloc_block_size,
548
                        session->variables.query_prealloc_size);
549
}
550
551
552
static void fix_trans_mem_root(Session *session, enum_var_type type)
553
{
554
  if (type != OPT_GLOBAL)
555
    reset_root_defaults(&session->transaction.mem_root,
556
                        session->variables.trans_alloc_block_size,
557
                        session->variables.trans_prealloc_size);
558
}
559
560
988.1.3 by Jay Pipes
Fixed up the removal of Session::server_id
561
static void fix_server_id(Session *, enum_var_type)
1 by brian
clean slate
562
{
563
}
564
565
520.1.22 by Brian Aker
Second pass of thd cleanup
566
bool throw_bounds_warning(Session *session, bool fixed, bool unsignd,
152 by Brian Aker
longlong replacement
567
                          const char *name, int64_t val)
1 by brian
clean slate
568
{
569
  if (fixed)
570
  {
571
    char buf[22];
572
573
    if (unsignd)
151 by Brian Aker
Ulonglong to uint64_t
574
      ullstr((uint64_t) val, buf);
1 by brian
clean slate
575
    else
576
      llstr(val, buf);
577
910.4.10 by Stewart Smith
fix system variables for correct endian architectures.
578
    push_warning_printf(session, DRIZZLE_ERROR::WARN_LEVEL_ERROR,
1 by brian
clean slate
579
                        ER_TRUNCATED_WRONG_VALUE,
580
                        ER(ER_TRUNCATED_WRONG_VALUE), name, buf);
581
  }
51.1.46 by Jay Pipes
Removed/replaced DBUG symbols and standardized TRUE/FALSE
582
  return false;
1 by brian
clean slate
583
}
584
520.1.22 by Brian Aker
Second pass of thd cleanup
585
static uint64_t fix_unsigned(Session *session, uint64_t num,
1 by brian
clean slate
586
                              const struct my_option *option_limits)
587
{
143 by Brian Aker
Bool cleanup.
588
  bool fixed= false;
151 by Brian Aker
Ulonglong to uint64_t
589
  uint64_t out= getopt_ull_limit_value(num, option_limits, &fixed);
1 by brian
clean slate
590
520.1.22 by Brian Aker
Second pass of thd cleanup
591
  throw_bounds_warning(session, fixed, true, option_limits->name, (int64_t) num);
1 by brian
clean slate
592
  return out;
593
}
594
629.4.1 by Monty Taylor
First step in support size_t sys_var stuff.
595
596
static size_t fix_size_t(Session *session, size_t num,
597
                           const struct my_option *option_limits)
598
{
599
  bool fixed= false;
600
  size_t out= (size_t)getopt_ull_limit_value(num, option_limits, &fixed);
601
602
  throw_bounds_warning(session, fixed, true, option_limits->name, (int64_t) num);
603
  return out;
604
}
605
910.4.10 by Stewart Smith
fix system variables for correct endian architectures.
606
static bool get_unsigned32(Session *, set_var *var)
607
{
608
  if (var->value->unsigned_flag)
609
    var->save_result.uint32_t_value= (uint32_t) var->value->val_int();
610
  else
611
  {
612
    int64_t v= var->value->val_int();
613
    var->save_result.uint32_t_value= (uint32_t) ((v < 0) ? 0 : v);
614
  }
615
  return 0;
616
}
617
618
static bool get_unsigned64(Session *, set_var *var)
619
{
620
  if (var->value->unsigned_flag)
621
      var->save_result.uint64_t_value=(uint64_t) var->value->val_int();
622
  else
623
  {
624
    int64_t v= var->value->val_int();
625
      var->save_result.uint64_t_value= (uint64_t) ((v < 0) ? 0 : v);
1 by brian
clean slate
626
  }
627
  return 0;
628
}
629
629.4.1 by Monty Taylor
First step in support size_t sys_var stuff.
630
static bool get_size_t(Session *, set_var *var)
631
{
632
  if (var->value->unsigned_flag)
910.4.9 by Stewart Smith
fix size_t variables on platforms where sizeof(size_t)=4
633
    var->save_result.size_t_value= (size_t) var->value->val_int();
629.4.1 by Monty Taylor
First step in support size_t sys_var stuff.
634
  else
635
  {
892.2.2 by Monty Taylor
More solaris warnings.
636
    ssize_t v= (ssize_t)var->value->val_int();
910.4.9 by Stewart Smith
fix size_t variables on platforms where sizeof(size_t)=4
637
    var->save_result.size_t_value= (size_t) ((v < 0) ? 0 : v);
629.4.1 by Monty Taylor
First step in support size_t sys_var stuff.
638
  }
639
  return 0;
640
}
641
910.4.10 by Stewart Smith
fix system variables for correct endian architectures.
642
bool sys_var_uint32_t_ptr::check(Session *, set_var *var)
643
{
988.2.2 by Trond Norbye
size_t and uint64_t is not the same in 32 bit builds. Add explicit casting
644
  var->save_result.uint32_t_value= (uint32_t)var->value->val_int();
1 by brian
clean slate
645
  return 0;
646
}
647
520.4.14 by Monty Taylor
Removed korr.h and tztime.h from common_includes. Also removed the HAVE_DTRACE block and stuck it in autoconf.
648
bool sys_var_uint32_t_ptr::update(Session *session, set_var *var)
649
{
650
  uint32_t tmp= var->save_result.uint32_t_value;
651
  pthread_mutex_lock(&LOCK_global_system_variables);
652
  if (option_limits)
910.4.10 by Stewart Smith
fix system variables for correct endian architectures.
653
  {
654
    uint32_t newvalue= (uint32_t) fix_unsigned(session, tmp, option_limits);
655
    if(newvalue==tmp)
656
      *value= newvalue;
657
  }
520.4.14 by Monty Taylor
Removed korr.h and tztime.h from common_includes. Also removed the HAVE_DTRACE block and stuck it in autoconf.
658
  else
659
    *value= (uint32_t) tmp;
660
  pthread_mutex_unlock(&LOCK_global_system_variables);
661
  return 0;
662
}
663
664
575.1.2 by Monty Taylor
Changed a bunch of __attribute__((unused)) to removing the parameter name instead.
665
void sys_var_uint32_t_ptr::set_default(Session *, enum_var_type)
520.4.14 by Monty Taylor
Removed korr.h and tztime.h from common_includes. Also removed the HAVE_DTRACE block and stuck it in autoconf.
666
{
667
  bool not_used;
668
  pthread_mutex_lock(&LOCK_global_system_variables);
892.2.2 by Monty Taylor
More solaris warnings.
669
  *value= (uint32_t)getopt_ull_limit_value((uint32_t) option_limits->def_value,
670
                                           option_limits, &not_used);
520.4.14 by Monty Taylor
Removed korr.h and tztime.h from common_includes. Also removed the HAVE_DTRACE block and stuck it in autoconf.
671
  pthread_mutex_unlock(&LOCK_global_system_variables);
672
}
673
1 by brian
clean slate
674
520.1.22 by Brian Aker
Second pass of thd cleanup
675
bool sys_var_uint64_t_ptr::update(Session *session, set_var *var)
1 by brian
clean slate
676
{
151 by Brian Aker
Ulonglong to uint64_t
677
  uint64_t tmp= var->save_result.uint64_t_value;
1 by brian
clean slate
678
  pthread_mutex_lock(&LOCK_global_system_variables);
679
  if (option_limits)
910.4.10 by Stewart Smith
fix system variables for correct endian architectures.
680
  {
681
    uint64_t newvalue= (uint64_t) fix_unsigned(session, tmp, option_limits);
682
    if(newvalue==tmp)
683
      *value= newvalue;
684
  }
1 by brian
clean slate
685
  else
151 by Brian Aker
Ulonglong to uint64_t
686
    *value= (uint64_t) tmp;
1 by brian
clean slate
687
  pthread_mutex_unlock(&LOCK_global_system_variables);
688
  return 0;
689
}
690
691
575.1.2 by Monty Taylor
Changed a bunch of __attribute__((unused)) to removing the parameter name instead.
692
void sys_var_uint64_t_ptr::set_default(Session *, enum_var_type)
1 by brian
clean slate
693
{
143 by Brian Aker
Bool cleanup.
694
  bool not_used;
1 by brian
clean slate
695
  pthread_mutex_lock(&LOCK_global_system_variables);
151 by Brian Aker
Ulonglong to uint64_t
696
  *value= getopt_ull_limit_value((uint64_t) option_limits->def_value,
1 by brian
clean slate
697
                                 option_limits, &not_used);
698
  pthread_mutex_unlock(&LOCK_global_system_variables);
699
}
700
701
629.4.1 by Monty Taylor
First step in support size_t sys_var stuff.
702
bool sys_var_size_t_ptr::update(Session *session, set_var *var)
703
{
704
  size_t tmp= var->save_result.size_t_value;
705
  pthread_mutex_lock(&LOCK_global_system_variables);
706
  if (option_limits)
707
    *value= fix_size_t(session, tmp, option_limits);
708
  else
709
    *value= tmp;
710
  pthread_mutex_unlock(&LOCK_global_system_variables);
711
  return 0;
712
}
713
714
715
void sys_var_size_t_ptr::set_default(Session *, enum_var_type)
716
{
717
  bool not_used;
718
  pthread_mutex_lock(&LOCK_global_system_variables);
719
  *value= (size_t)getopt_ull_limit_value((size_t) option_limits->def_value,
720
                                         option_limits, &not_used);
721
  pthread_mutex_unlock(&LOCK_global_system_variables);
722
}
723
575.1.2 by Monty Taylor
Changed a bunch of __attribute__((unused)) to removing the parameter name instead.
724
bool sys_var_bool_ptr::update(Session *, set_var *var)
1 by brian
clean slate
725
{
576 by Brian Aker
ulong conversion work
726
  *value= (bool) var->save_result.uint32_t_value;
1 by brian
clean slate
727
  return 0;
728
}
729
730
575.1.2 by Monty Taylor
Changed a bunch of __attribute__((unused)) to removing the parameter name instead.
731
void sys_var_bool_ptr::set_default(Session *, enum_var_type)
1 by brian
clean slate
732
{
146 by Brian Aker
my_bool cleanup.
733
  *value= (bool) option_limits->def_value;
734
}
735
1 by brian
clean slate
736
575.1.2 by Monty Taylor
Changed a bunch of __attribute__((unused)) to removing the parameter name instead.
737
bool sys_var_enum::update(Session *, set_var *var)
1 by brian
clean slate
738
{
895 by Brian Aker
Completion (?) of uint conversion.
739
  *value= (uint32_t) var->save_result.uint32_t_value;
1 by brian
clean slate
740
  return 0;
741
}
742
743
779.3.10 by Monty Taylor
Turned on -Wshadow.
744
unsigned char *sys_var_enum::value_ptr(Session *, enum_var_type, const LEX_STRING *)
1 by brian
clean slate
745
{
481 by Brian Aker
Remove all of uchar.
746
  return (unsigned char*) enum_names->type_names[*value];
1 by brian
clean slate
747
}
748
749
575.1.2 by Monty Taylor
Changed a bunch of __attribute__((unused)) to removing the parameter name instead.
750
unsigned char *sys_var_enum_const::value_ptr(Session *, enum_var_type,
779.3.10 by Monty Taylor
Turned on -Wshadow.
751
                                             const LEX_STRING *)
1 by brian
clean slate
752
{
481 by Brian Aker
Remove all of uchar.
753
  return (unsigned char*) enum_names->type_names[global_system_variables.*offset];
1 by brian
clean slate
754
}
755
615 by Brian Aker
Added 32bit system variable support
756
/*
660.1.3 by Eric Herman
removed trailing whitespace with simple script:
757
  32 bit types for session variables
615 by Brian Aker
Added 32bit system variable support
758
*/
759
bool sys_var_session_uint32_t::check(Session *session, set_var *var)
760
{
910.4.10 by Stewart Smith
fix system variables for correct endian architectures.
761
  return (get_unsigned32(session, var) ||
615 by Brian Aker
Added 32bit system variable support
762
          (check_func && (*check_func)(session, var)));
763
}
764
765
bool sys_var_session_uint32_t::update(Session *session, set_var *var)
766
{
910.4.10 by Stewart Smith
fix system variables for correct endian architectures.
767
  uint64_t tmp= (uint64_t) var->save_result.uint32_t_value;
660.1.3 by Eric Herman
removed trailing whitespace with simple script:
768
615 by Brian Aker
Added 32bit system variable support
769
  /* Don't use bigger value than given with --maximum-variable-name=.. */
770
  if ((uint32_t) tmp > max_system_variables.*offset)
771
  {
772
    throw_bounds_warning(session, true, true, name, (int64_t) tmp);
773
    tmp= max_system_variables.*offset;
774
  }
660.1.3 by Eric Herman
removed trailing whitespace with simple script:
775
615 by Brian Aker
Added 32bit system variable support
776
  if (option_limits)
777
    tmp= (uint32_t) fix_unsigned(session, tmp, option_limits);
778
  else if (tmp > UINT32_MAX)
779
  {
780
    tmp= UINT32_MAX;
781
    throw_bounds_warning(session, true, true, name, (int64_t) var->save_result.uint64_t_value);
782
  }
660.1.3 by Eric Herman
removed trailing whitespace with simple script:
783
615 by Brian Aker
Added 32bit system variable support
784
  if (var->type == OPT_GLOBAL)
785
     global_system_variables.*offset= (uint32_t) tmp;
786
   else
787
     session->variables.*offset= (uint32_t) tmp;
788
789
   return 0;
790
 }
791
792
793
 void sys_var_session_uint32_t::set_default(Session *session, enum_var_type type)
794
 {
795
   if (type == OPT_GLOBAL)
796
   {
797
     bool not_used;
798
     /* We will not come here if option_limits is not set */
799
     global_system_variables.*offset=
800
       (uint32_t) getopt_ull_limit_value((uint32_t) option_limits->def_value,
801
                                      option_limits, &not_used);
802
   }
803
   else
804
     session->variables.*offset= global_system_variables.*offset;
805
 }
806
807
808
unsigned char *sys_var_session_uint32_t::value_ptr(Session *session,
809
                                                enum_var_type type,
779.3.10 by Monty Taylor
Turned on -Wshadow.
810
                                                const LEX_STRING *)
615 by Brian Aker
Added 32bit system variable support
811
{
812
  if (type == OPT_GLOBAL)
813
    return (unsigned char*) &(global_system_variables.*offset);
814
  return (unsigned char*) &(session->variables.*offset);
815
}
816
1 by brian
clean slate
817
520.1.22 by Brian Aker
Second pass of thd cleanup
818
bool sys_var_session_ha_rows::update(Session *session, set_var *var)
1 by brian
clean slate
819
{
151 by Brian Aker
Ulonglong to uint64_t
820
  uint64_t tmp= var->save_result.uint64_t_value;
1 by brian
clean slate
821
822
  /* Don't use bigger value than given with --maximum-variable-name=.. */
823
  if ((ha_rows) tmp > max_system_variables.*offset)
824
    tmp= max_system_variables.*offset;
825
826
  if (option_limits)
520.1.22 by Brian Aker
Second pass of thd cleanup
827
    tmp= (ha_rows) fix_unsigned(session, tmp, option_limits);
1 by brian
clean slate
828
  if (var->type == OPT_GLOBAL)
829
  {
830
    /* Lock is needed to make things safe on 32 bit systems */
660.1.3 by Eric Herman
removed trailing whitespace with simple script:
831
    pthread_mutex_lock(&LOCK_global_system_variables);
1 by brian
clean slate
832
    global_system_variables.*offset= (ha_rows) tmp;
833
    pthread_mutex_unlock(&LOCK_global_system_variables);
834
  }
835
  else
520.1.22 by Brian Aker
Second pass of thd cleanup
836
    session->variables.*offset= (ha_rows) tmp;
1 by brian
clean slate
837
  return 0;
838
}
839
840
520.1.22 by Brian Aker
Second pass of thd cleanup
841
void sys_var_session_ha_rows::set_default(Session *session, enum_var_type type)
1 by brian
clean slate
842
{
843
  if (type == OPT_GLOBAL)
844
  {
143 by Brian Aker
Bool cleanup.
845
    bool not_used;
1 by brian
clean slate
846
    /* We will not come here if option_limits is not set */
847
    pthread_mutex_lock(&LOCK_global_system_variables);
848
    global_system_variables.*offset=
849
      (ha_rows) getopt_ull_limit_value((ha_rows) option_limits->def_value,
850
                                       option_limits, &not_used);
851
    pthread_mutex_unlock(&LOCK_global_system_variables);
852
  }
853
  else
520.1.22 by Brian Aker
Second pass of thd cleanup
854
    session->variables.*offset= global_system_variables.*offset;
1 by brian
clean slate
855
}
856
857
575.1.2 by Monty Taylor
Changed a bunch of __attribute__((unused)) to removing the parameter name instead.
858
unsigned char *sys_var_session_ha_rows::value_ptr(Session *session,
859
                                                  enum_var_type type,
779.3.10 by Monty Taylor
Turned on -Wshadow.
860
                                                  const LEX_STRING *)
1 by brian
clean slate
861
{
862
  if (type == OPT_GLOBAL)
481 by Brian Aker
Remove all of uchar.
863
    return (unsigned char*) &(global_system_variables.*offset);
520.1.22 by Brian Aker
Second pass of thd cleanup
864
  return (unsigned char*) &(session->variables.*offset);
1 by brian
clean slate
865
}
866
520.1.22 by Brian Aker
Second pass of thd cleanup
867
bool sys_var_session_uint64_t::check(Session *session, set_var *var)
1 by brian
clean slate
868
{
910.4.10 by Stewart Smith
fix system variables for correct endian architectures.
869
  return (get_unsigned64(session, var) ||
555 by Monty
Fixed 32-bit issues.
870
	  (check_func && (*check_func)(session, var)));
1 by brian
clean slate
871
}
872
520.1.22 by Brian Aker
Second pass of thd cleanup
873
bool sys_var_session_uint64_t::update(Session *session,  set_var *var)
1 by brian
clean slate
874
{
151 by Brian Aker
Ulonglong to uint64_t
875
  uint64_t tmp= var->save_result.uint64_t_value;
1 by brian
clean slate
876
877
  if (tmp > max_system_variables.*offset)
878
    tmp= max_system_variables.*offset;
879
880
  if (option_limits)
520.1.22 by Brian Aker
Second pass of thd cleanup
881
    tmp= fix_unsigned(session, tmp, option_limits);
1 by brian
clean slate
882
  if (var->type == OPT_GLOBAL)
883
  {
884
    /* Lock is needed to make things safe on 32 bit systems */
885
    pthread_mutex_lock(&LOCK_global_system_variables);
151 by Brian Aker
Ulonglong to uint64_t
886
    global_system_variables.*offset= (uint64_t) tmp;
1 by brian
clean slate
887
    pthread_mutex_unlock(&LOCK_global_system_variables);
888
  }
889
  else
520.1.22 by Brian Aker
Second pass of thd cleanup
890
    session->variables.*offset= (uint64_t) tmp;
1 by brian
clean slate
891
  return 0;
892
}
893
894
520.1.22 by Brian Aker
Second pass of thd cleanup
895
void sys_var_session_uint64_t::set_default(Session *session, enum_var_type type)
1 by brian
clean slate
896
{
897
  if (type == OPT_GLOBAL)
898
  {
143 by Brian Aker
Bool cleanup.
899
    bool not_used;
1 by brian
clean slate
900
    pthread_mutex_lock(&LOCK_global_system_variables);
901
    global_system_variables.*offset=
151 by Brian Aker
Ulonglong to uint64_t
902
      getopt_ull_limit_value((uint64_t) option_limits->def_value,
1 by brian
clean slate
903
                             option_limits, &not_used);
904
    pthread_mutex_unlock(&LOCK_global_system_variables);
905
  }
906
  else
520.1.22 by Brian Aker
Second pass of thd cleanup
907
    session->variables.*offset= global_system_variables.*offset;
1 by brian
clean slate
908
}
909
910
575.1.2 by Monty Taylor
Changed a bunch of __attribute__((unused)) to removing the parameter name instead.
911
unsigned char *sys_var_session_uint64_t::value_ptr(Session *session,
912
                                                   enum_var_type type,
779.3.10 by Monty Taylor
Turned on -Wshadow.
913
                                                   const LEX_STRING *)
1 by brian
clean slate
914
{
915
  if (type == OPT_GLOBAL)
481 by Brian Aker
Remove all of uchar.
916
    return (unsigned char*) &(global_system_variables.*offset);
520.1.22 by Brian Aker
Second pass of thd cleanup
917
  return (unsigned char*) &(session->variables.*offset);
1 by brian
clean slate
918
}
919
629.4.1 by Monty Taylor
First step in support size_t sys_var stuff.
920
bool sys_var_session_size_t::check(Session *session, set_var *var)
921
{
922
  return (get_size_t(session, var) ||
923
	  (check_func && (*check_func)(session, var)));
924
}
925
926
bool sys_var_session_size_t::update(Session *session,  set_var *var)
927
{
928
  size_t tmp= var->save_result.size_t_value;
929
930
  if (tmp > max_system_variables.*offset)
931
    tmp= max_system_variables.*offset;
932
933
  if (option_limits)
934
    tmp= fix_size_t(session, tmp, option_limits);
935
  if (var->type == OPT_GLOBAL)
936
  {
937
    /* Lock is needed to make things safe on 32 bit systems */
938
    pthread_mutex_lock(&LOCK_global_system_variables);
939
    global_system_variables.*offset= tmp;
940
    pthread_mutex_unlock(&LOCK_global_system_variables);
941
  }
942
  else
943
    session->variables.*offset= tmp;
944
  return 0;
945
}
946
947
948
void sys_var_session_size_t::set_default(Session *session, enum_var_type type)
949
{
950
  if (type == OPT_GLOBAL)
951
  {
952
    bool not_used;
953
    pthread_mutex_lock(&LOCK_global_system_variables);
954
    global_system_variables.*offset=
892.2.2 by Monty Taylor
More solaris warnings.
955
      (size_t)getopt_ull_limit_value((size_t) option_limits->def_value,
956
                                     option_limits, &not_used);
629.4.1 by Monty Taylor
First step in support size_t sys_var stuff.
957
    pthread_mutex_unlock(&LOCK_global_system_variables);
958
  }
959
  else
960
    session->variables.*offset= global_system_variables.*offset;
961
}
962
963
964
unsigned char *sys_var_session_size_t::value_ptr(Session *session,
965
                                                 enum_var_type type,
779.3.10 by Monty Taylor
Turned on -Wshadow.
966
                                                 const LEX_STRING *)
629.4.1 by Monty Taylor
First step in support size_t sys_var stuff.
967
{
968
  if (type == OPT_GLOBAL)
969
    return (unsigned char*) &(global_system_variables.*offset);
970
  return (unsigned char*) &(session->variables.*offset);
971
}
972
1 by brian
clean slate
973
520.1.22 by Brian Aker
Second pass of thd cleanup
974
bool sys_var_session_bool::update(Session *session,  set_var *var)
1 by brian
clean slate
975
{
976
  if (var->type == OPT_GLOBAL)
576 by Brian Aker
ulong conversion work
977
    global_system_variables.*offset= (bool) var->save_result.uint32_t_value;
1 by brian
clean slate
978
  else
576 by Brian Aker
ulong conversion work
979
    session->variables.*offset= (bool) var->save_result.uint32_t_value;
1 by brian
clean slate
980
  return 0;
981
}
982
983
520.1.22 by Brian Aker
Second pass of thd cleanup
984
void sys_var_session_bool::set_default(Session *session,  enum_var_type type)
1 by brian
clean slate
985
{
986
  if (type == OPT_GLOBAL)
200 by Brian Aker
my_bool from handler and set_var
987
    global_system_variables.*offset= (bool) option_limits->def_value;
1 by brian
clean slate
988
  else
520.1.22 by Brian Aker
Second pass of thd cleanup
989
    session->variables.*offset= global_system_variables.*offset;
1 by brian
clean slate
990
}
991
992
575.1.2 by Monty Taylor
Changed a bunch of __attribute__((unused)) to removing the parameter name instead.
993
unsigned char *sys_var_session_bool::value_ptr(Session *session,
994
                                               enum_var_type type,
779.3.10 by Monty Taylor
Turned on -Wshadow.
995
                                               const LEX_STRING *)
1 by brian
clean slate
996
{
997
  if (type == OPT_GLOBAL)
481 by Brian Aker
Remove all of uchar.
998
    return (unsigned char*) &(global_system_variables.*offset);
520.1.22 by Brian Aker
Second pass of thd cleanup
999
  return (unsigned char*) &(session->variables.*offset);
1 by brian
clean slate
1000
}
1001
1002
575.1.2 by Monty Taylor
Changed a bunch of __attribute__((unused)) to removing the parameter name instead.
1003
bool sys_var::check_enum(Session *,
77.1.45 by Monty Taylor
Warning fixes.
1004
                         set_var *var, const TYPELIB *enum_names)
1 by brian
clean slate
1005
{
1006
  char buff[STRING_BUFFER_USUAL_SIZE];
1007
  const char *value;
1008
  String str(buff, sizeof(buff), system_charset_info), *res;
1009
1010
  if (var->value->result_type() == STRING_RESULT)
1011
  {
971.2.1 by Eric Day
Fix for bug #311025. This was due to code that was removed during ulong cleanup (r576).
1012
    if (!(res=var->value->val_str(&str)) ||
1013
        (var->save_result.uint32_t_value= find_type(enum_names, res->ptr(),
1014
                                                    res->length(),1)) == 0)
1 by brian
clean slate
1015
    {
1016
      value= res ? res->c_ptr() : "NULL";
1017
      goto err;
1018
    }
971.2.1 by Eric Day
Fix for bug #311025. This was due to code that was removed during ulong cleanup (r576).
1019
1020
    var->save_result.uint32_t_value--;
1 by brian
clean slate
1021
  }
1022
  else
1023
  {
151 by Brian Aker
Ulonglong to uint64_t
1024
    uint64_t tmp=var->value->val_int();
1 by brian
clean slate
1025
    if (tmp >= enum_names->count)
1026
    {
1027
      llstr(tmp,buff);
1028
      value=buff;				// Wrong value is here
1029
      goto err;
1030
    }
576 by Brian Aker
ulong conversion work
1031
    var->save_result.uint32_t_value= (uint32_t) tmp;	// Save for update
1 by brian
clean slate
1032
  }
1033
  return 0;
1034
1035
err:
1036
  my_error(ER_WRONG_VALUE_FOR_VAR, MYF(0), name, value);
1037
  return 1;
1038
}
1039
1040
575.1.2 by Monty Taylor
Changed a bunch of __attribute__((unused)) to removing the parameter name instead.
1041
bool sys_var::check_set(Session *, set_var *var, TYPELIB *enum_names)
1 by brian
clean slate
1042
{
1043
  bool not_used;
1044
  char buff[STRING_BUFFER_USUAL_SIZE], *error= 0;
482 by Brian Aker
Remove uint.
1045
  uint32_t error_len= 0;
1 by brian
clean slate
1046
  String str(buff, sizeof(buff), system_charset_info), *res;
1047
1048
  if (var->value->result_type() == STRING_RESULT)
1049
  {
1050
    if (!(res= var->value->val_str(&str)))
1051
    {
641.4.1 by Toru Maesaka
First pass of replacing MySQL's my_stpcpy() with appropriate libc calls
1052
      strcpy(buff, "NULL");
1 by brian
clean slate
1053
      goto err;
1054
    }
1055
1056
    if (!m_allow_empty_value &&
1057
        res->length() == 0)
1058
    {
1059
      buff[0]= 0;
1060
      goto err;
1061
    }
1062
576 by Brian Aker
ulong conversion work
1063
    var->save_result.uint32_t_value= ((uint32_t)
1 by brian
clean slate
1064
				   find_set(enum_names, res->c_ptr(),
1065
					    res->length(),
1066
                                            NULL,
1067
                                            &error, &error_len,
1068
					    &not_used));
1069
    if (error_len)
1070
    {
629.5.3 by Toru Maesaka
Third pass of replacing MySQL's strmake() with libc calls
1071
      size_t len = cmin(sizeof(buff) - 1, error_len);
1072
      strncpy(buff, error, len);
1073
      buff[len]= '\0';
1 by brian
clean slate
1074
      goto err;
1075
    }
1076
  }
1077
  else
1078
  {
151 by Brian Aker
Ulonglong to uint64_t
1079
    uint64_t tmp= var->value->val_int();
1 by brian
clean slate
1080
1081
    if (!m_allow_empty_value &&
1082
        tmp == 0)
1083
    {
1084
      buff[0]= '0';
1085
      buff[1]= 0;
1086
      goto err;
1087
    }
1088
1089
    /*
1090
      For when the enum is made to contain 64 elements, as 1ULL<<64 is
1091
      undefined, we guard with a "count<64" test.
1092
    */
398.1.8 by Monty Taylor
Enabled -Wlong-long.
1093
    if (unlikely((tmp >= ((1UL) << enum_names->count)) &&
1 by brian
clean slate
1094
                 (enum_names->count < 64)))
1095
    {
1096
      llstr(tmp, buff);
1097
      goto err;
1098
    }
576 by Brian Aker
ulong conversion work
1099
    var->save_result.uint32_t_value= (uint32_t) tmp;  // Save for update
1 by brian
clean slate
1100
  }
1101
  return 0;
1102
1103
err:
1104
  my_error(ER_WRONG_VALUE_FOR_VAR, MYF(0), name, buff);
1105
  return 1;
1106
}
1107
1108
1109
/**
1110
  Return an Item for a variable.
1111
1112
  Used with @@[global.]variable_name.
1113
1114
  If type is not given, return local value if exists, else global.
1115
*/
1116
779.3.10 by Monty Taylor
Turned on -Wshadow.
1117
Item *sys_var::item(Session *session, enum_var_type var_type, const LEX_STRING *base)
1 by brian
clean slate
1118
{
1119
  if (check_type(var_type))
1120
  {
1121
    if (var_type != OPT_DEFAULT)
1122
    {
1123
      my_error(ER_INCORRECT_GLOBAL_LOCAL_VAR, MYF(0),
1124
               name, var_type == OPT_GLOBAL ? "SESSION" : "GLOBAL");
1125
      return 0;
1126
    }
1127
    /* As there was no local variable, return the global value */
1128
    var_type= OPT_GLOBAL;
1129
  }
1130
  switch (show_type()) {
625 by Brian Aker
ulong/64 bit straighten out.
1131
  case SHOW_LONG:
1 by brian
clean slate
1132
  case SHOW_INT:
1133
  {
482 by Brian Aker
Remove uint.
1134
    uint32_t value;
1 by brian
clean slate
1135
    pthread_mutex_lock(&LOCK_global_system_variables);
520.1.22 by Brian Aker
Second pass of thd cleanup
1136
    value= *(uint*) value_ptr(session, var_type, base);
1 by brian
clean slate
1137
    pthread_mutex_unlock(&LOCK_global_system_variables);
151 by Brian Aker
Ulonglong to uint64_t
1138
    return new Item_uint((uint64_t) value);
1 by brian
clean slate
1139
  }
1140
  case SHOW_LONGLONG:
1141
  {
152 by Brian Aker
longlong replacement
1142
    int64_t value;
1 by brian
clean slate
1143
    pthread_mutex_lock(&LOCK_global_system_variables);
520.1.22 by Brian Aker
Second pass of thd cleanup
1144
    value= *(int64_t*) value_ptr(session, var_type, base);
1 by brian
clean slate
1145
    pthread_mutex_unlock(&LOCK_global_system_variables);
1146
    return new Item_int(value);
1147
  }
1148
  case SHOW_DOUBLE:
1149
  {
1150
    double value;
1151
    pthread_mutex_lock(&LOCK_global_system_variables);
520.1.22 by Brian Aker
Second pass of thd cleanup
1152
    value= *(double*) value_ptr(session, var_type, base);
1 by brian
clean slate
1153
    pthread_mutex_unlock(&LOCK_global_system_variables);
1154
    /* 6, as this is for now only used with microseconds */
1155
    return new Item_float(value, 6);
1156
  }
1157
  case SHOW_HA_ROWS:
1158
  {
1159
    ha_rows value;
1160
    pthread_mutex_lock(&LOCK_global_system_variables);
520.1.22 by Brian Aker
Second pass of thd cleanup
1161
    value= *(ha_rows*) value_ptr(session, var_type, base);
1 by brian
clean slate
1162
    pthread_mutex_unlock(&LOCK_global_system_variables);
151 by Brian Aker
Ulonglong to uint64_t
1163
    return new Item_int((uint64_t) value);
1 by brian
clean slate
1164
  }
673.3.17 by Stewart Smith
mostly fix repair test. fix syntax for Drizzle (all tests are MyISAM reliant).
1165
  case SHOW_SIZE:
1166
  {
1167
    size_t value;
1168
    pthread_mutex_lock(&LOCK_global_system_variables);
1169
    value= *(size_t*) value_ptr(session, var_type, base);
1170
    pthread_mutex_unlock(&LOCK_global_system_variables);
1171
    return new Item_int((uint64_t) value);
1172
  }
1 by brian
clean slate
1173
  case SHOW_MY_BOOL:
1174
  {
205 by Brian Aker
uint32 -> uin32_t
1175
    int32_t value;
1 by brian
clean slate
1176
    pthread_mutex_lock(&LOCK_global_system_variables);
520.1.22 by Brian Aker
Second pass of thd cleanup
1177
    value= *(bool*) value_ptr(session, var_type, base);
1 by brian
clean slate
1178
    pthread_mutex_unlock(&LOCK_global_system_variables);
1179
    return new Item_int(value,1);
1180
  }
1181
  case SHOW_CHAR_PTR:
1182
  {
1183
    Item *tmp;
1184
    pthread_mutex_lock(&LOCK_global_system_variables);
520.1.22 by Brian Aker
Second pass of thd cleanup
1185
    char *str= *(char**) value_ptr(session, var_type, base);
1 by brian
clean slate
1186
    if (str)
1187
    {
482 by Brian Aker
Remove uint.
1188
      uint32_t length= strlen(str);
520.1.22 by Brian Aker
Second pass of thd cleanup
1189
      tmp= new Item_string(session->strmake(str, length), length,
1 by brian
clean slate
1190
                           system_charset_info, DERIVATION_SYSCONST);
1191
    }
1192
    else
1193
    {
1194
      tmp= new Item_null();
1195
      tmp->collation.set(system_charset_info, DERIVATION_SYSCONST);
1196
    }
1197
    pthread_mutex_unlock(&LOCK_global_system_variables);
1198
    return tmp;
1199
  }
1200
  case SHOW_CHAR:
1201
  {
1202
    Item *tmp;
1203
    pthread_mutex_lock(&LOCK_global_system_variables);
520.1.22 by Brian Aker
Second pass of thd cleanup
1204
    char *str= (char*) value_ptr(session, var_type, base);
1 by brian
clean slate
1205
    if (str)
1206
      tmp= new Item_string(str, strlen(str),
1207
                           system_charset_info, DERIVATION_SYSCONST);
1208
    else
1209
    {
1210
      tmp= new Item_null();
1211
      tmp->collation.set(system_charset_info, DERIVATION_SYSCONST);
1212
    }
1213
    pthread_mutex_unlock(&LOCK_global_system_variables);
1214
    return tmp;
1215
  }
1216
  default:
1217
    my_error(ER_VAR_CANT_BE_READ, MYF(0), name);
1218
  }
1219
  return 0;
1220
}
1221
1222
520.1.22 by Brian Aker
Second pass of thd cleanup
1223
bool sys_var_session_enum::update(Session *session, set_var *var)
1 by brian
clean slate
1224
{
1225
  if (var->type == OPT_GLOBAL)
576 by Brian Aker
ulong conversion work
1226
    global_system_variables.*offset= var->save_result.uint32_t_value;
1 by brian
clean slate
1227
  else
576 by Brian Aker
ulong conversion work
1228
    session->variables.*offset= var->save_result.uint32_t_value;
1 by brian
clean slate
1229
  return 0;
1230
}
1231
1232
520.1.22 by Brian Aker
Second pass of thd cleanup
1233
void sys_var_session_enum::set_default(Session *session, enum_var_type type)
1 by brian
clean slate
1234
{
1235
  if (type == OPT_GLOBAL)
621 by Brian Aker
ulong fixes
1236
    global_system_variables.*offset= (uint32_t) option_limits->def_value;
1 by brian
clean slate
1237
  else
520.1.22 by Brian Aker
Second pass of thd cleanup
1238
    session->variables.*offset= global_system_variables.*offset;
1 by brian
clean slate
1239
}
1240
1241
575.1.2 by Monty Taylor
Changed a bunch of __attribute__((unused)) to removing the parameter name instead.
1242
unsigned char *sys_var_session_enum::value_ptr(Session *session,
1243
                                               enum_var_type type,
779.3.10 by Monty Taylor
Turned on -Wshadow.
1244
                                               const LEX_STRING *)
1 by brian
clean slate
1245
{
621 by Brian Aker
ulong fixes
1246
  uint32_t tmp= ((type == OPT_GLOBAL) ?
1 by brian
clean slate
1247
	      global_system_variables.*offset :
520.1.22 by Brian Aker
Second pass of thd cleanup
1248
	      session->variables.*offset);
481 by Brian Aker
Remove all of uchar.
1249
  return (unsigned char*) enum_names->type_names[tmp];
1 by brian
clean slate
1250
}
1251
520.1.22 by Brian Aker
Second pass of thd cleanup
1252
bool sys_var_session_bit::check(Session *session, set_var *var)
1 by brian
clean slate
1253
{
520.1.22 by Brian Aker
Second pass of thd cleanup
1254
  return (check_enum(session, var, &bool_typelib) ||
1255
          (check_func && (*check_func)(session, var)));
1 by brian
clean slate
1256
}
1257
520.1.22 by Brian Aker
Second pass of thd cleanup
1258
bool sys_var_session_bit::update(Session *session, set_var *var)
1 by brian
clean slate
1259
{
520.1.22 by Brian Aker
Second pass of thd cleanup
1260
  int res= (*update_func)(session, var);
1 by brian
clean slate
1261
  return res;
1262
}
1263
1264
575.1.2 by Monty Taylor
Changed a bunch of __attribute__((unused)) to removing the parameter name instead.
1265
unsigned char *sys_var_session_bit::value_ptr(Session *session, enum_var_type,
779.3.10 by Monty Taylor
Turned on -Wshadow.
1266
                                              const LEX_STRING *)
1 by brian
clean slate
1267
{
1268
  /*
1269
    If reverse is 0 (default) return 1 if bit is set.
1270
    If reverse is 1, return 0 if bit is set
1271
  */
520.1.22 by Brian Aker
Second pass of thd cleanup
1272
  session->sys_var_tmp.bool_value= ((session->options & bit_flag) ?
1 by brian
clean slate
1273
				   !reverse : reverse);
520.1.22 by Brian Aker
Second pass of thd cleanup
1274
  return (unsigned char*) &session->sys_var_tmp.bool_value;
1 by brian
clean slate
1275
}
1276
1277
1278
typedef struct old_names_map_st
1279
{
1280
  const char *old_name;
1281
  const char *new_name;
1282
} my_old_conv;
1283
575.1.2 by Monty Taylor
Changed a bunch of __attribute__((unused)) to removing the parameter name instead.
1284
bool sys_var_collation::check(Session *, set_var *var)
1 by brian
clean slate
1285
{
264.2.6 by Andrey Hristov
Constify the usage of CHARSET_INFO almost to the last place in the code.
1286
  const CHARSET_INFO *tmp;
1 by brian
clean slate
1287
1288
  if (var->value->result_type() == STRING_RESULT)
1289
  {
1290
    char buff[STRING_BUFFER_USUAL_SIZE];
1291
    String str(buff,sizeof(buff), system_charset_info), *res;
1292
    if (!(res=var->value->val_str(&str)))
1293
    {
1294
      my_error(ER_WRONG_VALUE_FOR_VAR, MYF(0), name, "NULL");
1295
      return 1;
1296
    }
862 by Brian Aker
Remove charset directory code.
1297
    if (!(tmp=get_charset_by_name(res->c_ptr())))
1 by brian
clean slate
1298
    {
1299
      my_error(ER_UNKNOWN_COLLATION, MYF(0), res->c_ptr());
1300
      return 1;
1301
    }
1302
  }
1303
  else // INT_RESULT
1304
  {
862 by Brian Aker
Remove charset directory code.
1305
    if (!(tmp=get_charset((int) var->value->val_int())))
1 by brian
clean slate
1306
    {
1307
      char buf[20];
1308
      int10_to_str((int) var->value->val_int(), buf, -10);
1309
      my_error(ER_UNKNOWN_COLLATION, MYF(0), buf);
1310
      return 1;
1311
    }
1312
  }
1313
  var->save_result.charset= tmp;	// Save for update
1314
  return 0;
1315
}
1316
1317
520.1.22 by Brian Aker
Second pass of thd cleanup
1318
bool sys_var_collation_sv::update(Session *session, set_var *var)
1 by brian
clean slate
1319
{
1320
  if (var->type == OPT_GLOBAL)
1321
    global_system_variables.*offset= var->save_result.charset;
1322
  else
1323
  {
520.1.22 by Brian Aker
Second pass of thd cleanup
1324
    session->variables.*offset= var->save_result.charset;
1325
    session->update_charset();
1 by brian
clean slate
1326
  }
1327
  return 0;
1328
}
1329
1330
520.1.22 by Brian Aker
Second pass of thd cleanup
1331
void sys_var_collation_sv::set_default(Session *session, enum_var_type type)
1 by brian
clean slate
1332
{
1333
  if (type == OPT_GLOBAL)
1334
    global_system_variables.*offset= *global_default;
1335
  else
1336
  {
520.1.22 by Brian Aker
Second pass of thd cleanup
1337
    session->variables.*offset= global_system_variables.*offset;
1338
    session->update_charset();
1 by brian
clean slate
1339
  }
1340
}
1341
1342
575.1.2 by Monty Taylor
Changed a bunch of __attribute__((unused)) to removing the parameter name instead.
1343
unsigned char *sys_var_collation_sv::value_ptr(Session *session,
1344
                                               enum_var_type type,
779.3.10 by Monty Taylor
Turned on -Wshadow.
1345
                                               const LEX_STRING *)
1 by brian
clean slate
1346
{
264.2.6 by Andrey Hristov
Constify the usage of CHARSET_INFO almost to the last place in the code.
1347
  const CHARSET_INFO *cs= ((type == OPT_GLOBAL) ?
575.1.2 by Monty Taylor
Changed a bunch of __attribute__((unused)) to removing the parameter name instead.
1348
                           global_system_variables.*offset :
1349
                           session->variables.*offset);
481 by Brian Aker
Remove all of uchar.
1350
  return cs ? (unsigned char*) cs->name : (unsigned char*) "NULL";
1 by brian
clean slate
1351
}
1352
1353
1354
LEX_STRING default_key_cache_base= {(char *) "default", 7 };
1355
1356
static KEY_CACHE zero_key_cache;
1357
779.3.10 by Monty Taylor
Turned on -Wshadow.
1358
KEY_CACHE *get_key_cache(const LEX_STRING *cache_name)
1 by brian
clean slate
1359
{
1360
  safe_mutex_assert_owner(&LOCK_global_system_variables);
1361
  if (!cache_name || ! cache_name->length)
1362
    cache_name= &default_key_cache_base;
1363
  return ((KEY_CACHE*) find_named(&key_caches,
779.3.10 by Monty Taylor
Turned on -Wshadow.
1364
                                  cache_name->str, cache_name->length, 0));
1 by brian
clean slate
1365
}
1366
1367
575.1.2 by Monty Taylor
Changed a bunch of __attribute__((unused)) to removing the parameter name instead.
1368
unsigned char *sys_var_key_cache_param::value_ptr(Session *, enum_var_type,
779.3.10 by Monty Taylor
Turned on -Wshadow.
1369
                                                  const LEX_STRING *base)
1 by brian
clean slate
1370
{
1371
  KEY_CACHE *key_cache= get_key_cache(base);
1372
  if (!key_cache)
1373
    key_cache= &zero_key_cache;
481 by Brian Aker
Remove all of uchar.
1374
  return (unsigned char*) key_cache + offset ;
1 by brian
clean slate
1375
}
1376
1377
520.1.22 by Brian Aker
Second pass of thd cleanup
1378
bool sys_var_key_buffer_size::update(Session *session, set_var *var)
1 by brian
clean slate
1379
{
151 by Brian Aker
Ulonglong to uint64_t
1380
  uint64_t tmp= var->save_result.uint64_t_value;
1 by brian
clean slate
1381
  LEX_STRING *base_name= &var->base;
1382
  KEY_CACHE *key_cache;
1383
  bool error= 0;
1384
1385
  /* If no basename, assume it's for the key cache named 'default' */
1386
  if (!base_name->length)
1387
    base_name= &default_key_cache_base;
1388
1389
  pthread_mutex_lock(&LOCK_global_system_variables);
1390
  key_cache= get_key_cache(base_name);
660.1.3 by Eric Herman
removed trailing whitespace with simple script:
1391
1 by brian
clean slate
1392
  if (!key_cache)
1393
  {
1394
    /* Key cache didn't exists */
1395
    if (!tmp)					// Tried to delete cache
1396
      goto end;					// Ok, nothing to do
1397
    if (!(key_cache= create_key_cache(base_name->str, base_name->length)))
1398
    {
1399
      error= 1;
1400
      goto end;
1401
    }
1402
  }
1403
1404
  /*
1405
    Abort if some other thread is changing the key cache
1406
    TODO: This should be changed so that we wait until the previous
1407
    assignment is done and then do the new assign
1408
  */
1409
  if (key_cache->in_init)
1410
    goto end;
1411
1412
  if (!tmp)					// Zero size means delete
1413
  {
1414
    if (key_cache == dflt_key_cache)
1415
    {
520.1.22 by Brian Aker
Second pass of thd cleanup
1416
      push_warning_printf(session, DRIZZLE_ERROR::WARN_LEVEL_WARN,
1 by brian
clean slate
1417
                          ER_WARN_CANT_DROP_DEFAULT_KEYCACHE,
1418
                          ER(ER_WARN_CANT_DROP_DEFAULT_KEYCACHE));
1419
      goto end;					// Ignore default key cache
1420
    }
1421
1422
    if (key_cache->key_cache_inited)		// If initied
1423
    {
1424
      /*
1425
	Move tables using this key cache to the default key cache
1426
	and clear the old key cache.
1427
      */
660.1.3 by Eric Herman
removed trailing whitespace with simple script:
1428
      NAMED_LIST *list;
1 by brian
clean slate
1429
      key_cache= (KEY_CACHE *) find_named(&key_caches, base_name->str,
1430
					      base_name->length, &list);
1431
      key_cache->in_init= 1;
1432
      pthread_mutex_unlock(&LOCK_global_system_variables);
520.1.22 by Brian Aker
Second pass of thd cleanup
1433
      error= reassign_keycache_tables(session, key_cache, dflt_key_cache);
1 by brian
clean slate
1434
      pthread_mutex_lock(&LOCK_global_system_variables);
1435
      key_cache->in_init= 0;
1436
    }
1437
    /*
1438
      We don't delete the key cache as some running threads my still be
1439
      in the key cache code with a pointer to the deleted (empty) key cache
1440
    */
1441
    goto end;
1442
  }
1443
1444
  key_cache->param_buff_size=
520.1.22 by Brian Aker
Second pass of thd cleanup
1445
    (uint64_t) fix_unsigned(session, tmp, option_limits);
1 by brian
clean slate
1446
1447
  /* If key cache didn't existed initialize it, else resize it */
1448
  key_cache->in_init= 1;
1449
  pthread_mutex_unlock(&LOCK_global_system_variables);
1450
1451
  if (!key_cache->key_cache_inited)
1452
    error= (bool) (ha_init_key_cache("", key_cache));
1453
  else
1454
    error= (bool)(ha_resize_key_cache(key_cache));
1455
1456
  pthread_mutex_lock(&LOCK_global_system_variables);
660.1.3 by Eric Herman
removed trailing whitespace with simple script:
1457
  key_cache->in_init= 0;
1 by brian
clean slate
1458
1459
end:
1460
  pthread_mutex_unlock(&LOCK_global_system_variables);
1461
  return error;
1462
}
1463
1464
1465
/**
1466
  @todo
1467
  Abort if some other thread is changing the key cache.
1468
  This should be changed so that we wait until the previous
1469
  assignment is done and then do the new assign
1470
*/
910.4.18 by Stewart Smith
fix alignment of variables (incl key cache). fixes SIGBUS on SPARC64
1471
bool sys_var_key_cache_uint32_t::update(Session *session, set_var *var)
1 by brian
clean slate
1472
{
622 by Brian Aker
More ulong work.
1473
  uint64_t tmp= (uint64_t) var->value->val_int();
1 by brian
clean slate
1474
  LEX_STRING *base_name= &var->base;
1475
  bool error= 0;
1476
1477
  if (!base_name->length)
1478
    base_name= &default_key_cache_base;
1479
1480
  pthread_mutex_lock(&LOCK_global_system_variables);
1481
  KEY_CACHE *key_cache= get_key_cache(base_name);
1482
1483
  if (!key_cache && !(key_cache= create_key_cache(base_name->str,
1484
				                  base_name->length)))
1485
  {
1486
    error= 1;
1487
    goto end;
1488
  }
1489
1490
  /*
1491
    Abort if some other thread is changing the key cache
1492
    TODO: This should be changed so that we wait until the previous
1493
    assignment is done and then do the new assign
1494
  */
1495
  if (key_cache->in_init)
1496
    goto end;
1497
910.4.18 by Stewart Smith
fix alignment of variables (incl key cache). fixes SIGBUS on SPARC64
1498
  *((uint32_t*) (((char*) key_cache) + offset))=
1499
    (uint32_t) fix_unsigned(session, tmp, option_limits);
1 by brian
clean slate
1500
1501
  /*
1502
    Don't create a new key cache if it didn't exist
1503
    (key_caches are created only when the user sets block_size)
1504
  */
1505
  key_cache->in_init= 1;
1506
1507
  pthread_mutex_unlock(&LOCK_global_system_variables);
1508
1509
  error= (bool) (ha_resize_key_cache(key_cache));
1510
1511
  pthread_mutex_lock(&LOCK_global_system_variables);
575.1.2 by Monty Taylor
Changed a bunch of __attribute__((unused)) to removing the parameter name instead.
1512
  key_cache->in_init= 0;
1 by brian
clean slate
1513
1514
end:
1515
  pthread_mutex_unlock(&LOCK_global_system_variables);
1516
  return error;
1517
}
1518
1519
1520
/****************************************************************************/
1521
520.1.22 by Brian Aker
Second pass of thd cleanup
1522
bool sys_var_timestamp::update(Session *session,  set_var *var)
1 by brian
clean slate
1523
{
520.1.22 by Brian Aker
Second pass of thd cleanup
1524
  session->set_time((time_t) var->save_result.uint64_t_value);
1 by brian
clean slate
1525
  return 0;
1526
}
1527
1528
575.1.2 by Monty Taylor
Changed a bunch of __attribute__((unused)) to removing the parameter name instead.
1529
void sys_var_timestamp::set_default(Session *session, enum_var_type)
1 by brian
clean slate
1530
{
520.1.22 by Brian Aker
Second pass of thd cleanup
1531
  session->user_time=0;
1 by brian
clean slate
1532
}
1533
1534
575.1.2 by Monty Taylor
Changed a bunch of __attribute__((unused)) to removing the parameter name instead.
1535
unsigned char *sys_var_timestamp::value_ptr(Session *session, enum_var_type,
779.3.10 by Monty Taylor
Turned on -Wshadow.
1536
                                            const LEX_STRING *)
1 by brian
clean slate
1537
{
520.1.22 by Brian Aker
Second pass of thd cleanup
1538
  session->sys_var_tmp.long_value= (long) session->start_time;
1539
  return (unsigned char*) &session->sys_var_tmp.long_value;
1 by brian
clean slate
1540
}
1541
1542
520.1.22 by Brian Aker
Second pass of thd cleanup
1543
bool sys_var_last_insert_id::update(Session *session, set_var *var)
1 by brian
clean slate
1544
{
520.1.22 by Brian Aker
Second pass of thd cleanup
1545
  session->first_successful_insert_id_in_prev_stmt=
151 by Brian Aker
Ulonglong to uint64_t
1546
    var->save_result.uint64_t_value;
1 by brian
clean slate
1547
  return 0;
1548
}
1549
1550
520.1.22 by Brian Aker
Second pass of thd cleanup
1551
unsigned char *sys_var_last_insert_id::value_ptr(Session *session,
575.1.2 by Monty Taylor
Changed a bunch of __attribute__((unused)) to removing the parameter name instead.
1552
                                                 enum_var_type,
779.3.10 by Monty Taylor
Turned on -Wshadow.
1553
                                                 const LEX_STRING *)
1 by brian
clean slate
1554
{
1555
  /*
77.1.45 by Monty Taylor
Warning fixes.
1556
    this tmp var makes it robust againt change of type of
1 by brian
clean slate
1557
    read_first_successful_insert_id_in_prev_stmt().
1558
  */
575.1.2 by Monty Taylor
Changed a bunch of __attribute__((unused)) to removing the parameter name instead.
1559
  session->sys_var_tmp.uint64_t_value=
520.1.22 by Brian Aker
Second pass of thd cleanup
1560
    session->read_first_successful_insert_id_in_prev_stmt();
1561
  return (unsigned char*) &session->sys_var_tmp.uint64_t_value;
1 by brian
clean slate
1562
}
1563
1564
520.1.22 by Brian Aker
Second pass of thd cleanup
1565
bool sys_var_session_time_zone::check(Session *session, set_var *var)
1 by brian
clean slate
1566
{
1567
  char buff[MAX_TIME_ZONE_NAME_LENGTH];
383.1.12 by Brian Aker
Much closer toward UTF8 being around all the time...
1568
  String str(buff, sizeof(buff), &my_charset_utf8_general_ci);
1 by brian
clean slate
1569
  String *res= var->value->val_str(&str);
1570
520.1.22 by Brian Aker
Second pass of thd cleanup
1571
  if (!(var->save_result.time_zone= my_tz_find(session, res)))
1 by brian
clean slate
1572
  {
1573
    my_error(ER_UNKNOWN_TIME_ZONE, MYF(0), res ? res->c_ptr() : "NULL");
1574
    return 1;
1575
  }
1576
  return 0;
1577
}
1578
1579
520.1.22 by Brian Aker
Second pass of thd cleanup
1580
bool sys_var_session_time_zone::update(Session *session, set_var *var)
1 by brian
clean slate
1581
{
1582
  /* We are using Time_zone object found during check() phase. */
1583
  if (var->type == OPT_GLOBAL)
1584
  {
1585
    pthread_mutex_lock(&LOCK_global_system_variables);
1586
    global_system_variables.time_zone= var->save_result.time_zone;
1587
    pthread_mutex_unlock(&LOCK_global_system_variables);
1588
  }
1589
  else
520.1.22 by Brian Aker
Second pass of thd cleanup
1590
    session->variables.time_zone= var->save_result.time_zone;
1 by brian
clean slate
1591
  return 0;
1592
}
1593
1594
575.1.2 by Monty Taylor
Changed a bunch of __attribute__((unused)) to removing the parameter name instead.
1595
unsigned char *sys_var_session_time_zone::value_ptr(Session *session,
1596
                                                    enum_var_type type,
779.3.10 by Monty Taylor
Turned on -Wshadow.
1597
                                                    const LEX_STRING *)
1 by brian
clean slate
1598
{
575.1.2 by Monty Taylor
Changed a bunch of __attribute__((unused)) to removing the parameter name instead.
1599
  /*
1 by brian
clean slate
1600
    We can use ptr() instead of c_ptr() here because String contaning
1601
    time zone name is guaranteed to be zero ended.
1602
  */
1603
  if (type == OPT_GLOBAL)
481 by Brian Aker
Remove all of uchar.
1604
    return (unsigned char *)(global_system_variables.time_zone->get_name()->ptr());
1 by brian
clean slate
1605
  else
1606
  {
1607
    /*
1608
      This is an ugly fix for replication: we don't replicate properly queries
1609
      invoking system variables' values to update tables; but
1610
      CONVERT_TZ(,,@@session.time_zone) is so popular that we make it
1611
      replicable (i.e. we tell the binlog code to store the session
1612
      timezone). If it's the global value which was used we can't replicate
1613
      (binlog code stores session value only).
1614
    */
520.1.22 by Brian Aker
Second pass of thd cleanup
1615
    return (unsigned char *)(session->variables.time_zone->get_name()->ptr());
1 by brian
clean slate
1616
  }
1617
}
1618
1619
520.1.22 by Brian Aker
Second pass of thd cleanup
1620
void sys_var_session_time_zone::set_default(Session *session, enum_var_type type)
1 by brian
clean slate
1621
{
1622
 pthread_mutex_lock(&LOCK_global_system_variables);
1623
 if (type == OPT_GLOBAL)
1624
 {
1625
   if (default_tz_name)
1626
   {
383.1.12 by Brian Aker
Much closer toward UTF8 being around all the time...
1627
     String str(default_tz_name, &my_charset_utf8_general_ci);
1 by brian
clean slate
1628
     /*
1629
       We are guaranteed to find this time zone since its existence
1630
       is checked during start-up.
1631
     */
520.1.22 by Brian Aker
Second pass of thd cleanup
1632
     global_system_variables.time_zone= my_tz_find(session, &str);
1 by brian
clean slate
1633
   }
1634
   else
1635
     global_system_variables.time_zone= my_tz_SYSTEM;
1636
 }
1637
 else
520.1.22 by Brian Aker
Second pass of thd cleanup
1638
   session->variables.time_zone= global_system_variables.time_zone;
1 by brian
clean slate
1639
 pthread_mutex_unlock(&LOCK_global_system_variables);
1640
}
1641
1642
575.1.2 by Monty Taylor
Changed a bunch of __attribute__((unused)) to removing the parameter name instead.
1643
bool sys_var_session_lc_time_names::check(Session *, set_var *var)
1 by brian
clean slate
1644
{
1645
  MY_LOCALE *locale_match;
1646
1647
  if (var->value->result_type() == INT_RESULT)
1648
  {
895 by Brian Aker
Completion (?) of uint conversion.
1649
    if (!(locale_match= my_locale_by_number((uint32_t) var->value->val_int())))
1 by brian
clean slate
1650
    {
1651
      char buf[20];
1652
      int10_to_str((int) var->value->val_int(), buf, -10);
1653
      my_printf_error(ER_UNKNOWN_ERROR, "Unknown locale: '%s'", MYF(0), buf);
1654
      return 1;
1655
    }
1656
  }
1657
  else // STRING_RESULT
1658
  {
660.1.3 by Eric Herman
removed trailing whitespace with simple script:
1659
    char buff[6];
383.1.12 by Brian Aker
Much closer toward UTF8 being around all the time...
1660
    String str(buff, sizeof(buff), &my_charset_utf8_general_ci), *res;
1 by brian
clean slate
1661
    if (!(res=var->value->val_str(&str)))
1662
    {
1663
      my_error(ER_WRONG_VALUE_FOR_VAR, MYF(0), name, "NULL");
1664
      return 1;
1665
    }
1666
    const char *locale_str= res->c_ptr();
1667
    if (!(locale_match= my_locale_by_name(locale_str)))
1668
    {
1669
      my_printf_error(ER_UNKNOWN_ERROR,
1670
                      "Unknown locale: '%s'", MYF(0), locale_str);
1671
      return 1;
1672
    }
1673
  }
1674
1675
  var->save_result.locale_value= locale_match;
1676
  return 0;
1677
}
1678
1679
520.1.22 by Brian Aker
Second pass of thd cleanup
1680
bool sys_var_session_lc_time_names::update(Session *session, set_var *var)
1 by brian
clean slate
1681
{
1682
  if (var->type == OPT_GLOBAL)
1683
    global_system_variables.lc_time_names= var->save_result.locale_value;
1684
  else
520.1.22 by Brian Aker
Second pass of thd cleanup
1685
    session->variables.lc_time_names= var->save_result.locale_value;
1 by brian
clean slate
1686
  return 0;
1687
}
1688
1689
520.1.22 by Brian Aker
Second pass of thd cleanup
1690
unsigned char *sys_var_session_lc_time_names::value_ptr(Session *session,
575.1.2 by Monty Taylor
Changed a bunch of __attribute__((unused)) to removing the parameter name instead.
1691
                                                        enum_var_type type,
779.3.10 by Monty Taylor
Turned on -Wshadow.
1692
                                                        const LEX_STRING *)
1 by brian
clean slate
1693
{
1694
  return type == OPT_GLOBAL ?
481 by Brian Aker
Remove all of uchar.
1695
                 (unsigned char *) global_system_variables.lc_time_names->name :
520.1.22 by Brian Aker
Second pass of thd cleanup
1696
                 (unsigned char *) session->variables.lc_time_names->name;
1 by brian
clean slate
1697
}
1698
1699
520.1.22 by Brian Aker
Second pass of thd cleanup
1700
void sys_var_session_lc_time_names::set_default(Session *session, enum_var_type type)
1 by brian
clean slate
1701
{
1702
  if (type == OPT_GLOBAL)
1703
    global_system_variables.lc_time_names= my_default_lc_time_names;
1704
  else
520.1.22 by Brian Aker
Second pass of thd cleanup
1705
    session->variables.lc_time_names= global_system_variables.lc_time_names;
1 by brian
clean slate
1706
}
1707
1708
/*
1709
  Handling of microseoncds given as seconds.part_seconds
1710
1711
  NOTES
1712
    The argument to long query time is in seconds in decimal
151 by Brian Aker
Ulonglong to uint64_t
1713
    which is converted to uint64_t integer holding microseconds for storage.
1 by brian
clean slate
1714
    This is used for handling long_query_time
1715
*/
1716
520.1.22 by Brian Aker
Second pass of thd cleanup
1717
bool sys_var_microseconds::update(Session *session, set_var *var)
1 by brian
clean slate
1718
{
1719
  double num= var->value->val_real();
152 by Brian Aker
longlong replacement
1720
  int64_t microseconds;
1 by brian
clean slate
1721
  if (num > (double) option_limits->max_value)
1722
    num= (double) option_limits->max_value;
1723
  if (num < (double) option_limits->min_value)
1724
    num= (double) option_limits->min_value;
152 by Brian Aker
longlong replacement
1725
  microseconds= (int64_t) (num * 1000000.0 + 0.5);
1 by brian
clean slate
1726
  if (var->type == OPT_GLOBAL)
1727
  {
1728
    pthread_mutex_lock(&LOCK_global_system_variables);
1729
    (global_system_variables.*offset)= microseconds;
1730
    pthread_mutex_unlock(&LOCK_global_system_variables);
1731
  }
1732
  else
520.1.22 by Brian Aker
Second pass of thd cleanup
1733
    session->variables.*offset= microseconds;
1 by brian
clean slate
1734
  return 0;
1735
}
1736
1737
520.1.22 by Brian Aker
Second pass of thd cleanup
1738
void sys_var_microseconds::set_default(Session *session, enum_var_type type)
1 by brian
clean slate
1739
{
152 by Brian Aker
longlong replacement
1740
  int64_t microseconds= (int64_t) (option_limits->def_value * 1000000.0);
1 by brian
clean slate
1741
  if (type == OPT_GLOBAL)
1742
  {
1743
    pthread_mutex_lock(&LOCK_global_system_variables);
1744
    global_system_variables.*offset= microseconds;
1745
    pthread_mutex_unlock(&LOCK_global_system_variables);
1746
  }
1747
  else
520.1.22 by Brian Aker
Second pass of thd cleanup
1748
    session->variables.*offset= microseconds;
1 by brian
clean slate
1749
}
1750
1751
575.1.2 by Monty Taylor
Changed a bunch of __attribute__((unused)) to removing the parameter name instead.
1752
unsigned char *sys_var_microseconds::value_ptr(Session *session,
1753
                                               enum_var_type type,
779.3.10 by Monty Taylor
Turned on -Wshadow.
1754
                                               const LEX_STRING *)
1 by brian
clean slate
1755
{
520.1.22 by Brian Aker
Second pass of thd cleanup
1756
  session->tmp_double_value= (double) ((type == OPT_GLOBAL) ?
1 by brian
clean slate
1757
                                   global_system_variables.*offset :
520.1.22 by Brian Aker
Second pass of thd cleanup
1758
                                   session->variables.*offset) / 1000000.0;
1759
  return (unsigned char*) &session->tmp_double_value;
1 by brian
clean slate
1760
}
1761
1762
1763
/*
520.1.22 by Brian Aker
Second pass of thd cleanup
1764
  Functions to update session->options bits
1 by brian
clean slate
1765
*/
1766
520.1.22 by Brian Aker
Second pass of thd cleanup
1767
static bool set_option_bit(Session *session, set_var *var)
1 by brian
clean slate
1768
{
520.1.22 by Brian Aker
Second pass of thd cleanup
1769
  sys_var_session_bit *sys_var= ((sys_var_session_bit*) var->var);
576 by Brian Aker
ulong conversion work
1770
  if ((var->save_result.uint32_t_value != 0) == sys_var->reverse)
520.1.22 by Brian Aker
Second pass of thd cleanup
1771
    session->options&= ~sys_var->bit_flag;
1 by brian
clean slate
1772
  else
520.1.22 by Brian Aker
Second pass of thd cleanup
1773
    session->options|= sys_var->bit_flag;
1 by brian
clean slate
1774
  return 0;
1775
}
1776
1777
520.1.22 by Brian Aker
Second pass of thd cleanup
1778
static bool set_option_autocommit(Session *session, set_var *var)
1 by brian
clean slate
1779
{
1780
  /* The test is negative as the flag we use is NOT autocommit */
1781
520.1.22 by Brian Aker
Second pass of thd cleanup
1782
  uint64_t org_options= session->options;
1 by brian
clean slate
1783
576 by Brian Aker
ulong conversion work
1784
  if (var->save_result.uint32_t_value != 0)
520.1.22 by Brian Aker
Second pass of thd cleanup
1785
    session->options&= ~((sys_var_session_bit*) var->var)->bit_flag;
1 by brian
clean slate
1786
  else
520.1.22 by Brian Aker
Second pass of thd cleanup
1787
    session->options|= ((sys_var_session_bit*) var->var)->bit_flag;
1 by brian
clean slate
1788
520.1.22 by Brian Aker
Second pass of thd cleanup
1789
  if ((org_options ^ session->options) & OPTION_NOT_AUTOCOMMIT)
1 by brian
clean slate
1790
  {
1791
    if ((org_options & OPTION_NOT_AUTOCOMMIT))
1792
    {
1793
      /* We changed to auto_commit mode */
520.1.22 by Brian Aker
Second pass of thd cleanup
1794
      session->options&= ~(uint64_t) (OPTION_BEGIN | OPTION_KEEP_LOG);
1795
      session->transaction.all.modified_non_trans_table= false;
1796
      session->server_status|= SERVER_STATUS_AUTOCOMMIT;
1797
      if (ha_commit(session))
1 by brian
clean slate
1798
	return 1;
1799
    }
1800
    else
1801
    {
520.1.22 by Brian Aker
Second pass of thd cleanup
1802
      session->transaction.all.modified_non_trans_table= false;
1803
      session->server_status&= ~SERVER_STATUS_AUTOCOMMIT;
1 by brian
clean slate
1804
    }
1805
  }
1806
  return 0;
1807
}
1808
575.1.2 by Monty Taylor
Changed a bunch of __attribute__((unused)) to removing the parameter name instead.
1809
static int check_pseudo_thread_id(Session *, set_var *var)
1 by brian
clean slate
1810
{
151 by Brian Aker
Ulonglong to uint64_t
1811
  var->save_result.uint64_t_value= var->value->val_int();
1 by brian
clean slate
1812
  return 0;
1813
}
1814
520.1.22 by Brian Aker
Second pass of thd cleanup
1815
static unsigned char *get_warning_count(Session *session)
1 by brian
clean slate
1816
{
937.2.3 by Stewart Smith
yet another 4/8byte long issue with variables. Fix up warning and error count to use uint32_t instead.
1817
  session->sys_var_tmp.uint32_t_value=
626 by Brian Aker
More of the same (ulong/64)
1818
    (session->warn_count[(uint32_t) DRIZZLE_ERROR::WARN_LEVEL_NOTE] +
1819
     session->warn_count[(uint32_t) DRIZZLE_ERROR::WARN_LEVEL_ERROR] +
1820
     session->warn_count[(uint32_t) DRIZZLE_ERROR::WARN_LEVEL_WARN]);
937.2.3 by Stewart Smith
yet another 4/8byte long issue with variables. Fix up warning and error count to use uint32_t instead.
1821
  return (unsigned char*) &session->sys_var_tmp.uint32_t_value;
1 by brian
clean slate
1822
}
1823
520.1.22 by Brian Aker
Second pass of thd cleanup
1824
static unsigned char *get_error_count(Session *session)
1 by brian
clean slate
1825
{
937.2.3 by Stewart Smith
yet another 4/8byte long issue with variables. Fix up warning and error count to use uint32_t instead.
1826
  session->sys_var_tmp.uint32_t_value=
626 by Brian Aker
More of the same (ulong/64)
1827
    session->warn_count[(uint32_t) DRIZZLE_ERROR::WARN_LEVEL_ERROR];
937.2.3 by Stewart Smith
yet another 4/8byte long issue with variables. Fix up warning and error count to use uint32_t instead.
1828
  return (unsigned char*) &session->sys_var_tmp.uint32_t_value;
1 by brian
clean slate
1829
}
1830
1831
1832
/**
1833
  Get the tmpdir that was specified or chosen by default.
1834
1835
  This is necessary because if the user does not specify a temporary
1836
  directory via the command line, one is chosen based on the environment
575.4.3 by ysano
Rename mysql to drizzle.
1837
  or system defaults.  But we can't just always use drizzle_tmpdir, because
1 by brian
clean slate
1838
  that is actually a call to my_tmpdir() which cycles among possible
1839
  temporary directories.
1840
520.1.22 by Brian Aker
Second pass of thd cleanup
1841
  @param session		thread handle
1 by brian
clean slate
1842
1843
  @retval
1844
    ptr		pointer to NUL-terminated string
1845
*/
575.1.2 by Monty Taylor
Changed a bunch of __attribute__((unused)) to removing the parameter name instead.
1846
static unsigned char *get_tmpdir(Session *)
1 by brian
clean slate
1847
{
680 by Brian Aker
Remove locks around temp tables for searching tmp directory path.
1848
  assert(drizzle_tmpdir);
575.4.3 by ysano
Rename mysql to drizzle.
1849
  return (unsigned char*)drizzle_tmpdir;
1 by brian
clean slate
1850
}
1851
1852
/****************************************************************************
1853
  Main handling of variables:
1854
  - Initialisation
1855
  - Searching during parsing
1856
  - Update loop
1857
****************************************************************************/
1858
1859
/**
1860
  Find variable name in option my_getopt structure used for
1861
  command line args.
1862
1863
  @param opt	option structure array to search in
1864
  @param name	variable name
1865
1866
  @retval
1867
    0		Error
1868
  @retval
1869
    ptr		pointer to option structure
1870
*/
1871
660.1.3 by Eric Herman
removed trailing whitespace with simple script:
1872
static struct my_option *find_option(struct my_option *opt, const char *name)
1 by brian
clean slate
1873
{
482 by Brian Aker
Remove uint.
1874
  uint32_t length=strlen(name);
1 by brian
clean slate
1875
  for (; opt->name; opt++)
1876
  {
1877
    if (!getopt_compare_strings(opt->name, name, length) &&
1878
	!opt->name[length])
1879
    {
1880
      /*
1881
	Only accept the option if one can set values through it.
1882
	If not, there is no default value or limits in the option.
1883
      */
1884
      return (opt->value) ? opt : 0;
1885
    }
1886
  }
1887
  return 0;
1888
}
1889
1890
1891
/*
1892
  Add variables to the dynamic hash of system variables
660.1.3 by Eric Herman
removed trailing whitespace with simple script:
1893
1 by brian
clean slate
1894
  SYNOPSIS
1895
    mysql_add_sys_var_chain()
1896
    first       Pointer to first system variable to add
1897
    long_opt    (optional)command line arguments may be tied for limit checks.
660.1.3 by Eric Herman
removed trailing whitespace with simple script:
1898
1 by brian
clean slate
1899
  RETURN VALUES
1900
    0           SUCCESS
1901
    otherwise   FAILURE
1902
*/
1903
1904
1905
int mysql_add_sys_var_chain(sys_var *first, struct my_option *long_options)
1906
{
1907
  sys_var *var;
1908
  /* A write lock should be held on LOCK_system_variables_hash */
660.1.3 by Eric Herman
removed trailing whitespace with simple script:
1909
1 by brian
clean slate
1910
  for (var= first; var; var= var->next)
1911
  {
873.2.16 by Monty Taylor
Replaced HASH with std::map - avoid utf8 hashing on every sys_var lookup.
1912
    /* Make a temp string to hold this and then make it lower so that matching
1913
     * happens case-insensitive.
1914
     */
1915
    string var_name(var->name);
1916
    transform(var_name.begin(), var_name.end(), var_name.begin(), ::tolower);
1917
    var->name_length= var_name.length();
1918
1919
    /* this fails if there is a conflicting variable name. */
1920
    if (system_variable_hash.count(var_name) == 0)
1921
    {
1922
      system_variable_hash[var_name]= var;
1923
    } 
1924
    else
1925
    {
1926
      for (; first != var; first= first->next)
1927
      {
1928
        /*
1929
         * This is slightly expensive, since we have to do the transform 
1930
         * _again_ but should rarely happen unless there is a pretty
1931
         * major problem in the code
1932
         */
1933
        var_name= first->name;
1934
        transform(var_name.begin(), var_name.end(),
1935
                  var_name.begin(), ::tolower);
1936
        system_variable_hash.erase(var_name);
1937
      }
1938
      return 1;
1939
    }
1 by brian
clean slate
1940
    if (long_options)
1941
      var->option_limits= find_option(long_options, var->name);
1942
  }
1943
  return 0;
1944
1945
}
660.1.3 by Eric Herman
removed trailing whitespace with simple script:
1946
1947
1 by brian
clean slate
1948
/*
1949
  Remove variables to the dynamic hash of system variables
660.1.3 by Eric Herman
removed trailing whitespace with simple script:
1950
1 by brian
clean slate
1951
  SYNOPSIS
1952
    mysql_del_sys_var_chain()
1953
    first       Pointer to first system variable to remove
660.1.3 by Eric Herman
removed trailing whitespace with simple script:
1954
1 by brian
clean slate
1955
  RETURN VALUES
1956
    0           SUCCESS
1957
    otherwise   FAILURE
1958
*/
660.1.3 by Eric Herman
removed trailing whitespace with simple script:
1959
1 by brian
clean slate
1960
int mysql_del_sys_var_chain(sys_var *first)
1961
{
1962
  int result= 0;
873.2.16 by Monty Taylor
Replaced HASH with std::map - avoid utf8 hashing on every sys_var lookup.
1963
  string var_name;
660.1.3 by Eric Herman
removed trailing whitespace with simple script:
1964
1 by brian
clean slate
1965
  /* A write lock should be held on LOCK_system_variables_hash */
1966
  for (sys_var *var= first; var; var= var->next)
873.2.16 by Monty Taylor
Replaced HASH with std::map - avoid utf8 hashing on every sys_var lookup.
1967
  {
1968
    var_name= var->name;
1969
    transform(var_name.begin(), var_name.end(),
1970
              var_name.begin(), ::tolower);
1971
    result|= system_variable_hash.erase(var_name);
1972
  }
1 by brian
clean slate
1973
1974
  return result;
1975
}
660.1.3 by Eric Herman
removed trailing whitespace with simple script:
1976
1977
1978
1 by brian
clean slate
1979
/*
1980
  Constructs an array of system variables for display to the user.
660.1.3 by Eric Herman
removed trailing whitespace with simple script:
1981
1 by brian
clean slate
1982
  SYNOPSIS
1983
    enumerate_sys_vars()
520.1.22 by Brian Aker
Second pass of thd cleanup
1984
    session         current thread
1 by brian
clean slate
1985
    sorted      If TRUE, the system variables should be sorted
660.1.3 by Eric Herman
removed trailing whitespace with simple script:
1986
1 by brian
clean slate
1987
  RETURN VALUES
1988
    pointer     Array of SHOW_VAR elements for display
1989
    NULL        FAILURE
1990
*/
1991
873.2.16 by Monty Taylor
Replaced HASH with std::map - avoid utf8 hashing on every sys_var lookup.
1992
SHOW_VAR* enumerate_sys_vars(Session *session, bool)
1 by brian
clean slate
1993
{
1994
  int fixed_count= fixed_show_vars.elements;
873.2.16 by Monty Taylor
Replaced HASH with std::map - avoid utf8 hashing on every sys_var lookup.
1995
  int size= sizeof(SHOW_VAR) * (system_variable_hash.size() + fixed_count + 1);
520.1.22 by Brian Aker
Second pass of thd cleanup
1996
  SHOW_VAR *result= (SHOW_VAR*) session->alloc(size);
1 by brian
clean slate
1997
1998
  if (result)
1999
  {
2000
    SHOW_VAR *show= result + fixed_count;
2001
    memcpy(result, fixed_show_vars.buffer, fixed_count * sizeof(SHOW_VAR));
2002
873.2.16 by Monty Taylor
Replaced HASH with std::map - avoid utf8 hashing on every sys_var lookup.
2003
    map<string, sys_var *>::iterator iter;
2004
    for(iter= system_variable_hash.begin();
2005
        iter != system_variable_hash.end();
2006
        iter++)
1 by brian
clean slate
2007
    {
873.2.16 by Monty Taylor
Replaced HASH with std::map - avoid utf8 hashing on every sys_var lookup.
2008
      sys_var *var= (*iter).second;
1 by brian
clean slate
2009
      show->name= var->name;
2010
      show->value= (char*) var;
2011
      show->type= SHOW_SYS;
2012
      show++;
2013
    }
2014
2015
    /* make last element empty */
212.6.1 by Mats Kindahl
Replacing all bzero() calls with memset() calls and removing the bzero.c file.
2016
    memset(show, 0, sizeof(SHOW_VAR));
1 by brian
clean slate
2017
  }
2018
  return result;
2019
}
2020
2021
656.1.34 by Monty Taylor
Got closer...
2022
NAMED_LIST::NAMED_LIST(I_List<NAMED_LIST> *links, const char *name_arg,
2023
                       uint32_t name_length_arg, unsigned char* data_arg)
2024
    :data(data_arg)
2025
{
2026
  name.assign(name_arg, name_length_arg);
2027
  links->push_back(this);
2028
}
2029
2030
2031
bool NAMED_LIST::cmp(const char *name_cmp, uint32_t length)
2032
{
2033
  return length == name.length() && !name.compare(name_cmp);
2034
}
2035
2036
1 by brian
clean slate
2037
/*
2038
  Initialize the system variables
660.1.3 by Eric Herman
removed trailing whitespace with simple script:
2039
1 by brian
clean slate
2040
  SYNOPSIS
2041
    set_var_init()
660.1.3 by Eric Herman
removed trailing whitespace with simple script:
2042
1 by brian
clean slate
2043
  RETURN VALUES
2044
    0           SUCCESS
2045
    otherwise   FAILURE
2046
*/
2047
2048
int set_var_init()
2049
{
482 by Brian Aker
Remove uint.
2050
  uint32_t count= 0;
660.1.3 by Eric Herman
removed trailing whitespace with simple script:
2051
1 by brian
clean slate
2052
  for (sys_var *var=vars.first; var; var= var->next, count++) {};
2053
2054
  if (my_init_dynamic_array(&fixed_show_vars, sizeof(SHOW_VAR),
2055
                            FIXED_VARS_SIZE + 64, 64))
2056
    goto error;
2057
2058
  fixed_show_vars.elements= FIXED_VARS_SIZE;
2059
  memcpy(fixed_show_vars.buffer, fixed_vars, sizeof(fixed_vars));
2060
2061
  vars.last->next= NULL;
2062
  if (mysql_add_sys_var_chain(vars.first, my_long_options))
2063
    goto error;
2064
51.1.46 by Jay Pipes
Removed/replaced DBUG symbols and standardized TRUE/FALSE
2065
  return(0);
1 by brian
clean slate
2066
2067
error:
2068
  fprintf(stderr, "failed to initialize system variables");
51.1.46 by Jay Pipes
Removed/replaced DBUG symbols and standardized TRUE/FALSE
2069
  return(1);
1 by brian
clean slate
2070
}
2071
2072
2073
void set_var_free()
2074
{
2075
  delete_dynamic(&fixed_show_vars);
2076
}
2077
2078
2079
/*
2080
  Add elements to the dynamic list of read-only system variables.
660.1.3 by Eric Herman
removed trailing whitespace with simple script:
2081
1 by brian
clean slate
2082
  SYNOPSIS
2083
    mysql_append_static_vars()
2084
    show_vars	Pointer to start of array
2085
    count       Number of elements
660.1.3 by Eric Herman
removed trailing whitespace with simple script:
2086
1 by brian
clean slate
2087
  RETURN VALUES
2088
    0           SUCCESS
2089
    otherwise   FAILURE
2090
*/
482 by Brian Aker
Remove uint.
2091
int mysql_append_static_vars(const SHOW_VAR *show_vars, uint32_t count)
1 by brian
clean slate
2092
{
2093
  for (; count > 0; count--, show_vars++)
481 by Brian Aker
Remove all of uchar.
2094
    if (insert_dynamic(&fixed_show_vars, (unsigned char*) show_vars))
1 by brian
clean slate
2095
      return 1;
2096
  return 0;
2097
}
2098
2099
2100
/**
2101
  Find a user set-table variable.
2102
2103
  @param str	   Name of system variable to find
2104
  @param length    Length of variable.  zero means that we should use strlen()
2105
                   on the variable
2106
  @param no_error  Refuse to emit an error, even if one occurred.
2107
2108
  @retval
2109
    pointer	pointer to variable definitions
2110
  @retval
2111
    0		Unknown variable (error message is given)
2112
*/
2113
873.2.16 by Monty Taylor
Replaced HASH with std::map - avoid utf8 hashing on every sys_var lookup.
2114
sys_var *intern_find_sys_var(const char *str, uint32_t, bool no_error)
1 by brian
clean slate
2115
{
2116
  /*
2117
    This function is only called from the sql_plugin.cc.
2118
    A lock on LOCK_system_variable_hash should be held
2119
  */
873.2.16 by Monty Taylor
Replaced HASH with std::map - avoid utf8 hashing on every sys_var lookup.
2120
  string lower_var(str);
2121
  transform(lower_var.begin(), lower_var.end(), lower_var.begin(), ::tolower);
2122
  map<string, sys_var *>::iterator result_iter=
2123
    system_variable_hash.find(lower_var);
896.1.1 by Monty Taylor
Actually return NULL from intern_find_sys_var on error thank you.
2124
  if (result_iter == system_variable_hash.end())
2125
  {
2126
    if (no_error)
2127
    {
2128
      return NULL;
2129
    }
2130
    else
2131
    {
2132
      my_error(ER_UNKNOWN_SYSTEM_VARIABLE, MYF(0), (char*) str);
2133
      return NULL;
2134
    }
2135
  }
1 by brian
clean slate
2136
873.2.16 by Monty Taylor
Replaced HASH with std::map - avoid utf8 hashing on every sys_var lookup.
2137
  return (*result_iter).second;
1 by brian
clean slate
2138
}
2139
2140
2141
/**
2142
  Execute update of all variables.
2143
2144
  First run a check of all variables that all updates will go ok.
2145
  If yes, then execute all updates, returning an error if any one failed.
2146
2147
  This should ensure that in all normal cases none all or variables are
2148
  updated.
2149
520.1.21 by Brian Aker
THD -> Session rename
2150
  @param Session		Thread id
1 by brian
clean slate
2151
  @param var_list       List of variables to update
2152
2153
  @retval
2154
    0	ok
2155
  @retval
2156
    1	ERROR, message sent (normally no variables was updated)
2157
  @retval
2158
    -1  ERROR, message not sent
2159
*/
2160
520.1.22 by Brian Aker
Second pass of thd cleanup
2161
int sql_set_variables(Session *session, List<set_var_base> *var_list)
1 by brian
clean slate
2162
{
2163
  int error;
2164
  List_iterator_fast<set_var_base> it(*var_list);
2165
2166
  set_var_base *var;
2167
  while ((var=it++))
2168
  {
520.1.22 by Brian Aker
Second pass of thd cleanup
2169
    if ((error= var->check(session)))
1 by brian
clean slate
2170
      goto err;
2171
  }
520.1.22 by Brian Aker
Second pass of thd cleanup
2172
  if (!(error= test(session->is_error())))
1 by brian
clean slate
2173
  {
2174
    it.rewind();
2175
    while ((var= it++))
520.1.22 by Brian Aker
Second pass of thd cleanup
2176
      error|= var->update(session);         // Returns 0, -1 or 1
1 by brian
clean slate
2177
  }
2178
2179
err:
520.1.22 by Brian Aker
Second pass of thd cleanup
2180
  free_underlaid_joins(session, &session->lex->select_lex);
51.1.46 by Jay Pipes
Removed/replaced DBUG symbols and standardized TRUE/FALSE
2181
  return(error);
1 by brian
clean slate
2182
}
2183
2184
2185
/*****************************************************************************
2186
  Functions to handle SET mysql_internal_variable=const_expr
2187
*****************************************************************************/
2188
520.1.22 by Brian Aker
Second pass of thd cleanup
2189
int set_var::check(Session *session)
1 by brian
clean slate
2190
{
2191
  if (var->is_readonly())
2192
  {
2193
    my_error(ER_INCORRECT_GLOBAL_LOCAL_VAR, MYF(0), var->name, "read only");
2194
    return -1;
2195
  }
2196
  if (var->check_type(type))
2197
  {
2198
    int err= type == OPT_GLOBAL ? ER_LOCAL_VARIABLE : ER_GLOBAL_VARIABLE;
2199
    my_error(err, MYF(0), var->name);
2200
    return -1;
2201
  }
2202
  /* value is a NULL pointer if we are using SET ... = DEFAULT */
2203
  if (!value)
2204
  {
2205
    if (var->check_default(type))
2206
    {
2207
      my_error(ER_NO_DEFAULT, MYF(0), var->name);
2208
      return -1;
2209
    }
2210
    return 0;
2211
  }
2212
2213
  if ((!value->fixed &&
520.1.22 by Brian Aker
Second pass of thd cleanup
2214
       value->fix_fields(session, &value)) || value->check_cols(1))
1 by brian
clean slate
2215
    return -1;
2216
  if (var->check_update_type(value->result_type()))
2217
  {
2218
    my_error(ER_WRONG_TYPE_FOR_VAR, MYF(0), var->name);
2219
    return -1;
2220
  }
520.1.22 by Brian Aker
Second pass of thd cleanup
2221
  return var->check(session, this) ? -1 : 0;
1 by brian
clean slate
2222
}
2223
2224
/**
2225
  Update variable
2226
520.1.22 by Brian Aker
Second pass of thd cleanup
2227
  @param   session    thread handler
1 by brian
clean slate
2228
  @returns 0|1    ok or	ERROR
2229
2230
  @note ERROR can be only due to abnormal operations involving
2231
  the server's execution evironment such as
2232
  out of memory, hard disk failure or the computer blows up.
2233
  Consider set_var::check() method if there is a need to return
2234
  an error due to logics.
2235
*/
520.1.22 by Brian Aker
Second pass of thd cleanup
2236
int set_var::update(Session *session)
1 by brian
clean slate
2237
{
2238
  if (!value)
520.1.22 by Brian Aker
Second pass of thd cleanup
2239
    var->set_default(session, type);
2240
  else if (var->update(session, this))
1 by brian
clean slate
2241
    return -1;				// should never happen
2242
  if (var->after_update)
520.1.22 by Brian Aker
Second pass of thd cleanup
2243
    (*var->after_update)(session, type);
1 by brian
clean slate
2244
  return 0;
2245
}
2246
2247
2248
/*****************************************************************************
2249
  Functions to handle SET @user_variable=const_expr
2250
*****************************************************************************/
2251
520.1.22 by Brian Aker
Second pass of thd cleanup
2252
int set_var_user::check(Session *session)
1 by brian
clean slate
2253
{
2254
  /*
2255
    Item_func_set_user_var can't substitute something else on its place =>
2256
    0 can be passed as last argument (reference on item)
2257
  */
520.1.22 by Brian Aker
Second pass of thd cleanup
2258
  return (user_var_item->fix_fields(session, (Item**) 0) ||
1 by brian
clean slate
2259
	  user_var_item->check(0)) ? -1 : 0;
2260
}
2261
2262
575.1.2 by Monty Taylor
Changed a bunch of __attribute__((unused)) to removing the parameter name instead.
2263
int set_var_user::update(Session *)
1 by brian
clean slate
2264
{
2265
  if (user_var_item->update())
2266
  {
2267
    /* Give an error if it's not given already */
2268
    my_message(ER_SET_CONSTANTS_ONLY, ER(ER_SET_CONSTANTS_ONLY), MYF(0));
2269
    return -1;
2270
  }
2271
  return 0;
2272
}
2273
2274
/****************************************************************************
2275
 Functions to handle table_type
2276
****************************************************************************/
2277
2278
/* Based upon sys_var::check_enum() */
2279
520.1.22 by Brian Aker
Second pass of thd cleanup
2280
bool sys_var_session_storage_engine::check(Session *session, set_var *var)
1 by brian
clean slate
2281
{
2282
  char buff[STRING_BUFFER_USUAL_SIZE];
2283
  const char *value;
383.1.12 by Brian Aker
Much closer toward UTF8 being around all the time...
2284
  String str(buff, sizeof(buff), &my_charset_utf8_general_ci), *res;
1 by brian
clean slate
2285
971.1.21 by Monty Taylor
Store StorageEngine in system variables, rather than storage engine plugin.
2286
  var->save_result.storage_engine= NULL;
1 by brian
clean slate
2287
  if (var->value->result_type() == STRING_RESULT)
2288
  {
2289
    LEX_STRING engine_name;
960.2.26 by Monty Taylor
Rename hton to engine.
2290
    StorageEngine *engine;
1 by brian
clean slate
2291
    if (!(res=var->value->val_str(&str)) ||
2292
        !(engine_name.str= (char *)res->ptr()) ||
2293
        !(engine_name.length= res->length()) ||
971.1.21 by Monty Taylor
Store StorageEngine in system variables, rather than storage engine plugin.
2294
	      !(var->save_result.storage_engine=
2295
            ha_resolve_by_name(session, &engine_name)) ||
2296
        !(engine= var->save_result.storage_engine))
1 by brian
clean slate
2297
    {
2298
      value= res ? res->c_ptr() : "NULL";
2299
      goto err;
2300
    }
2301
    return 0;
2302
  }
2303
  value= "unknown";
2304
2305
err:
2306
  my_error(ER_UNKNOWN_STORAGE_ENGINE, MYF(0), value);
2307
  return 1;
2308
}
2309
2310
575.1.2 by Monty Taylor
Changed a bunch of __attribute__((unused)) to removing the parameter name instead.
2311
unsigned char *sys_var_session_storage_engine::value_ptr(Session *session,
2312
                                                         enum_var_type type,
779.3.10 by Monty Taylor
Turned on -Wshadow.
2313
                                                         const LEX_STRING *)
1 by brian
clean slate
2314
{
481 by Brian Aker
Remove all of uchar.
2315
  unsigned char* result;
968.2.29 by Monty Taylor
First steps towards new plugin reg.
2316
  string engine_name;
971.1.21 by Monty Taylor
Store StorageEngine in system variables, rather than storage engine plugin.
2317
  StorageEngine *engine= session->variables.*offset;
1 by brian
clean slate
2318
  if (type == OPT_GLOBAL)
971.1.21 by Monty Taylor
Store StorageEngine in system variables, rather than storage engine plugin.
2319
    engine= global_system_variables.*offset;
971.1.14 by Monty Taylor
Slurp around strings rather than char* for storage engine name.
2320
  engine_name= engine->getName();
968.2.29 by Monty Taylor
First steps towards new plugin reg.
2321
  result= (unsigned char *) session->strmake(engine_name.c_str(),
2322
                                             engine_name.size());
1 by brian
clean slate
2323
  return result;
2324
}
2325
2326
520.1.22 by Brian Aker
Second pass of thd cleanup
2327
void sys_var_session_storage_engine::set_default(Session *session, enum_var_type type)
1 by brian
clean slate
2328
{
971.1.21 by Monty Taylor
Store StorageEngine in system variables, rather than storage engine plugin.
2329
  StorageEngine *old_value, *new_value, **value;
1 by brian
clean slate
2330
  if (type == OPT_GLOBAL)
2331
  {
2332
    value= &(global_system_variables.*offset);
971.1.21 by Monty Taylor
Store StorageEngine in system variables, rather than storage engine plugin.
2333
    new_value= myisam_engine;
1 by brian
clean slate
2334
  }
2335
  else
2336
  {
520.1.22 by Brian Aker
Second pass of thd cleanup
2337
    value= &(session->variables.*offset);
971.1.19 by Monty Taylor
Remove most of plugin_ref. Fix several leaks (where the malloc was happening but never freed). One step away from no more plugin_ref. Yippee. It's so much easier the second time you try to do this.
2338
    new_value= global_system_variables.*offset;
1 by brian
clean slate
2339
  }
51.1.46 by Jay Pipes
Removed/replaced DBUG symbols and standardized TRUE/FALSE
2340
  assert(new_value);
1 by brian
clean slate
2341
  old_value= *value;
2342
  *value= new_value;
2343
}
2344
2345
520.1.22 by Brian Aker
Second pass of thd cleanup
2346
bool sys_var_session_storage_engine::update(Session *session, set_var *var)
1 by brian
clean slate
2347
{
971.1.21 by Monty Taylor
Store StorageEngine in system variables, rather than storage engine plugin.
2348
  StorageEngine **value= &(global_system_variables.*offset), *old_value;
1 by brian
clean slate
2349
   if (var->type != OPT_GLOBAL)
520.1.22 by Brian Aker
Second pass of thd cleanup
2350
     value= &(session->variables.*offset);
1 by brian
clean slate
2351
  old_value= *value;
971.1.21 by Monty Taylor
Store StorageEngine in system variables, rather than storage engine plugin.
2352
  if (old_value != var->save_result.storage_engine)
1 by brian
clean slate
2353
  {
971.1.21 by Monty Taylor
Store StorageEngine in system variables, rather than storage engine plugin.
2354
    *value= var->save_result.storage_engine;
1 by brian
clean slate
2355
  }
2356
  return 0;
2357
}
2358
2359
bool
520.1.22 by Brian Aker
Second pass of thd cleanup
2360
sys_var_session_optimizer_switch::
617 by Brian Aker
ulong fixes
2361
symbolic_mode_representation(Session *session, uint32_t val, LEX_STRING *rep)
1 by brian
clean slate
2362
{
2363
  char buff[STRING_BUFFER_USUAL_SIZE*8];
383.1.12 by Brian Aker
Much closer toward UTF8 being around all the time...
2364
  String tmp(buff, sizeof(buff), &my_charset_utf8_general_ci);
1 by brian
clean slate
2365
2366
  tmp.length(0);
2367
482 by Brian Aker
Remove uint.
2368
  for (uint32_t i= 0; val; val>>= 1, i++)
1 by brian
clean slate
2369
  {
2370
    if (val & 1)
2371
    {
2372
      tmp.append(optimizer_switch_typelib.type_names[i],
2373
                 optimizer_switch_typelib.type_lengths[i]);
2374
      tmp.append(',');
2375
    }
2376
  }
2377
2378
  if (tmp.length())
2379
    tmp.length(tmp.length() - 1); /* trim the trailing comma */
2380
520.1.22 by Brian Aker
Second pass of thd cleanup
2381
  rep->str= session->strmake(tmp.ptr(), tmp.length());
1 by brian
clean slate
2382
2383
  rep->length= rep->str ? tmp.length() : 0;
2384
2385
  return rep->length != tmp.length();
2386
}
2387
2388
575.1.2 by Monty Taylor
Changed a bunch of __attribute__((unused)) to removing the parameter name instead.
2389
unsigned char *sys_var_session_optimizer_switch::value_ptr(Session *session,
2390
                                                           enum_var_type type,
779.3.10 by Monty Taylor
Turned on -Wshadow.
2391
                                                           const LEX_STRING *)
1 by brian
clean slate
2392
{
2393
  LEX_STRING opts;
892.2.2 by Monty Taylor
More solaris warnings.
2394
  uint32_t val= ((type == OPT_GLOBAL) ? global_system_variables.*offset :
520.1.22 by Brian Aker
Second pass of thd cleanup
2395
                  session->variables.*offset);
2396
  (void) symbolic_mode_representation(session, val, &opts);
481 by Brian Aker
Remove all of uchar.
2397
  return (unsigned char *) opts.str;
1 by brian
clean slate
2398
}
2399
2400
520.1.22 by Brian Aker
Second pass of thd cleanup
2401
void sys_var_session_optimizer_switch::set_default(Session *session, enum_var_type type)
1 by brian
clean slate
2402
{
2403
  if (type == OPT_GLOBAL)
2404
    global_system_variables.*offset= 0;
2405
  else
520.1.22 by Brian Aker
Second pass of thd cleanup
2406
    session->variables.*offset= global_system_variables.*offset;
1 by brian
clean slate
2407
}
2408
2409
2410
/****************************************************************************
2411
  Named list handling
2412
****************************************************************************/
2413
482 by Brian Aker
Remove uint.
2414
unsigned char* find_named(I_List<NAMED_LIST> *list, const char *name, uint32_t length,
1 by brian
clean slate
2415
		NAMED_LIST **found)
2416
{
2417
  I_List_iterator<NAMED_LIST> it(*list);
2418
  NAMED_LIST *element;
2419
  while ((element= it++))
2420
  {
2421
    if (element->cmp(name, length))
2422
    {
2423
      if (found)
2424
        *found= element;
2425
      return element->data;
2426
    }
2427
  }
2428
  return 0;
2429
}
2430
2431
2432
void delete_elements(I_List<NAMED_LIST> *list,
481 by Brian Aker
Remove all of uchar.
2433
		     void (*free_element)(const char *name, unsigned char*))
1 by brian
clean slate
2434
{
2435
  NAMED_LIST *element;
2436
  while ((element= list->get()))
2437
  {
656.1.34 by Monty Taylor
Got closer...
2438
    (*free_element)(element->name.c_str(), element->data);
1 by brian
clean slate
2439
    delete element;
2440
  }
51.1.46 by Jay Pipes
Removed/replaced DBUG symbols and standardized TRUE/FALSE
2441
  return;
1 by brian
clean slate
2442
}
2443
2444
2445
/* Key cache functions */
2446
482 by Brian Aker
Remove uint.
2447
static KEY_CACHE *create_key_cache(const char *name, uint32_t length)
1 by brian
clean slate
2448
{
2449
  KEY_CACHE *key_cache;
660.1.3 by Eric Herman
removed trailing whitespace with simple script:
2450
641.3.8 by Monty Taylor
Removed my_malloc from drizzled.
2451
  if ((key_cache= (KEY_CACHE*) malloc(sizeof(KEY_CACHE))))
1 by brian
clean slate
2452
  {
641.3.8 by Monty Taylor
Removed my_malloc from drizzled.
2453
    memset(key_cache, 0, sizeof(KEY_CACHE));
481 by Brian Aker
Remove all of uchar.
2454
    if (!new NAMED_LIST(&key_caches, name, length, (unsigned char*) key_cache))
1 by brian
clean slate
2455
    {
477 by Monty Taylor
Removed my_free(). It turns out that it had been def'd to ignore the flags passed to it in the second arg anyway. Gotta love that.
2456
      free((char*) key_cache);
1 by brian
clean slate
2457
      key_cache= 0;
2458
    }
2459
    else
2460
    {
2461
      /*
2462
	Set default values for a key cache
2463
	The values in dflt_key_cache_var is set by my_getopt() at startup
2464
2465
	We don't set 'buff_size' as this is used to enable the key cache
2466
      */
2467
      key_cache->param_block_size=     dflt_key_cache_var.param_block_size;
2468
      key_cache->param_division_limit= dflt_key_cache_var.param_division_limit;
2469
      key_cache->param_age_threshold=  dflt_key_cache_var.param_age_threshold;
2470
    }
2471
  }
51.1.46 by Jay Pipes
Removed/replaced DBUG symbols and standardized TRUE/FALSE
2472
  return(key_cache);
1 by brian
clean slate
2473
}
2474
2475
482 by Brian Aker
Remove uint.
2476
KEY_CACHE *get_or_create_key_cache(const char *name, uint32_t length)
1 by brian
clean slate
2477
{
2478
  LEX_STRING key_cache_name;
2479
  KEY_CACHE *key_cache;
2480
2481
  key_cache_name.str= (char *) name;
2482
  key_cache_name.length= length;
2483
  pthread_mutex_lock(&LOCK_global_system_variables);
2484
  if (!(key_cache= get_key_cache(&key_cache_name)))
2485
    key_cache= create_key_cache(name, length);
2486
  pthread_mutex_unlock(&LOCK_global_system_variables);
2487
  return key_cache;
2488
}
2489
2490
575.1.2 by Monty Taylor
Changed a bunch of __attribute__((unused)) to removing the parameter name instead.
2491
void free_key_cache(const char *, KEY_CACHE *key_cache)
1 by brian
clean slate
2492
{
2493
  ha_end_key_cache(key_cache);
477 by Monty Taylor
Removed my_free(). It turns out that it had been def'd to ignore the flags passed to it in the second arg anyway. Gotta love that.
2494
  free((char*) key_cache);
1 by brian
clean slate
2495
}
2496
2497
2498
bool process_key_caches(process_key_cache_t func)
2499
{
2500
  I_List_iterator<NAMED_LIST> it(key_caches);
2501
  NAMED_LIST *element;
2502
2503
  while ((element= it++))
2504
  {
2505
    KEY_CACHE *key_cache= (KEY_CACHE *) element->data;
656.1.34 by Monty Taylor
Got closer...
2506
    func(element->name.c_str(), key_cache);
1 by brian
clean slate
2507
  }
2508
  return 0;
2509
}
2510
2511
/****************************************************************************
2512
  Used templates
2513
****************************************************************************/
2514
2515
#ifdef HAVE_EXPLICIT_TEMPLATE_INSTANTIATION
2516
template class List<set_var_base>;
2517
template class List_iterator_fast<set_var_base>;
2518
template class I_List_iterator<NAMED_LIST>;
2519
#endif