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