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