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