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