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