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