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