~drizzle-trunk/drizzle/development

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