~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
 *
1999.6.1 by kalebral at gmail
update Copyright strings to a more common format to help with creating the master debian copyright file
4
 *  Copyright (C) 2008 Sun Microsystems, Inc.
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.
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
1410.3.4 by Djellel E. Difallah
update references to old my_'s
32
    of it in the option structure list in mysqld.cc
1 by brian
clean slate
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
*/
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.
40
2173.2.1 by Monty Taylor
Fixes incorrect usage of include
41
#include <config.h>
42
#include <drizzled/option.h>
43
#include <drizzled/error.h>
44
#include <drizzled/gettext.h>
45
#include <drizzled/tztime.h>
46
#include <drizzled/data_home.h>
47
#include <drizzled/set_var.h>
48
#include <drizzled/session.h>
2269.1.5 by Olaf van der Spek
Session Times
49
#include <drizzled/session/times.h>
2173.2.1 by Monty Taylor
Fixes incorrect usage of include
50
#include <drizzled/sql_base.h>
51
#include <drizzled/lock.h>
52
#include <drizzled/item/uint.h>
53
#include <drizzled/item/null.h>
54
#include <drizzled/item/float.h>
55
#include <drizzled/item/string.h>
56
#include <drizzled/plugin.h>
57
#include <drizzled/version.h>
58
#include <drizzled/internal/m_string.h>
59
#include <drizzled/pthread_globals.h>
60
#include <drizzled/charset.h>
61
#include <drizzled/transaction_services.h>
62
#include <drizzled/constrained_value.h>
63
#include <drizzled/visibility.h>
64
#include <drizzled/typelib.h>
65
#include <drizzled/plugin/storage_engine.h>
2241.3.2 by Olaf van der Spek
Refactor Session::variables
66
#include <drizzled/system_variables.h>
2241.3.14 by Olaf van der Spek
Refactor
67
#include <drizzled/catalog/instance.h>
1 by brian
clean slate
68
1502.3.1 by iwamatsu at nigauri
Add cstdio include to files needing it. Fixes the build on some debian
69
#include <cstdio>
873.2.16 by Monty Taylor
Replaced HASH with std::map - avoid utf8 hashing on every sys_var lookup.
70
#include <map>
1851.1.1 by Monty Taylor
Removed sys_var_chain.
71
#include <vector>
873.2.16 by Monty Taylor
Replaced HASH with std::map - avoid utf8 hashing on every sys_var lookup.
72
#include <algorithm>
73
74
using namespace std;
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
75
2241.3.14 by Olaf van der Spek
Refactor
76
namespace drizzled {
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
77
78
namespace internal
79
{
2241.3.14 by Olaf van der Spek
Refactor
80
	extern bool timed_mutexes;
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
81
}
873.2.16 by Monty Taylor
Replaced HASH with std::map - avoid utf8 hashing on every sys_var lookup.
82
1241.9.32 by Monty Taylor
Moved global myisam and heap pointers out of server_includes.
83
extern plugin::StorageEngine *myisam_engine;
1251.2.3 by Jay Pipes
Merge trunk and resolve conflicts
84
extern bool timed_mutexes;
1241.9.27 by Monty Taylor
Removed mysys/m_sys.h from server_includes.h.
85
1410.3.4 by Djellel E. Difallah
update references to old my_'s
86
extern struct option my_long_options[];
2254 by Brian Aker
Shift CHARSET_INFO to charset_info_st
87
extern const charset_info_st *character_set_filesystem;
629.2.7 by Monty Taylor
Fixed a couple of memory buffer size issues.
88
extern size_t my_thread_stack_size;
1 by brian
clean slate
89
1228.3.1 by Monty Taylor
Removed NameMap. Also remove the aliases from the plugin, since we can just
90
typedef map<string, sys_var *> SystemVariableMap;
91
static SystemVariableMap system_variable_map;
670.2.4 by Monty Taylor
Removed more stuff from the headers.
92
extern char *opt_drizzle_tmpdir;
1 by brian
clean slate
93
1241.9.57 by Monty Taylor
Oy. Bigger change than I normally like - but this stuff is all intertwined.
94
extern TYPELIB tx_isolation_typelib;
95
2183.1.2 by Monty Taylor
A slew of tiny meaningless changes.
96
namespace
97
{
98
static size_t revno= DRIZZLE7_VC_REVNO;
99
static size_t release_id= DRIZZLE7_RELEASE_ID;
100
}
101
461 by Monty Taylor
Removed NullS. bu-bye.
102
const char *bool_type_names[]= { "OFF", "ON", NULL };
1 by brian
clean slate
103
TYPELIB bool_typelib=
104
{
105
  array_elements(bool_type_names)-1, "", bool_type_names, NULL
106
};
107
520.1.22 by Brian Aker
Second pass of thd cleanup
108
static bool set_option_bit(Session *session, set_var *var);
109
static bool set_option_autocommit(Session *session, set_var *var);
110
static int  check_pseudo_thread_id(Session *session, set_var *var);
111
static int check_tx_isolation(Session *session, set_var *var);
1273.13.24 by Brian Aker
Updating style, simplified code.
112
static void fix_tx_isolation(Session *session, sql_var_t type);
520.1.22 by Brian Aker
Second pass of thd cleanup
113
static int check_completion_type(Session *session, set_var *var);
1273.13.24 by Brian Aker
Updating style, simplified code.
114
static void fix_completion_type(Session *session, sql_var_t type);
115
static void fix_max_join_size(Session *session, sql_var_t type);
116
static void fix_session_mem_root(Session *session, sql_var_t type);
117
static void fix_server_id(Session *session, sql_var_t type);
520.1.22 by Brian Aker
Second pass of thd cleanup
118
bool throw_bounds_warning(Session *session, bool fixed, bool unsignd,
1022.2.38 by Monty Taylor
Changed name to std::string.
119
                          const std::string &name, int64_t val);
520.1.22 by Brian Aker
Second pass of thd cleanup
120
static unsigned char *get_error_count(Session *session);
121
static unsigned char *get_warning_count(Session *session);
122
static unsigned char *get_tmpdir(Session *session);
1 by brian
clean slate
123
124
/*
125
  Variable definition list
126
127
  These are variables that can be set from the command line, in
128
  alphabetic order.
129
130
  The variables are linked into the list. A variable is added to
131
  it in the constructor (see sys_var class for details).
132
*/
819.1.1 by Toru Maesaka
Removed the 16bit limitation of auto_increment_(increment|offset) system variables
133
static sys_var_session_uint64_t
1851.1.1 by Monty Taylor
Removed sys_var_chain.
134
sys_auto_increment_increment("auto_increment_increment",
1878.3.2 by Monty Taylor
Split out show_type into its own header and made sys_var work through
135
                             &drizzle_system_variables::auto_increment_increment);
819.1.1 by Toru Maesaka
Removed the 16bit limitation of auto_increment_(increment|offset) system variables
136
static sys_var_session_uint64_t
1851.1.1 by Monty Taylor
Removed sys_var_chain.
137
sys_auto_increment_offset("auto_increment_offset",
1878.3.2 by Monty Taylor
Split out show_type into its own header and made sys_var work through
138
                          &drizzle_system_variables::auto_increment_offset);
1 by brian
clean slate
139
1851.1.1 by Monty Taylor
Removed sys_var_chain.
140
static sys_var_fs_path sys_basedir("basedir", basedir);
141
static sys_var_fs_path sys_pid_file("pid_file", pid_file);
142
static sys_var_fs_path sys_plugin_dir("plugin_dir", plugin_dir);
1813.2.7 by Monty Taylor
Migrated plugin_dir to fs::path.
143
1851.1.1 by Monty Taylor
Removed sys_var_chain.
144
static sys_var_size_t_ptr sys_thread_stack_size("thread_stack",
1813.2.8 by Monty Taylor
Removed the fixed_vars.
145
                                                      &my_thread_stack_size);
1897.4.1 by Monty Taylor
Added readonly constrained_value class.
146
static sys_var_constrained_value_readonly<uint32_t> sys_back_log("back_log", back_log);
1813.2.8 by Monty Taylor
Removed the fixed_vars.
147
1851.1.1 by Monty Taylor
Removed sys_var_chain.
148
static sys_var_session_uint64_t	sys_bulk_insert_buff_size("bulk_insert_buffer_size",
1878.3.2 by Monty Taylor
Split out show_type into its own header and made sys_var work through
149
                                                          &drizzle_system_variables::bulk_insert_buff_size);
1851.1.1 by Monty Taylor
Removed sys_var_chain.
150
static sys_var_session_uint32_t	sys_completion_type("completion_type",
1878.3.2 by Monty Taylor
Split out show_type into its own header and made sys_var work through
151
                                                    &drizzle_system_variables::completion_type,
619 by Brian Aker
Removed ulong methods from vars.
152
                                                    check_completion_type,
153
                                                    fix_completion_type);
1 by brian
clean slate
154
static sys_var_collation_sv
1878.3.2 by Monty Taylor
Split out show_type into its own header and made sys_var work through
155
sys_collation_server("collation_server", &drizzle_system_variables::collation_server, &default_charset_info);
1851.1.1 by Monty Taylor
Removed sys_var_chain.
156
static sys_var_fs_path       sys_datadir("datadir", getDataHome());
1 by brian
clean slate
157
1851.1.1 by Monty Taylor
Removed sys_var_chain.
158
static sys_var_session_uint64_t	sys_join_buffer_size("join_buffer_size",
1878.3.2 by Monty Taylor
Split out show_type into its own header and made sys_var work through
159
                                                     &drizzle_system_variables::join_buff_size);
1851.1.1 by Monty Taylor
Removed sys_var_chain.
160
static sys_var_session_uint32_t	sys_max_allowed_packet("max_allowed_packet",
1878.3.2 by Monty Taylor
Split out show_type into its own header and made sys_var work through
161
                                                       &drizzle_system_variables::max_allowed_packet);
1851.1.1 by Monty Taylor
Removed sys_var_chain.
162
static sys_var_session_uint64_t	sys_max_error_count("max_error_count",
1878.3.2 by Monty Taylor
Split out show_type into its own header and made sys_var work through
163
                                                  &drizzle_system_variables::max_error_count);
1851.1.1 by Monty Taylor
Removed sys_var_chain.
164
static sys_var_session_uint64_t	sys_max_heap_table_size("max_heap_table_size",
1878.3.2 by Monty Taylor
Split out show_type into its own header and made sys_var work through
165
                                                        &drizzle_system_variables::max_heap_table_size);
1851.1.1 by Monty Taylor
Removed sys_var_chain.
166
static sys_var_session_uint64_t sys_pseudo_thread_id("pseudo_thread_id",
1878.3.2 by Monty Taylor
Split out show_type into its own header and made sys_var work through
167
                                              &drizzle_system_variables::pseudo_thread_id,
1018 by Brian Aker
Remove "BINLOG" from variables (we don't need this for our replication).
168
                                              0, check_pseudo_thread_id);
1851.1.1 by Monty Taylor
Removed sys_var_chain.
169
static sys_var_session_ha_rows	sys_max_join_size("max_join_size",
1878.3.2 by Monty Taylor
Split out show_type into its own header and made sys_var work through
170
                                                  &drizzle_system_variables::max_join_size,
617 by Brian Aker
ulong fixes
171
                                                  fix_max_join_size);
1851.1.1 by Monty Taylor
Removed sys_var_chain.
172
static sys_var_session_uint64_t	sys_max_seeks_for_key("max_seeks_for_key",
1878.3.2 by Monty Taylor
Split out show_type into its own header and made sys_var work through
173
                                                      &drizzle_system_variables::max_seeks_for_key);
1851.1.1 by Monty Taylor
Removed sys_var_chain.
174
static sys_var_session_uint64_t   sys_max_length_for_sort_data("max_length_for_sort_data",
1878.3.2 by Monty Taylor
Split out show_type into its own header and made sys_var work through
175
                                                               &drizzle_system_variables::max_length_for_sort_data);
1851.1.1 by Monty Taylor
Removed sys_var_chain.
176
static sys_var_session_size_t	sys_max_sort_length("max_sort_length",
1878.3.2 by Monty Taylor
Split out show_type into its own header and made sys_var work through
177
                                                    &drizzle_system_variables::max_sort_length);
1851.1.1 by Monty Taylor
Removed sys_var_chain.
178
static sys_var_uint64_t_ptr	sys_max_write_lock_count("max_write_lock_count",
622.1.1 by Brian Aker
32bit fixes around vars
179
                                                 &max_write_lock_count);
1851.1.1 by Monty Taylor
Removed sys_var_chain.
180
static sys_var_session_uint64_t sys_min_examined_row_limit("min_examined_row_limit",
1878.3.2 by Monty Taylor
Split out show_type into its own header and made sys_var work through
181
                                                           &drizzle_system_variables::min_examined_row_limit);
1 by brian
clean slate
182
183
/* these two cannot be static */
1851.1.1 by Monty Taylor
Removed sys_var_chain.
184
static sys_var_session_bool sys_optimizer_prune_level("optimizer_prune_level",
1878.3.2 by Monty Taylor
Split out show_type into its own header and made sys_var work through
185
                                                      &drizzle_system_variables::optimizer_prune_level);
1851.1.1 by Monty Taylor
Removed sys_var_chain.
186
static sys_var_session_uint32_t sys_optimizer_search_depth("optimizer_search_depth",
1878.3.2 by Monty Taylor
Split out show_type into its own header and made sys_var work through
187
                                                           &drizzle_system_variables::optimizer_search_depth);
1 by brian
clean slate
188
1851.1.1 by Monty Taylor
Removed sys_var_chain.
189
static sys_var_session_uint64_t sys_preload_buff_size("preload_buffer_size",
1878.3.2 by Monty Taylor
Split out show_type into its own header and made sys_var work through
190
                                                      &drizzle_system_variables::preload_buff_size);
1851.1.1 by Monty Taylor
Removed sys_var_chain.
191
static sys_var_session_uint32_t sys_read_buff_size("read_buffer_size",
1878.3.2 by Monty Taylor
Split out show_type into its own header and made sys_var work through
192
                                                   &drizzle_system_variables::read_buff_size);
1851.1.1 by Monty Taylor
Removed sys_var_chain.
193
static sys_var_session_uint32_t	sys_read_rnd_buff_size("read_rnd_buffer_size",
1878.3.2 by Monty Taylor
Split out show_type into its own header and made sys_var work through
194
                                                       &drizzle_system_variables::read_rnd_buff_size);
1851.1.1 by Monty Taylor
Removed sys_var_chain.
195
static sys_var_session_uint32_t	sys_div_precincrement("div_precision_increment",
1878.3.2 by Monty Taylor
Split out show_type into its own header and made sys_var work through
196
                                                      &drizzle_system_variables::div_precincrement);
1 by brian
clean slate
197
1851.1.1 by Monty Taylor
Removed sys_var_chain.
198
static sys_var_session_size_t	sys_range_alloc_block_size("range_alloc_block_size",
1878.3.2 by Monty Taylor
Split out show_type into its own header and made sys_var work through
199
                                                           &drizzle_system_variables::range_alloc_block_size);
1938.3.1 by David Shrewsbury
Add --replicate-query option.
200
201
static sys_var_session_bool sys_replicate_query("replicate_query",
202
                                                &drizzle_system_variables::replicate_query);
203
1851.1.1 by Monty Taylor
Removed sys_var_chain.
204
static sys_var_session_uint32_t	sys_query_alloc_block_size("query_alloc_block_size",
1878.3.2 by Monty Taylor
Split out show_type into its own header and made sys_var work through
205
                                                           &drizzle_system_variables::query_alloc_block_size,
1831.1.1 by Andrew Hutchings
Fix new warnings in GCC 4.5
206
                                                           NULL, fix_session_mem_root);
1851.1.1 by Monty Taylor
Removed sys_var_chain.
207
static sys_var_session_uint32_t	sys_query_prealloc_size("query_prealloc_size",
1878.3.2 by Monty Taylor
Split out show_type into its own header and made sys_var work through
208
                                                        &drizzle_system_variables::query_prealloc_size,
1831.1.1 by Andrew Hutchings
Fix new warnings in GCC 4.5
209
                                                        NULL, fix_session_mem_root);
1851.1.1 by Monty Taylor
Removed sys_var_chain.
210
static sys_var_readonly sys_tmpdir("tmpdir", OPT_GLOBAL, SHOW_CHAR, get_tmpdir);
1 by brian
clean slate
211
1851.1.1 by Monty Taylor
Removed sys_var_chain.
212
static sys_var_fs_path sys_secure_file_priv("secure_file_priv",
1813.2.6 by Monty Taylor
Made secure_file_priv be an fs::path from the beginning.
213
                                            secure_file_priv);
1555.1.1 by Joe Daly
fix to display scheduler in show variables
214
1851.1.1 by Monty Taylor
Removed sys_var_chain.
215
static sys_var_const_str_ptr sys_scheduler("scheduler",
1794.3.2 by Andrew Hutchings
Re-enabled scheduler option.
216
                                           (char**)&opt_scheduler);
1555.1.1 by Joe Daly
fix to display scheduler in show variables
217
1851.1.1 by Monty Taylor
Removed sys_var_chain.
218
static sys_var_uint32_t_ptr  sys_server_id("server_id", &server_id,
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.
219
                                           fix_server_id);
220
1851.1.1 by Monty Taylor
Removed sys_var_chain.
221
static sys_var_session_size_t	sys_sort_buffer("sort_buffer_size",
1878.3.2 by Monty Taylor
Split out show_type into its own header and made sys_var work through
222
                                                &drizzle_system_variables::sortbuff_size);
1 by brian
clean slate
223
2132.3.1 by Andrew Hutchings
Make transaction_message_threshold a read-only global variable instead of a per-session variable
224
static sys_var_size_t_ptr_readonly sys_transaction_message_threshold("transaction_message_threshold",
225
                                                                &transaction_message_threshold);
1802.14.2 by Joseph Daly
fix up transaction_message_threshold
226
1851.1.1 by Monty Taylor
Removed sys_var_chain.
227
static sys_var_session_storage_engine sys_storage_engine("storage_engine",
1878.3.2 by Monty Taylor
Split out show_type into its own header and made sys_var work through
228
				       &drizzle_system_variables::storage_engine);
1851.1.1 by Monty Taylor
Removed sys_var_chain.
229
static sys_var_size_t_ptr	sys_table_def_size("table_definition_cache",
1226.1.3 by Brian Aker
Possible solution for hash/rehash.
230
                                             &table_def_size);
1851.1.1 by Monty Taylor
Removed sys_var_chain.
231
static sys_var_uint64_t_ptr	sys_table_cache_size("table_open_cache",
1 by brian
clean slate
232
					     &table_cache_size);
1851.1.1 by Monty Taylor
Removed sys_var_chain.
233
static sys_var_uint64_t_ptr	sys_table_lock_wait_timeout("table_lock_wait_timeout",
1 by brian
clean slate
234
                                                    &table_lock_wait_timeout);
1851.1.1 by Monty Taylor
Removed sys_var_chain.
235
static sys_var_session_enum	sys_tx_isolation("tx_isolation",
1878.3.2 by Monty Taylor
Split out show_type into its own header and made sys_var work through
236
                                             &drizzle_system_variables::tx_isolation,
617 by Brian Aker
ulong fixes
237
                                             &tx_isolation_typelib,
238
                                             fix_tx_isolation,
239
                                             check_tx_isolation);
1851.1.1 by Monty Taylor
Removed sys_var_chain.
240
static sys_var_session_uint64_t	sys_tmp_table_size("tmp_table_size",
1878.3.2 by Monty Taylor
Split out show_type into its own header and made sys_var work through
241
					   &drizzle_system_variables::tmp_table_size);
1851.1.1 by Monty Taylor
Removed sys_var_chain.
242
static sys_var_bool_ptr  sys_timed_mutexes("timed_mutexes", &internal::timed_mutexes);
243
static sys_var_const_str  sys_version("version", version().c_str());
1228.1.10 by Monty Taylor
Version, length, transaction_log.
244
1851.1.1 by Monty Taylor
Removed sys_var_chain.
245
static sys_var_const_str	sys_version_comment("version_comment",
546 by Monty Taylor
Cleaned up version.h. (And by cleaned, I mean removed)
246
                                            COMPILATION_COMMENT);
1851.1.1 by Monty Taylor
Removed sys_var_chain.
247
static sys_var_const_str	sys_version_compile_machine("version_compile_machine",
1081.1.1 by Monty Taylor
Whole boat-load of build fixes.
248
                                                      HOST_CPU);
1851.1.1 by Monty Taylor
Removed sys_var_chain.
249
static sys_var_const_str	sys_version_compile_os("version_compile_os",
1081.1.1 by Monty Taylor
Whole boat-load of build fixes.
250
                                                 HOST_OS);
1851.1.1 by Monty Taylor
Removed sys_var_chain.
251
static sys_var_const_str	sys_version_compile_vendor("version_compile_vendor",
1081.1.1 by Monty Taylor
Whole boat-load of build fixes.
252
                                                 HOST_VENDOR);
1 by brian
clean slate
253
520.1.21 by Brian Aker
THD -> Session rename
254
/* Variables that are bits in Session */
1 by brian
clean slate
255
1851.1.1 by Monty Taylor
Removed sys_var_chain.
256
sys_var_session_bit sys_autocommit("autocommit", 0,
1 by brian
clean slate
257
                               set_option_autocommit,
258
                               OPTION_NOT_AUTOCOMMIT,
259
                               1);
1851.1.1 by Monty Taylor
Removed sys_var_chain.
260
static sys_var_session_bit	sys_big_selects("sql_big_selects", 0,
1 by brian
clean slate
261
					set_option_bit,
262
					OPTION_BIG_SELECTS);
1851.1.1 by Monty Taylor
Removed sys_var_chain.
263
static sys_var_session_bit	sys_sql_warnings("sql_warnings", 0,
1 by brian
clean slate
264
					 set_option_bit,
265
					 OPTION_WARNINGS);
1851.1.1 by Monty Taylor
Removed sys_var_chain.
266
static sys_var_session_bit	sys_sql_notes("sql_notes", 0,
1 by brian
clean slate
267
					 set_option_bit,
268
					 OPTION_SQL_NOTES);
1851.1.1 by Monty Taylor
Removed sys_var_chain.
269
static sys_var_session_bit	sys_buffer_results("sql_buffer_result", 0,
1 by brian
clean slate
270
					   set_option_bit,
271
					   OPTION_BUFFER_RESULT);
1851.1.1 by Monty Taylor
Removed sys_var_chain.
272
static sys_var_session_bit	sys_foreign_key_checks("foreign_key_checks", 0,
1 by brian
clean slate
273
					       set_option_bit,
1018 by Brian Aker
Remove "BINLOG" from variables (we don't need this for our replication).
274
					       OPTION_NO_FOREIGN_KEY_CHECKS, 1);
1851.1.1 by Monty Taylor
Removed sys_var_chain.
275
static sys_var_session_bit	sys_unique_checks("unique_checks", 0,
1 by brian
clean slate
276
					  set_option_bit,
1018 by Brian Aker
Remove "BINLOG" from variables (we don't need this for our replication).
277
					  OPTION_RELAXED_UNIQUE_CHECKS, 1);
1 by brian
clean slate
278
/* Local state variables */
279
1851.1.1 by Monty Taylor
Removed sys_var_chain.
280
static sys_var_session_ha_rows	sys_select_limit("sql_select_limit",
1878.3.2 by Monty Taylor
Split out show_type into its own header and made sys_var work through
281
						 &drizzle_system_variables::select_limit);
1851.1.1 by Monty Taylor
Removed sys_var_chain.
282
static sys_var_timestamp sys_timestamp("timestamp");
1 by brian
clean slate
283
static sys_var_last_insert_id
1851.1.1 by Monty Taylor
Removed sys_var_chain.
284
sys_last_insert_id("last_insert_id");
1 by brian
clean slate
285
/*
286
  identity is an alias for last_insert_id(), so that we are compatible
287
  with Sybase
288
*/
1851.1.1 by Monty Taylor
Removed sys_var_chain.
289
static sys_var_last_insert_id sys_identity("identity");
1 by brian
clean slate
290
1851.1.1 by Monty Taylor
Removed sys_var_chain.
291
static sys_var_session_lc_time_names sys_lc_time_names("lc_time_names");
1 by brian
clean slate
292
293
/*
294
  We want statements referring explicitly to @@session.insert_id to be
295
  unsafe, because insert_id is modified internally by the slave sql
296
  thread when NULL values are inserted in an AUTO_INCREMENT column.
297
  This modification interfers with the value of the
298
  @@session.insert_id variable if @@session.insert_id is referred
299
  explicitly by an insert statement (as is seen by executing "SET
300
  @@session.insert_id=0; CREATE TABLE t (a INT, b INT KEY
301
  AUTO_INCREMENT); INSERT INTO t(a) VALUES (@@session.insert_id);" in
302
  statement-based logging mode: t will be different on master and
303
  slave).
304
*/
1851.1.1 by Monty Taylor
Removed sys_var_chain.
305
static sys_var_readonly sys_error_count("error_count",
626 by Brian Aker
More of the same (ulong/64)
306
                                        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.
307
                                        SHOW_INT,
626 by Brian Aker
More of the same (ulong/64)
308
                                        get_error_count);
1851.1.1 by Monty Taylor
Removed sys_var_chain.
309
static sys_var_readonly sys_warning_count("warning_count",
626 by Brian Aker
More of the same (ulong/64)
310
                                          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.
311
                                          SHOW_INT,
626 by Brian Aker
More of the same (ulong/64)
312
                                          get_warning_count);
1 by brian
clean slate
313
1851.1.1 by Monty Taylor
Removed sys_var_chain.
314
sys_var_session_uint64_t sys_group_concat_max_len("group_concat_max_len",
1878.3.2 by Monty Taylor
Split out show_type into its own header and made sys_var work through
315
                                                  &drizzle_system_variables::group_concat_max_len);
1 by brian
clean slate
316
317
/* Global read-only variable containing hostname */
2183.1.2 by Monty Taylor
A slew of tiny meaningless changes.
318
static sys_var_const_string sys_hostname("hostname", getServerHostname());
319
320
static sys_var_const_str sys_revid("vc_revid", DRIZZLE7_VC_REVID);
321
static sys_var_const_str sys_branch("vc_branch", DRIZZLE7_VC_BRANCH);
322
static sys_var_size_t_ptr_readonly sys_revno("vc_revno", &revno);
323
static sys_var_size_t_ptr_readonly sys_release_id("vc_release_id", &release_id);
1 by brian
clean slate
324
1976.2.10 by Monty Taylor
Add ability to add a validation function to any sys_var. duh.
325
bool sys_var::check(Session *session, set_var *var)
1 by brian
clean slate
326
{
1976.2.10 by Monty Taylor
Add ability to add a validation function to any sys_var. duh.
327
  if (check_func)
328
  {
329
    int res;
330
    if ((res=(*check_func)(session, var)) < 0)
331
      my_error(ER_WRONG_VALUE_FOR_VAR, MYF(0), getName().c_str(), var->value->str_value.ptr());
332
    return res;
333
  }
2070.2.1 by Monty Taylor
First step in getting that anonymous union out of set_var.
334
  var->updateValue();
1 by brian
clean slate
335
  return 0;
336
}
337
520.1.22 by Brian Aker
Second pass of thd cleanup
338
bool sys_var_str::check(Session *session, set_var *var)
1 by brian
clean slate
339
{
1976.2.10 by Monty Taylor
Add ability to add a validation function to any sys_var. duh.
340
  if (!check_func)
341
    return 0;
342
1 by brian
clean slate
343
  int res;
520.1.22 by Brian Aker
Second pass of thd cleanup
344
  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.
345
    my_error(ER_WRONG_VALUE_FOR_VAR, MYF(0), getName().c_str(), var->value->str_value.ptr());
1 by brian
clean slate
346
  return res;
347
}
348
1945.1.2 by Monty Taylor
Add better support in constrained_check for min/max support. Add string ref class.
349
bool sys_var_std_string::check(Session *session, set_var *var)
350
{
351
  if (check_func == NULL)
352
  {
353
    return false;
354
  }
355
356
  int res= (*check_func)(session, var);
357
  if (res != 0)
358
  {
359
    my_error(ER_WRONG_VALUE_FOR_VAR, MYF(0), getName().c_str(), var->value->str_value.ptr());
360
    return true;
361
  }
362
  return false;
363
}
364
1 by brian
clean slate
365
/*
366
  Functions to check and update variables
367
*/
368
369
370
/**
371
  Set the OPTION_BIG_SELECTS flag if max_join_size == HA_POS_ERROR.
372
*/
373
1273.13.24 by Brian Aker
Updating style, simplified code.
374
static void fix_max_join_size(Session *session, sql_var_t type)
1 by brian
clean slate
375
{
376
  if (type != OPT_GLOBAL)
377
  {
520.1.22 by Brian Aker
Second pass of thd cleanup
378
    if (session->variables.max_join_size == HA_POS_ERROR)
379
      session->options|= OPTION_BIG_SELECTS;
1 by brian
clean slate
380
    else
520.1.22 by Brian Aker
Second pass of thd cleanup
381
      session->options&= ~OPTION_BIG_SELECTS;
1 by brian
clean slate
382
  }
383
}
384
385
386
/**
387
  Can't change the 'next' tx_isolation while we are already in
388
  a transaction
389
*/
520.1.22 by Brian Aker
Second pass of thd cleanup
390
static int check_tx_isolation(Session *session, set_var *var)
1 by brian
clean slate
391
{
520.1.22 by Brian Aker
Second pass of thd cleanup
392
  if (var->type == OPT_DEFAULT && (session->server_status & SERVER_STATUS_IN_TRANS))
1 by brian
clean slate
393
  {
394
    my_error(ER_CANT_CHANGE_TX_ISOLATION, MYF(0));
395
    return 1;
396
  }
397
  return 0;
398
}
399
400
/*
401
  If one doesn't use the SESSION modifier, the isolation level
402
  is only active for the next command.
403
*/
1273.13.24 by Brian Aker
Updating style, simplified code.
404
static void fix_tx_isolation(Session *session, sql_var_t type)
1 by brian
clean slate
405
{
406
  if (type == OPT_SESSION)
520.1.22 by Brian Aker
Second pass of thd cleanup
407
    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.
408
                                    session->variables.tx_isolation);
1 by brian
clean slate
409
}
410
1273.13.24 by Brian Aker
Updating style, simplified code.
411
static void fix_completion_type(Session *, sql_var_t) {}
1 by brian
clean slate
412
575.1.2 by Monty Taylor
Changed a bunch of __attribute__((unused)) to removing the parameter name instead.
413
static int check_completion_type(Session *, set_var *var)
1 by brian
clean slate
414
{
152 by Brian Aker
longlong replacement
415
  int64_t val= var->value->val_int();
1 by brian
clean slate
416
  if (val < 0 || val > 2)
417
  {
418
    char buf[64];
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
419
    my_error(ER_WRONG_VALUE_FOR_VAR, MYF(0), var->var->getName().c_str(), internal::llstr(val, buf));
1 by brian
clean slate
420
    return 1;
421
  }
422
  return 0;
423
}
424
425
1273.13.24 by Brian Aker
Updating style, simplified code.
426
static void fix_session_mem_root(Session *session, sql_var_t type)
520.1.22 by Brian Aker
Second pass of thd cleanup
427
{
428
  if (type != OPT_GLOBAL)
1485 by Brian Aker
Updates to confine memroot
429
    session->mem_root->reset_root_defaults(session->variables.query_alloc_block_size,
430
                                           session->variables.query_prealloc_size);
520.1.22 by Brian Aker
Second pass of thd cleanup
431
}
432
433
1273.13.24 by Brian Aker
Updating style, simplified code.
434
static void fix_server_id(Session *, sql_var_t)
1 by brian
clean slate
435
{
436
}
437
438
520.1.22 by Brian Aker
Second pass of thd cleanup
439
bool throw_bounds_warning(Session *session, bool fixed, bool unsignd,
1022.2.38 by Monty Taylor
Changed name to std::string.
440
                          const std::string &name, int64_t val)
1 by brian
clean slate
441
{
442
  if (fixed)
443
  {
2148.5.3 by Brian Aker
Remove hard coded array for numbers (this also fixes a couple of spots where
444
    char buf[DECIMAL_LONGLONG_DIGITS];
1 by brian
clean slate
445
446
    if (unsignd)
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
447
      internal::ullstr((uint64_t) val, buf);
1 by brian
clean slate
448
    else
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
449
      internal::llstr(val, buf);
1 by brian
clean slate
450
910.4.10 by Stewart Smith
fix system variables for correct endian architectures.
451
    push_warning_printf(session, DRIZZLE_ERROR::WARN_LEVEL_ERROR,
1 by brian
clean slate
452
                        ER_TRUNCATED_WRONG_VALUE,
1022.2.38 by Monty Taylor
Changed name to std::string.
453
                        ER(ER_TRUNCATED_WRONG_VALUE), name.c_str(), buf);
1 by brian
clean slate
454
  }
51.1.46 by Jay Pipes
Removed/replaced DBUG symbols and standardized TRUE/FALSE
455
  return false;
1 by brian
clean slate
456
}
457
1251.2.2 by Jay Pipes
Pulls MyISAM-specific server variables into the MyISAM
458
uint64_t fix_unsigned(Session *session, uint64_t num,
1410.3.4 by Djellel E. Difallah
update references to old my_'s
459
                              const struct option *option_limits)
1 by brian
clean slate
460
{
143 by Brian Aker
Bool cleanup.
461
  bool fixed= false;
151 by Brian Aker
Ulonglong to uint64_t
462
  uint64_t out= getopt_ull_limit_value(num, option_limits, &fixed);
1 by brian
clean slate
463
520.1.22 by Brian Aker
Second pass of thd cleanup
464
  throw_bounds_warning(session, fixed, true, option_limits->name, (int64_t) num);
1 by brian
clean slate
465
  return out;
466
}
467
629.4.1 by Monty Taylor
First step in support size_t sys_var stuff.
468
469
static size_t fix_size_t(Session *session, size_t num,
1410.3.4 by Djellel E. Difallah
update references to old my_'s
470
                           const struct option *option_limits)
629.4.1 by Monty Taylor
First step in support size_t sys_var stuff.
471
{
472
  bool fixed= false;
473
  size_t out= (size_t)getopt_ull_limit_value(num, option_limits, &fixed);
474
475
  throw_bounds_warning(session, fixed, true, option_limits->name, (int64_t) num);
476
  return out;
477
}
478
910.4.10 by Stewart Smith
fix system variables for correct endian architectures.
479
bool sys_var_uint32_t_ptr::check(Session *, set_var *var)
480
{
2070.2.2 by Monty Taylor
Removed some guts from set_var.
481
  var->updateValue();
1 by brian
clean slate
482
  return 0;
483
}
484
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.
485
bool sys_var_uint32_t_ptr::update(Session *session, set_var *var)
486
{
2070.2.2 by Monty Taylor
Removed some guts from set_var.
487
  uint64_t tmp= var->getInteger();
2114.3.1 by Brian Aker
Move variable lock into the catalog that the variables belong too.
488
  boost::mutex::scoped_lock scopedLock(session->catalog().systemVariableLock());
489
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.
490
  if (option_limits)
910.4.10 by Stewart Smith
fix system variables for correct endian architectures.
491
  {
492
    uint32_t newvalue= (uint32_t) fix_unsigned(session, tmp, option_limits);
2070.2.2 by Monty Taylor
Removed some guts from set_var.
493
    if(static_cast<uint64_t>(newvalue) == tmp)
910.4.10 by Stewart Smith
fix system variables for correct endian architectures.
494
      *value= newvalue;
495
  }
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.
496
  else
2114.3.1 by Brian Aker
Move variable lock into the catalog that the variables belong too.
497
  {
2070.2.2 by Monty Taylor
Removed some guts from set_var.
498
    *value= static_cast<uint32_t>(tmp);
2114.3.1 by Brian Aker
Move variable lock into the catalog that the variables belong too.
499
  }
500
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.
501
  return 0;
502
}
503
504
2114.3.1 by Brian Aker
Move variable lock into the catalog that the variables belong too.
505
void sys_var_uint32_t_ptr::set_default(Session *session, sql_var_t)
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.
506
{
507
  bool not_used;
2114.3.1 by Brian Aker
Move variable lock into the catalog that the variables belong too.
508
  boost::mutex::scoped_lock scopedLock(session->catalog().systemVariableLock());
892.2.2 by Monty Taylor
More solaris warnings.
509
  *value= (uint32_t)getopt_ull_limit_value((uint32_t) option_limits->def_value,
510
                                           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.
511
}
512
1 by brian
clean slate
513
520.1.22 by Brian Aker
Second pass of thd cleanup
514
bool sys_var_uint64_t_ptr::update(Session *session, set_var *var)
1 by brian
clean slate
515
{
2070.2.2 by Monty Taylor
Removed some guts from set_var.
516
  uint64_t tmp= var->getInteger();
2114.3.1 by Brian Aker
Move variable lock into the catalog that the variables belong too.
517
  boost::mutex::scoped_lock scopedLock(session->catalog().systemVariableLock());
518
1 by brian
clean slate
519
  if (option_limits)
910.4.10 by Stewart Smith
fix system variables for correct endian architectures.
520
  {
2070.2.2 by Monty Taylor
Removed some guts from set_var.
521
    uint64_t newvalue= fix_unsigned(session, tmp, option_limits);
910.4.10 by Stewart Smith
fix system variables for correct endian architectures.
522
    if(newvalue==tmp)
523
      *value= newvalue;
524
  }
1 by brian
clean slate
525
  else
2114.3.1 by Brian Aker
Move variable lock into the catalog that the variables belong too.
526
  {
2070.2.2 by Monty Taylor
Removed some guts from set_var.
527
    *value= tmp;
2114.3.1 by Brian Aker
Move variable lock into the catalog that the variables belong too.
528
  }
529
1 by brian
clean slate
530
  return 0;
531
}
532
533
2114.3.1 by Brian Aker
Move variable lock into the catalog that the variables belong too.
534
void sys_var_uint64_t_ptr::set_default(Session *session, sql_var_t)
1 by brian
clean slate
535
{
1897.4.14 by Monty Taylor
Update to support default values and properly throw warnings on value
536
  if (have_default_value)
537
  {
538
    *value= default_value;
539
  }
540
  else
541
  {
542
    bool not_used;
2114.3.1 by Brian Aker
Move variable lock into the catalog that the variables belong too.
543
    boost::mutex::scoped_lock scopedLock(session->catalog().systemVariableLock());
1897.4.14 by Monty Taylor
Update to support default values and properly throw warnings on value
544
    *value= getopt_ull_limit_value((uint64_t) option_limits->def_value,
545
                                   option_limits, &not_used);
546
  }
1 by brian
clean slate
547
}
548
549
629.4.1 by Monty Taylor
First step in support size_t sys_var stuff.
550
bool sys_var_size_t_ptr::update(Session *session, set_var *var)
551
{
2070.2.2 by Monty Taylor
Removed some guts from set_var.
552
  size_t tmp= size_t(var->getInteger());
2114.3.1 by Brian Aker
Move variable lock into the catalog that the variables belong too.
553
554
  boost::mutex::scoped_lock scopedLock(session->catalog().systemVariableLock());
555
629.4.1 by Monty Taylor
First step in support size_t sys_var stuff.
556
  if (option_limits)
557
    *value= fix_size_t(session, tmp, option_limits);
558
  else
559
    *value= tmp;
2114.3.1 by Brian Aker
Move variable lock into the catalog that the variables belong too.
560
629.4.1 by Monty Taylor
First step in support size_t sys_var stuff.
561
  return 0;
562
}
563
564
2114.3.1 by Brian Aker
Move variable lock into the catalog that the variables belong too.
565
void sys_var_size_t_ptr::set_default(Session *session, sql_var_t)
629.4.1 by Monty Taylor
First step in support size_t sys_var stuff.
566
{
567
  bool not_used;
2114.3.1 by Brian Aker
Move variable lock into the catalog that the variables belong too.
568
  boost::mutex::scoped_lock scopedLock(session->catalog().systemVariableLock());
629.4.1 by Monty Taylor
First step in support size_t sys_var stuff.
569
  *value= (size_t)getopt_ull_limit_value((size_t) option_limits->def_value,
570
                                         option_limits, &not_used);
571
}
572
2119.4.1 by Monty Taylor
Turns on -fvisibility=hidden by default. Symbols intended to be used by
573
bool sys_var_bool_ptr::check(Session *session, set_var *var)
574
{
575
  return check_enum(session, var, &bool_typelib);
576
}
577
575.1.2 by Monty Taylor
Changed a bunch of __attribute__((unused)) to removing the parameter name instead.
578
bool sys_var_bool_ptr::update(Session *, set_var *var)
1 by brian
clean slate
579
{
2070.2.2 by Monty Taylor
Removed some guts from set_var.
580
  *value= bool(var->getInteger());
1 by brian
clean slate
581
  return 0;
582
}
583
584
1273.13.24 by Brian Aker
Updating style, simplified code.
585
void sys_var_bool_ptr::set_default(Session *, sql_var_t)
1 by brian
clean slate
586
{
1964.2.16 by Monty Taylor
took care of innodb SessionVAR usage.
587
  *value= default_value;
146 by Brian Aker
my_bool cleanup.
588
}
589
1 by brian
clean slate
590
615 by Brian Aker
Added 32bit system variable support
591
/*
660.1.3 by Eric Herman
removed trailing whitespace with simple script:
592
  32 bit types for session variables
615 by Brian Aker
Added 32bit system variable support
593
*/
594
bool sys_var_session_uint32_t::check(Session *session, set_var *var)
595
{
2070.2.2 by Monty Taylor
Removed some guts from set_var.
596
  var->updateValue();
597
  return (check_func && (*check_func)(session, var));
615 by Brian Aker
Added 32bit system variable support
598
}
599
600
bool sys_var_session_uint32_t::update(Session *session, set_var *var)
601
{
2070.2.2 by Monty Taylor
Removed some guts from set_var.
602
  uint64_t tmp= var->getInteger();
660.1.3 by Eric Herman
removed trailing whitespace with simple script:
603
615 by Brian Aker
Added 32bit system variable support
604
  /* Don't use bigger value than given with --maximum-variable-name=.. */
605
  if ((uint32_t) tmp > max_system_variables.*offset)
606
  {
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.
607
    throw_bounds_warning(session, true, true, getName(), (int64_t) tmp);
615 by Brian Aker
Added 32bit system variable support
608
    tmp= max_system_variables.*offset;
609
  }
660.1.3 by Eric Herman
removed trailing whitespace with simple script:
610
615 by Brian Aker
Added 32bit system variable support
611
  if (option_limits)
612
    tmp= (uint32_t) fix_unsigned(session, tmp, option_limits);
613
  else if (tmp > UINT32_MAX)
614
  {
615
    tmp= UINT32_MAX;
2070.2.2 by Monty Taylor
Removed some guts from set_var.
616
    throw_bounds_warning(session, true, true, getName(), int64_t(var->getInteger()));
615 by Brian Aker
Added 32bit system variable support
617
  }
660.1.3 by Eric Herman
removed trailing whitespace with simple script:
618
615 by Brian Aker
Added 32bit system variable support
619
  if (var->type == OPT_GLOBAL)
620
     global_system_variables.*offset= (uint32_t) tmp;
621
   else
622
     session->variables.*offset= (uint32_t) tmp;
623
624
   return 0;
625
 }
626
627
1273.13.24 by Brian Aker
Updating style, simplified code.
628
 void sys_var_session_uint32_t::set_default(Session *session, sql_var_t type)
615 by Brian Aker
Added 32bit system variable support
629
 {
630
   if (type == OPT_GLOBAL)
631
   {
632
     bool not_used;
633
     /* We will not come here if option_limits is not set */
634
     global_system_variables.*offset=
635
       (uint32_t) getopt_ull_limit_value((uint32_t) option_limits->def_value,
636
                                      option_limits, &not_used);
637
   }
638
   else
639
     session->variables.*offset= global_system_variables.*offset;
640
 }
641
642
643
unsigned char *sys_var_session_uint32_t::value_ptr(Session *session,
1273.13.24 by Brian Aker
Updating style, simplified code.
644
                                                sql_var_t type,
779.3.10 by Monty Taylor
Turned on -Wshadow.
645
                                                const LEX_STRING *)
615 by Brian Aker
Added 32bit system variable support
646
{
647
  if (type == OPT_GLOBAL)
648
    return (unsigned char*) &(global_system_variables.*offset);
649
  return (unsigned char*) &(session->variables.*offset);
650
}
651
1 by brian
clean slate
652
520.1.22 by Brian Aker
Second pass of thd cleanup
653
bool sys_var_session_ha_rows::update(Session *session, set_var *var)
1 by brian
clean slate
654
{
2070.2.2 by Monty Taylor
Removed some guts from set_var.
655
  uint64_t tmp= var->getInteger();
1 by brian
clean slate
656
657
  /* Don't use bigger value than given with --maximum-variable-name=.. */
658
  if ((ha_rows) tmp > max_system_variables.*offset)
659
    tmp= max_system_variables.*offset;
660
661
  if (option_limits)
520.1.22 by Brian Aker
Second pass of thd cleanup
662
    tmp= (ha_rows) fix_unsigned(session, tmp, option_limits);
1 by brian
clean slate
663
  if (var->type == OPT_GLOBAL)
664
  {
665
    /* Lock is needed to make things safe on 32 bit systems */
2114.3.1 by Brian Aker
Move variable lock into the catalog that the variables belong too.
666
    boost::mutex::scoped_lock scopedLock(session->catalog().systemVariableLock());
1 by brian
clean slate
667
    global_system_variables.*offset= (ha_rows) tmp;
668
  }
669
  else
2114.3.1 by Brian Aker
Move variable lock into the catalog that the variables belong too.
670
  {
520.1.22 by Brian Aker
Second pass of thd cleanup
671
    session->variables.*offset= (ha_rows) tmp;
2114.3.1 by Brian Aker
Move variable lock into the catalog that the variables belong too.
672
  }
673
1 by brian
clean slate
674
  return 0;
675
}
676
677
1273.13.24 by Brian Aker
Updating style, simplified code.
678
void sys_var_session_ha_rows::set_default(Session *session, sql_var_t type)
1 by brian
clean slate
679
{
680
  if (type == OPT_GLOBAL)
681
  {
143 by Brian Aker
Bool cleanup.
682
    bool not_used;
1 by brian
clean slate
683
    /* We will not come here if option_limits is not set */
2114.3.1 by Brian Aker
Move variable lock into the catalog that the variables belong too.
684
    boost::mutex::scoped_lock scopedLock(session->catalog().systemVariableLock());
1 by brian
clean slate
685
    global_system_variables.*offset=
686
      (ha_rows) getopt_ull_limit_value((ha_rows) option_limits->def_value,
687
                                       option_limits, &not_used);
688
  }
689
  else
2114.3.1 by Brian Aker
Move variable lock into the catalog that the variables belong too.
690
  {
520.1.22 by Brian Aker
Second pass of thd cleanup
691
    session->variables.*offset= global_system_variables.*offset;
2114.3.1 by Brian Aker
Move variable lock into the catalog that the variables belong too.
692
  }
1 by brian
clean slate
693
}
694
695
575.1.2 by Monty Taylor
Changed a bunch of __attribute__((unused)) to removing the parameter name instead.
696
unsigned char *sys_var_session_ha_rows::value_ptr(Session *session,
1273.13.24 by Brian Aker
Updating style, simplified code.
697
                                                  sql_var_t type,
779.3.10 by Monty Taylor
Turned on -Wshadow.
698
                                                  const LEX_STRING *)
1 by brian
clean slate
699
{
700
  if (type == OPT_GLOBAL)
481 by Brian Aker
Remove all of uchar.
701
    return (unsigned char*) &(global_system_variables.*offset);
520.1.22 by Brian Aker
Second pass of thd cleanup
702
  return (unsigned char*) &(session->variables.*offset);
1 by brian
clean slate
703
}
704
520.1.22 by Brian Aker
Second pass of thd cleanup
705
bool sys_var_session_uint64_t::check(Session *session, set_var *var)
1 by brian
clean slate
706
{
2070.2.2 by Monty Taylor
Removed some guts from set_var.
707
  var->updateValue();
708
  return (check_func && (*check_func)(session, var));
1 by brian
clean slate
709
}
710
520.1.22 by Brian Aker
Second pass of thd cleanup
711
bool sys_var_session_uint64_t::update(Session *session,  set_var *var)
1 by brian
clean slate
712
{
2070.2.2 by Monty Taylor
Removed some guts from set_var.
713
  uint64_t tmp= var->getInteger();
1 by brian
clean slate
714
715
  if (tmp > max_system_variables.*offset)
1124.2.2 by Diego Medina
Added missing { } for if statement
716
  {
717
    throw_bounds_warning(session, true, true, getName(), (int64_t) tmp);
1 by brian
clean slate
718
    tmp= max_system_variables.*offset;
1124.2.2 by Diego Medina
Added missing { } for if statement
719
  }
1 by brian
clean slate
720
721
  if (option_limits)
520.1.22 by Brian Aker
Second pass of thd cleanup
722
    tmp= fix_unsigned(session, tmp, option_limits);
1 by brian
clean slate
723
  if (var->type == OPT_GLOBAL)
724
  {
725
    /* Lock is needed to make things safe on 32 bit systems */
2114.3.1 by Brian Aker
Move variable lock into the catalog that the variables belong too.
726
    boost::mutex::scoped_lock scopedLock(session->catalog().systemVariableLock());
151 by Brian Aker
Ulonglong to uint64_t
727
    global_system_variables.*offset= (uint64_t) tmp;
1 by brian
clean slate
728
  }
729
  else
2114.3.1 by Brian Aker
Move variable lock into the catalog that the variables belong too.
730
  {
520.1.22 by Brian Aker
Second pass of thd cleanup
731
    session->variables.*offset= (uint64_t) tmp;
2114.3.1 by Brian Aker
Move variable lock into the catalog that the variables belong too.
732
  }
733
1 by brian
clean slate
734
  return 0;
735
}
736
737
1273.13.24 by Brian Aker
Updating style, simplified code.
738
void sys_var_session_uint64_t::set_default(Session *session, sql_var_t type)
1 by brian
clean slate
739
{
740
  if (type == OPT_GLOBAL)
741
  {
143 by Brian Aker
Bool cleanup.
742
    bool not_used;
2114.3.1 by Brian Aker
Move variable lock into the catalog that the variables belong too.
743
    boost::mutex::scoped_lock scopedLock(session->catalog().systemVariableLock());
1 by brian
clean slate
744
    global_system_variables.*offset=
151 by Brian Aker
Ulonglong to uint64_t
745
      getopt_ull_limit_value((uint64_t) option_limits->def_value,
1 by brian
clean slate
746
                             option_limits, &not_used);
747
  }
748
  else
2114.3.1 by Brian Aker
Move variable lock into the catalog that the variables belong too.
749
  {
520.1.22 by Brian Aker
Second pass of thd cleanup
750
    session->variables.*offset= global_system_variables.*offset;
2114.3.1 by Brian Aker
Move variable lock into the catalog that the variables belong too.
751
  }
1 by brian
clean slate
752
}
753
754
575.1.2 by Monty Taylor
Changed a bunch of __attribute__((unused)) to removing the parameter name instead.
755
unsigned char *sys_var_session_uint64_t::value_ptr(Session *session,
1273.13.24 by Brian Aker
Updating style, simplified code.
756
                                                   sql_var_t type,
779.3.10 by Monty Taylor
Turned on -Wshadow.
757
                                                   const LEX_STRING *)
1 by brian
clean slate
758
{
759
  if (type == OPT_GLOBAL)
481 by Brian Aker
Remove all of uchar.
760
    return (unsigned char*) &(global_system_variables.*offset);
520.1.22 by Brian Aker
Second pass of thd cleanup
761
  return (unsigned char*) &(session->variables.*offset);
1 by brian
clean slate
762
}
763
629.4.1 by Monty Taylor
First step in support size_t sys_var stuff.
764
bool sys_var_session_size_t::check(Session *session, set_var *var)
765
{
2070.2.2 by Monty Taylor
Removed some guts from set_var.
766
  var->updateValue();
767
  return (check_func && (*check_func)(session, var));
629.4.1 by Monty Taylor
First step in support size_t sys_var stuff.
768
}
769
770
bool sys_var_session_size_t::update(Session *session,  set_var *var)
771
{
2070.2.2 by Monty Taylor
Removed some guts from set_var.
772
  size_t tmp= size_t(var->getInteger());
629.4.1 by Monty Taylor
First step in support size_t sys_var stuff.
773
774
  if (tmp > max_system_variables.*offset)
775
    tmp= max_system_variables.*offset;
776
777
  if (option_limits)
778
    tmp= fix_size_t(session, tmp, option_limits);
779
  if (var->type == OPT_GLOBAL)
780
  {
781
    /* Lock is needed to make things safe on 32 bit systems */
2114.3.1 by Brian Aker
Move variable lock into the catalog that the variables belong too.
782
    boost::mutex::scoped_lock scopedLock(session->catalog().systemVariableLock());
629.4.1 by Monty Taylor
First step in support size_t sys_var stuff.
783
    global_system_variables.*offset= tmp;
784
  }
785
  else
2114.3.1 by Brian Aker
Move variable lock into the catalog that the variables belong too.
786
  {
629.4.1 by Monty Taylor
First step in support size_t sys_var stuff.
787
    session->variables.*offset= tmp;
2114.3.1 by Brian Aker
Move variable lock into the catalog that the variables belong too.
788
  }
789
629.4.1 by Monty Taylor
First step in support size_t sys_var stuff.
790
  return 0;
791
}
792
793
1273.13.24 by Brian Aker
Updating style, simplified code.
794
void sys_var_session_size_t::set_default(Session *session, sql_var_t type)
629.4.1 by Monty Taylor
First step in support size_t sys_var stuff.
795
{
796
  if (type == OPT_GLOBAL)
797
  {
798
    bool not_used;
2114.3.1 by Brian Aker
Move variable lock into the catalog that the variables belong too.
799
    boost::mutex::scoped_lock scopedLock(session->catalog().systemVariableLock());
629.4.1 by Monty Taylor
First step in support size_t sys_var stuff.
800
    global_system_variables.*offset=
892.2.2 by Monty Taylor
More solaris warnings.
801
      (size_t)getopt_ull_limit_value((size_t) option_limits->def_value,
802
                                     option_limits, &not_used);
629.4.1 by Monty Taylor
First step in support size_t sys_var stuff.
803
  }
804
  else
2114.3.1 by Brian Aker
Move variable lock into the catalog that the variables belong too.
805
  {
629.4.1 by Monty Taylor
First step in support size_t sys_var stuff.
806
    session->variables.*offset= global_system_variables.*offset;
2114.3.1 by Brian Aker
Move variable lock into the catalog that the variables belong too.
807
  }
629.4.1 by Monty Taylor
First step in support size_t sys_var stuff.
808
}
809
810
811
unsigned char *sys_var_session_size_t::value_ptr(Session *session,
1273.13.24 by Brian Aker
Updating style, simplified code.
812
                                                 sql_var_t type,
779.3.10 by Monty Taylor
Turned on -Wshadow.
813
                                                 const LEX_STRING *)
629.4.1 by Monty Taylor
First step in support size_t sys_var stuff.
814
{
815
  if (type == OPT_GLOBAL)
816
    return (unsigned char*) &(global_system_variables.*offset);
817
  return (unsigned char*) &(session->variables.*offset);
818
}
819
2119.4.1 by Monty Taylor
Turns on -fvisibility=hidden by default. Symbols intended to be used by
820
bool sys_var_session_bool::check(Session *session, set_var *var)
821
{
822
  return check_enum(session, var, &bool_typelib);
823
}
1 by brian
clean slate
824
520.1.22 by Brian Aker
Second pass of thd cleanup
825
bool sys_var_session_bool::update(Session *session,  set_var *var)
1 by brian
clean slate
826
{
827
  if (var->type == OPT_GLOBAL)
2070.2.2 by Monty Taylor
Removed some guts from set_var.
828
    global_system_variables.*offset= bool(var->getInteger());
1 by brian
clean slate
829
  else
2070.2.2 by Monty Taylor
Removed some guts from set_var.
830
    session->variables.*offset= bool(var->getInteger());
2114.3.1 by Brian Aker
Move variable lock into the catalog that the variables belong too.
831
1 by brian
clean slate
832
  return 0;
833
}
834
835
1273.13.24 by Brian Aker
Updating style, simplified code.
836
void sys_var_session_bool::set_default(Session *session,  sql_var_t type)
1 by brian
clean slate
837
{
838
  if (type == OPT_GLOBAL)
200 by Brian Aker
my_bool from handler and set_var
839
    global_system_variables.*offset= (bool) option_limits->def_value;
1 by brian
clean slate
840
  else
520.1.22 by Brian Aker
Second pass of thd cleanup
841
    session->variables.*offset= global_system_variables.*offset;
1 by brian
clean slate
842
}
843
844
575.1.2 by Monty Taylor
Changed a bunch of __attribute__((unused)) to removing the parameter name instead.
845
unsigned char *sys_var_session_bool::value_ptr(Session *session,
1273.13.24 by Brian Aker
Updating style, simplified code.
846
                                               sql_var_t type,
779.3.10 by Monty Taylor
Turned on -Wshadow.
847
                                               const LEX_STRING *)
1 by brian
clean slate
848
{
849
  if (type == OPT_GLOBAL)
481 by Brian Aker
Remove all of uchar.
850
    return (unsigned char*) &(global_system_variables.*offset);
520.1.22 by Brian Aker
Second pass of thd cleanup
851
  return (unsigned char*) &(session->variables.*offset);
1 by brian
clean slate
852
}
853
854
575.1.2 by Monty Taylor
Changed a bunch of __attribute__((unused)) to removing the parameter name instead.
855
bool sys_var::check_enum(Session *,
77.1.45 by Monty Taylor
Warning fixes.
856
                         set_var *var, const TYPELIB *enum_names)
1 by brian
clean slate
857
{
858
  char buff[STRING_BUFFER_USUAL_SIZE];
859
  const char *value;
860
  String str(buff, sizeof(buff), system_charset_info), *res;
861
862
  if (var->value->result_type() == STRING_RESULT)
863
  {
2070.2.2 by Monty Taylor
Removed some guts from set_var.
864
    res= var->value->val_str(&str);
865
    if (res == NULL)
1 by brian
clean slate
866
    {
2070.2.2 by Monty Taylor
Removed some guts from set_var.
867
      value= "NULL";
1 by brian
clean slate
868
      goto err;
869
    }
971.2.1 by Eric Day
Fix for bug #311025. This was due to code that was removed during ulong cleanup (r576).
870
2151.5.4 by Olaf van der Spek
Move strfunc functions into TYPELIB class
871
    uint64_t tmp_val= enum_names->find_type(res->ptr(), res->length(), true);
2070.2.2 by Monty Taylor
Removed some guts from set_var.
872
    if (tmp_val == 0)
873
    {
874
      value= res->c_ptr();
875
      goto err;
876
    }
877
    var->setValue(tmp_val-1);
1 by brian
clean slate
878
  }
879
  else
880
  {
2070.2.2 by Monty Taylor
Removed some guts from set_var.
881
    uint64_t tmp= var->value->val_int();
1 by brian
clean slate
882
    if (tmp >= enum_names->count)
883
    {
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
884
      internal::llstr(tmp,buff);
1 by brian
clean slate
885
      value=buff;				// Wrong value is here
886
      goto err;
887
    }
2070.2.2 by Monty Taylor
Removed some guts from set_var.
888
    var->setValue(tmp);	// Save for update
1 by brian
clean slate
889
  }
890
  return 0;
891
892
err:
1022.2.38 by Monty Taylor
Changed name to std::string.
893
  my_error(ER_WRONG_VALUE_FOR_VAR, MYF(0), name.c_str(), value);
1 by brian
clean slate
894
  return 1;
895
}
896
897
898
/**
899
  Return an Item for a variable.
900
901
  Used with @@[global.]variable_name.
902
903
  If type is not given, return local value if exists, else global.
904
*/
905
1273.13.24 by Brian Aker
Updating style, simplified code.
906
Item *sys_var::item(Session *session, sql_var_t var_type, const LEX_STRING *base)
1 by brian
clean slate
907
{
908
  if (check_type(var_type))
909
  {
910
    if (var_type != OPT_DEFAULT)
911
    {
912
      my_error(ER_INCORRECT_GLOBAL_LOCAL_VAR, MYF(0),
1022.2.38 by Monty Taylor
Changed name to std::string.
913
               name.c_str(), var_type == OPT_GLOBAL ? "SESSION" : "GLOBAL");
1 by brian
clean slate
914
      return 0;
915
    }
916
    /* As there was no local variable, return the global value */
917
    var_type= OPT_GLOBAL;
918
  }
919
  switch (show_type()) {
625 by Brian Aker
ulong/64 bit straighten out.
920
  case SHOW_LONG:
1 by brian
clean slate
921
  case SHOW_INT:
922
  {
482 by Brian Aker
Remove uint.
923
    uint32_t value;
2114.3.1 by Brian Aker
Move variable lock into the catalog that the variables belong too.
924
    boost::mutex::scoped_lock scopedLock(session->catalog().systemVariableLock());
520.1.22 by Brian Aker
Second pass of thd cleanup
925
    value= *(uint*) value_ptr(session, var_type, base);
2114.3.1 by Brian Aker
Move variable lock into the catalog that the variables belong too.
926
151 by Brian Aker
Ulonglong to uint64_t
927
    return new Item_uint((uint64_t) value);
1 by brian
clean slate
928
  }
929
  case SHOW_LONGLONG:
930
  {
152 by Brian Aker
longlong replacement
931
    int64_t value;
2114.3.1 by Brian Aker
Move variable lock into the catalog that the variables belong too.
932
    boost::mutex::scoped_lock scopedLock(session->catalog().systemVariableLock());
520.1.22 by Brian Aker
Second pass of thd cleanup
933
    value= *(int64_t*) value_ptr(session, var_type, base);
2114.3.1 by Brian Aker
Move variable lock into the catalog that the variables belong too.
934
1 by brian
clean slate
935
    return new Item_int(value);
936
  }
937
  case SHOW_DOUBLE:
938
  {
939
    double value;
2114.3.1 by Brian Aker
Move variable lock into the catalog that the variables belong too.
940
    {
941
      boost::mutex::scoped_lock scopedLock(session->catalog().systemVariableLock());
942
      value= *(double*) value_ptr(session, var_type, base);
943
    }
944
1 by brian
clean slate
945
    /* 6, as this is for now only used with microseconds */
946
    return new Item_float(value, 6);
947
  }
948
  case SHOW_HA_ROWS:
949
  {
950
    ha_rows value;
2114.3.1 by Brian Aker
Move variable lock into the catalog that the variables belong too.
951
    boost::mutex::scoped_lock scopedLock(session->catalog().systemVariableLock());
520.1.22 by Brian Aker
Second pass of thd cleanup
952
    value= *(ha_rows*) value_ptr(session, var_type, base);
2114.3.1 by Brian Aker
Move variable lock into the catalog that the variables belong too.
953
151 by Brian Aker
Ulonglong to uint64_t
954
    return new Item_int((uint64_t) value);
1 by brian
clean slate
955
  }
673.3.17 by Stewart Smith
mostly fix repair test. fix syntax for Drizzle (all tests are MyISAM reliant).
956
  case SHOW_SIZE:
957
  {
958
    size_t value;
2114.3.1 by Brian Aker
Move variable lock into the catalog that the variables belong too.
959
    boost::mutex::scoped_lock scopedLock(session->catalog().systemVariableLock());
673.3.17 by Stewart Smith
mostly fix repair test. fix syntax for Drizzle (all tests are MyISAM reliant).
960
    value= *(size_t*) value_ptr(session, var_type, base);
2114.3.1 by Brian Aker
Move variable lock into the catalog that the variables belong too.
961
673.3.17 by Stewart Smith
mostly fix repair test. fix syntax for Drizzle (all tests are MyISAM reliant).
962
    return new Item_int((uint64_t) value);
963
  }
1 by brian
clean slate
964
  case SHOW_MY_BOOL:
965
  {
205 by Brian Aker
uint32 -> uin32_t
966
    int32_t value;
2114.3.1 by Brian Aker
Move variable lock into the catalog that the variables belong too.
967
    boost::mutex::scoped_lock scopedLock(session->catalog().systemVariableLock());
520.1.22 by Brian Aker
Second pass of thd cleanup
968
    value= *(bool*) value_ptr(session, var_type, base);
1 by brian
clean slate
969
    return new Item_int(value,1);
970
  }
971
  case SHOW_CHAR_PTR:
972
  {
973
    Item *tmp;
2114.3.1 by Brian Aker
Move variable lock into the catalog that the variables belong too.
974
    boost::mutex::scoped_lock scopedLock(session->catalog().systemVariableLock());
520.1.22 by Brian Aker
Second pass of thd cleanup
975
    char *str= *(char**) value_ptr(session, var_type, base);
1 by brian
clean slate
976
    if (str)
977
    {
482 by Brian Aker
Remove uint.
978
      uint32_t length= strlen(str);
520.1.22 by Brian Aker
Second pass of thd cleanup
979
      tmp= new Item_string(session->strmake(str, length), length,
1 by brian
clean slate
980
                           system_charset_info, DERIVATION_SYSCONST);
981
    }
982
    else
983
    {
984
      tmp= new Item_null();
985
      tmp->collation.set(system_charset_info, DERIVATION_SYSCONST);
986
    }
2114.3.1 by Brian Aker
Move variable lock into the catalog that the variables belong too.
987
1 by brian
clean slate
988
    return tmp;
989
  }
990
  case SHOW_CHAR:
991
  {
992
    Item *tmp;
2114.3.1 by Brian Aker
Move variable lock into the catalog that the variables belong too.
993
    boost::mutex::scoped_lock scopedLock(session->catalog().systemVariableLock());
520.1.22 by Brian Aker
Second pass of thd cleanup
994
    char *str= (char*) value_ptr(session, var_type, base);
1 by brian
clean slate
995
    if (str)
996
      tmp= new Item_string(str, strlen(str),
997
                           system_charset_info, DERIVATION_SYSCONST);
998
    else
999
    {
1000
      tmp= new Item_null();
1001
      tmp->collation.set(system_charset_info, DERIVATION_SYSCONST);
1002
    }
2114.3.1 by Brian Aker
Move variable lock into the catalog that the variables belong too.
1003
1 by brian
clean slate
1004
    return tmp;
1005
  }
1006
  default:
1022.2.38 by Monty Taylor
Changed name to std::string.
1007
    my_error(ER_VAR_CANT_BE_READ, MYF(0), name.c_str());
1 by brian
clean slate
1008
  }
1009
  return 0;
1010
}
1011
1012
520.1.22 by Brian Aker
Second pass of thd cleanup
1013
bool sys_var_session_enum::update(Session *session, set_var *var)
1 by brian
clean slate
1014
{
1015
  if (var->type == OPT_GLOBAL)
2070.2.2 by Monty Taylor
Removed some guts from set_var.
1016
    global_system_variables.*offset= var->getInteger();
1 by brian
clean slate
1017
  else
2070.2.2 by Monty Taylor
Removed some guts from set_var.
1018
    session->variables.*offset= var->getInteger();
1 by brian
clean slate
1019
  return 0;
1020
}
1021
1022
1273.13.24 by Brian Aker
Updating style, simplified code.
1023
void sys_var_session_enum::set_default(Session *session, sql_var_t type)
1 by brian
clean slate
1024
{
1025
  if (type == OPT_GLOBAL)
621 by Brian Aker
ulong fixes
1026
    global_system_variables.*offset= (uint32_t) option_limits->def_value;
1 by brian
clean slate
1027
  else
520.1.22 by Brian Aker
Second pass of thd cleanup
1028
    session->variables.*offset= global_system_variables.*offset;
1 by brian
clean slate
1029
}
1030
1031
575.1.2 by Monty Taylor
Changed a bunch of __attribute__((unused)) to removing the parameter name instead.
1032
unsigned char *sys_var_session_enum::value_ptr(Session *session,
1273.13.24 by Brian Aker
Updating style, simplified code.
1033
                                               sql_var_t type,
779.3.10 by Monty Taylor
Turned on -Wshadow.
1034
                                               const LEX_STRING *)
1 by brian
clean slate
1035
{
621 by Brian Aker
ulong fixes
1036
  uint32_t tmp= ((type == OPT_GLOBAL) ?
1 by brian
clean slate
1037
	      global_system_variables.*offset :
520.1.22 by Brian Aker
Second pass of thd cleanup
1038
	      session->variables.*offset);
481 by Brian Aker
Remove all of uchar.
1039
  return (unsigned char*) enum_names->type_names[tmp];
1 by brian
clean slate
1040
}
1041
520.1.22 by Brian Aker
Second pass of thd cleanup
1042
bool sys_var_session_bit::check(Session *session, set_var *var)
1 by brian
clean slate
1043
{
520.1.22 by Brian Aker
Second pass of thd cleanup
1044
  return (check_enum(session, var, &bool_typelib) ||
1045
          (check_func && (*check_func)(session, var)));
1 by brian
clean slate
1046
}
1047
520.1.22 by Brian Aker
Second pass of thd cleanup
1048
bool sys_var_session_bit::update(Session *session, set_var *var)
1 by brian
clean slate
1049
{
520.1.22 by Brian Aker
Second pass of thd cleanup
1050
  int res= (*update_func)(session, var);
1 by brian
clean slate
1051
  return res;
1052
}
1053
1054
1273.13.24 by Brian Aker
Updating style, simplified code.
1055
unsigned char *sys_var_session_bit::value_ptr(Session *session, sql_var_t,
779.3.10 by Monty Taylor
Turned on -Wshadow.
1056
                                              const LEX_STRING *)
1 by brian
clean slate
1057
{
1058
  /*
1059
    If reverse is 0 (default) return 1 if bit is set.
1060
    If reverse is 1, return 0 if bit is set
1061
  */
520.1.22 by Brian Aker
Second pass of thd cleanup
1062
  session->sys_var_tmp.bool_value= ((session->options & bit_flag) ?
1 by brian
clean slate
1063
				   !reverse : reverse);
520.1.22 by Brian Aker
Second pass of thd cleanup
1064
  return (unsigned char*) &session->sys_var_tmp.bool_value;
1 by brian
clean slate
1065
}
1066
1067
2070.2.2 by Monty Taylor
Removed some guts from set_var.
1068
bool sys_var_collation_sv::update(Session *session, set_var *var)
1 by brian
clean slate
1069
{
2254 by Brian Aker
Shift CHARSET_INFO to charset_info_st
1070
  const charset_info_st *tmp;
1 by brian
clean slate
1071
1072
  if (var->value->result_type() == STRING_RESULT)
1073
  {
1074
    char buff[STRING_BUFFER_USUAL_SIZE];
1075
    String str(buff,sizeof(buff), system_charset_info), *res;
1076
    if (!(res=var->value->val_str(&str)))
1077
    {
2070.2.2 by Monty Taylor
Removed some guts from set_var.
1078
      boost::throw_exception(invalid_option_value(var->var->getName()) << invalid_value(std::string("NULL")));
1 by brian
clean slate
1079
      return 1;
1080
    }
862 by Brian Aker
Remove charset directory code.
1081
    if (!(tmp=get_charset_by_name(res->c_ptr())))
1 by brian
clean slate
1082
    {
1083
      my_error(ER_UNKNOWN_COLLATION, MYF(0), res->c_ptr());
2070.2.2 by Monty Taylor
Removed some guts from set_var.
1084
      boost::throw_exception(invalid_option_value(var->var->getName()) << invalid_value(std::string(res->c_ptr())));
1 by brian
clean slate
1085
      return 1;
1086
    }
1087
  }
1088
  else // INT_RESULT
1089
  {
862 by Brian Aker
Remove charset directory code.
1090
    if (!(tmp=get_charset((int) var->value->val_int())))
1 by brian
clean slate
1091
    {
1092
      char buf[20];
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
1093
      internal::int10_to_str((int) var->value->val_int(), buf, -10);
1 by brian
clean slate
1094
      my_error(ER_UNKNOWN_COLLATION, MYF(0), buf);
2070.2.2 by Monty Taylor
Removed some guts from set_var.
1095
      boost::throw_exception(invalid_option_value(var->var->getName()) << invalid_value(boost::lexical_cast<std::string>(var->value->val_int())));
1 by brian
clean slate
1096
      return 1;
1097
    }
1098
  }
1099
  if (var->type == OPT_GLOBAL)
2070.2.2 by Monty Taylor
Removed some guts from set_var.
1100
    global_system_variables.*offset= tmp;
1 by brian
clean slate
1101
  else
1102
  {
2070.2.2 by Monty Taylor
Removed some guts from set_var.
1103
    session->variables.*offset= tmp;
1 by brian
clean slate
1104
  }
1105
  return 0;
1106
}
1107
1108
1273.13.24 by Brian Aker
Updating style, simplified code.
1109
void sys_var_collation_sv::set_default(Session *session, sql_var_t type)
1 by brian
clean slate
1110
{
1111
  if (type == OPT_GLOBAL)
1112
    global_system_variables.*offset= *global_default;
1113
  else
1114
  {
520.1.22 by Brian Aker
Second pass of thd cleanup
1115
    session->variables.*offset= global_system_variables.*offset;
1 by brian
clean slate
1116
  }
1117
}
1118
1119
575.1.2 by Monty Taylor
Changed a bunch of __attribute__((unused)) to removing the parameter name instead.
1120
unsigned char *sys_var_collation_sv::value_ptr(Session *session,
1273.13.24 by Brian Aker
Updating style, simplified code.
1121
                                               sql_var_t type,
779.3.10 by Monty Taylor
Turned on -Wshadow.
1122
                                               const LEX_STRING *)
1 by brian
clean slate
1123
{
2254 by Brian Aker
Shift CHARSET_INFO to charset_info_st
1124
  const charset_info_st *cs= ((type == OPT_GLOBAL) ?
575.1.2 by Monty Taylor
Changed a bunch of __attribute__((unused)) to removing the parameter name instead.
1125
                           global_system_variables.*offset :
1126
                           session->variables.*offset);
481 by Brian Aker
Remove all of uchar.
1127
  return cs ? (unsigned char*) cs->name : (unsigned char*) "NULL";
1 by brian
clean slate
1128
}
1129
1130
/****************************************************************************/
1131
520.1.22 by Brian Aker
Second pass of thd cleanup
1132
bool sys_var_timestamp::update(Session *session,  set_var *var)
1 by brian
clean slate
1133
{
2269.1.6 by Olaf van der Spek
Session Times
1134
  session->times.set_time(time_t(var->getInteger()));
1 by brian
clean slate
1135
  return 0;
1136
}
1137
1138
1273.13.24 by Brian Aker
Updating style, simplified code.
1139
void sys_var_timestamp::set_default(Session *session, sql_var_t)
1 by brian
clean slate
1140
{
2269.1.6 by Olaf van der Spek
Session Times
1141
  session->times.resetUserTime();
1 by brian
clean slate
1142
}
1143
1144
1273.13.24 by Brian Aker
Updating style, simplified code.
1145
unsigned char *sys_var_timestamp::value_ptr(Session *session, sql_var_t,
779.3.10 by Monty Taylor
Turned on -Wshadow.
1146
                                            const LEX_STRING *)
1 by brian
clean slate
1147
{
2269.1.5 by Olaf van der Spek
Session Times
1148
  session->sys_var_tmp.int32_t_value= (int32_t) session->times.getCurrentTimestampEpoch();
1055.2.17 by Jay Pipes
More style cleanups in Session
1149
  return (unsigned char*) &session->sys_var_tmp.int32_t_value;
1 by brian
clean slate
1150
}
1151
1152
520.1.22 by Brian Aker
Second pass of thd cleanup
1153
bool sys_var_last_insert_id::update(Session *session, set_var *var)
1 by brian
clean slate
1154
{
2070.2.2 by Monty Taylor
Removed some guts from set_var.
1155
  session->first_successful_insert_id_in_prev_stmt= var->getInteger();
1 by brian
clean slate
1156
  return 0;
1157
}
1158
1159
520.1.22 by Brian Aker
Second pass of thd cleanup
1160
unsigned char *sys_var_last_insert_id::value_ptr(Session *session,
1273.13.24 by Brian Aker
Updating style, simplified code.
1161
                                                 sql_var_t,
779.3.10 by Monty Taylor
Turned on -Wshadow.
1162
                                                 const LEX_STRING *)
1 by brian
clean slate
1163
{
1164
  /*
77.1.45 by Monty Taylor
Warning fixes.
1165
    this tmp var makes it robust againt change of type of
1 by brian
clean slate
1166
    read_first_successful_insert_id_in_prev_stmt().
1167
  */
575.1.2 by Monty Taylor
Changed a bunch of __attribute__((unused)) to removing the parameter name instead.
1168
  session->sys_var_tmp.uint64_t_value=
520.1.22 by Brian Aker
Second pass of thd cleanup
1169
    session->read_first_successful_insert_id_in_prev_stmt();
1170
  return (unsigned char*) &session->sys_var_tmp.uint64_t_value;
1 by brian
clean slate
1171
}
1172
2070.2.2 by Monty Taylor
Removed some guts from set_var.
1173
bool sys_var_session_lc_time_names::update(Session *session, set_var *var)
1 by brian
clean slate
1174
{
1175
  MY_LOCALE *locale_match;
1176
1177
  if (var->value->result_type() == INT_RESULT)
1178
  {
895 by Brian Aker
Completion (?) of uint conversion.
1179
    if (!(locale_match= my_locale_by_number((uint32_t) var->value->val_int())))
1 by brian
clean slate
1180
    {
2148.5.3 by Brian Aker
Remove hard coded array for numbers (this also fixes a couple of spots where
1181
      char buf[DECIMAL_LONGLONG_DIGITS];
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
1182
      internal::int10_to_str((int) var->value->val_int(), buf, -10);
1 by brian
clean slate
1183
      my_printf_error(ER_UNKNOWN_ERROR, "Unknown locale: '%s'", MYF(0), buf);
1184
      return 1;
1185
    }
1186
  }
1187
  else // STRING_RESULT
1188
  {
660.1.3 by Eric Herman
removed trailing whitespace with simple script:
1189
    char buff[6];
383.1.12 by Brian Aker
Much closer toward UTF8 being around all the time...
1190
    String str(buff, sizeof(buff), &my_charset_utf8_general_ci), *res;
1 by brian
clean slate
1191
    if (!(res=var->value->val_str(&str)))
1192
    {
1022.2.38 by Monty Taylor
Changed name to std::string.
1193
      my_error(ER_WRONG_VALUE_FOR_VAR, MYF(0), name.c_str(), "NULL");
1 by brian
clean slate
1194
      return 1;
1195
    }
1196
    const char *locale_str= res->c_ptr();
1197
    if (!(locale_match= my_locale_by_name(locale_str)))
1198
    {
1199
      my_printf_error(ER_UNKNOWN_ERROR,
1200
                      "Unknown locale: '%s'", MYF(0), locale_str);
1201
      return 1;
1202
    }
1203
  }
1204
1205
  if (var->type == OPT_GLOBAL)
2070.2.2 by Monty Taylor
Removed some guts from set_var.
1206
    global_system_variables.lc_time_names= locale_match;
1 by brian
clean slate
1207
  else
2070.2.2 by Monty Taylor
Removed some guts from set_var.
1208
    session->variables.lc_time_names= locale_match;
1 by brian
clean slate
1209
  return 0;
1210
}
1211
1212
520.1.22 by Brian Aker
Second pass of thd cleanup
1213
unsigned char *sys_var_session_lc_time_names::value_ptr(Session *session,
1273.13.24 by Brian Aker
Updating style, simplified code.
1214
                                                        sql_var_t type,
779.3.10 by Monty Taylor
Turned on -Wshadow.
1215
                                                        const LEX_STRING *)
1 by brian
clean slate
1216
{
1217
  return type == OPT_GLOBAL ?
481 by Brian Aker
Remove all of uchar.
1218
                 (unsigned char *) global_system_variables.lc_time_names->name :
520.1.22 by Brian Aker
Second pass of thd cleanup
1219
                 (unsigned char *) session->variables.lc_time_names->name;
1 by brian
clean slate
1220
}
1221
1222
1273.13.24 by Brian Aker
Updating style, simplified code.
1223
void sys_var_session_lc_time_names::set_default(Session *session, sql_var_t type)
1 by brian
clean slate
1224
{
1225
  if (type == OPT_GLOBAL)
1226
    global_system_variables.lc_time_names= my_default_lc_time_names;
1227
  else
520.1.22 by Brian Aker
Second pass of thd cleanup
1228
    session->variables.lc_time_names= global_system_variables.lc_time_names;
1 by brian
clean slate
1229
}
1230
1231
/*
1232
  Handling of microseoncds given as seconds.part_seconds
1233
1234
  NOTES
1235
    The argument to long query time is in seconds in decimal
151 by Brian Aker
Ulonglong to uint64_t
1236
    which is converted to uint64_t integer holding microseconds for storage.
1 by brian
clean slate
1237
    This is used for handling long_query_time
1238
*/
1239
520.1.22 by Brian Aker
Second pass of thd cleanup
1240
bool sys_var_microseconds::update(Session *session, set_var *var)
1 by brian
clean slate
1241
{
1242
  double num= var->value->val_real();
152 by Brian Aker
longlong replacement
1243
  int64_t microseconds;
1 by brian
clean slate
1244
  if (num > (double) option_limits->max_value)
1245
    num= (double) option_limits->max_value;
1246
  if (num < (double) option_limits->min_value)
1247
    num= (double) option_limits->min_value;
152 by Brian Aker
longlong replacement
1248
  microseconds= (int64_t) (num * 1000000.0 + 0.5);
1 by brian
clean slate
1249
  if (var->type == OPT_GLOBAL)
1250
  {
2114.3.1 by Brian Aker
Move variable lock into the catalog that the variables belong too.
1251
    boost::mutex::scoped_lock scopedLock(session->catalog().systemVariableLock());
1 by brian
clean slate
1252
    (global_system_variables.*offset)= microseconds;
1253
  }
1254
  else
520.1.22 by Brian Aker
Second pass of thd cleanup
1255
    session->variables.*offset= microseconds;
1 by brian
clean slate
1256
  return 0;
1257
}
1258
1259
1273.13.24 by Brian Aker
Updating style, simplified code.
1260
void sys_var_microseconds::set_default(Session *session, sql_var_t type)
1 by brian
clean slate
1261
{
152 by Brian Aker
longlong replacement
1262
  int64_t microseconds= (int64_t) (option_limits->def_value * 1000000.0);
1 by brian
clean slate
1263
  if (type == OPT_GLOBAL)
1264
  {
2114.3.1 by Brian Aker
Move variable lock into the catalog that the variables belong too.
1265
    boost::mutex::scoped_lock scopedLock(session->catalog().systemVariableLock());
1 by brian
clean slate
1266
    global_system_variables.*offset= microseconds;
1267
  }
1268
  else
520.1.22 by Brian Aker
Second pass of thd cleanup
1269
    session->variables.*offset= microseconds;
1 by brian
clean slate
1270
}
1271
1272
/*
520.1.22 by Brian Aker
Second pass of thd cleanup
1273
  Functions to update session->options bits
1 by brian
clean slate
1274
*/
1275
520.1.22 by Brian Aker
Second pass of thd cleanup
1276
static bool set_option_bit(Session *session, set_var *var)
1 by brian
clean slate
1277
{
520.1.22 by Brian Aker
Second pass of thd cleanup
1278
  sys_var_session_bit *sys_var= ((sys_var_session_bit*) var->var);
2070.2.2 by Monty Taylor
Removed some guts from set_var.
1279
  if ((var->getInteger() != 0) == sys_var->reverse)
520.1.22 by Brian Aker
Second pass of thd cleanup
1280
    session->options&= ~sys_var->bit_flag;
1 by brian
clean slate
1281
  else
520.1.22 by Brian Aker
Second pass of thd cleanup
1282
    session->options|= sys_var->bit_flag;
1 by brian
clean slate
1283
  return 0;
1284
}
1285
1286
520.1.22 by Brian Aker
Second pass of thd cleanup
1287
static bool set_option_autocommit(Session *session, set_var *var)
1 by brian
clean slate
1288
{
1890.2.5 by Stewart Smith
SET AUTOCOMMIT=1 was not completely performing a COMMIT
1289
  bool success= true;
1 by brian
clean slate
1290
  /* The test is negative as the flag we use is NOT autocommit */
1291
520.1.22 by Brian Aker
Second pass of thd cleanup
1292
  uint64_t org_options= session->options;
1890.2.5 by Stewart Smith
SET AUTOCOMMIT=1 was not completely performing a COMMIT
1293
  uint64_t new_options= session->options;
1 by brian
clean slate
1294
2070.2.2 by Monty Taylor
Removed some guts from set_var.
1295
  if (var->getInteger() != 0)
1890.2.5 by Stewart Smith
SET AUTOCOMMIT=1 was not completely performing a COMMIT
1296
    new_options&= ~((sys_var_session_bit*) var->var)->bit_flag;
1 by brian
clean slate
1297
  else
1890.2.5 by Stewart Smith
SET AUTOCOMMIT=1 was not completely performing a COMMIT
1298
    new_options|= ((sys_var_session_bit*) var->var)->bit_flag;
1 by brian
clean slate
1299
1890.2.5 by Stewart Smith
SET AUTOCOMMIT=1 was not completely performing a COMMIT
1300
  if ((org_options ^ new_options) & OPTION_NOT_AUTOCOMMIT)
1 by brian
clean slate
1301
  {
1302
    if ((org_options & OPTION_NOT_AUTOCOMMIT))
1303
    {
1890.2.5 by Stewart Smith
SET AUTOCOMMIT=1 was not completely performing a COMMIT
1304
      success= session->endActiveTransaction();
1 by brian
clean slate
1305
      /* We changed to auto_commit mode */
1172.1.2 by Brian Aker
Remove worthless call (ok... for not current replication system).
1306
      session->options&= ~(uint64_t) (OPTION_BEGIN);
520.1.22 by Brian Aker
Second pass of thd cleanup
1307
      session->server_status|= SERVER_STATUS_AUTOCOMMIT;
1 by brian
clean slate
1308
    }
1309
    else
1310
    {
520.1.22 by Brian Aker
Second pass of thd cleanup
1311
      session->server_status&= ~SERVER_STATUS_AUTOCOMMIT;
1 by brian
clean slate
1312
    }
1313
  }
1890.2.5 by Stewart Smith
SET AUTOCOMMIT=1 was not completely performing a COMMIT
1314
1890.2.53 by Stewart Smith
merge trunk
1315
  if (var->getInteger() != 0)
1890.2.5 by Stewart Smith
SET AUTOCOMMIT=1 was not completely performing a COMMIT
1316
    session->options&= ~((sys_var_session_bit*) var->var)->bit_flag;
1317
  else
1318
    session->options|= ((sys_var_session_bit*) var->var)->bit_flag;
1319
1320
  if (not success)
1321
    return true;
1322
1 by brian
clean slate
1323
  return 0;
1324
}
1325
575.1.2 by Monty Taylor
Changed a bunch of __attribute__((unused)) to removing the parameter name instead.
1326
static int check_pseudo_thread_id(Session *, set_var *var)
1 by brian
clean slate
1327
{
2070.2.1 by Monty Taylor
First step in getting that anonymous union out of set_var.
1328
  var->updateValue();
1 by brian
clean slate
1329
  return 0;
1330
}
1331
520.1.22 by Brian Aker
Second pass of thd cleanup
1332
static unsigned char *get_warning_count(Session *session)
1 by brian
clean slate
1333
{
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.
1334
  session->sys_var_tmp.uint32_t_value=
626 by Brian Aker
More of the same (ulong/64)
1335
    (session->warn_count[(uint32_t) DRIZZLE_ERROR::WARN_LEVEL_NOTE] +
1336
     session->warn_count[(uint32_t) DRIZZLE_ERROR::WARN_LEVEL_ERROR] +
1337
     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.
1338
  return (unsigned char*) &session->sys_var_tmp.uint32_t_value;
1 by brian
clean slate
1339
}
1340
520.1.22 by Brian Aker
Second pass of thd cleanup
1341
static unsigned char *get_error_count(Session *session)
1 by brian
clean slate
1342
{
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.
1343
  session->sys_var_tmp.uint32_t_value=
626 by Brian Aker
More of the same (ulong/64)
1344
    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.
1345
  return (unsigned char*) &session->sys_var_tmp.uint32_t_value;
1 by brian
clean slate
1346
}
1347
1348
1349
/**
1350
  Get the tmpdir that was specified or chosen by default.
1351
1352
  This is necessary because if the user does not specify a temporary
1353
  directory via the command line, one is chosen based on the environment
575.4.3 by ysano
Rename mysql to drizzle.
1354
  or system defaults.  But we can't just always use drizzle_tmpdir, because
1 by brian
clean slate
1355
  that is actually a call to my_tmpdir() which cycles among possible
1356
  temporary directories.
1357
520.1.22 by Brian Aker
Second pass of thd cleanup
1358
  @param session		thread handle
1 by brian
clean slate
1359
1360
  @retval
1361
    ptr		pointer to NUL-terminated string
1362
*/
575.1.2 by Monty Taylor
Changed a bunch of __attribute__((unused)) to removing the parameter name instead.
1363
static unsigned char *get_tmpdir(Session *)
1 by brian
clean slate
1364
{
1556.1.1 by Brian Aker
Updates for moving temporary directory.
1365
  assert(drizzle_tmpdir.size());
1366
  return (unsigned char*)drizzle_tmpdir.c_str();
1 by brian
clean slate
1367
}
1368
1369
/****************************************************************************
1370
  Main handling of variables:
1371
  - Initialisation
1372
  - Searching during parsing
1373
  - Update loop
1374
****************************************************************************/
1375
1376
/**
1377
  Find variable name in option my_getopt structure used for
1378
  command line args.
1379
1380
  @param opt	option structure array to search in
1381
  @param name	variable name
1382
1383
  @retval
1384
    0		Error
1385
  @retval
1386
    ptr		pointer to option structure
1387
*/
1388
1410.3.4 by Djellel E. Difallah
update references to old my_'s
1389
static struct option *find_option(struct option *opt, const char *name)
1 by brian
clean slate
1390
{
482 by Brian Aker
Remove uint.
1391
  uint32_t length=strlen(name);
1 by brian
clean slate
1392
  for (; opt->name; opt++)
1393
  {
1394
    if (!getopt_compare_strings(opt->name, name, length) &&
1395
	!opt->name[length])
1396
    {
1397
      /*
1398
	Only accept the option if one can set values through it.
1399
	If not, there is no default value or limits in the option.
1400
      */
1401
      return (opt->value) ? opt : 0;
1402
    }
1403
  }
1404
  return 0;
1405
}
1406
1407
660.1.3 by Eric Herman
removed trailing whitespace with simple script:
1408
1409
1410
1 by brian
clean slate
1411
/*
1412
  Constructs an array of system variables for display to the user.
660.1.3 by Eric Herman
removed trailing whitespace with simple script:
1413
1 by brian
clean slate
1414
  SYNOPSIS
1415
    enumerate_sys_vars()
520.1.22 by Brian Aker
Second pass of thd cleanup
1416
    session         current thread
660.1.3 by Eric Herman
removed trailing whitespace with simple script:
1417
1 by brian
clean slate
1418
  RETURN VALUES
1273.13.73 by Brian Aker
Remove typedef and drop some dead code.
1419
    pointer     Array of drizzle_show_var elements for display
1 by brian
clean slate
1420
    NULL        FAILURE
1421
*/
1422
1813.2.8 by Monty Taylor
Removed the fixed_vars.
1423
drizzle_show_var* enumerate_sys_vars(Session *session)
1 by brian
clean slate
1424
{
1813.2.8 by Monty Taylor
Removed the fixed_vars.
1425
  int size= sizeof(drizzle_show_var) * (system_variable_map.size() + 1);
2148.7.8 by Brian Aker
Remove bits from Session where was providing a service directly.
1426
  drizzle_show_var *result= (drizzle_show_var*) session->getMemRoot()->allocate(size);
1 by brian
clean slate
1427
1428
  if (result)
1429
  {
1813.2.8 by Monty Taylor
Removed the fixed_vars.
1430
    drizzle_show_var *show= result;
2246.4.1 by Olaf van der Spek
Use BOOST_FOREACH
1431
    BOOST_FOREACH(SystemVariableMap::const_reference iter, system_variable_map)
1 by brian
clean slate
1432
    {
2246.4.1 by Olaf van der Spek
Use BOOST_FOREACH
1433
      sys_var *var= iter.second;
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.
1434
      show->name= var->getName().c_str();
1 by brian
clean slate
1435
      show->value= (char*) var;
1436
      show->type= SHOW_SYS;
1813.2.8 by Monty Taylor
Removed the fixed_vars.
1437
      ++show;
1 by brian
clean slate
1438
    }
1439
1440
    /* make last element empty */
1273.13.73 by Brian Aker
Remove typedef and drop some dead code.
1441
    memset(show, 0, sizeof(drizzle_show_var));
1 by brian
clean slate
1442
  }
1443
  return result;
1444
}
1445
1851.1.1 by Monty Taylor
Removed sys_var_chain.
1446
void add_sys_var_to_list(sys_var *var)
1447
{
1448
  string lower_name(var->getName());
2246.4.1 by Olaf van der Spek
Use BOOST_FOREACH
1449
  transform(lower_name.begin(), lower_name.end(), lower_name.begin(), ::tolower);
1851.1.1 by Monty Taylor
Removed sys_var_chain.
1450
1451
  /* this fails if there is a conflicting variable name. */
2192.5.2 by Olaf van der Spek
Use map::count
1452
  if (system_variable_map.count(lower_name))
1851.1.1 by Monty Taylor
Removed sys_var_chain.
1453
  {
2126.3.3 by Brian Aker
Merge in error message rework. Many error messages are fixed in this patch.
1454
    errmsg_printf(error::ERROR, _("Variable named %s already exists!\n"),
1851.1.1 by Monty Taylor
Removed sys_var_chain.
1455
                  var->getName().c_str());
1456
    throw exception();
1457
  } 
1458
1459
  pair<SystemVariableMap::iterator, bool> ret= 
1460
    system_variable_map.insert(make_pair(lower_name, var));
1461
  if (ret.second == false)
1462
  {
2126.3.3 by Brian Aker
Merge in error message rework. Many error messages are fixed in this patch.
1463
    errmsg_printf(error::ERROR, _("Could not add Variable: %s\n"),
1851.1.1 by Monty Taylor
Removed sys_var_chain.
1464
                  var->getName().c_str());
1465
    throw exception();
1466
  }
1467
}
1468
1469
void add_sys_var_to_list(sys_var *var, struct option *long_options)
1470
{
1471
  add_sys_var_to_list(var);
1472
  var->setOptionLimits(find_option(long_options, var->getName().c_str()));
1473
}
1474
1 by brian
clean slate
1475
/*
1476
  Initialize the system variables
660.1.3 by Eric Herman
removed trailing whitespace with simple script:
1477
1 by brian
clean slate
1478
  SYNOPSIS
1878.3.1 by Monty Taylor
Split set_var.* into sys_var.* and set_var.*
1479
    sys_var_init()
660.1.3 by Eric Herman
removed trailing whitespace with simple script:
1480
1 by brian
clean slate
1481
  RETURN VALUES
1482
    0           SUCCESS
1483
    otherwise   FAILURE
1484
*/
1485
1878.3.1 by Monty Taylor
Split set_var.* into sys_var.* and set_var.*
1486
int sys_var_init()
1 by brian
clean slate
1487
{
1851.1.1 by Monty Taylor
Removed sys_var_chain.
1488
  try
1489
  {
1490
    add_sys_var_to_list(&sys_auto_increment_increment, my_long_options);
1491
    add_sys_var_to_list(&sys_auto_increment_offset, my_long_options);
1492
    add_sys_var_to_list(&sys_autocommit, my_long_options);
1493
    add_sys_var_to_list(&sys_back_log, my_long_options);
1494
    add_sys_var_to_list(&sys_basedir, my_long_options);
1495
    add_sys_var_to_list(&sys_big_selects, my_long_options);
2183.1.2 by Monty Taylor
A slew of tiny meaningless changes.
1496
    add_sys_var_to_list(&sys_branch, my_long_options);
1851.1.1 by Monty Taylor
Removed sys_var_chain.
1497
    add_sys_var_to_list(&sys_buffer_results, my_long_options);
1498
    add_sys_var_to_list(&sys_bulk_insert_buff_size, my_long_options);
1499
    add_sys_var_to_list(&sys_collation_server, my_long_options);
1500
    add_sys_var_to_list(&sys_completion_type, my_long_options);
1501
    add_sys_var_to_list(&sys_datadir, my_long_options);
1502
    add_sys_var_to_list(&sys_div_precincrement, my_long_options);
1503
    add_sys_var_to_list(&sys_error_count, my_long_options);
1504
    add_sys_var_to_list(&sys_foreign_key_checks, my_long_options);
1505
    add_sys_var_to_list(&sys_group_concat_max_len, my_long_options);
1506
    add_sys_var_to_list(&sys_hostname, my_long_options);
1507
    add_sys_var_to_list(&sys_identity, my_long_options);
1508
    add_sys_var_to_list(&sys_join_buffer_size, my_long_options);
1509
    add_sys_var_to_list(&sys_last_insert_id, my_long_options);
1510
    add_sys_var_to_list(&sys_lc_time_names, my_long_options);
1511
    add_sys_var_to_list(&sys_max_allowed_packet, my_long_options);
1512
    add_sys_var_to_list(&sys_max_error_count, my_long_options);
1513
    add_sys_var_to_list(&sys_max_heap_table_size, my_long_options);
1514
    add_sys_var_to_list(&sys_max_join_size, my_long_options);
1515
    add_sys_var_to_list(&sys_max_length_for_sort_data, my_long_options);
1516
    add_sys_var_to_list(&sys_max_seeks_for_key, my_long_options);
1517
    add_sys_var_to_list(&sys_max_sort_length, my_long_options);
1518
    add_sys_var_to_list(&sys_max_write_lock_count, my_long_options);
1519
    add_sys_var_to_list(&sys_min_examined_row_limit, my_long_options);
1520
    add_sys_var_to_list(&sys_optimizer_prune_level, my_long_options);
1521
    add_sys_var_to_list(&sys_optimizer_search_depth, my_long_options);
1522
    add_sys_var_to_list(&sys_pid_file, my_long_options);
1523
    add_sys_var_to_list(&sys_plugin_dir, my_long_options);
1524
    add_sys_var_to_list(&sys_preload_buff_size, my_long_options);
1525
    add_sys_var_to_list(&sys_pseudo_thread_id, my_long_options);
1526
    add_sys_var_to_list(&sys_query_alloc_block_size, my_long_options);
1527
    add_sys_var_to_list(&sys_query_prealloc_size, my_long_options);
1528
    add_sys_var_to_list(&sys_range_alloc_block_size, my_long_options);
1529
    add_sys_var_to_list(&sys_read_buff_size, my_long_options);
1530
    add_sys_var_to_list(&sys_read_rnd_buff_size, my_long_options);
2183.1.2 by Monty Taylor
A slew of tiny meaningless changes.
1531
    add_sys_var_to_list(&sys_release_id, my_long_options);
1938.3.1 by David Shrewsbury
Add --replicate-query option.
1532
    add_sys_var_to_list(&sys_replicate_query, my_long_options);
2183.1.2 by Monty Taylor
A slew of tiny meaningless changes.
1533
    add_sys_var_to_list(&sys_revid, my_long_options);
1534
    add_sys_var_to_list(&sys_revno, my_long_options);
1851.1.1 by Monty Taylor
Removed sys_var_chain.
1535
    add_sys_var_to_list(&sys_scheduler, my_long_options);
1536
    add_sys_var_to_list(&sys_secure_file_priv, my_long_options);
1537
    add_sys_var_to_list(&sys_select_limit, my_long_options);
1538
    add_sys_var_to_list(&sys_server_id, my_long_options);
1539
    add_sys_var_to_list(&sys_sort_buffer, my_long_options);
1540
    add_sys_var_to_list(&sys_sql_notes, my_long_options);
1541
    add_sys_var_to_list(&sys_sql_warnings, my_long_options);
1542
    add_sys_var_to_list(&sys_storage_engine, my_long_options);
1543
    add_sys_var_to_list(&sys_table_cache_size, my_long_options);
1544
    add_sys_var_to_list(&sys_table_def_size, my_long_options);
1545
    add_sys_var_to_list(&sys_table_lock_wait_timeout, my_long_options);
1546
    add_sys_var_to_list(&sys_thread_stack_size, my_long_options);
1547
    add_sys_var_to_list(&sys_timed_mutexes, my_long_options);
1548
    add_sys_var_to_list(&sys_timestamp, my_long_options);
1549
    add_sys_var_to_list(&sys_tmp_table_size, my_long_options);
1550
    add_sys_var_to_list(&sys_tmpdir, my_long_options);
1551
    add_sys_var_to_list(&sys_transaction_message_threshold, my_long_options);
1552
    add_sys_var_to_list(&sys_tx_isolation, my_long_options);
1553
    add_sys_var_to_list(&sys_unique_checks, my_long_options);
1554
    add_sys_var_to_list(&sys_version, my_long_options);
1555
    add_sys_var_to_list(&sys_version_comment, my_long_options);
1556
    add_sys_var_to_list(&sys_version_compile_machine, my_long_options);
1557
    add_sys_var_to_list(&sys_version_compile_os, my_long_options);
1558
    add_sys_var_to_list(&sys_version_compile_vendor, my_long_options);
1559
    add_sys_var_to_list(&sys_warning_count, my_long_options);
1560
  }
1966.3.1 by Monty Taylor
Use std::exception instead of catch(...)
1561
  catch (std::exception&)
1851.1.1 by Monty Taylor
Removed sys_var_chain.
1562
  {
2126.3.3 by Brian Aker
Merge in error message rework. Many error messages are fixed in this patch.
1563
    errmsg_printf(error::ERROR, _("Failed to initialize system variables"));
1851.1.1 by Monty Taylor
Removed sys_var_chain.
1564
    return(1);
1565
  }
51.1.46 by Jay Pipes
Removed/replaced DBUG symbols and standardized TRUE/FALSE
1566
  return(0);
1 by brian
clean slate
1567
}
1568
1569
1570
/**
1571
  Find a user set-table variable.
1572
2040.6.2 by Monty Taylor
Made find_sys_var take a const std::string& instead.
1573
  @param name	   Name of system variable to find
1 by brian
clean slate
1574
1575
  @retval
1576
    pointer	pointer to variable definitions
1577
  @retval
1578
    0		Unknown variable (error message is given)
1579
*/
1580
2040.6.3 by Monty Taylor
Removed unused no_error bool param.
1581
sys_var *find_sys_var(const std::string &name)
1 by brian
clean slate
1582
{
2040.6.2 by Monty Taylor
Made find_sys_var take a const std::string& instead.
1583
  string lower_name(name);
2246.4.1 by Olaf van der Spek
Use BOOST_FOREACH
1584
  transform(lower_name.begin(), lower_name.end(), lower_name.begin(), ::tolower);
1228.3.1 by Monty Taylor
Removed NameMap. Also remove the aliases from the plugin, since we can just
1585
1586
  sys_var *result= NULL;
1587
2192.5.8 by Olaf van der Spek
Use ptr instead of i
1588
  if (SystemVariableMap::mapped_type* ptr= find_ptr(system_variable_map, lower_name))
1589
    result= *ptr;
1228.3.1 by Monty Taylor
Removed NameMap. Also remove the aliases from the plugin, since we can just
1590
1022.2.37 by Monty Taylor
Moved more tolower calls to setup rather than during runtime.
1591
  if (result == NULL)
896.1.1 by Monty Taylor
Actually return NULL from intern_find_sys_var on error thank you.
1592
  {
2040.6.3 by Monty Taylor
Removed unused no_error bool param.
1593
    my_error(ER_UNKNOWN_SYSTEM_VARIABLE, MYF(0), name.c_str());
1594
    return NULL;
896.1.1 by Monty Taylor
Actually return NULL from intern_find_sys_var on error thank you.
1595
  }
1 by brian
clean slate
1596
1022.2.37 by Monty Taylor
Moved more tolower calls to setup rather than during runtime.
1597
  return result;
1 by brian
clean slate
1598
}
1599
1600
1601
/****************************************************************************
1602
 Functions to handle table_type
1603
****************************************************************************/
1604
575.1.2 by Monty Taylor
Changed a bunch of __attribute__((unused)) to removing the parameter name instead.
1605
unsigned char *sys_var_session_storage_engine::value_ptr(Session *session,
1273.13.24 by Brian Aker
Updating style, simplified code.
1606
                                                         sql_var_t type,
779.3.10 by Monty Taylor
Turned on -Wshadow.
1607
                                                         const LEX_STRING *)
1 by brian
clean slate
1608
{
481 by Brian Aker
Remove all of uchar.
1609
  unsigned char* result;
968.2.29 by Monty Taylor
First steps towards new plugin reg.
1610
  string engine_name;
1130.1.4 by Monty Taylor
Moved StorageEngine into plugin namespace.
1611
  plugin::StorageEngine *engine= session->variables.*offset;
1 by brian
clean slate
1612
  if (type == OPT_GLOBAL)
971.1.21 by Monty Taylor
Store StorageEngine in system variables, rather than storage engine plugin.
1613
    engine= global_system_variables.*offset;
971.1.14 by Monty Taylor
Slurp around strings rather than char* for storage engine name.
1614
  engine_name= engine->getName();
968.2.29 by Monty Taylor
First steps towards new plugin reg.
1615
  result= (unsigned char *) session->strmake(engine_name.c_str(),
1616
                                             engine_name.size());
1 by brian
clean slate
1617
  return result;
1618
}
1619
1620
1273.13.24 by Brian Aker
Updating style, simplified code.
1621
void sys_var_session_storage_engine::set_default(Session *session, sql_var_t type)
1 by brian
clean slate
1622
{
2253.1.1 by Andrew Hutchings
Fix Drizzle to compile in GCC 4.6 (which fires warnings and therefore errors if a variable is set and not read)
1623
  plugin::StorageEngine *new_value, **value;
1 by brian
clean slate
1624
  if (type == OPT_GLOBAL)
1625
  {
1626
    value= &(global_system_variables.*offset);
971.1.21 by Monty Taylor
Store StorageEngine in system variables, rather than storage engine plugin.
1627
    new_value= myisam_engine;
1 by brian
clean slate
1628
  }
1629
  else
1630
  {
520.1.22 by Brian Aker
Second pass of thd cleanup
1631
    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.
1632
    new_value= global_system_variables.*offset;
1 by brian
clean slate
1633
  }
51.1.46 by Jay Pipes
Removed/replaced DBUG symbols and standardized TRUE/FALSE
1634
  assert(new_value);
1 by brian
clean slate
1635
  *value= new_value;
1636
}
1637
1638
520.1.22 by Brian Aker
Second pass of thd cleanup
1639
bool sys_var_session_storage_engine::update(Session *session, set_var *var)
1 by brian
clean slate
1640
{
2070.2.2 by Monty Taylor
Removed some guts from set_var.
1641
  char buff[STRING_BUFFER_USUAL_SIZE];
1642
  const char *name_value;
1643
  String str(buff, sizeof(buff), &my_charset_utf8_general_ci), *res;
1644
1645
  plugin::StorageEngine *tmp= NULL;
1646
  plugin::StorageEngine **value= NULL;
1647
    
1648
  if (var->value->result_type() == STRING_RESULT)
1649
  {
1650
    res= var->value->val_str(&str);
1651
    if (res == NULL || res->ptr() == NULL)
1652
    {
1653
      name_value= "NULL";
1654
      goto err;
1655
    }
1656
    else
1657
    {
1658
      const std::string engine_name(res->ptr());
1659
      tmp= plugin::StorageEngine::findByName(*session, engine_name);
1660
      if (tmp == NULL)
1661
      {
1662
        name_value= res->c_ptr();
1663
        goto err;
1664
      }
1665
    }
1666
  }
1667
  else
1668
  {
1669
    name_value= "unknown";
1670
  }
1671
1672
  value= &(global_system_variables.*offset);
1 by brian
clean slate
1673
   if (var->type != OPT_GLOBAL)
520.1.22 by Brian Aker
Second pass of thd cleanup
1674
     value= &(session->variables.*offset);
2070.2.2 by Monty Taylor
Removed some guts from set_var.
1675
  if (*value != tmp)
1 by brian
clean slate
1676
  {
2070.2.2 by Monty Taylor
Removed some guts from set_var.
1677
    *value= tmp;
1 by brian
clean slate
1678
  }
1679
  return 0;
2070.2.2 by Monty Taylor
Removed some guts from set_var.
1680
err:
1681
  my_error(ER_UNKNOWN_STORAGE_ENGINE, MYF(0), name_value);
1682
  return 1;
1 by brian
clean slate
1683
}
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
1684
1685
} /* namespace drizzled */