~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/set_var.cc

  • Committer: Brian Aker
  • Date: 2009-07-01 02:41:00 UTC
  • mfrom: (1081.1.4 mordred)
  • Revision ID: brian@gaz-20090701024100-nefdy7pnychzpg7h
Merge Monty

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* Copyright (C) 2000-2003 MySQL AB
2
 
 
3
 
   This program is free software; you can redistribute it and/or modify
4
 
   it under the terms of the GNU General Public License as published by
5
 
   the Free Software Foundation; version 2 of the License.
6
 
 
7
 
   This program is distributed in the hope that it will be useful,
8
 
   but WITHOUT ANY WARRANTY; without even the implied warranty of
9
 
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
10
 
   GNU General Public License for more details.
11
 
 
12
 
   You should have received a copy of the GNU General Public License
13
 
   along with this program; if not, write to the Free Software
14
 
   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */
 
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
 */
15
19
 
16
20
/**
17
 
  @file
18
 
 
19
 
  @brief
20
 
  Handling of MySQL SQL variables
 
21
  @file Handling of MySQL SQL variables
21
22
 
22
23
  @details
23
24
  To add a new variable, one has to do the following:
46
47
    them you must first assign a value to them (in specific ::check() for
47
48
    example).
48
49
*/
 
50
 
49
51
#include <drizzled/server_includes.h>
50
 
#include "rpl_mi.h"
51
52
#include <mysys/my_getopt.h>
52
 
#include <mysys/thr_alarm.h>
53
 
#include <storage/myisam/myisam.h>
54
 
#include <drizzled/drizzled_error_messages.h>
 
53
#include <plugin/myisam/myisam.h>
 
54
#include <drizzled/error.h>
 
55
#include <drizzled/gettext.h>
 
56
#include <drizzled/tztime.h>
 
57
#include <drizzled/data_home.h>
 
58
#include <drizzled/set_var.h>
 
59
#include <drizzled/session.h>
 
60
#include <drizzled/sql_base.h>
 
61
#include <drizzled/lock.h>
 
62
#include <drizzled/item/uint.h>
 
63
#include <drizzled/item/null.h>
 
64
#include <drizzled/item/float.h>
 
65
 
 
66
#include "drizzled/registry.h"
 
67
#include <map>
 
68
#include <algorithm>
 
69
 
 
70
using namespace std;
55
71
 
56
72
extern const CHARSET_INFO *character_set_filesystem;
57
 
 
 
73
extern I_List<NAMED_LIST> key_caches;
 
74
extern size_t my_thread_stack_size;
58
75
 
59
76
static DYNAMIC_ARRAY fixed_show_vars;
60
 
static HASH system_variable_hash;
 
77
static drizzled::Registry<sys_var *> system_variable_hash;
 
78
extern char *opt_drizzle_tmpdir;
61
79
 
62
 
const char *bool_type_names[]= { "OFF", "ON", NullS };
 
80
const char *bool_type_names[]= { "OFF", "ON", NULL };
63
81
TYPELIB bool_typelib=
64
82
{
65
83
  array_elements(bool_type_names)-1, "", bool_type_names, NULL
66
84
};
67
85
 
68
 
const char *delay_key_write_type_names[]= { "OFF", "ON", "ALL", NullS };
 
86
const char *delay_key_write_type_names[]= { "OFF", "ON", "ALL", NULL };
69
87
TYPELIB delay_key_write_typelib=
70
88
{
71
89
  array_elements(delay_key_write_type_names)-1, "",
72
90
  delay_key_write_type_names, NULL
73
91
};
74
92
 
75
 
const char *slave_exec_mode_names[]=
76
 
{ "STRICT", "IDEMPOTENT", NullS };
77
 
static const unsigned int slave_exec_mode_names_len[]=
78
 
{ sizeof("STRICT") - 1, sizeof("IDEMPOTENT") - 1, 0 };
79
 
TYPELIB slave_exec_mode_typelib=
80
 
{
81
 
  array_elements(slave_exec_mode_names)-1, "",
82
 
  slave_exec_mode_names, (unsigned int *) slave_exec_mode_names_len
83
 
};
84
 
 
85
 
static bool sys_update_init_connect(THD*, set_var*);
86
 
static void sys_default_init_connect(THD*, enum_var_type type);
87
 
static bool sys_update_init_slave(THD*, set_var*);
88
 
static void sys_default_init_slave(THD*, enum_var_type type);
89
 
static bool set_option_bit(THD *thd, set_var *var);
90
 
static bool set_option_autocommit(THD *thd, set_var *var);
91
 
static int  check_log_update(THD *thd, set_var *var);
92
 
static bool set_log_update(THD *thd, set_var *var);
93
 
static int  check_pseudo_thread_id(THD *thd, set_var *var);
94
 
static void fix_low_priority_updates(THD *thd, enum_var_type type);
95
 
static int check_tx_isolation(THD *thd, set_var *var);
96
 
static void fix_tx_isolation(THD *thd, enum_var_type type);
97
 
static int check_completion_type(THD *thd, set_var *var);
98
 
static void fix_completion_type(THD *thd, enum_var_type type);
99
 
static void fix_net_read_timeout(THD *thd, enum_var_type type);
100
 
static void fix_net_write_timeout(THD *thd, enum_var_type type);
101
 
static void fix_net_retry_count(THD *thd, enum_var_type type);
102
 
static void fix_max_join_size(THD *thd, enum_var_type type);
103
 
static void fix_myisam_max_sort_file_size(THD *thd, enum_var_type type);
104
 
static void fix_max_binlog_size(THD *thd, enum_var_type type);
105
 
static void fix_max_relay_log_size(THD *thd, enum_var_type type);
106
 
static void fix_max_connections(THD *thd, enum_var_type type);
107
 
static void fix_thd_mem_root(THD *thd, enum_var_type type);
108
 
static void fix_trans_mem_root(THD *thd, enum_var_type type);
109
 
static void fix_server_id(THD *thd, enum_var_type type);
110
 
static uint64_t fix_unsigned(THD *, uint64_t, const struct my_option *);
111
 
static bool get_unsigned(THD *thd, set_var *var);
112
 
bool throw_bounds_warning(THD *thd, bool fixed, bool unsignd,
113
 
                          const char *name, int64_t val);
114
 
static KEY_CACHE *create_key_cache(const char *name, uint length);
115
 
static uchar *get_error_count(THD *thd);
116
 
static uchar *get_warning_count(THD *thd);
117
 
static uchar *get_tmpdir(THD *thd);
118
 
static int  sys_check_log_path(THD *thd,  set_var *var);
119
 
static bool sys_update_general_log_path(THD *thd, set_var * var);
120
 
static void sys_default_general_log_path(THD *thd, enum_var_type type);
121
 
static bool sys_update_slow_log_path(THD *thd, set_var * var);
122
 
static void sys_default_slow_log_path(THD *thd, enum_var_type type);
 
93
static bool set_option_bit(Session *session, set_var *var);
 
94
static bool set_option_autocommit(Session *session, set_var *var);
 
95
static int  check_pseudo_thread_id(Session *session, set_var *var);
 
96
static int check_tx_isolation(Session *session, set_var *var);
 
97
static void fix_tx_isolation(Session *session, enum_var_type type);
 
98
static int check_completion_type(Session *session, set_var *var);
 
99
static void fix_completion_type(Session *session, enum_var_type type);
 
100
static void fix_net_read_timeout(Session *session, enum_var_type type);
 
101
static void fix_net_write_timeout(Session *session, enum_var_type type);
 
102
static void fix_net_retry_count(Session *session, enum_var_type type);
 
103
static void fix_max_join_size(Session *session, enum_var_type type);
 
104
static void fix_session_mem_root(Session *session, enum_var_type type);
 
105
static void fix_trans_mem_root(Session *session, enum_var_type type);
 
106
static void fix_server_id(Session *session, enum_var_type type);
 
107
static uint64_t fix_unsigned(Session *, uint64_t, const struct my_option *);
 
108
static bool get_unsigned32(Session *session, set_var *var);
 
109
static bool get_unsigned64(Session *session, set_var *var);
 
110
bool throw_bounds_warning(Session *session, bool fixed, bool unsignd,
 
111
                          const std::string &name, int64_t val);
 
112
static KEY_CACHE *create_key_cache(const char *name, uint32_t length);
 
113
static unsigned char *get_error_count(Session *session);
 
114
static unsigned char *get_warning_count(Session *session);
 
115
static unsigned char *get_tmpdir(Session *session);
123
116
 
124
117
/*
125
118
  Variable definition list
130
123
  The variables are linked into the list. A variable is added to
131
124
  it in the constructor (see sys_var class for details).
132
125
*/
133
 
 
134
126
static sys_var_chain vars = { NULL, NULL };
135
127
 
136
 
static sys_var_thd_ulong
 
128
static sys_var_session_uint64_t
137
129
sys_auto_increment_increment(&vars, "auto_increment_increment",
138
 
                             &SV::auto_increment_increment, NULL, NULL,
139
 
                             sys_var::SESSION_VARIABLE_IN_BINLOG);
140
 
static sys_var_thd_ulong
 
130
                             &SV::auto_increment_increment);
 
131
static sys_var_session_uint64_t
141
132
sys_auto_increment_offset(&vars, "auto_increment_offset",
142
 
                          &SV::auto_increment_offset, NULL, NULL,
143
 
                          sys_var::SESSION_VARIABLE_IN_BINLOG);
 
133
                          &SV::auto_increment_offset);
144
134
 
145
 
static sys_var_const_str       sys_basedir(&vars, "basedir", mysql_home);
146
 
static sys_var_long_ptr sys_binlog_cache_size(&vars, "binlog_cache_size",
147
 
                                              &binlog_cache_size);
148
 
static sys_var_thd_binlog_format sys_binlog_format(&vars, "binlog_format",
149
 
                                            &SV::binlog_format);
150
 
static sys_var_thd_ulong        sys_bulk_insert_buff_size(&vars, "bulk_insert_buffer_size",
151
 
                                                  &SV::bulk_insert_buff_size);
152
 
static sys_var_character_set_sv
153
 
sys_character_set_server(&vars, "character_set_server",
154
 
                         &SV::collation_server, &default_charset_info, 0,
155
 
                         sys_var::SESSION_VARIABLE_IN_BINLOG);
156
 
sys_var_const_str       sys_charset_system(&vars, "character_set_system",
157
 
                                           (char *)my_charset_utf8_general_ci.name);
158
 
static sys_var_character_set_database
159
 
sys_character_set_database(&vars, "character_set_database",
160
 
                           sys_var::SESSION_VARIABLE_IN_BINLOG);
161
 
static sys_var_character_set_client
162
 
sys_character_set_client(&vars, "character_set_client",
163
 
                         &SV::character_set_client,
164
 
                         &default_charset_info,
165
 
                         sys_var::SESSION_VARIABLE_IN_BINLOG);
166
 
static sys_var_character_set_sv
167
 
sys_character_set_connection(&vars, "character_set_connection",
168
 
                             &SV::collation_connection,
169
 
                             &default_charset_info, 0,
170
 
                             sys_var::SESSION_VARIABLE_IN_BINLOG);
171
 
static sys_var_character_set_sv sys_character_set_results(&vars, "character_set_results",
172
 
                                        &SV::character_set_results,
173
 
                                        &default_charset_info, true);
174
 
static sys_var_character_set_sv sys_character_set_filesystem(&vars, "character_set_filesystem",
175
 
                                        &SV::character_set_filesystem,
176
 
                                        &character_set_filesystem);
177
 
static sys_var_thd_ulong        sys_completion_type(&vars, "completion_type",
178
 
                                         &SV::completion_type,
179
 
                                         check_completion_type,
180
 
                                         fix_completion_type);
181
 
static sys_var_collation_sv
182
 
sys_collation_connection(&vars, "collation_connection",
183
 
                         &SV::collation_connection, &default_charset_info,
184
 
                         sys_var::SESSION_VARIABLE_IN_BINLOG);
185
 
static sys_var_collation_sv
186
 
sys_collation_database(&vars, "collation_database", &SV::collation_database,
187
 
                       &default_charset_info,
188
 
                       sys_var::SESSION_VARIABLE_IN_BINLOG);
189
 
static sys_var_collation_sv
190
 
sys_collation_server(&vars, "collation_server", &SV::collation_server,
191
 
                     &default_charset_info,
192
 
                     sys_var::SESSION_VARIABLE_IN_BINLOG);
193
 
static sys_var_long_ptr sys_connect_timeout(&vars, "connect_timeout",
194
 
                                            &connect_timeout);
195
 
static sys_var_const_str       sys_datadir(&vars, "datadir", mysql_real_data_home);
 
135
static sys_var_const_str       sys_basedir(&vars, "basedir", drizzle_home);
 
136
static sys_var_session_uint64_t sys_bulk_insert_buff_size(&vars, "bulk_insert_buffer_size",
 
137
                                                          &SV::bulk_insert_buff_size);
 
138
static sys_var_session_uint32_t sys_completion_type(&vars, "completion_type",
 
139
                                                    &SV::completion_type,
 
140
                                                    check_completion_type,
 
141
                                                    fix_completion_type);
 
142
static sys_var_collation_sv
 
143
sys_collation_server(&vars, "collation_server", &SV::collation_server, &default_charset_info);
 
144
static sys_var_uint32_t_ptr     sys_connect_timeout(&vars, "connect_timeout",
 
145
                                                &connect_timeout);
 
146
static sys_var_const_str       sys_datadir(&vars, "datadir", drizzle_real_data_home);
196
147
static sys_var_enum             sys_delay_key_write(&vars, "delay_key_write",
197
148
                                            &delay_key_write_options,
198
149
                                            &delay_key_write_typelib,
199
150
                                            fix_delay_key_write);
200
151
 
201
 
static sys_var_long_ptr sys_expire_logs_days(&vars, "expire_logs_days",
202
 
                                             &expire_logs_days);
203
152
static sys_var_bool_ptr sys_flush(&vars, "flush", &myisam_flush);
204
 
sys_var_str             sys_init_connect(&vars, "init_connect", 0,
205
 
                                         sys_update_init_connect,
206
 
                                         sys_default_init_connect,0);
207
 
sys_var_str             sys_init_slave(&vars, "init_slave", 0,
208
 
                                       sys_update_init_slave,
209
 
                                       sys_default_init_slave,0);
210
 
static sys_var_thd_ulong        sys_interactive_timeout(&vars, "interactive_timeout",
211
 
                                                &SV::net_interactive_timeout);
212
 
static sys_var_thd_ulong        sys_join_buffer_size(&vars, "join_buffer_size",
213
 
                                             &SV::join_buff_size);
 
153
static sys_var_session_uint64_t sys_join_buffer_size(&vars, "join_buffer_size",
 
154
                                                     &SV::join_buff_size);
214
155
static sys_var_key_buffer_size  sys_key_buffer_size(&vars, "key_buffer_size");
215
 
static sys_var_key_cache_long  sys_key_cache_block_size(&vars, "key_cache_block_size",
216
 
                                                 offsetof(KEY_CACHE,
217
 
                                                          param_block_size));
218
 
static sys_var_key_cache_long   sys_key_cache_division_limit(&vars, "key_cache_division_limit",
219
 
                                                     offsetof(KEY_CACHE,
220
 
                                                              param_division_limit));
221
 
static sys_var_key_cache_long  sys_key_cache_age_threshold(&vars, "key_cache_age_threshold",
222
 
                                                     offsetof(KEY_CACHE,
223
 
                                                              param_age_threshold));
224
 
static sys_var_bool_ptr sys_local_infile(&vars, "local_infile",
225
 
                                         &opt_local_infile);
226
 
static sys_var_bool_ptr
227
 
  sys_log_queries_not_using_indexes(&vars, "log_queries_not_using_indexes",
228
 
                                    &opt_log_queries_not_using_indexes);
229
 
static sys_var_thd_ulong        sys_log_warnings(&vars, "log_warnings", &SV::log_warnings);
230
 
static sys_var_microseconds     sys_var_long_query_time(&vars, "long_query_time",
231
 
                                                        &SV::long_query_time);
232
 
static sys_var_thd_bool sys_low_priority_updates(&vars, "low_priority_updates",
233
 
                                                 &SV::low_priority_updates,
234
 
                                                 fix_low_priority_updates);
235
 
#ifndef TO_BE_DELETED   /* Alias for the low_priority_updates */
236
 
static sys_var_thd_bool sys_sql_low_priority_updates(&vars, "sql_low_priority_updates",
237
 
                                                     &SV::low_priority_updates,
238
 
                                                     fix_low_priority_updates);
239
 
#endif
240
 
static sys_var_thd_ulong        sys_max_allowed_packet(&vars, "max_allowed_packet",
241
 
                                               &SV::max_allowed_packet);
242
 
static sys_var_long_ptr sys_max_binlog_cache_size(&vars, "max_binlog_cache_size",
243
 
                                                  &max_binlog_cache_size);
244
 
static sys_var_long_ptr sys_max_binlog_size(&vars, "max_binlog_size",
245
 
                                            &max_binlog_size,
246
 
                                            fix_max_binlog_size);
247
 
static sys_var_long_ptr sys_max_connections(&vars, "max_connections",
248
 
                                            &max_connections,
249
 
                                            fix_max_connections);
250
 
static sys_var_long_ptr sys_max_connect_errors(&vars, "max_connect_errors",
251
 
                                               &max_connect_errors);
252
 
static sys_var_thd_ulong        sys_max_error_count(&vars, "max_error_count",
253
 
                                            &SV::max_error_count);
254
 
static sys_var_thd_uint64_t     sys_max_heap_table_size(&vars, "max_heap_table_size",
255
 
                                                &SV::max_heap_table_size);
256
 
static sys_var_thd_ulong sys_pseudo_thread_id(&vars, "pseudo_thread_id",
 
156
static sys_var_key_cache_uint32_t  sys_key_cache_block_size(&vars, "key_cache_block_size",
 
157
                                                        offsetof(KEY_CACHE,
 
158
                                                                 param_block_size));
 
159
static sys_var_key_cache_uint32_t       sys_key_cache_division_limit(&vars, "key_cache_division_limit",
 
160
                                                           offsetof(KEY_CACHE,
 
161
                                                                    param_division_limit));
 
162
static sys_var_key_cache_uint32_t  sys_key_cache_age_threshold(&vars, "key_cache_age_threshold",
 
163
                                                           offsetof(KEY_CACHE,
 
164
                                                                    param_age_threshold));
 
165
static sys_var_session_uint32_t sys_max_allowed_packet(&vars, "max_allowed_packet",
 
166
                                                       &SV::max_allowed_packet);
 
167
static sys_var_uint64_t_ptr     sys_max_connect_errors(&vars, "max_connect_errors",
 
168
                                               &max_connect_errors);
 
169
static sys_var_session_uint64_t sys_max_error_count(&vars, "max_error_count",
 
170
                                                  &SV::max_error_count);
 
171
static sys_var_session_uint64_t sys_max_heap_table_size(&vars, "max_heap_table_size",
 
172
                                                        &SV::max_heap_table_size);
 
173
static sys_var_session_uint64_t sys_pseudo_thread_id(&vars, "pseudo_thread_id",
257
174
                                              &SV::pseudo_thread_id,
258
 
                                              check_pseudo_thread_id, 0,
259
 
                                              sys_var::SESSION_VARIABLE_IN_BINLOG);
260
 
static sys_var_thd_ha_rows      sys_max_join_size(&vars, "max_join_size",
261
 
                                          &SV::max_join_size,
262
 
                                          fix_max_join_size);
263
 
static sys_var_thd_ulong        sys_max_seeks_for_key(&vars, "max_seeks_for_key",
264
 
                                              &SV::max_seeks_for_key);
265
 
static sys_var_thd_ulong   sys_max_length_for_sort_data(&vars, "max_length_for_sort_data",
266
 
                                                 &SV::max_length_for_sort_data);
267
 
static sys_var_long_ptr sys_max_relay_log_size(&vars, "max_relay_log_size",
268
 
                                               &max_relay_log_size,
269
 
                                               fix_max_relay_log_size);
270
 
static sys_var_thd_ulong        sys_max_sort_length(&vars, "max_sort_length",
271
 
                                            &SV::max_sort_length);
272
 
static sys_var_max_user_conn   sys_max_user_connections(&vars, "max_user_connections");
273
 
static sys_var_thd_ulong        sys_max_tmp_tables(&vars, "max_tmp_tables",
274
 
                                           &SV::max_tmp_tables);
275
 
static sys_var_long_ptr sys_max_write_lock_count(&vars, "max_write_lock_count",
276
 
                                                 &max_write_lock_count);
277
 
static sys_var_thd_ulong       sys_min_examined_row_limit(&vars, "min_examined_row_limit",
278
 
                                                          &SV::min_examined_row_limit);
279
 
static sys_var_thd_uint64_t     sys_myisam_max_sort_file_size(&vars, "myisam_max_sort_file_size", &SV::myisam_max_sort_file_size, fix_myisam_max_sort_file_size, 1);
280
 
static sys_var_thd_ulong       sys_myisam_repair_threads(&vars, "myisam_repair_threads", &SV::myisam_repair_threads);
281
 
static sys_var_thd_ulong        sys_myisam_sort_buffer_size(&vars, "myisam_sort_buffer_size", &SV::myisam_sort_buff_size);
 
175
                                              0, check_pseudo_thread_id);
 
176
static sys_var_session_ha_rows  sys_max_join_size(&vars, "max_join_size",
 
177
                                                  &SV::max_join_size,
 
178
                                                  fix_max_join_size);
 
179
static sys_var_session_uint64_t sys_max_seeks_for_key(&vars, "max_seeks_for_key",
 
180
                                                      &SV::max_seeks_for_key);
 
181
static sys_var_session_uint64_t   sys_max_length_for_sort_data(&vars, "max_length_for_sort_data",
 
182
                                                               &SV::max_length_for_sort_data);
 
183
static sys_var_session_size_t   sys_max_sort_length(&vars, "max_sort_length",
 
184
                                                    &SV::max_sort_length);
 
185
static sys_var_uint64_t_ptr     sys_max_write_lock_count(&vars, "max_write_lock_count",
 
186
                                                 &max_write_lock_count);
 
187
static sys_var_session_uint64_t sys_min_examined_row_limit(&vars, "min_examined_row_limit",
 
188
                                                           &SV::min_examined_row_limit);
282
189
 
283
 
static sys_var_thd_enum         sys_myisam_stats_method(&vars, "myisam_stats_method",
284
 
                                                &SV::myisam_stats_method,
285
 
                                                &myisam_stats_method_typelib,
286
 
                                                NULL);
287
 
static sys_var_thd_ulong        sys_net_buffer_length(&vars, "net_buffer_length",
288
 
                                              &SV::net_buffer_length);
289
 
static sys_var_thd_ulong        sys_net_read_timeout(&vars, "net_read_timeout",
290
 
                                             &SV::net_read_timeout,
291
 
                                             0, fix_net_read_timeout);
292
 
static sys_var_thd_ulong        sys_net_write_timeout(&vars, "net_write_timeout",
293
 
                                              &SV::net_write_timeout,
294
 
                                              0, fix_net_write_timeout);
295
 
static sys_var_thd_ulong        sys_net_retry_count(&vars, "net_retry_count",
296
 
                                            &SV::net_retry_count,
297
 
                                            0, fix_net_retry_count);
298
 
static sys_var_thd_bool sys_new_mode(&vars, "new", &SV::new_mode);
299
 
static sys_var_bool_ptr_readonly sys_old_mode(&vars, "old",
300
 
                                       &global_system_variables.old_mode);
 
190
static sys_var_session_enum         sys_myisam_stats_method(&vars, "myisam_stats_method",
 
191
                                                            &SV::myisam_stats_method,
 
192
                                                            &myisam_stats_method_typelib,
 
193
                                                            NULL);
 
194
static sys_var_session_uint32_t sys_net_buffer_length(&vars, "net_buffer_length",
 
195
                                                      &SV::net_buffer_length);
 
196
static sys_var_session_uint32_t sys_net_read_timeout(&vars, "net_read_timeout",
 
197
                                                     &SV::net_read_timeout,
 
198
                                                     0, fix_net_read_timeout);
 
199
static sys_var_session_uint32_t sys_net_write_timeout(&vars, "net_write_timeout",
 
200
                                                      &SV::net_write_timeout,
 
201
                                                      0, fix_net_write_timeout);
 
202
static sys_var_session_uint32_t sys_net_retry_count(&vars, "net_retry_count",
 
203
                                                    &SV::net_retry_count,
 
204
                                                    0, fix_net_retry_count);
301
205
/* these two cannot be static */
302
 
sys_var_thd_bool                sys_old_alter_table(&vars, "old_alter_table",
303
 
                                            &SV::old_alter_table);
304
 
static sys_var_thd_ulong        sys_optimizer_prune_level(&vars, "optimizer_prune_level",
305
 
                                                  &SV::optimizer_prune_level);
306
 
static sys_var_thd_ulong        sys_optimizer_search_depth(&vars, "optimizer_search_depth",
307
 
                                                   &SV::optimizer_search_depth);
 
206
static sys_var_session_bool sys_optimizer_prune_level(&vars, "optimizer_prune_level",
 
207
                                                      &SV::optimizer_prune_level);
 
208
static sys_var_session_uint32_t sys_optimizer_search_depth(&vars, "optimizer_search_depth",
 
209
                                                           &SV::optimizer_search_depth);
308
210
 
309
 
const char *optimizer_use_mrr_names[] = {"auto", "force", "disable", NullS};
 
211
const char *optimizer_use_mrr_names[] = {"auto", "force", "disable", NULL};
310
212
TYPELIB optimizer_use_mrr_typelib= {
311
213
  array_elements(optimizer_use_mrr_names) - 1, "",
312
214
  optimizer_use_mrr_names, NULL
313
215
};
314
216
 
315
 
static sys_var_thd_enum        sys_optimizer_use_mrr(&vars, "optimizer_use_mrr",
316
 
                                              &SV::optimizer_use_mrr,
317
 
                                              &optimizer_use_mrr_typelib,
318
 
                                              NULL);
319
 
 
320
 
static sys_var_thd_ulong        sys_preload_buff_size(&vars, "preload_buffer_size",
321
 
                                              &SV::preload_buff_size);
322
 
static sys_var_thd_ulong        sys_read_buff_size(&vars, "read_buffer_size",
323
 
                                           &SV::read_buff_size);
324
 
static sys_var_opt_readonly     sys_readonly(&vars, "read_only", &opt_readonly);
325
 
static sys_var_thd_ulong        sys_read_rnd_buff_size(&vars, "read_rnd_buffer_size",
326
 
                                               &SV::read_rnd_buff_size);
327
 
static sys_var_thd_ulong        sys_div_precincrement(&vars, "div_precision_increment",
328
 
                                              &SV::div_precincrement);
329
 
static sys_var_long_ptr sys_rpl_recovery_rank(&vars, "rpl_recovery_rank",
330
 
                                              &rpl_recovery_rank);
331
 
 
332
 
static sys_var_thd_ulong        sys_range_alloc_block_size(&vars, "range_alloc_block_size",
333
 
                                                   &SV::range_alloc_block_size);
334
 
static sys_var_thd_ulong        sys_query_alloc_block_size(&vars, "query_alloc_block_size",
335
 
                                                   &SV::query_alloc_block_size,
336
 
                                                   0, fix_thd_mem_root);
337
 
static sys_var_thd_ulong        sys_query_prealloc_size(&vars, "query_prealloc_size",
338
 
                                                &SV::query_prealloc_size,
339
 
                                                0, fix_thd_mem_root);
340
 
static sys_var_readonly        sys_tmpdir(&vars, "tmpdir", OPT_GLOBAL, SHOW_CHAR, get_tmpdir);
341
 
static sys_var_thd_ulong        sys_trans_alloc_block_size(&vars, "transaction_alloc_block_size",
342
 
                                                   &SV::trans_alloc_block_size,
343
 
                                                   0, fix_trans_mem_root);
344
 
static sys_var_thd_ulong        sys_trans_prealloc_size(&vars, "transaction_prealloc_size",
345
 
                                                &SV::trans_prealloc_size,
346
 
                                                0, fix_trans_mem_root);
347
 
 
348
 
static sys_var_bool_ptr sys_secure_auth(&vars, "secure_auth", &opt_secure_auth);
 
217
static sys_var_session_enum sys_optimizer_use_mrr(&vars, "optimizer_use_mrr",
 
218
                                                  &SV::optimizer_use_mrr,
 
219
                                                  &optimizer_use_mrr_typelib,
 
220
                                                  NULL);
 
221
 
 
222
static sys_var_session_uint64_t sys_preload_buff_size(&vars, "preload_buffer_size",
 
223
                                                      &SV::preload_buff_size);
 
224
static sys_var_session_uint32_t sys_read_buff_size(&vars, "read_buffer_size",
 
225
                                                   &SV::read_buff_size);
 
226
static sys_var_session_uint32_t sys_read_rnd_buff_size(&vars, "read_rnd_buffer_size",
 
227
                                                       &SV::read_rnd_buff_size);
 
228
static sys_var_session_uint32_t sys_div_precincrement(&vars, "div_precision_increment",
 
229
                                                      &SV::div_precincrement);
 
230
 
 
231
static sys_var_session_size_t   sys_range_alloc_block_size(&vars, "range_alloc_block_size",
 
232
                                                           &SV::range_alloc_block_size);
 
233
static sys_var_session_uint32_t sys_query_alloc_block_size(&vars, "query_alloc_block_size",
 
234
                                                           &SV::query_alloc_block_size,
 
235
                                                           false, fix_session_mem_root);
 
236
static sys_var_session_uint32_t sys_query_prealloc_size(&vars, "query_prealloc_size",
 
237
                                                        &SV::query_prealloc_size,
 
238
                                                        false, fix_session_mem_root);
 
239
static sys_var_readonly sys_tmpdir(&vars, "tmpdir", OPT_GLOBAL, SHOW_CHAR, get_tmpdir);
 
240
static sys_var_session_uint32_t sys_trans_alloc_block_size(&vars, "transaction_alloc_block_size",
 
241
                                                           &SV::trans_alloc_block_size,
 
242
                                                           false, fix_trans_mem_root);
 
243
static sys_var_session_uint32_t sys_trans_prealloc_size(&vars, "transaction_prealloc_size",
 
244
                                                        &SV::trans_prealloc_size,
 
245
                                                        false, fix_trans_mem_root);
 
246
 
349
247
static sys_var_const_str_ptr sys_secure_file_priv(&vars, "secure_file_priv",
350
248
                                             &opt_secure_file_priv);
351
 
static sys_var_long_ptr sys_server_id(&vars, "server_id", &server_id, fix_server_id);
352
 
static sys_var_bool_ptr sys_slave_compressed_protocol(&vars, "slave_compressed_protocol",
353
 
                                                      &opt_slave_compressed_protocol);
354
 
#ifdef HAVE_REPLICATION
355
 
static sys_var_bool_ptr         sys_slave_allow_batching(&vars, "slave_allow_batching",
356
 
                                                         &slave_allow_batching);
357
 
static sys_var_set_slave_mode slave_exec_mode(&vars,
358
 
                                              "slave_exec_mode",
359
 
                                              &slave_exec_mode_options,
360
 
                                              &slave_exec_mode_typelib,
361
 
                                              0);
362
 
#endif
363
 
static sys_var_long_ptr sys_slow_launch_time(&vars, "slow_launch_time",
364
 
                                             &slow_launch_time);
365
 
static sys_var_thd_ulong        sys_sort_buffer(&vars, "sort_buffer_size",
366
 
                                        &SV::sortbuff_size);
367
 
/*
368
 
  sql_mode should *not* have binlog_mode=SESSION_VARIABLE_IN_BINLOG:
369
 
  even though it is written to the binlog, the slave ignores the
370
 
  MODE_NO_DIR_IN_CREATE variable, so slave's value differs from
371
 
  master's (see log_event.cc: Query_log_event::do_apply_event()).
372
 
*/
373
 
static sys_var_thd_optimizer_switch   sys_optimizer_switch(&vars, "optimizer_switch",
374
 
                                     &SV::optimizer_switch);
375
 
static sys_var_const_str        sys_ssl_ca(&vars, "ssl_ca", NULL);
376
 
static sys_var_const_str        sys_ssl_capath(&vars, "ssl_capath", NULL);
377
 
static sys_var_const_str        sys_ssl_cert(&vars, "ssl_cert", NULL);
378
 
static sys_var_const_str        sys_ssl_cipher(&vars, "ssl_cipher", NULL);
379
 
static sys_var_const_str        sys_ssl_key(&vars, "ssl_key", NULL);
380
 
 
381
 
static sys_var_thd_storage_engine sys_storage_engine(&vars, "storage_engine",
382
 
                                       &SV::table_plugin);
383
 
static sys_var_bool_ptr sys_sync_frm(&vars, "sync_frm", &opt_sync_frm);
 
249
static sys_var_uint32_t_ptr  sys_server_id(&vars, "server_id", &server_id,
 
250
                                           fix_server_id);
 
251
 
 
252
static sys_var_session_size_t   sys_sort_buffer(&vars, "sort_buffer_size",
 
253
                                                &SV::sortbuff_size);
 
254
static sys_var_session_optimizer_switch   sys_optimizer_switch(&vars, "optimizer_switch",
 
255
                                                               &SV::optimizer_switch);
 
256
 
 
257
static sys_var_session_storage_engine sys_storage_engine(&vars, "storage_engine",
 
258
                                       &SV::storage_engine);
384
259
static sys_var_const_str        sys_system_time_zone(&vars, "system_time_zone",
385
260
                                             system_time_zone);
386
 
static sys_var_long_ptr sys_table_def_size(&vars, "table_definition_cache",
 
261
static sys_var_uint64_t_ptr     sys_table_def_size(&vars, "table_definition_cache",
387
262
                                           &table_def_size);
388
 
static sys_var_long_ptr sys_table_cache_size(&vars, "table_open_cache",
 
263
static sys_var_uint64_t_ptr     sys_table_cache_size(&vars, "table_open_cache",
389
264
                                             &table_cache_size);
390
 
static sys_var_long_ptr sys_table_lock_wait_timeout(&vars, "table_lock_wait_timeout",
 
265
static sys_var_uint64_t_ptr     sys_table_lock_wait_timeout(&vars, "table_lock_wait_timeout",
391
266
                                                    &table_lock_wait_timeout);
392
 
static sys_var_long_ptr sys_thread_cache_size(&vars, "thread_cache_size",
393
 
                                              &thread_cache_size);
394
 
sys_var_long_ptr        sys_thread_pool_size(&vars, "thread_pool_size",
395
 
                                              &thread_pool_size);
396
 
static sys_var_thd_enum sys_tx_isolation(&vars, "tx_isolation",
397
 
                                         &SV::tx_isolation,
398
 
                                         &tx_isolation_typelib,
399
 
                                         fix_tx_isolation,
400
 
                                         check_tx_isolation);
401
 
static sys_var_thd_uint64_t     sys_tmp_table_size(&vars, "tmp_table_size",
 
267
static sys_var_session_enum     sys_tx_isolation(&vars, "tx_isolation",
 
268
                                             &SV::tx_isolation,
 
269
                                             &tx_isolation_typelib,
 
270
                                             fix_tx_isolation,
 
271
                                             check_tx_isolation);
 
272
static sys_var_session_uint64_t sys_tmp_table_size(&vars, "tmp_table_size",
402
273
                                           &SV::tmp_table_size);
403
274
static sys_var_bool_ptr  sys_timed_mutexes(&vars, "timed_mutexes", &timed_mutexes);
404
 
static sys_var_const_str        sys_version(&vars, "version", server_version);
 
275
static sys_var_const_str        sys_version(&vars, "version", VERSION);
405
276
static sys_var_const_str        sys_version_comment(&vars, "version_comment",
406
 
                                            DRIZZLE_COMPILATION_COMMENT);
 
277
                                            COMPILATION_COMMENT);
407
278
static sys_var_const_str        sys_version_compile_machine(&vars, "version_compile_machine",
408
 
                                                    MACHINE_TYPE);
 
279
                                                      HOST_CPU);
409
280
static sys_var_const_str        sys_version_compile_os(&vars, "version_compile_os",
410
 
                                               SYSTEM_TYPE);
411
 
static sys_var_thd_ulong        sys_net_wait_timeout(&vars, "wait_timeout",
412
 
                                             &SV::net_wait_timeout);
 
281
                                                 HOST_OS);
 
282
static sys_var_const_str        sys_version_compile_vendor(&vars, "version_compile_vendor",
 
283
                                                 HOST_VENDOR);
 
284
static sys_var_session_uint32_t sys_net_wait_timeout(&vars, "wait_timeout",
 
285
                                                     &SV::net_wait_timeout);
413
286
 
414
287
/* Condition pushdown to storage engine */
415
 
static sys_var_thd_bool
 
288
static sys_var_session_bool
416
289
sys_engine_condition_pushdown(&vars, "engine_condition_pushdown",
417
290
                              &SV::engine_condition_pushdown);
418
291
 
419
 
/* Time/date/datetime formats */
420
 
 
421
 
static sys_var_thd_date_time_format sys_time_format(&vars, "time_format",
422
 
                                             &SV::time_format,
423
 
                                             DRIZZLE_TIMESTAMP_TIME);
424
 
static sys_var_thd_date_time_format sys_date_format(&vars, "date_format",
425
 
                                             &SV::date_format,
426
 
                                             DRIZZLE_TIMESTAMP_DATE);
427
 
static sys_var_thd_date_time_format sys_datetime_format(&vars, "datetime_format",
428
 
                                                 &SV::datetime_format,
429
 
                                                 DRIZZLE_TIMESTAMP_DATETIME);
430
 
 
431
 
/* Variables that are bits in THD */
432
 
 
433
 
sys_var_thd_bit sys_autocommit(&vars, "autocommit", 0,
 
292
/* Variables that are bits in Session */
 
293
 
 
294
sys_var_session_bit sys_autocommit(&vars, "autocommit", 0,
434
295
                               set_option_autocommit,
435
296
                               OPTION_NOT_AUTOCOMMIT,
436
297
                               1);
437
 
static sys_var_thd_bit  sys_big_tables(&vars, "big_tables", 0,
438
 
                                       set_option_bit,
439
 
                                       OPTION_BIG_TABLES);
440
 
#ifndef TO_BE_DELETED   /* Alias for big_tables */
441
 
static sys_var_thd_bit  sys_sql_big_tables(&vars, "sql_big_tables", 0,
442
 
                                           set_option_bit,
443
 
                                           OPTION_BIG_TABLES);
444
 
#endif
445
 
static sys_var_thd_bit  sys_big_selects(&vars, "sql_big_selects", 0,
 
298
static sys_var_session_bit      sys_big_selects(&vars, "sql_big_selects", 0,
446
299
                                        set_option_bit,
447
300
                                        OPTION_BIG_SELECTS);
448
 
static sys_var_thd_bit  sys_log_off(&vars, "sql_log_off",
449
 
                                    check_log_update,
450
 
                                    set_option_bit,
451
 
                                    OPTION_LOG_OFF);
452
 
static sys_var_thd_bit  sys_log_update(&vars, "sql_log_update",
453
 
                                       check_log_update,
454
 
                                       set_log_update,
455
 
                                       OPTION_BIN_LOG);
456
 
static sys_var_thd_bit  sys_log_binlog(&vars, "sql_log_bin",
457
 
                                       check_log_update,
458
 
                                       set_option_bit,
459
 
                                       OPTION_BIN_LOG);
460
 
static sys_var_thd_bit  sys_sql_warnings(&vars, "sql_warnings", 0,
 
301
static sys_var_session_bit      sys_sql_warnings(&vars, "sql_warnings", 0,
461
302
                                         set_option_bit,
462
303
                                         OPTION_WARNINGS);
463
 
static sys_var_thd_bit  sys_sql_notes(&vars, "sql_notes", 0,
 
304
static sys_var_session_bit      sys_sql_notes(&vars, "sql_notes", 0,
464
305
                                         set_option_bit,
465
306
                                         OPTION_SQL_NOTES);
466
 
static sys_var_thd_bit  sys_auto_is_null(&vars, "sql_auto_is_null", 0,
467
 
                                         set_option_bit,
468
 
                                         OPTION_AUTO_IS_NULL, 0,
469
 
                                         sys_var::SESSION_VARIABLE_IN_BINLOG);
470
 
static sys_var_thd_bit  sys_safe_updates(&vars, "sql_safe_updates", 0,
 
307
static sys_var_session_bit      sys_safe_updates(&vars, "sql_safe_updates", 0,
471
308
                                         set_option_bit,
472
309
                                         OPTION_SAFE_UPDATES);
473
 
static sys_var_thd_bit  sys_buffer_results(&vars, "sql_buffer_result", 0,
 
310
static sys_var_session_bit      sys_buffer_results(&vars, "sql_buffer_result", 0,
474
311
                                           set_option_bit,
475
312
                                           OPTION_BUFFER_RESULT);
476
 
static sys_var_thd_bit  sys_quote_show_create(&vars, "sql_quote_show_create", 0,
477
 
                                              set_option_bit,
478
 
                                              OPTION_QUOTE_SHOW_CREATE);
479
 
static sys_var_thd_bit  sys_foreign_key_checks(&vars, "foreign_key_checks", 0,
 
313
static sys_var_session_bit      sys_foreign_key_checks(&vars, "foreign_key_checks", 0,
480
314
                                               set_option_bit,
481
 
                                               OPTION_NO_FOREIGN_KEY_CHECKS,
482
 
                                               1, sys_var::SESSION_VARIABLE_IN_BINLOG);
483
 
static sys_var_thd_bit  sys_unique_checks(&vars, "unique_checks", 0,
 
315
                                               OPTION_NO_FOREIGN_KEY_CHECKS, 1);
 
316
static sys_var_session_bit      sys_unique_checks(&vars, "unique_checks", 0,
484
317
                                          set_option_bit,
485
 
                                          OPTION_RELAXED_UNIQUE_CHECKS,
486
 
                                          1,
487
 
                                          sys_var::SESSION_VARIABLE_IN_BINLOG);
 
318
                                          OPTION_RELAXED_UNIQUE_CHECKS, 1);
488
319
/* Local state variables */
489
320
 
490
 
static sys_var_thd_ha_rows      sys_select_limit(&vars, "sql_select_limit",
 
321
static sys_var_session_ha_rows  sys_select_limit(&vars, "sql_select_limit",
491
322
                                                 &SV::select_limit);
492
 
static sys_var_timestamp sys_timestamp(&vars, "timestamp",
493
 
                                       sys_var::SESSION_VARIABLE_IN_BINLOG);
 
323
static sys_var_timestamp sys_timestamp(&vars, "timestamp");
494
324
static sys_var_last_insert_id
495
 
sys_last_insert_id(&vars, "last_insert_id",
496
 
                   sys_var::SESSION_VARIABLE_IN_BINLOG);
 
325
sys_last_insert_id(&vars, "last_insert_id");
497
326
/*
498
327
  identity is an alias for last_insert_id(), so that we are compatible
499
328
  with Sybase
500
329
*/
501
 
static sys_var_last_insert_id
502
 
sys_identity(&vars, "identity", sys_var::SESSION_VARIABLE_IN_BINLOG);
 
330
static sys_var_last_insert_id sys_identity(&vars, "identity");
503
331
 
504
 
static sys_var_thd_lc_time_names
505
 
sys_lc_time_names(&vars, "lc_time_names", sys_var::SESSION_VARIABLE_IN_BINLOG);
 
332
static sys_var_session_lc_time_names sys_lc_time_names(&vars, "lc_time_names");
506
333
 
507
334
/*
508
 
  insert_id should *not* be marked as written to the binlog (i.e., it
509
 
  should *not* have binlog_status==SESSION_VARIABLE_IN_BINLOG),
510
 
  because we want any statement that refers to insert_id explicitly to
511
 
  be unsafe.  (By "explicitly", we mean using @@session.insert_id,
512
 
  whereas insert_id is used "implicitly" when NULL value is inserted
513
 
  into an auto_increment column).
514
 
 
515
335
  We want statements referring explicitly to @@session.insert_id to be
516
336
  unsafe, because insert_id is modified internally by the slave sql
517
337
  thread when NULL values are inserted in an AUTO_INCREMENT column.
523
343
  statement-based logging mode: t will be different on master and
524
344
  slave).
525
345
*/
526
 
static sys_var_insert_id sys_insert_id(&vars, "insert_id");
527
 
static sys_var_readonly         sys_error_count(&vars, "error_count",
528
 
                                                OPT_SESSION,
529
 
                                                SHOW_LONG,
530
 
                                                get_error_count);
531
 
static sys_var_readonly         sys_warning_count(&vars, "warning_count",
532
 
                                                  OPT_SESSION,
533
 
                                                  SHOW_LONG,
534
 
                                                  get_warning_count);
535
 
 
536
 
static sys_var_rand_seed1 sys_rand_seed1(&vars, "rand_seed1",
537
 
                                         sys_var::SESSION_VARIABLE_IN_BINLOG);
538
 
static sys_var_rand_seed2 sys_rand_seed2(&vars, "rand_seed2",
539
 
                                         sys_var::SESSION_VARIABLE_IN_BINLOG);
540
 
 
541
 
static sys_var_thd_ulong        sys_default_week_format(&vars, "default_week_format",
542
 
                                                        &SV::default_week_format);
543
 
 
544
 
sys_var_thd_ulong               sys_group_concat_max_len(&vars, "group_concat_max_len",
545
 
                                                         &SV::group_concat_max_len);
546
 
 
547
 
sys_var_thd_time_zone sys_time_zone(&vars, "time_zone",
548
 
                                    sys_var::SESSION_VARIABLE_IN_BINLOG);
 
346
static sys_var_readonly sys_error_count(&vars, "error_count",
 
347
                                        OPT_SESSION,
 
348
                                        SHOW_INT,
 
349
                                        get_error_count);
 
350
static sys_var_readonly sys_warning_count(&vars, "warning_count",
 
351
                                          OPT_SESSION,
 
352
                                          SHOW_INT,
 
353
                                          get_warning_count);
 
354
 
 
355
sys_var_session_uint64_t sys_group_concat_max_len(&vars, "group_concat_max_len",
 
356
                                                  &SV::group_concat_max_len);
 
357
 
 
358
sys_var_session_time_zone sys_time_zone(&vars, "time_zone");
549
359
 
550
360
/* Global read-only variable containing hostname */
551
361
static sys_var_const_str        sys_hostname(&vars, "hostname", glob_hostname);
552
362
 
553
 
static sys_var_const_str_ptr    sys_repl_report_host(&vars, "report_host", &report_host);
554
 
static sys_var_const_str_ptr    sys_repl_report_user(&vars, "report_user", &report_user);
555
 
static sys_var_const_str_ptr    sys_repl_report_password(&vars, "report_password", &report_password);
556
 
 
557
 
static uchar *slave_get_report_port(THD *thd)
558
 
{
559
 
  thd->sys_var_tmp.long_value= report_port;
560
 
  return (uchar*) &thd->sys_var_tmp.long_value;
561
 
}
562
 
 
563
 
static sys_var_readonly    sys_repl_report_port(&vars, "report_port", OPT_GLOBAL, SHOW_INT, slave_get_report_port);
564
 
 
565
 
sys_var_thd_bool  sys_keep_files_on_create(&vars, "keep_files_on_create", 
566
 
                                           &SV::keep_files_on_create);
567
363
/* Read only variables */
568
364
 
569
 
static sys_var_have_variable sys_have_compress(&vars, "have_compress", &have_compress);
570
365
static sys_var_have_variable sys_have_symlink(&vars, "have_symlink", &have_symlink);
571
 
/* Global variables which enable|disable logging */
572
 
static sys_var_log_state sys_var_general_log(&vars, "general_log", &opt_log,
573
 
                                      QUERY_LOG_GENERAL);
574
 
/* Synonym of "general_log" for consistency with SHOW VARIABLES output */
575
 
static sys_var_log_state sys_var_log(&vars, "log", &opt_log, QUERY_LOG_GENERAL);
576
 
static sys_var_log_state sys_var_slow_query_log(&vars, "slow_query_log", &opt_slow_log,
577
 
                                         QUERY_LOG_SLOW);
578
 
/* Synonym of "slow_query_log" for consistency with SHOW VARIABLES output */
579
 
static sys_var_log_state sys_var_log_slow(&vars, "log_slow_queries",
580
 
                                          &opt_slow_log, QUERY_LOG_SLOW);
581
 
sys_var_str sys_var_general_log_path(&vars, "general_log_file", sys_check_log_path,
582
 
                                     sys_update_general_log_path,
583
 
                                     sys_default_general_log_path,
584
 
                                     opt_logname);
585
 
sys_var_str sys_var_slow_log_path(&vars, "slow_query_log_file", sys_check_log_path,
586
 
                                  sys_update_slow_log_path, 
587
 
                                  sys_default_slow_log_path,
588
 
                                  opt_slow_logname);
589
 
static sys_var_log_output sys_var_log_output_state(&vars, "log_output", &log_output_options,
590
 
                                            &log_output_typelib, 0);
591
 
 
592
 
 
593
366
/*
594
367
  Additional variables (not derived from sys_var class, not accessible as
595
368
  @@varname in SELECT or SET). Sorted in alphabetical order to facilitate
599
372
 
600
373
#define FIXED_VARS_SIZE (sizeof(fixed_vars) / sizeof(SHOW_VAR))
601
374
static SHOW_VAR fixed_vars[]= {
602
 
  {"back_log",                (char*) &back_log,                    SHOW_LONG},
603
 
  {"character_sets_dir",      mysql_charsets_dir,                   SHOW_CHAR},
604
 
  {"init_file",               (char*) &opt_init_file,               SHOW_CHAR_PTR},
 
375
  {"back_log",                (char*) &back_log,                    SHOW_INT},
605
376
  {"language",                language,                             SHOW_CHAR},
606
377
#ifdef HAVE_MLOCKALL
607
378
  {"locked_in_memory",        (char*) &locked_in_memory,            SHOW_MY_BOOL},
608
379
#endif
609
 
  {"log_bin",                 (char*) &opt_bin_log,                 SHOW_BOOL},
610
 
  {"log_error",               (char*) log_error_file,               SHOW_CHAR},
611
 
  {"myisam_recover_options",  (char*) &myisam_recover_options_str,  SHOW_CHAR_PTR},
612
 
  {"open_files_limit",        (char*) &open_files_limit,            SHOW_LONG},
613
380
  {"pid_file",                (char*) pidfile_name,                 SHOW_CHAR},
614
381
  {"plugin_dir",              (char*) opt_plugin_dir,               SHOW_CHAR},
615
 
  {"port",                    (char*) &mysqld_port,                 SHOW_INT},
616
 
  {"protocol_version",        (char*) &protocol_version,            SHOW_INT},
617
 
  {"thread_stack",            (char*) &my_thread_stack_size,        SHOW_LONG},
 
382
  {"port",                    (char*) &drizzled_tcp_port,           SHOW_INT},
 
383
  {"thread_stack",            (char*) &my_thread_stack_size,        SHOW_INT},
618
384
};
619
385
 
620
 
 
621
 
bool sys_var::check(THD *thd __attribute__((unused)), set_var *var)
 
386
bool sys_var::check(Session *, set_var *var)
622
387
{
623
388
  var->save_result.uint64_t_value= var->value->val_int();
624
389
  return 0;
625
390
}
626
391
 
627
 
bool sys_var_str::check(THD *thd, set_var *var)
 
392
bool sys_var_str::check(Session *session, set_var *var)
628
393
{
629
394
  int res;
630
395
  if (!check_func)
631
396
    return 0;
632
397
 
633
 
  if ((res=(*check_func)(thd, var)) < 0)
634
 
    my_error(ER_WRONG_VALUE_FOR_VAR, MYF(0),
635
 
             name, var->value->str_value.ptr());
 
398
  if ((res=(*check_func)(session, var)) < 0)
 
399
    my_error(ER_WRONG_VALUE_FOR_VAR, MYF(0), getName().c_str(), var->value->str_value.ptr());
636
400
  return res;
637
401
}
638
402
 
641
405
*/
642
406
 
643
407
 
644
 
/*
645
 
  Update variables 'init_connect, init_slave'.
646
 
 
647
 
  In case of 'DEFAULT' value
648
 
  (for example: 'set GLOBAL init_connect=DEFAULT')
649
 
  'var' parameter is NULL pointer.
650
 
*/
651
 
 
652
 
bool update_sys_var_str(sys_var_str *var_str, rw_lock_t *var_mutex,
653
 
                        set_var *var)
654
 
{
655
 
  char *res= 0, *old_value=(char *)(var ? var->value->str_value.ptr() : 0);
656
 
  uint new_length= (var ? var->value->str_value.length() : 0);
657
 
  if (!old_value)
658
 
    old_value= (char*) "";
659
 
  if (!(res= my_strndup(old_value, new_length, MYF(0))))
660
 
    return 1;
661
 
  /*
662
 
    Replace the old value in such a way that the any thread using
663
 
    the value will work.
664
 
  */
665
 
  rw_wrlock(var_mutex);
666
 
  old_value= var_str->value;
667
 
  var_str->value= res;
668
 
  var_str->value_length= new_length;
669
 
  rw_unlock(var_mutex);
670
 
  my_free(old_value, MYF(MY_ALLOW_ZERO_PTR));
671
 
  return 0;
672
 
}
673
 
 
674
 
 
675
 
static bool sys_update_init_connect(THD *thd __attribute__((unused)), set_var *var)
676
 
{
677
 
  return update_sys_var_str(&sys_init_connect, &LOCK_sys_init_connect, var);
678
 
}
679
 
 
680
 
 
681
 
static void sys_default_init_connect(THD* thd __attribute__((unused)),
682
 
                                     enum_var_type type __attribute__((unused)))
683
 
{
684
 
  update_sys_var_str(&sys_init_connect, &LOCK_sys_init_connect, 0);
685
 
}
686
 
 
687
 
 
688
 
static bool sys_update_init_slave(THD *thd __attribute__((unused)),
689
 
                                  set_var *var)
690
 
{
691
 
  return update_sys_var_str(&sys_init_slave, &LOCK_sys_init_slave, var);
692
 
}
693
 
 
694
 
 
695
 
static void sys_default_init_slave(THD* thd __attribute__((unused)),
696
 
                                   enum_var_type type __attribute__((unused)))
697
 
{
698
 
  update_sys_var_str(&sys_init_slave, &LOCK_sys_init_slave, 0);
699
 
}
700
 
 
701
 
 
702
 
/**
703
 
  If one sets the LOW_PRIORIY UPDATES flag, we also must change the
704
 
  used lock type.
705
 
*/
706
 
 
707
 
static void fix_low_priority_updates(THD *thd, enum_var_type type)
708
 
{
709
 
  if (type == OPT_GLOBAL)
710
 
    thr_upgraded_concurrent_insert_lock= 
711
 
      (global_system_variables.low_priority_updates ?
712
 
       TL_WRITE_LOW_PRIORITY : TL_WRITE);
713
 
  else
714
 
    thd->update_lock_default= (thd->variables.low_priority_updates ?
715
 
                               TL_WRITE_LOW_PRIORITY : TL_WRITE);
716
 
}
717
 
 
718
 
 
719
 
static void
720
 
fix_myisam_max_sort_file_size(THD *thd __attribute__((unused)),
721
 
                              enum_var_type type __attribute__((unused)))
722
 
{
723
 
  myisam_max_temp_length=
724
 
    (my_off_t) global_system_variables.myisam_max_sort_file_size;
725
 
}
726
 
 
727
408
/**
728
409
  Set the OPTION_BIG_SELECTS flag if max_join_size == HA_POS_ERROR.
729
410
*/
730
411
 
731
 
static void fix_max_join_size(THD *thd, enum_var_type type)
 
412
static void fix_max_join_size(Session *session, enum_var_type type)
732
413
{
733
414
  if (type != OPT_GLOBAL)
734
415
  {
735
 
    if (thd->variables.max_join_size == HA_POS_ERROR)
736
 
      thd->options|= OPTION_BIG_SELECTS;
 
416
    if (session->variables.max_join_size == HA_POS_ERROR)
 
417
      session->options|= OPTION_BIG_SELECTS;
737
418
    else
738
 
      thd->options&= ~OPTION_BIG_SELECTS;
 
419
      session->options&= ~OPTION_BIG_SELECTS;
739
420
  }
740
421
}
741
422
 
744
425
  Can't change the 'next' tx_isolation while we are already in
745
426
  a transaction
746
427
*/
747
 
static int check_tx_isolation(THD *thd, set_var *var)
 
428
static int check_tx_isolation(Session *session, set_var *var)
748
429
{
749
 
  if (var->type == OPT_DEFAULT && (thd->server_status & SERVER_STATUS_IN_TRANS))
 
430
  if (var->type == OPT_DEFAULT && (session->server_status & SERVER_STATUS_IN_TRANS))
750
431
  {
751
432
    my_error(ER_CANT_CHANGE_TX_ISOLATION, MYF(0));
752
433
    return 1;
758
439
  If one doesn't use the SESSION modifier, the isolation level
759
440
  is only active for the next command.
760
441
*/
761
 
static void fix_tx_isolation(THD *thd, enum_var_type type)
 
442
static void fix_tx_isolation(Session *session, enum_var_type type)
762
443
{
763
444
  if (type == OPT_SESSION)
764
 
    thd->session_tx_isolation= ((enum_tx_isolation)
765
 
                                thd->variables.tx_isolation);
 
445
    session->session_tx_isolation= ((enum_tx_isolation)
 
446
                                    session->variables.tx_isolation);
766
447
}
767
448
 
768
 
static void fix_completion_type(THD *thd __attribute__((unused)),
769
 
                                enum_var_type type __attribute__((unused))) {}
 
449
static void fix_completion_type(Session *, enum_var_type) {}
770
450
 
771
 
static int check_completion_type(THD *thd __attribute__((unused)),
772
 
                                 set_var *var)
 
451
static int check_completion_type(Session *, set_var *var)
773
452
{
774
453
  int64_t val= var->value->val_int();
775
454
  if (val < 0 || val > 2)
776
455
  {
777
456
    char buf[64];
778
 
    my_error(ER_WRONG_VALUE_FOR_VAR, MYF(0), var->var->name, llstr(val, buf));
 
457
    my_error(ER_WRONG_VALUE_FOR_VAR, MYF(0), var->var->getName().c_str(), llstr(val, buf));
779
458
    return 1;
780
459
  }
781
460
  return 0;
783
462
 
784
463
 
785
464
/*
786
 
  If we are changing the thread variable, we have to copy it to NET too
 
465
  If we are changing the thread variable, we have to copy it to Protocol too
787
466
*/
788
467
 
789
 
#ifdef HAVE_REPLICATION
790
 
static void fix_net_read_timeout(THD *thd, enum_var_type type)
791
 
{
792
 
  if (type != OPT_GLOBAL)
793
 
    my_net_set_read_timeout(&thd->net, thd->variables.net_read_timeout);
794
 
}
795
 
 
796
 
 
797
 
static void fix_net_write_timeout(THD *thd, enum_var_type type)
798
 
{
799
 
  if (type != OPT_GLOBAL)
800
 
    my_net_set_write_timeout(&thd->net, thd->variables.net_write_timeout);
801
 
}
802
 
 
803
 
static void fix_net_retry_count(THD *thd, enum_var_type type)
804
 
{
805
 
  if (type != OPT_GLOBAL)
806
 
    thd->net.retry_count=thd->variables.net_retry_count;
807
 
}
808
 
#else /* HAVE_REPLICATION */
809
 
static void fix_net_read_timeout(THD *thd __attribute__((unused)),
810
 
                                 enum_var_type type __attribute__((unused)))
811
 
{}
812
 
static void fix_net_write_timeout(THD *thd __attribute__((unused)),
813
 
                                  enum_var_type type __attribute__((unused)))
814
 
{}
815
 
static void fix_net_retry_count(THD *thd __attribute__((unused)),
816
 
                                enum_var_type type __attribute__((unused)))
817
 
{}
818
 
#endif /* HAVE_REPLICATION */
819
 
 
820
 
 
821
 
extern void fix_delay_key_write(THD *thd __attribute__((unused)),
822
 
                                enum_var_type type __attribute__((unused)))
 
468
static void fix_net_read_timeout(Session *session, enum_var_type type)
 
469
{
 
470
  if (type != OPT_GLOBAL)
 
471
    session->protocol->setReadTimeout(session->variables.net_read_timeout);
 
472
}
 
473
 
 
474
 
 
475
static void fix_net_write_timeout(Session *session, enum_var_type type)
 
476
{
 
477
  if (type != OPT_GLOBAL)
 
478
    session->protocol->setWriteTimeout(session->variables.net_write_timeout);
 
479
}
 
480
 
 
481
static void fix_net_retry_count(Session *session, enum_var_type type)
 
482
{
 
483
  if (type != OPT_GLOBAL)
 
484
    session->protocol->setRetryCount(session->variables.net_retry_count);
 
485
}
 
486
 
 
487
 
 
488
extern void fix_delay_key_write(Session *, enum_var_type)
823
489
{
824
490
  switch ((enum_delay_key_write) delay_key_write_options) {
825
491
  case DELAY_KEY_WRITE_NONE:
835
501
  }
836
502
}
837
503
 
838
 
bool sys_var_set::update(THD *thd __attribute__((unused)),
839
 
                         set_var *var)
840
 
{
841
 
  *value= var->save_result.ulong_value;
842
 
  return 0;
843
 
}
844
 
 
845
 
uchar *sys_var_set::value_ptr(THD *thd,
846
 
                              enum_var_type type __attribute__((unused)),
847
 
                              LEX_STRING *base __attribute__((unused)))
848
 
{
849
 
  char buff[256];
850
 
  String tmp(buff, sizeof(buff), &my_charset_latin1);
851
 
  ulong length;
852
 
  ulong val= *value;
853
 
 
854
 
  tmp.length(0);
855
 
  for (uint i= 0; val; val>>= 1, i++)
856
 
  {
857
 
    if (val & 1)
858
 
    {
859
 
      tmp.append(enum_names->type_names[i],
860
 
                 enum_names->type_lengths[i]);
861
 
      tmp.append(',');
862
 
    }
863
 
  }
864
 
 
865
 
  if ((length= tmp.length()))
866
 
    length--;
867
 
  return (uchar*) thd->strmake(tmp.ptr(), length);
868
 
}
869
 
 
870
 
void sys_var_set_slave_mode::set_default(THD *thd __attribute__((unused)),
871
 
                                         enum_var_type type __attribute__((unused)))
872
 
{
873
 
  slave_exec_mode_options= 0;
874
 
  bit_do_set(slave_exec_mode_options, SLAVE_EXEC_MODE_STRICT);
875
 
}
876
 
 
877
 
bool sys_var_set_slave_mode::check(THD *thd, set_var *var)
878
 
{
879
 
  bool rc=  sys_var_set::check(thd, var);
880
 
  if (!rc &&
881
 
      bit_is_set(var->save_result.ulong_value, SLAVE_EXEC_MODE_STRICT) == 1 &&
882
 
      bit_is_set(var->save_result.ulong_value, SLAVE_EXEC_MODE_IDEMPOTENT) == 1)
883
 
  {
884
 
    rc= true;
885
 
    my_error(ER_SLAVE_AMBIGOUS_EXEC_MODE, MYF(0), "");
886
 
  }
887
 
  return rc;
888
 
}
889
 
 
890
 
bool sys_var_set_slave_mode::update(THD *thd, set_var *var)
891
 
{
892
 
  bool rc;
893
 
  pthread_mutex_lock(&LOCK_global_system_variables);
894
 
  rc= sys_var_set::update(thd, var);
895
 
  pthread_mutex_unlock(&LOCK_global_system_variables);
896
 
  return rc;
897
 
}
898
 
 
899
 
void fix_slave_exec_mode(enum_var_type type __attribute__((unused)))
900
 
{
901
 
  if (bit_is_set(slave_exec_mode_options, SLAVE_EXEC_MODE_STRICT) == 1 &&
902
 
      bit_is_set(slave_exec_mode_options, SLAVE_EXEC_MODE_IDEMPOTENT) == 1)
903
 
  {
904
 
    sql_print_error("Ambiguous slave modes combination."
905
 
                    " STRICT will be used");
906
 
    bit_do_clear(slave_exec_mode_options, SLAVE_EXEC_MODE_IDEMPOTENT);
907
 
  }
908
 
  if (bit_is_set(slave_exec_mode_options, SLAVE_EXEC_MODE_IDEMPOTENT) == 0)
909
 
    bit_do_set(slave_exec_mode_options, SLAVE_EXEC_MODE_STRICT);
910
 
}
911
 
 
912
 
bool sys_var_thd_binlog_format::is_readonly() const
913
 
{
914
 
  /*
915
 
    Under certain circumstances, the variable is read-only (unchangeable):
916
 
  */
917
 
  THD *thd= current_thd;
918
 
  /*
919
 
    If RBR and open temporary tables, their CREATE TABLE may not be in the
920
 
    binlog, so we can't toggle to SBR in this connection.
921
 
    The test below will also prevent SET GLOBAL, well it was not easy to test
922
 
    if global or not here.
923
 
    And this test will also prevent switching from RBR to RBR (a no-op which
924
 
    should not happen too often).
925
 
 
926
 
    If we don't have row-based replication compiled in, the variable
927
 
    is always read-only.
928
 
  */
929
 
  if ((thd->variables.binlog_format == BINLOG_FORMAT_ROW) &&
930
 
      thd->temporary_tables)
931
 
  {
932
 
    my_error(ER_TEMP_TABLE_PREVENTS_SWITCH_OUT_OF_RBR, MYF(0));
933
 
    return 1;
934
 
  }
935
 
  /*
936
 
    if in a stored function/trigger, it's too late to change mode
937
 
  */
938
 
  if (thd->in_sub_stmt)
939
 
  {
940
 
    my_error(ER_STORED_FUNCTION_PREVENTS_SWITCH_BINLOG_FORMAT, MYF(0));
941
 
    return 1;    
942
 
  }
943
 
  return sys_var_thd_enum::is_readonly();
944
 
}
945
 
 
946
 
 
947
 
void fix_binlog_format_after_update(THD *thd,
948
 
                                    enum_var_type type __attribute__((unused)))
949
 
{
950
 
  thd->reset_current_stmt_binlog_row_based();
951
 
}
952
 
 
953
 
 
954
 
static void fix_max_binlog_size(THD *thd __attribute__((unused)),
955
 
                                enum_var_type type __attribute__((unused)))
956
 
{
957
 
  mysql_bin_log.set_max_size(max_binlog_size);
958
 
#ifdef HAVE_REPLICATION
959
 
  if (!max_relay_log_size)
960
 
    active_mi->rli.relay_log.set_max_size(max_binlog_size);
961
 
#endif
962
 
  return;
963
 
}
964
 
 
965
 
static void fix_max_relay_log_size(THD *thd __attribute__((unused)),
966
 
                                   enum_var_type type __attribute__((unused)))
967
 
{
968
 
#ifdef HAVE_REPLICATION
969
 
  active_mi->rli.relay_log.set_max_size(max_relay_log_size ?
970
 
                                        max_relay_log_size: max_binlog_size);
971
 
#endif
972
 
  return;
973
 
}
974
 
 
975
 
static void fix_max_connections(THD *thd __attribute__((unused)),
976
 
                                enum_var_type type __attribute__((unused)))
977
 
{
978
 
  resize_thr_alarm(max_connections +  10);
979
 
}
980
 
 
981
 
 
982
 
static void fix_thd_mem_root(THD *thd, enum_var_type type)
983
 
{
984
 
  if (type != OPT_GLOBAL)
985
 
    reset_root_defaults(thd->mem_root,
986
 
                        thd->variables.query_alloc_block_size,
987
 
                        thd->variables.query_prealloc_size);
988
 
}
989
 
 
990
 
 
991
 
static void fix_trans_mem_root(THD *thd, enum_var_type type)
992
 
{
993
 
  if (type != OPT_GLOBAL)
994
 
    reset_root_defaults(&thd->transaction.mem_root,
995
 
                        thd->variables.trans_alloc_block_size,
996
 
                        thd->variables.trans_prealloc_size);
997
 
}
998
 
 
999
 
 
1000
 
static void fix_server_id(THD *thd __attribute__((unused)),
1001
 
                          enum_var_type type __attribute__((unused)))
1002
 
{
1003
 
  server_id_supplied = 1;
1004
 
  thd->server_id= server_id;
1005
 
}
1006
 
 
1007
 
 
1008
 
bool throw_bounds_warning(THD *thd, bool fixed, bool unsignd,
1009
 
                          const char *name, int64_t val)
 
504
 
 
505
static void fix_session_mem_root(Session *session, enum_var_type type)
 
506
{
 
507
  if (type != OPT_GLOBAL)
 
508
    reset_root_defaults(session->mem_root,
 
509
                        session->variables.query_alloc_block_size,
 
510
                        session->variables.query_prealloc_size);
 
511
}
 
512
 
 
513
 
 
514
static void fix_trans_mem_root(Session *session, enum_var_type type)
 
515
{
 
516
  if (type != OPT_GLOBAL)
 
517
    reset_root_defaults(&session->transaction.mem_root,
 
518
                        session->variables.trans_alloc_block_size,
 
519
                        session->variables.trans_prealloc_size);
 
520
}
 
521
 
 
522
 
 
523
static void fix_server_id(Session *, enum_var_type)
 
524
{
 
525
}
 
526
 
 
527
 
 
528
bool throw_bounds_warning(Session *session, bool fixed, bool unsignd,
 
529
                          const std::string &name, int64_t val)
1010
530
{
1011
531
  if (fixed)
1012
532
  {
1017
537
    else
1018
538
      llstr(val, buf);
1019
539
 
1020
 
    push_warning_printf(thd, DRIZZLE_ERROR::WARN_LEVEL_WARN,
 
540
    push_warning_printf(session, DRIZZLE_ERROR::WARN_LEVEL_ERROR,
1021
541
                        ER_TRUNCATED_WRONG_VALUE,
1022
 
                        ER(ER_TRUNCATED_WRONG_VALUE), name, buf);
 
542
                        ER(ER_TRUNCATED_WRONG_VALUE), name.c_str(), buf);
1023
543
  }
1024
544
  return false;
1025
545
}
1026
546
 
1027
 
static uint64_t fix_unsigned(THD *thd, uint64_t num,
 
547
static uint64_t fix_unsigned(Session *session, uint64_t num,
1028
548
                              const struct my_option *option_limits)
1029
549
{
1030
550
  bool fixed= false;
1031
551
  uint64_t out= getopt_ull_limit_value(num, option_limits, &fixed);
1032
552
 
1033
 
  throw_bounds_warning(thd, fixed, true, option_limits->name, (int64_t) num);
1034
 
  return out;
1035
 
}
1036
 
 
1037
 
static bool get_unsigned(THD *thd __attribute__((unused)), set_var *var)
1038
 
{
1039
 
  if (var->value->unsigned_flag)
1040
 
    var->save_result.uint64_t_value= (uint64_t) var->value->val_int();
1041
 
  else
1042
 
  {
1043
 
    int64_t v= var->value->val_int();
1044
 
    var->save_result.uint64_t_value= (uint64_t) ((v < 0) ? 0 : v);
1045
 
  }
1046
 
  return 0;
1047
 
}
1048
 
 
1049
 
 
1050
 
sys_var_long_ptr::
1051
 
sys_var_long_ptr(sys_var_chain *chain, const char *name_arg, ulong *value_ptr_arg,
1052
 
                 sys_after_update_func after_update_arg)
1053
 
  :sys_var_long_ptr_global(chain, name_arg, value_ptr_arg,
1054
 
                           &LOCK_global_system_variables, after_update_arg)
1055
 
{}
1056
 
 
1057
 
 
1058
 
bool sys_var_long_ptr_global::check(THD *thd, set_var *var)
1059
 
{
1060
 
  return get_unsigned(thd, var);
1061
 
}
1062
 
 
1063
 
bool sys_var_long_ptr_global::update(THD *thd, set_var *var)
1064
 
{
1065
 
  uint64_t tmp= var->save_result.uint64_t_value;
1066
 
  pthread_mutex_lock(guard);
 
553
  throw_bounds_warning(session, fixed, true, option_limits->name, (int64_t) num);
 
554
  return out;
 
555
}
 
556
 
 
557
 
 
558
static size_t fix_size_t(Session *session, size_t num,
 
559
                           const struct my_option *option_limits)
 
560
{
 
561
  bool fixed= false;
 
562
  size_t out= (size_t)getopt_ull_limit_value(num, option_limits, &fixed);
 
563
 
 
564
  throw_bounds_warning(session, fixed, true, option_limits->name, (int64_t) num);
 
565
  return out;
 
566
}
 
567
 
 
568
static bool get_unsigned32(Session *, set_var *var)
 
569
{
 
570
  if (var->value->unsigned_flag)
 
571
    var->save_result.uint32_t_value= (uint32_t) var->value->val_int();
 
572
  else
 
573
  {
 
574
    int64_t v= var->value->val_int();
 
575
    var->save_result.uint32_t_value= (uint32_t) ((v < 0) ? 0 : v);
 
576
  }
 
577
  return 0;
 
578
}
 
579
 
 
580
static bool get_unsigned64(Session *, set_var *var)
 
581
{
 
582
  if (var->value->unsigned_flag)
 
583
      var->save_result.uint64_t_value=(uint64_t) var->value->val_int();
 
584
  else
 
585
  {
 
586
    int64_t v= var->value->val_int();
 
587
      var->save_result.uint64_t_value= (uint64_t) ((v < 0) ? 0 : v);
 
588
  }
 
589
  return 0;
 
590
}
 
591
 
 
592
static bool get_size_t(Session *, set_var *var)
 
593
{
 
594
  if (var->value->unsigned_flag)
 
595
    var->save_result.size_t_value= (size_t) var->value->val_int();
 
596
  else
 
597
  {
 
598
    ssize_t v= (ssize_t)var->value->val_int();
 
599
    var->save_result.size_t_value= (size_t) ((v < 0) ? 0 : v);
 
600
  }
 
601
  return 0;
 
602
}
 
603
 
 
604
bool sys_var_uint32_t_ptr::check(Session *, set_var *var)
 
605
{
 
606
  var->save_result.uint32_t_value= (uint32_t)var->value->val_int();
 
607
  return 0;
 
608
}
 
609
 
 
610
bool sys_var_uint32_t_ptr::update(Session *session, set_var *var)
 
611
{
 
612
  uint32_t tmp= var->save_result.uint32_t_value;
 
613
  pthread_mutex_lock(&LOCK_global_system_variables);
1067
614
  if (option_limits)
1068
 
    *value= (ulong) fix_unsigned(thd, tmp, option_limits);
1069
 
  else
1070
615
  {
1071
 
#if SIZEOF_LONG < SIZEOF_LONG_LONG
1072
 
    /* Avoid overflows on 32 bit systems */
1073
 
    if (tmp > ULONG_MAX)
1074
 
    {
1075
 
      tmp= ULONG_MAX;
1076
 
      throw_bounds_warning(thd, true, true, name,
1077
 
                           (int64_t) var->save_result.uint64_t_value);
1078
 
    }
1079
 
#endif
1080
 
    *value= (ulong) tmp;
 
616
    uint32_t newvalue= (uint32_t) fix_unsigned(session, tmp, option_limits);
 
617
    if(newvalue==tmp)
 
618
      *value= newvalue;
1081
619
  }
1082
 
 
1083
 
  pthread_mutex_unlock(guard);
 
620
  else
 
621
    *value= (uint32_t) tmp;
 
622
  pthread_mutex_unlock(&LOCK_global_system_variables);
1084
623
  return 0;
1085
624
}
1086
625
 
1087
626
 
1088
 
void sys_var_long_ptr_global::set_default(THD *thd __attribute__((unused)), enum_var_type type __attribute__((unused)))
 
627
void sys_var_uint32_t_ptr::set_default(Session *, enum_var_type)
1089
628
{
1090
629
  bool not_used;
1091
 
  pthread_mutex_lock(guard);
1092
 
  *value= (ulong) getopt_ull_limit_value((ulong) option_limits->def_value,
1093
 
                                         option_limits, &not_used);
1094
 
  pthread_mutex_unlock(guard);
 
630
  pthread_mutex_lock(&LOCK_global_system_variables);
 
631
  *value= (uint32_t)getopt_ull_limit_value((uint32_t) option_limits->def_value,
 
632
                                           option_limits, &not_used);
 
633
  pthread_mutex_unlock(&LOCK_global_system_variables);
1095
634
}
1096
635
 
1097
636
 
1098
 
bool sys_var_uint64_t_ptr::update(THD *thd, set_var *var)
 
637
bool sys_var_uint64_t_ptr::update(Session *session, set_var *var)
1099
638
{
1100
639
  uint64_t tmp= var->save_result.uint64_t_value;
1101
640
  pthread_mutex_lock(&LOCK_global_system_variables);
1102
641
  if (option_limits)
1103
 
    *value= (uint64_t) fix_unsigned(thd, tmp, option_limits);
 
642
  {
 
643
    uint64_t newvalue= (uint64_t) fix_unsigned(session, tmp, option_limits);
 
644
    if(newvalue==tmp)
 
645
      *value= newvalue;
 
646
  }
1104
647
  else
1105
648
    *value= (uint64_t) tmp;
1106
649
  pthread_mutex_unlock(&LOCK_global_system_variables);
1108
651
}
1109
652
 
1110
653
 
1111
 
void sys_var_uint64_t_ptr::set_default(THD *thd __attribute__((unused)),
1112
 
                                        enum_var_type type __attribute__((unused)))
 
654
void sys_var_uint64_t_ptr::set_default(Session *, enum_var_type)
1113
655
{
1114
656
  bool not_used;
1115
657
  pthread_mutex_lock(&LOCK_global_system_variables);
1119
661
}
1120
662
 
1121
663
 
1122
 
bool sys_var_bool_ptr::update(THD *thd __attribute__((unused)), set_var *var)
1123
 
{
1124
 
  *value= (bool) var->save_result.ulong_value;
1125
 
  return 0;
1126
 
}
1127
 
 
1128
 
 
1129
 
void sys_var_bool_ptr::set_default(THD *thd __attribute__((unused)), enum_var_type type __attribute__((unused)))
 
664
bool sys_var_size_t_ptr::update(Session *session, set_var *var)
 
665
{
 
666
  size_t tmp= var->save_result.size_t_value;
 
667
  pthread_mutex_lock(&LOCK_global_system_variables);
 
668
  if (option_limits)
 
669
    *value= fix_size_t(session, tmp, option_limits);
 
670
  else
 
671
    *value= tmp;
 
672
  pthread_mutex_unlock(&LOCK_global_system_variables);
 
673
  return 0;
 
674
}
 
675
 
 
676
 
 
677
void sys_var_size_t_ptr::set_default(Session *, enum_var_type)
 
678
{
 
679
  bool not_used;
 
680
  pthread_mutex_lock(&LOCK_global_system_variables);
 
681
  *value= (size_t)getopt_ull_limit_value((size_t) option_limits->def_value,
 
682
                                         option_limits, &not_used);
 
683
  pthread_mutex_unlock(&LOCK_global_system_variables);
 
684
}
 
685
 
 
686
bool sys_var_bool_ptr::update(Session *, set_var *var)
 
687
{
 
688
  *value= (bool) var->save_result.uint32_t_value;
 
689
  return 0;
 
690
}
 
691
 
 
692
 
 
693
void sys_var_bool_ptr::set_default(Session *, enum_var_type)
1130
694
{
1131
695
  *value= (bool) option_limits->def_value;
1132
696
}
1133
697
 
1134
698
 
1135
 
bool sys_var_enum::update(THD *thd __attribute__((unused)), set_var *var)
 
699
bool sys_var_enum::update(Session *, set_var *var)
1136
700
{
1137
 
  *value= (uint) var->save_result.ulong_value;
 
701
  *value= (uint32_t) var->save_result.uint32_t_value;
1138
702
  return 0;
1139
703
}
1140
704
 
1141
705
 
1142
 
uchar *sys_var_enum::value_ptr(THD *thd __attribute__((unused)),
1143
 
                               enum_var_type type __attribute__((unused)),
1144
 
                               LEX_STRING *base __attribute__((unused)))
1145
 
{
1146
 
  return (uchar*) enum_names->type_names[*value];
1147
 
}
1148
 
 
1149
 
 
1150
 
uchar *sys_var_enum_const::value_ptr(THD *thd __attribute__((unused)),
1151
 
                                     enum_var_type type __attribute__((unused)),
1152
 
                                     LEX_STRING *base __attribute__((unused)))
1153
 
{
1154
 
  return (uchar*) enum_names->type_names[global_system_variables.*offset];
1155
 
}
1156
 
 
1157
 
bool sys_var_thd_ulong::check(THD *thd, set_var *var)
1158
 
{
1159
 
  return (get_unsigned(thd, var) ||
1160
 
          (check_func && (*check_func)(thd, var)));
1161
 
}
1162
 
 
1163
 
bool sys_var_thd_ulong::update(THD *thd, set_var *var)
1164
 
{
1165
 
  uint64_t tmp= var->save_result.uint64_t_value;
1166
 
  
 
706
unsigned char *sys_var_enum::value_ptr(Session *, enum_var_type, const LEX_STRING *)
 
707
{
 
708
  return (unsigned char*) enum_names->type_names[*value];
 
709
}
 
710
 
 
711
 
 
712
unsigned char *sys_var_enum_const::value_ptr(Session *, enum_var_type,
 
713
                                             const LEX_STRING *)
 
714
{
 
715
  return (unsigned char*) enum_names->type_names[global_system_variables.*offset];
 
716
}
 
717
 
 
718
/*
 
719
  32 bit types for session variables
 
720
*/
 
721
bool sys_var_session_uint32_t::check(Session *session, set_var *var)
 
722
{
 
723
  return (get_unsigned32(session, var) ||
 
724
          (check_func && (*check_func)(session, var)));
 
725
}
 
726
 
 
727
bool sys_var_session_uint32_t::update(Session *session, set_var *var)
 
728
{
 
729
  uint64_t tmp= (uint64_t) var->save_result.uint32_t_value;
 
730
 
1167
731
  /* Don't use bigger value than given with --maximum-variable-name=.. */
1168
 
  if ((ulong) tmp > max_system_variables.*offset)
 
732
  if ((uint32_t) tmp > max_system_variables.*offset)
1169
733
  {
1170
 
    throw_bounds_warning(thd, true, true, name, (int64_t) tmp);
 
734
    throw_bounds_warning(session, true, true, getName(), (int64_t) tmp);
1171
735
    tmp= max_system_variables.*offset;
1172
736
  }
1173
 
  
 
737
 
1174
738
  if (option_limits)
1175
 
    tmp= (ulong) fix_unsigned(thd, tmp, option_limits);
1176
 
#if SIZEOF_LONG < SIZEOF_LONG_LONG
1177
 
  else if (tmp > ULONG_MAX)
 
739
    tmp= (uint32_t) fix_unsigned(session, tmp, option_limits);
 
740
  else if (tmp > UINT32_MAX)
1178
741
  {
1179
 
    tmp= ULONG_MAX;
1180
 
    throw_bounds_warning(thd, true, true, name, (int64_t) var->save_result.uint64_t_value);
 
742
    tmp= UINT32_MAX;
 
743
    throw_bounds_warning(session, true, true, getName(), (int64_t) var->save_result.uint64_t_value);
1181
744
  }
1182
 
#endif
1183
 
  
 
745
 
1184
746
  if (var->type == OPT_GLOBAL)
1185
 
     global_system_variables.*offset= (ulong) tmp;
 
747
     global_system_variables.*offset= (uint32_t) tmp;
1186
748
   else
1187
 
     thd->variables.*offset= (ulong) tmp;
 
749
     session->variables.*offset= (uint32_t) tmp;
1188
750
 
1189
751
   return 0;
1190
752
 }
1191
753
 
1192
754
 
1193
 
 void sys_var_thd_ulong::set_default(THD *thd, enum_var_type type)
 
755
 void sys_var_session_uint32_t::set_default(Session *session, enum_var_type type)
1194
756
 {
1195
757
   if (type == OPT_GLOBAL)
1196
758
   {
1197
759
     bool not_used;
1198
760
     /* We will not come here if option_limits is not set */
1199
761
     global_system_variables.*offset=
1200
 
       (ulong) getopt_ull_limit_value((ulong) option_limits->def_value,
 
762
       (uint32_t) getopt_ull_limit_value((uint32_t) option_limits->def_value,
1201
763
                                      option_limits, &not_used);
1202
764
   }
1203
765
   else
1204
 
     thd->variables.*offset= global_system_variables.*offset;
 
766
     session->variables.*offset= global_system_variables.*offset;
1205
767
 }
1206
768
 
1207
769
 
1208
 
uchar *sys_var_thd_ulong::value_ptr(THD *thd, enum_var_type type,
1209
 
                                    LEX_STRING *base __attribute__((unused)))
 
770
unsigned char *sys_var_session_uint32_t::value_ptr(Session *session,
 
771
                                                enum_var_type type,
 
772
                                                const LEX_STRING *)
1210
773
{
1211
774
  if (type == OPT_GLOBAL)
1212
 
    return (uchar*) &(global_system_variables.*offset);
1213
 
  return (uchar*) &(thd->variables.*offset);
 
775
    return (unsigned char*) &(global_system_variables.*offset);
 
776
  return (unsigned char*) &(session->variables.*offset);
1214
777
}
1215
778
 
1216
779
 
1217
 
bool sys_var_thd_ha_rows::update(THD *thd, set_var *var)
 
780
bool sys_var_session_ha_rows::update(Session *session, set_var *var)
1218
781
{
1219
782
  uint64_t tmp= var->save_result.uint64_t_value;
1220
783
 
1223
786
    tmp= max_system_variables.*offset;
1224
787
 
1225
788
  if (option_limits)
1226
 
    tmp= (ha_rows) fix_unsigned(thd, tmp, option_limits);
 
789
    tmp= (ha_rows) fix_unsigned(session, tmp, option_limits);
1227
790
  if (var->type == OPT_GLOBAL)
1228
791
  {
1229
792
    /* Lock is needed to make things safe on 32 bit systems */
1230
 
    pthread_mutex_lock(&LOCK_global_system_variables);    
 
793
    pthread_mutex_lock(&LOCK_global_system_variables);
1231
794
    global_system_variables.*offset= (ha_rows) tmp;
1232
795
    pthread_mutex_unlock(&LOCK_global_system_variables);
1233
796
  }
1234
797
  else
1235
 
    thd->variables.*offset= (ha_rows) tmp;
 
798
    session->variables.*offset= (ha_rows) tmp;
1236
799
  return 0;
1237
800
}
1238
801
 
1239
802
 
1240
 
void sys_var_thd_ha_rows::set_default(THD *thd, enum_var_type type)
 
803
void sys_var_session_ha_rows::set_default(Session *session, enum_var_type type)
1241
804
{
1242
805
  if (type == OPT_GLOBAL)
1243
806
  {
1250
813
    pthread_mutex_unlock(&LOCK_global_system_variables);
1251
814
  }
1252
815
  else
1253
 
    thd->variables.*offset= global_system_variables.*offset;
 
816
    session->variables.*offset= global_system_variables.*offset;
1254
817
}
1255
818
 
1256
819
 
1257
 
uchar *sys_var_thd_ha_rows::value_ptr(THD *thd, enum_var_type type,
1258
 
                                      LEX_STRING *base __attribute__((unused)))
 
820
unsigned char *sys_var_session_ha_rows::value_ptr(Session *session,
 
821
                                                  enum_var_type type,
 
822
                                                  const LEX_STRING *)
1259
823
{
1260
824
  if (type == OPT_GLOBAL)
1261
 
    return (uchar*) &(global_system_variables.*offset);
1262
 
  return (uchar*) &(thd->variables.*offset);
 
825
    return (unsigned char*) &(global_system_variables.*offset);
 
826
  return (unsigned char*) &(session->variables.*offset);
1263
827
}
1264
828
 
1265
 
bool sys_var_thd_uint64_t::check(THD *thd, set_var *var)
 
829
bool sys_var_session_uint64_t::check(Session *session, set_var *var)
1266
830
{
1267
 
  return get_unsigned(thd, var);
 
831
  return (get_unsigned64(session, var) ||
 
832
          (check_func && (*check_func)(session, var)));
1268
833
}
1269
834
 
1270
 
bool sys_var_thd_uint64_t::update(THD *thd,  set_var *var)
 
835
bool sys_var_session_uint64_t::update(Session *session,  set_var *var)
1271
836
{
1272
837
  uint64_t tmp= var->save_result.uint64_t_value;
1273
838
 
1275
840
    tmp= max_system_variables.*offset;
1276
841
 
1277
842
  if (option_limits)
1278
 
    tmp= fix_unsigned(thd, tmp, option_limits);
 
843
    tmp= fix_unsigned(session, tmp, option_limits);
1279
844
  if (var->type == OPT_GLOBAL)
1280
845
  {
1281
846
    /* Lock is needed to make things safe on 32 bit systems */
1284
849
    pthread_mutex_unlock(&LOCK_global_system_variables);
1285
850
  }
1286
851
  else
1287
 
    thd->variables.*offset= (uint64_t) tmp;
 
852
    session->variables.*offset= (uint64_t) tmp;
1288
853
  return 0;
1289
854
}
1290
855
 
1291
856
 
1292
 
void sys_var_thd_uint64_t::set_default(THD *thd, enum_var_type type)
 
857
void sys_var_session_uint64_t::set_default(Session *session, enum_var_type type)
1293
858
{
1294
859
  if (type == OPT_GLOBAL)
1295
860
  {
1301
866
    pthread_mutex_unlock(&LOCK_global_system_variables);
1302
867
  }
1303
868
  else
1304
 
    thd->variables.*offset= global_system_variables.*offset;
1305
 
}
1306
 
 
1307
 
 
1308
 
uchar *sys_var_thd_uint64_t::value_ptr(THD *thd, enum_var_type type,
1309
 
                                        LEX_STRING *base __attribute__((unused)))
1310
 
{
1311
 
  if (type == OPT_GLOBAL)
1312
 
    return (uchar*) &(global_system_variables.*offset);
1313
 
  return (uchar*) &(thd->variables.*offset);
1314
 
}
1315
 
 
1316
 
 
1317
 
bool sys_var_thd_bool::update(THD *thd,  set_var *var)
1318
 
{
1319
 
  if (var->type == OPT_GLOBAL)
1320
 
    global_system_variables.*offset= (bool) var->save_result.ulong_value;
1321
 
  else
1322
 
    thd->variables.*offset= (bool) var->save_result.ulong_value;
1323
 
  return 0;
1324
 
}
1325
 
 
1326
 
 
1327
 
void sys_var_thd_bool::set_default(THD *thd,  enum_var_type type)
 
869
    session->variables.*offset= global_system_variables.*offset;
 
870
}
 
871
 
 
872
 
 
873
unsigned char *sys_var_session_uint64_t::value_ptr(Session *session,
 
874
                                                   enum_var_type type,
 
875
                                                   const LEX_STRING *)
 
876
{
 
877
  if (type == OPT_GLOBAL)
 
878
    return (unsigned char*) &(global_system_variables.*offset);
 
879
  return (unsigned char*) &(session->variables.*offset);
 
880
}
 
881
 
 
882
bool sys_var_session_size_t::check(Session *session, set_var *var)
 
883
{
 
884
  return (get_size_t(session, var) ||
 
885
          (check_func && (*check_func)(session, var)));
 
886
}
 
887
 
 
888
bool sys_var_session_size_t::update(Session *session,  set_var *var)
 
889
{
 
890
  size_t tmp= var->save_result.size_t_value;
 
891
 
 
892
  if (tmp > max_system_variables.*offset)
 
893
    tmp= max_system_variables.*offset;
 
894
 
 
895
  if (option_limits)
 
896
    tmp= fix_size_t(session, tmp, option_limits);
 
897
  if (var->type == OPT_GLOBAL)
 
898
  {
 
899
    /* Lock is needed to make things safe on 32 bit systems */
 
900
    pthread_mutex_lock(&LOCK_global_system_variables);
 
901
    global_system_variables.*offset= tmp;
 
902
    pthread_mutex_unlock(&LOCK_global_system_variables);
 
903
  }
 
904
  else
 
905
    session->variables.*offset= tmp;
 
906
  return 0;
 
907
}
 
908
 
 
909
 
 
910
void sys_var_session_size_t::set_default(Session *session, enum_var_type type)
 
911
{
 
912
  if (type == OPT_GLOBAL)
 
913
  {
 
914
    bool not_used;
 
915
    pthread_mutex_lock(&LOCK_global_system_variables);
 
916
    global_system_variables.*offset=
 
917
      (size_t)getopt_ull_limit_value((size_t) option_limits->def_value,
 
918
                                     option_limits, &not_used);
 
919
    pthread_mutex_unlock(&LOCK_global_system_variables);
 
920
  }
 
921
  else
 
922
    session->variables.*offset= global_system_variables.*offset;
 
923
}
 
924
 
 
925
 
 
926
unsigned char *sys_var_session_size_t::value_ptr(Session *session,
 
927
                                                 enum_var_type type,
 
928
                                                 const LEX_STRING *)
 
929
{
 
930
  if (type == OPT_GLOBAL)
 
931
    return (unsigned char*) &(global_system_variables.*offset);
 
932
  return (unsigned char*) &(session->variables.*offset);
 
933
}
 
934
 
 
935
 
 
936
bool sys_var_session_bool::update(Session *session,  set_var *var)
 
937
{
 
938
  if (var->type == OPT_GLOBAL)
 
939
    global_system_variables.*offset= (bool) var->save_result.uint32_t_value;
 
940
  else
 
941
    session->variables.*offset= (bool) var->save_result.uint32_t_value;
 
942
  return 0;
 
943
}
 
944
 
 
945
 
 
946
void sys_var_session_bool::set_default(Session *session,  enum_var_type type)
1328
947
{
1329
948
  if (type == OPT_GLOBAL)
1330
949
    global_system_variables.*offset= (bool) option_limits->def_value;
1331
950
  else
1332
 
    thd->variables.*offset= global_system_variables.*offset;
 
951
    session->variables.*offset= global_system_variables.*offset;
1333
952
}
1334
953
 
1335
954
 
1336
 
uchar *sys_var_thd_bool::value_ptr(THD *thd, enum_var_type type,
1337
 
                                   LEX_STRING *base __attribute__((unused)))
 
955
unsigned char *sys_var_session_bool::value_ptr(Session *session,
 
956
                                               enum_var_type type,
 
957
                                               const LEX_STRING *)
1338
958
{
1339
959
  if (type == OPT_GLOBAL)
1340
 
    return (uchar*) &(global_system_variables.*offset);
1341
 
  return (uchar*) &(thd->variables.*offset);
 
960
    return (unsigned char*) &(global_system_variables.*offset);
 
961
  return (unsigned char*) &(session->variables.*offset);
1342
962
}
1343
963
 
1344
964
 
1345
 
bool sys_var::check_enum(THD *thd __attribute__((unused)),
 
965
bool sys_var::check_enum(Session *,
1346
966
                         set_var *var, const TYPELIB *enum_names)
1347
967
{
1348
968
  char buff[STRING_BUFFER_USUAL_SIZE];
1352
972
  if (var->value->result_type() == STRING_RESULT)
1353
973
  {
1354
974
    if (!(res=var->value->val_str(&str)) ||
1355
 
        ((long) (var->save_result.ulong_value=
1356
 
                 (ulong) find_type(enum_names, res->ptr(),
1357
 
                                   res->length(),1)-1)) < 0)
 
975
        (var->save_result.uint32_t_value= find_type(enum_names, res->ptr(),
 
976
                                                    res->length(),1)) == 0)
1358
977
    {
1359
978
      value= res ? res->c_ptr() : "NULL";
1360
979
      goto err;
1361
980
    }
 
981
 
 
982
    var->save_result.uint32_t_value--;
1362
983
  }
1363
984
  else
1364
985
  {
1369
990
      value=buff;                               // Wrong value is here
1370
991
      goto err;
1371
992
    }
1372
 
    var->save_result.ulong_value= (ulong) tmp;  // Save for update
 
993
    var->save_result.uint32_t_value= (uint32_t) tmp;    // Save for update
1373
994
  }
1374
995
  return 0;
1375
996
 
1376
997
err:
1377
 
  my_error(ER_WRONG_VALUE_FOR_VAR, MYF(0), name, value);
 
998
  my_error(ER_WRONG_VALUE_FOR_VAR, MYF(0), name.c_str(), value);
1378
999
  return 1;
1379
1000
}
1380
1001
 
1381
1002
 
1382
 
bool sys_var::check_set(THD *thd __attribute__((unused)),
1383
 
                        set_var *var, TYPELIB *enum_names)
 
1003
bool sys_var::check_set(Session *, set_var *var, TYPELIB *enum_names)
1384
1004
{
1385
1005
  bool not_used;
1386
1006
  char buff[STRING_BUFFER_USUAL_SIZE], *error= 0;
1387
 
  uint error_len= 0;
 
1007
  uint32_t error_len= 0;
1388
1008
  String str(buff, sizeof(buff), system_charset_info), *res;
1389
1009
 
1390
1010
  if (var->value->result_type() == STRING_RESULT)
1391
1011
  {
1392
1012
    if (!(res= var->value->val_str(&str)))
1393
1013
    {
1394
 
      stpcpy(buff, "NULL");
 
1014
      strcpy(buff, "NULL");
1395
1015
      goto err;
1396
1016
    }
1397
1017
 
1398
 
    if (!m_allow_empty_value &&
1399
 
        res->length() == 0)
 
1018
    if (! m_allow_empty_value && res->length() == 0)
1400
1019
    {
1401
1020
      buff[0]= 0;
1402
1021
      goto err;
1403
1022
    }
1404
1023
 
1405
 
    var->save_result.ulong_value= ((ulong)
1406
 
                                   find_set(enum_names, res->c_ptr(),
1407
 
                                            res->length(),
1408
 
                                            NULL,
1409
 
                                            &error, &error_len,
1410
 
                                            &not_used));
 
1024
    var->save_result.uint32_t_value= ((uint32_t)
 
1025
                                      find_set(enum_names, res->c_ptr(),
 
1026
                                               res->length(),
 
1027
                                               NULL,
 
1028
                                               &error, &error_len,
 
1029
                                               &not_used));
1411
1030
    if (error_len)
1412
1031
    {
1413
 
      strmake(buff, error, min(sizeof(buff) - 1, (ulong)error_len));
 
1032
      size_t len = min((uint32_t)(sizeof(buff) - 1), error_len);
 
1033
      strncpy(buff, error, len);
 
1034
      buff[len]= '\0';
1414
1035
      goto err;
1415
1036
    }
1416
1037
  }
1418
1039
  {
1419
1040
    uint64_t tmp= var->value->val_int();
1420
1041
 
1421
 
    if (!m_allow_empty_value &&
1422
 
        tmp == 0)
 
1042
    if (! m_allow_empty_value && tmp == 0)
1423
1043
    {
1424
1044
      buff[0]= '0';
1425
1045
      buff[1]= 0;
1430
1050
      For when the enum is made to contain 64 elements, as 1ULL<<64 is
1431
1051
      undefined, we guard with a "count<64" test.
1432
1052
    */
1433
 
    if (unlikely((tmp >= ((1ULL) << enum_names->count)) &&
 
1053
    if (unlikely((tmp >= ((1UL) << enum_names->count)) &&
1434
1054
                 (enum_names->count < 64)))
1435
1055
    {
1436
1056
      llstr(tmp, buff);
1437
1057
      goto err;
1438
1058
    }
1439
 
    var->save_result.ulong_value= (ulong) tmp;  // Save for update
 
1059
    var->save_result.uint32_t_value= (uint32_t) tmp;  // Save for update
1440
1060
  }
1441
1061
  return 0;
1442
1062
 
1443
1063
err:
1444
 
  my_error(ER_WRONG_VALUE_FOR_VAR, MYF(0), name, buff);
 
1064
  my_error(ER_WRONG_VALUE_FOR_VAR, MYF(0), name.c_str(), buff);
1445
1065
  return 1;
1446
1066
}
1447
1067
 
1454
1074
  If type is not given, return local value if exists, else global.
1455
1075
*/
1456
1076
 
1457
 
Item *sys_var::item(THD *thd, enum_var_type var_type, LEX_STRING *base)
 
1077
Item *sys_var::item(Session *session, enum_var_type var_type, const LEX_STRING *base)
1458
1078
{
1459
1079
  if (check_type(var_type))
1460
1080
  {
1461
1081
    if (var_type != OPT_DEFAULT)
1462
1082
    {
1463
1083
      my_error(ER_INCORRECT_GLOBAL_LOCAL_VAR, MYF(0),
1464
 
               name, var_type == OPT_GLOBAL ? "SESSION" : "GLOBAL");
 
1084
               name.c_str(), var_type == OPT_GLOBAL ? "SESSION" : "GLOBAL");
1465
1085
      return 0;
1466
1086
    }
1467
1087
    /* As there was no local variable, return the global value */
1468
1088
    var_type= OPT_GLOBAL;
1469
1089
  }
1470
1090
  switch (show_type()) {
 
1091
  case SHOW_LONG:
1471
1092
  case SHOW_INT:
1472
1093
  {
1473
 
    uint value;
1474
 
    pthread_mutex_lock(&LOCK_global_system_variables);
1475
 
    value= *(uint*) value_ptr(thd, var_type, base);
1476
 
    pthread_mutex_unlock(&LOCK_global_system_variables);
1477
 
    return new Item_uint((uint64_t) value);
1478
 
  }
1479
 
  case SHOW_LONG:
1480
 
  {
1481
 
    ulong value;
1482
 
    pthread_mutex_lock(&LOCK_global_system_variables);
1483
 
    value= *(ulong*) value_ptr(thd, var_type, base);
 
1094
    uint32_t value;
 
1095
    pthread_mutex_lock(&LOCK_global_system_variables);
 
1096
    value= *(uint*) value_ptr(session, var_type, base);
1484
1097
    pthread_mutex_unlock(&LOCK_global_system_variables);
1485
1098
    return new Item_uint((uint64_t) value);
1486
1099
  }
1488
1101
  {
1489
1102
    int64_t value;
1490
1103
    pthread_mutex_lock(&LOCK_global_system_variables);
1491
 
    value= *(int64_t*) value_ptr(thd, var_type, base);
 
1104
    value= *(int64_t*) value_ptr(session, var_type, base);
1492
1105
    pthread_mutex_unlock(&LOCK_global_system_variables);
1493
1106
    return new Item_int(value);
1494
1107
  }
1496
1109
  {
1497
1110
    double value;
1498
1111
    pthread_mutex_lock(&LOCK_global_system_variables);
1499
 
    value= *(double*) value_ptr(thd, var_type, base);
 
1112
    value= *(double*) value_ptr(session, var_type, base);
1500
1113
    pthread_mutex_unlock(&LOCK_global_system_variables);
1501
1114
    /* 6, as this is for now only used with microseconds */
1502
1115
    return new Item_float(value, 6);
1505
1118
  {
1506
1119
    ha_rows value;
1507
1120
    pthread_mutex_lock(&LOCK_global_system_variables);
1508
 
    value= *(ha_rows*) value_ptr(thd, var_type, base);
 
1121
    value= *(ha_rows*) value_ptr(session, var_type, base);
 
1122
    pthread_mutex_unlock(&LOCK_global_system_variables);
 
1123
    return new Item_int((uint64_t) value);
 
1124
  }
 
1125
  case SHOW_SIZE:
 
1126
  {
 
1127
    size_t value;
 
1128
    pthread_mutex_lock(&LOCK_global_system_variables);
 
1129
    value= *(size_t*) value_ptr(session, var_type, base);
1509
1130
    pthread_mutex_unlock(&LOCK_global_system_variables);
1510
1131
    return new Item_int((uint64_t) value);
1511
1132
  }
1513
1134
  {
1514
1135
    int32_t value;
1515
1136
    pthread_mutex_lock(&LOCK_global_system_variables);
1516
 
    value= *(bool*) value_ptr(thd, var_type, base);
 
1137
    value= *(bool*) value_ptr(session, var_type, base);
1517
1138
    pthread_mutex_unlock(&LOCK_global_system_variables);
1518
1139
    return new Item_int(value,1);
1519
1140
  }
1521
1142
  {
1522
1143
    Item *tmp;
1523
1144
    pthread_mutex_lock(&LOCK_global_system_variables);
1524
 
    char *str= *(char**) value_ptr(thd, var_type, base);
 
1145
    char *str= *(char**) value_ptr(session, var_type, base);
1525
1146
    if (str)
1526
1147
    {
1527
 
      uint length= strlen(str);
1528
 
      tmp= new Item_string(thd->strmake(str, length), length,
 
1148
      uint32_t length= strlen(str);
 
1149
      tmp= new Item_string(session->strmake(str, length), length,
1529
1150
                           system_charset_info, DERIVATION_SYSCONST);
1530
1151
    }
1531
1152
    else
1540
1161
  {
1541
1162
    Item *tmp;
1542
1163
    pthread_mutex_lock(&LOCK_global_system_variables);
1543
 
    char *str= (char*) value_ptr(thd, var_type, base);
 
1164
    char *str= (char*) value_ptr(session, var_type, base);
1544
1165
    if (str)
1545
1166
      tmp= new Item_string(str, strlen(str),
1546
1167
                           system_charset_info, DERIVATION_SYSCONST);
1553
1174
    return tmp;
1554
1175
  }
1555
1176
  default:
1556
 
    my_error(ER_VAR_CANT_BE_READ, MYF(0), name);
 
1177
    my_error(ER_VAR_CANT_BE_READ, MYF(0), name.c_str());
1557
1178
  }
1558
1179
  return 0;
1559
1180
}
1560
1181
 
1561
1182
 
1562
 
bool sys_var_thd_enum::update(THD *thd, set_var *var)
 
1183
bool sys_var_session_enum::update(Session *session, set_var *var)
1563
1184
{
1564
1185
  if (var->type == OPT_GLOBAL)
1565
 
    global_system_variables.*offset= var->save_result.ulong_value;
 
1186
    global_system_variables.*offset= var->save_result.uint32_t_value;
1566
1187
  else
1567
 
    thd->variables.*offset= var->save_result.ulong_value;
 
1188
    session->variables.*offset= var->save_result.uint32_t_value;
1568
1189
  return 0;
1569
1190
}
1570
1191
 
1571
1192
 
1572
 
void sys_var_thd_enum::set_default(THD *thd, enum_var_type type)
 
1193
void sys_var_session_enum::set_default(Session *session, enum_var_type type)
1573
1194
{
1574
1195
  if (type == OPT_GLOBAL)
1575
 
    global_system_variables.*offset= (ulong) option_limits->def_value;
 
1196
    global_system_variables.*offset= (uint32_t) option_limits->def_value;
1576
1197
  else
1577
 
    thd->variables.*offset= global_system_variables.*offset;
 
1198
    session->variables.*offset= global_system_variables.*offset;
1578
1199
}
1579
1200
 
1580
1201
 
1581
 
uchar *sys_var_thd_enum::value_ptr(THD *thd, enum_var_type type,
1582
 
                                   LEX_STRING *base __attribute__((unused)))
 
1202
unsigned char *sys_var_session_enum::value_ptr(Session *session,
 
1203
                                               enum_var_type type,
 
1204
                                               const LEX_STRING *)
1583
1205
{
1584
 
  ulong tmp= ((type == OPT_GLOBAL) ?
 
1206
  uint32_t tmp= ((type == OPT_GLOBAL) ?
1585
1207
              global_system_variables.*offset :
1586
 
              thd->variables.*offset);
1587
 
  return (uchar*) enum_names->type_names[tmp];
1588
 
}
1589
 
 
1590
 
bool sys_var_thd_bit::check(THD *thd, set_var *var)
1591
 
{
1592
 
  return (check_enum(thd, var, &bool_typelib) ||
1593
 
          (check_func && (*check_func)(thd, var)));
1594
 
}
1595
 
 
1596
 
bool sys_var_thd_bit::update(THD *thd, set_var *var)
1597
 
{
1598
 
  int res= (*update_func)(thd, var);
 
1208
              session->variables.*offset);
 
1209
  return (unsigned char*) enum_names->type_names[tmp];
 
1210
}
 
1211
 
 
1212
bool sys_var_session_bit::check(Session *session, set_var *var)
 
1213
{
 
1214
  return (check_enum(session, var, &bool_typelib) ||
 
1215
          (check_func && (*check_func)(session, var)));
 
1216
}
 
1217
 
 
1218
bool sys_var_session_bit::update(Session *session, set_var *var)
 
1219
{
 
1220
  int res= (*update_func)(session, var);
1599
1221
  return res;
1600
1222
}
1601
1223
 
1602
1224
 
1603
 
uchar *sys_var_thd_bit::value_ptr(THD *thd,
1604
 
                                  enum_var_type type __attribute__((unused)),
1605
 
                                  LEX_STRING *base __attribute__((unused)))
 
1225
unsigned char *sys_var_session_bit::value_ptr(Session *session, enum_var_type,
 
1226
                                              const LEX_STRING *)
1606
1227
{
1607
1228
  /*
1608
1229
    If reverse is 0 (default) return 1 if bit is set.
1609
1230
    If reverse is 1, return 0 if bit is set
1610
1231
  */
1611
 
  thd->sys_var_tmp.bool_value= ((thd->options & bit_flag) ?
 
1232
  session->sys_var_tmp.bool_value= ((session->options & bit_flag) ?
1612
1233
                                   !reverse : reverse);
1613
 
  return (uchar*) &thd->sys_var_tmp.bool_value;
1614
 
}
1615
 
 
1616
 
 
1617
 
/** Update a date_time format variable based on given value. */
1618
 
 
1619
 
void sys_var_thd_date_time_format::update2(THD *thd, enum_var_type type,
1620
 
                                           DATE_TIME_FORMAT *new_value)
1621
 
{
1622
 
  DATE_TIME_FORMAT *old;
1623
 
 
1624
 
  if (type == OPT_GLOBAL)
1625
 
  {
1626
 
    pthread_mutex_lock(&LOCK_global_system_variables);
1627
 
    old= (global_system_variables.*offset);
1628
 
    (global_system_variables.*offset)= new_value;
1629
 
    pthread_mutex_unlock(&LOCK_global_system_variables);
1630
 
  }
1631
 
  else
1632
 
  {
1633
 
    old= (thd->variables.*offset);
1634
 
    (thd->variables.*offset)= new_value;
1635
 
  }
1636
 
  my_free((char*) old, MYF(MY_ALLOW_ZERO_PTR));
1637
 
  return;
1638
 
}
1639
 
 
1640
 
 
1641
 
bool sys_var_thd_date_time_format::update(THD *thd, set_var *var)
1642
 
{
1643
 
  DATE_TIME_FORMAT *new_value;
1644
 
  /* We must make a copy of the last value to get it into normal memory */
1645
 
  new_value= date_time_format_copy((THD*) 0,
1646
 
                                   var->save_result.date_time_format);
1647
 
  if (!new_value)
1648
 
    return 1;                                   // Out of memory
1649
 
  update2(thd, var->type, new_value);           // Can't fail
1650
 
  return 0;
1651
 
}
1652
 
 
1653
 
 
1654
 
bool sys_var_thd_date_time_format::check(THD *thd, set_var *var)
1655
 
{
1656
 
  char buff[STRING_BUFFER_USUAL_SIZE];
1657
 
  String str(buff,sizeof(buff), system_charset_info), *res;
1658
 
  DATE_TIME_FORMAT *format;
1659
 
 
1660
 
  if (!(res=var->value->val_str(&str)))
1661
 
    res= &my_empty_string;
1662
 
 
1663
 
  if (!(format= date_time_format_make(date_time_type,
1664
 
                                      res->ptr(), res->length())))
1665
 
  {
1666
 
    my_error(ER_WRONG_VALUE_FOR_VAR, MYF(0), name, res->c_ptr());
1667
 
    return 1;
1668
 
  }
1669
 
  
1670
 
  /*
1671
 
    We must copy result to thread space to not get a memory leak if
1672
 
    update is aborted
1673
 
  */
1674
 
  var->save_result.date_time_format= date_time_format_copy(thd, format);
1675
 
  my_free((char*) format, MYF(0));
1676
 
  return var->save_result.date_time_format == 0;
1677
 
}
1678
 
 
1679
 
 
1680
 
void sys_var_thd_date_time_format::set_default(THD *thd, enum_var_type type)
1681
 
{
1682
 
  DATE_TIME_FORMAT *res= 0;
1683
 
 
1684
 
  if (type == OPT_GLOBAL)
1685
 
  {
1686
 
    const char *format;
1687
 
    if ((format= opt_date_time_formats[date_time_type]))
1688
 
      res= date_time_format_make(date_time_type, format, strlen(format));
1689
 
  }
1690
 
  else
1691
 
  {
1692
 
    /* Make copy with malloc */
1693
 
    res= date_time_format_copy((THD *) 0, global_system_variables.*offset);
1694
 
  }
1695
 
 
1696
 
  if (res)                                      // Should always be true
1697
 
    update2(thd, type, res);
1698
 
}
1699
 
 
1700
 
 
1701
 
uchar *sys_var_thd_date_time_format::value_ptr(THD *thd, enum_var_type type,
1702
 
                                               LEX_STRING *base __attribute__((unused)))
1703
 
{
1704
 
  if (type == OPT_GLOBAL)
1705
 
  {
1706
 
    char *res;
1707
 
    /*
1708
 
      We do a copy here just to be sure things will work even if someone
1709
 
      is modifying the original string while the copy is accessed
1710
 
      (Can't happen now in SQL SHOW, but this is a good safety for the future)
1711
 
    */
1712
 
    res= thd->strmake((global_system_variables.*offset)->format.str,
1713
 
                      (global_system_variables.*offset)->format.length);
1714
 
    return (uchar*) res;
1715
 
  }
1716
 
  return (uchar*) (thd->variables.*offset)->format.str;
 
1234
  return (unsigned char*) &session->sys_var_tmp.bool_value;
1717
1235
}
1718
1236
 
1719
1237
 
1723
1241
  const char *new_name;
1724
1242
} my_old_conv;
1725
1243
 
1726
 
static my_old_conv old_conv[]= 
1727
 
{
1728
 
  {     "cp1251_koi8"           ,       "cp1251"        },
1729
 
  {     "cp1250_latin2"         ,       "cp1250"        },
1730
 
  {     "kam_latin2"            ,       "keybcs2"       },
1731
 
  {     "mac_latin2"            ,       "MacRoman"      },
1732
 
  {     "macce_latin2"          ,       "MacCE"         },
1733
 
  {     "pc2_latin2"            ,       "pclatin2"      },
1734
 
  {     "vga_latin2"            ,       "pclatin1"      },
1735
 
  {     "koi8_cp1251"           ,       "koi8r"         },
1736
 
  {     "win1251ukr_koi8_ukr"   ,       "win1251ukr"    },
1737
 
  {     "koi8_ukr_win1251ukr"   ,       "koi8u"         },
1738
 
  {     NULL                    ,       NULL            }
1739
 
};
1740
 
 
1741
 
const CHARSET_INFO *get_old_charset_by_name(const char *name)
1742
 
{
1743
 
  my_old_conv *conv;
1744
 
 
1745
 
  for (conv= old_conv; conv->old_name; conv++)
1746
 
  {
1747
 
    if (!my_strcasecmp(&my_charset_latin1, name, conv->old_name))
1748
 
      return get_charset_by_csname(conv->new_name, MY_CS_PRIMARY, MYF(0));
1749
 
  }
1750
 
  return NULL;
1751
 
}
1752
 
 
1753
 
 
1754
 
bool sys_var_collation::check(THD *thd __attribute__((unused)),
1755
 
                              set_var *var)
 
1244
bool sys_var_collation::check(Session *, set_var *var)
1756
1245
{
1757
1246
  const CHARSET_INFO *tmp;
1758
1247
 
1762
1251
    String str(buff,sizeof(buff), system_charset_info), *res;
1763
1252
    if (!(res=var->value->val_str(&str)))
1764
1253
    {
1765
 
      my_error(ER_WRONG_VALUE_FOR_VAR, MYF(0), name, "NULL");
 
1254
      my_error(ER_WRONG_VALUE_FOR_VAR, MYF(0), name.c_str(), "NULL");
1766
1255
      return 1;
1767
1256
    }
1768
 
    if (!(tmp=get_charset_by_name(res->c_ptr(),MYF(0))))
 
1257
    if (!(tmp=get_charset_by_name(res->c_ptr())))
1769
1258
    {
1770
1259
      my_error(ER_UNKNOWN_COLLATION, MYF(0), res->c_ptr());
1771
1260
      return 1;
1773
1262
  }
1774
1263
  else // INT_RESULT
1775
1264
  {
1776
 
    if (!(tmp=get_charset((int) var->value->val_int(),MYF(0))))
 
1265
    if (!(tmp=get_charset((int) var->value->val_int())))
1777
1266
    {
1778
1267
      char buf[20];
1779
1268
      int10_to_str((int) var->value->val_int(), buf, -10);
1786
1275
}
1787
1276
 
1788
1277
 
1789
 
bool sys_var_character_set::check(THD *thd __attribute__((unused)),
1790
 
                                  set_var *var)
1791
 
{
1792
 
  const CHARSET_INFO *tmp;
1793
 
 
1794
 
  if (var->value->result_type() == STRING_RESULT)
1795
 
  {
1796
 
    char buff[STRING_BUFFER_USUAL_SIZE];
1797
 
    String str(buff,sizeof(buff), system_charset_info), *res;
1798
 
    if (!(res=var->value->val_str(&str)))
1799
 
    {
1800
 
      if (!nullable)
1801
 
      {
1802
 
        my_error(ER_WRONG_VALUE_FOR_VAR, MYF(0), name, "NULL");
1803
 
        return 1;
1804
 
      }
1805
 
      tmp= NULL;
1806
 
    }
1807
 
    else if (!(tmp=get_charset_by_csname(res->c_ptr(),MY_CS_PRIMARY,MYF(0))) &&
1808
 
             !(tmp=get_old_charset_by_name(res->c_ptr())))
1809
 
    {
1810
 
      my_error(ER_UNKNOWN_CHARACTER_SET, MYF(0), res->c_ptr());
1811
 
      return 1;
1812
 
    }
1813
 
  }
1814
 
  else // INT_RESULT
1815
 
  {
1816
 
    if (!(tmp=get_charset((int) var->value->val_int(),MYF(0))))
1817
 
    {
1818
 
      char buf[20];
1819
 
      int10_to_str((int) var->value->val_int(), buf, -10);
1820
 
      my_error(ER_UNKNOWN_CHARACTER_SET, MYF(0), buf);
1821
 
      return 1;
1822
 
    }
1823
 
  }
1824
 
  var->save_result.charset= tmp;        // Save for update
1825
 
  return 0;
1826
 
}
1827
 
 
1828
 
 
1829
 
bool sys_var_character_set::update(THD *thd, set_var *var)
1830
 
{
1831
 
  ci_ptr(thd,var->type)[0]= var->save_result.charset;
1832
 
  thd->update_charset();
1833
 
  return 0;
1834
 
}
1835
 
 
1836
 
 
1837
 
uchar *sys_var_character_set::value_ptr(THD *thd, enum_var_type type,
1838
 
                                        LEX_STRING *base __attribute__((unused)))
1839
 
{
1840
 
  const CHARSET_INFO * const cs= ci_ptr(thd,type)[0];
1841
 
  return cs ? (uchar*) cs->csname : (uchar*) NULL;
1842
 
}
1843
 
 
1844
 
 
1845
 
void sys_var_character_set_sv::set_default(THD *thd, enum_var_type type)
1846
 
{
1847
 
  if (type == OPT_GLOBAL)
1848
 
    global_system_variables.*offset= *global_default;
1849
 
  else
1850
 
  {
1851
 
    thd->variables.*offset= global_system_variables.*offset;
1852
 
    thd->update_charset();
1853
 
  }
1854
 
}
1855
 
const CHARSET_INFO **sys_var_character_set_sv::ci_ptr(THD *thd, enum_var_type type)
1856
 
{
1857
 
  if (type == OPT_GLOBAL)
1858
 
    return &(global_system_variables.*offset);
1859
 
  else
1860
 
    return &(thd->variables.*offset);
1861
 
}
1862
 
 
1863
 
 
1864
 
bool sys_var_character_set_client::check(THD *thd, set_var *var)
1865
 
{
1866
 
  if (sys_var_character_set_sv::check(thd, var))
1867
 
    return 1;
1868
 
  /* Currently, UCS-2 cannot be used as a client character set */
1869
 
  if (var->save_result.charset->mbminlen > 1)
1870
 
  {
1871
 
    my_error(ER_WRONG_VALUE_FOR_VAR, MYF(0), name, 
1872
 
             var->save_result.charset->csname);
1873
 
    return 1;
1874
 
  }
1875
 
  return 0;
1876
 
}
1877
 
 
1878
 
 
1879
 
const CHARSET_INFO ** sys_var_character_set_database::ci_ptr(THD *thd,
1880
 
                                                       enum_var_type type)
1881
 
{
1882
 
  if (type == OPT_GLOBAL)
1883
 
    return &global_system_variables.collation_database;
1884
 
  else
1885
 
    return &thd->variables.collation_database;
1886
 
}
1887
 
 
1888
 
 
1889
 
void sys_var_character_set_database::set_default(THD *thd, enum_var_type type)
1890
 
{
1891
 
 if (type == OPT_GLOBAL)
1892
 
    global_system_variables.collation_database= default_charset_info;
1893
 
  else
1894
 
  {
1895
 
    thd->variables.collation_database= thd->db_charset;
1896
 
    thd->update_charset();
1897
 
  }
1898
 
}
1899
 
 
1900
 
 
1901
 
bool sys_var_collation_sv::update(THD *thd, set_var *var)
 
1278
bool sys_var_collation_sv::update(Session *session, set_var *var)
1902
1279
{
1903
1280
  if (var->type == OPT_GLOBAL)
1904
1281
    global_system_variables.*offset= var->save_result.charset;
1905
1282
  else
1906
1283
  {
1907
 
    thd->variables.*offset= var->save_result.charset;
1908
 
    thd->update_charset();
 
1284
    session->variables.*offset= var->save_result.charset;
1909
1285
  }
1910
1286
  return 0;
1911
1287
}
1912
1288
 
1913
1289
 
1914
 
void sys_var_collation_sv::set_default(THD *thd, enum_var_type type)
 
1290
void sys_var_collation_sv::set_default(Session *session, enum_var_type type)
1915
1291
{
1916
1292
  if (type == OPT_GLOBAL)
1917
1293
    global_system_variables.*offset= *global_default;
1918
1294
  else
1919
1295
  {
1920
 
    thd->variables.*offset= global_system_variables.*offset;
1921
 
    thd->update_charset();
 
1296
    session->variables.*offset= global_system_variables.*offset;
1922
1297
  }
1923
1298
}
1924
1299
 
1925
1300
 
1926
 
uchar *sys_var_collation_sv::value_ptr(THD *thd, enum_var_type type,
1927
 
                                       LEX_STRING *base __attribute__((unused)))
 
1301
unsigned char *sys_var_collation_sv::value_ptr(Session *session,
 
1302
                                               enum_var_type type,
 
1303
                                               const LEX_STRING *)
1928
1304
{
1929
1305
  const CHARSET_INFO *cs= ((type == OPT_GLOBAL) ?
1930
 
                     global_system_variables.*offset : thd->variables.*offset);
1931
 
  return cs ? (uchar*) cs->name : (uchar*) "NULL";
 
1306
                           global_system_variables.*offset :
 
1307
                           session->variables.*offset);
 
1308
  return cs ? (unsigned char*) cs->name : (unsigned char*) "NULL";
1932
1309
}
1933
1310
 
1934
1311
 
1936
1313
 
1937
1314
static KEY_CACHE zero_key_cache;
1938
1315
 
1939
 
KEY_CACHE *get_key_cache(LEX_STRING *cache_name)
 
1316
KEY_CACHE *get_key_cache(const LEX_STRING *cache_name)
1940
1317
{
1941
1318
  safe_mutex_assert_owner(&LOCK_global_system_variables);
1942
1319
  if (!cache_name || ! cache_name->length)
1943
1320
    cache_name= &default_key_cache_base;
1944
1321
  return ((KEY_CACHE*) find_named(&key_caches,
1945
 
                                      cache_name->str, cache_name->length, 0));
 
1322
                                  cache_name->str, cache_name->length, 0));
1946
1323
}
1947
1324
 
1948
1325
 
1949
 
uchar *sys_var_key_cache_param::value_ptr(THD *thd __attribute__((unused)),
1950
 
                                          enum_var_type type __attribute__((unused)),
1951
 
                                          LEX_STRING *base __attribute__((unused)))
 
1326
unsigned char *sys_var_key_cache_param::value_ptr(Session *, enum_var_type,
 
1327
                                                  const LEX_STRING *base)
1952
1328
{
1953
1329
  KEY_CACHE *key_cache= get_key_cache(base);
1954
1330
  if (!key_cache)
1955
1331
    key_cache= &zero_key_cache;
1956
 
  return (uchar*) key_cache + offset ;
 
1332
  return (unsigned char*) key_cache + offset ;
1957
1333
}
1958
1334
 
1959
1335
 
1960
 
bool sys_var_key_buffer_size::update(THD *thd, set_var *var)
 
1336
bool sys_var_key_buffer_size::update(Session *session, set_var *var)
1961
1337
{
1962
1338
  uint64_t tmp= var->save_result.uint64_t_value;
1963
1339
  LEX_STRING *base_name= &var->base;
1970
1346
 
1971
1347
  pthread_mutex_lock(&LOCK_global_system_variables);
1972
1348
  key_cache= get_key_cache(base_name);
1973
 
                            
 
1349
 
1974
1350
  if (!key_cache)
1975
1351
  {
1976
1352
    /* Key cache didn't exists */
1995
1371
  {
1996
1372
    if (key_cache == dflt_key_cache)
1997
1373
    {
1998
 
      push_warning_printf(thd, DRIZZLE_ERROR::WARN_LEVEL_WARN,
 
1374
      push_warning_printf(session, DRIZZLE_ERROR::WARN_LEVEL_WARN,
1999
1375
                          ER_WARN_CANT_DROP_DEFAULT_KEYCACHE,
2000
1376
                          ER(ER_WARN_CANT_DROP_DEFAULT_KEYCACHE));
2001
1377
      goto end;                                 // Ignore default key cache
2004
1380
    if (key_cache->key_cache_inited)            // If initied
2005
1381
    {
2006
1382
      /*
2007
 
        Move tables using this key cache to the default key cache
2008
 
        and clear the old key cache.
 
1383
        Move tables using this key cache to the default key cache
 
1384
        and clear the old key cache.
2009
1385
      */
2010
 
      NAMED_LIST *list; 
 
1386
      NAMED_LIST *list;
2011
1387
      key_cache= (KEY_CACHE *) find_named(&key_caches, base_name->str,
2012
1388
                                              base_name->length, &list);
2013
1389
      key_cache->in_init= 1;
2014
1390
      pthread_mutex_unlock(&LOCK_global_system_variables);
2015
 
      error= reassign_keycache_tables(thd, key_cache, dflt_key_cache);
 
1391
      error= reassign_keycache_tables(session, key_cache, dflt_key_cache);
2016
1392
      pthread_mutex_lock(&LOCK_global_system_variables);
2017
1393
      key_cache->in_init= 0;
2018
1394
    }
2024
1400
  }
2025
1401
 
2026
1402
  key_cache->param_buff_size=
2027
 
    (uint64_t) fix_unsigned(thd, tmp, option_limits);
 
1403
    (uint64_t) fix_unsigned(session, tmp, option_limits);
2028
1404
 
2029
1405
  /* If key cache didn't existed initialize it, else resize it */
2030
1406
  key_cache->in_init= 1;
2036
1412
    error= (bool)(ha_resize_key_cache(key_cache));
2037
1413
 
2038
1414
  pthread_mutex_lock(&LOCK_global_system_variables);
2039
 
  key_cache->in_init= 0;  
 
1415
  key_cache->in_init= 0;
2040
1416
 
2041
1417
end:
2042
1418
  pthread_mutex_unlock(&LOCK_global_system_variables);
2050
1426
  This should be changed so that we wait until the previous
2051
1427
  assignment is done and then do the new assign
2052
1428
*/
2053
 
bool sys_var_key_cache_long::update(THD *thd, set_var *var)
 
1429
bool sys_var_key_cache_uint32_t::update(Session *session, set_var *var)
2054
1430
{
2055
 
  ulong tmp= (ulong) var->value->val_int();
 
1431
  uint64_t tmp= (uint64_t) var->value->val_int();
2056
1432
  LEX_STRING *base_name= &var->base;
2057
1433
  bool error= 0;
2058
1434
 
2077
1453
  if (key_cache->in_init)
2078
1454
    goto end;
2079
1455
 
2080
 
  *((ulong*) (((char*) key_cache) + offset))=
2081
 
    (ulong) fix_unsigned(thd, tmp, option_limits);
 
1456
  *((uint32_t*) (((char*) key_cache) + offset))=
 
1457
    (uint32_t) fix_unsigned(session, tmp, option_limits);
2082
1458
 
2083
1459
  /*
2084
1460
    Don't create a new key cache if it didn't exist
2091
1467
  error= (bool) (ha_resize_key_cache(key_cache));
2092
1468
 
2093
1469
  pthread_mutex_lock(&LOCK_global_system_variables);
2094
 
  key_cache->in_init= 0;  
 
1470
  key_cache->in_init= 0;
2095
1471
 
2096
1472
end:
2097
1473
  pthread_mutex_unlock(&LOCK_global_system_variables);
2099
1475
}
2100
1476
 
2101
1477
 
2102
 
bool sys_var_log_state::update(THD *thd, set_var *var)
2103
 
{
2104
 
  bool res;
2105
 
  pthread_mutex_lock(&LOCK_global_system_variables);
2106
 
  if (!var->save_result.ulong_value)
2107
 
  {
2108
 
    logger.deactivate_log_handler(thd, log_type);
2109
 
    res= false;
2110
 
  }
2111
 
  else
2112
 
    res= logger.activate_log_handler(thd, log_type);
2113
 
  pthread_mutex_unlock(&LOCK_global_system_variables);
2114
 
  return res;
2115
 
}
2116
 
 
2117
 
void sys_var_log_state::set_default(THD *thd,
2118
 
                                    enum_var_type type __attribute__((unused)))
2119
 
{
2120
 
  pthread_mutex_lock(&LOCK_global_system_variables);
2121
 
  logger.deactivate_log_handler(thd, log_type);
2122
 
  pthread_mutex_unlock(&LOCK_global_system_variables);
2123
 
}
2124
 
 
2125
 
 
2126
 
static int  sys_check_log_path(THD *thd __attribute__((unused)),
2127
 
                               set_var *var)
2128
 
{
2129
 
  char path[FN_REFLEN], buff[FN_REFLEN];
2130
 
  struct stat f_stat;
2131
 
  String str(buff, sizeof(buff), system_charset_info), *res;
2132
 
  const char *log_file_str;
2133
 
  size_t path_length;
2134
 
 
2135
 
  if (!(res= var->value->val_str(&str)))
2136
 
    goto err;
2137
 
 
2138
 
  log_file_str= res->c_ptr();
2139
 
  memset(&f_stat, 0, sizeof(struct stat));
2140
 
 
2141
 
  path_length= unpack_filename(path, log_file_str);
2142
 
 
2143
 
  if (!path_length)
2144
 
  {
2145
 
    /* File name is empty. */
2146
 
 
2147
 
    goto err;
2148
 
  }
2149
 
 
2150
 
  if (!stat(path, &f_stat))
2151
 
  {
2152
 
    /*
2153
 
      A file system object exists. Check if argument is a file and we have
2154
 
      'write' permission.
2155
 
    */
2156
 
 
2157
 
    if (!S_ISREG(f_stat.st_mode) ||
2158
 
        !(f_stat.st_mode & S_IWRITE))
2159
 
      goto err;
2160
 
 
2161
 
    return 0;
2162
 
  }
2163
 
 
2164
 
  /* Get dirname of the file path. */
2165
 
  (void) dirname_part(path, log_file_str, &path_length);
2166
 
 
2167
 
  /* Dirname is empty if file path is relative. */
2168
 
  if (!path_length)
2169
 
    return 0;
2170
 
 
2171
 
  /*
2172
 
    Check if directory exists and we have permission to create file and
2173
 
    write to file.
2174
 
  */
2175
 
  if (my_access(path, (F_OK|W_OK)))
2176
 
    goto err;
2177
 
 
2178
 
  return 0;
2179
 
 
2180
 
err:
2181
 
  my_error(ER_WRONG_VALUE_FOR_VAR, MYF(0), var->var->name, 
2182
 
           res ? log_file_str : "NULL");
2183
 
  return 1;
2184
 
}
2185
 
 
2186
 
 
2187
 
bool update_sys_var_str_path(THD *thd __attribute__((unused)),
2188
 
                             sys_var_str *var_str,
2189
 
                             set_var *var, const char *log_ext,
2190
 
                             bool log_state, uint log_type)
2191
 
{
2192
 
  DRIZZLE_QUERY_LOG *file_log;
2193
 
  char buff[FN_REFLEN];
2194
 
  char *res= 0, *old_value=(char *)(var ? var->value->str_value.ptr() : 0);
2195
 
  bool result= 0;
2196
 
  uint str_length= (var ? var->value->str_value.length() : 0);
2197
 
 
2198
 
  switch (log_type) {
2199
 
  case QUERY_LOG_SLOW:
2200
 
    file_log= logger.get_slow_log_file_handler();
2201
 
    break;
2202
 
  case QUERY_LOG_GENERAL:
2203
 
    file_log= logger.get_log_file_handler();
2204
 
    break;
2205
 
  default:
2206
 
    assert(0);                                  // Impossible
2207
 
  }
2208
 
 
2209
 
  if (!old_value)
2210
 
  {
2211
 
    old_value= make_default_log_name(buff, log_ext);
2212
 
    str_length= strlen(old_value);
2213
 
  }
2214
 
  if (!(res= my_strndup(old_value, str_length, MYF(MY_FAE+MY_WME))))
2215
 
  {
2216
 
    result= 1;
2217
 
    goto err;
2218
 
  }
2219
 
 
2220
 
  pthread_mutex_lock(&LOCK_global_system_variables);
2221
 
  logger.lock_exclusive();
2222
 
 
2223
 
  if (file_log && log_state)
2224
 
    file_log->close(0);
2225
 
  old_value= var_str->value;
2226
 
  var_str->value= res;
2227
 
  var_str->value_length= str_length;
2228
 
  my_free(old_value, MYF(MY_ALLOW_ZERO_PTR));
2229
 
  if (file_log && log_state)
2230
 
  {
2231
 
    switch (log_type) {
2232
 
    case QUERY_LOG_SLOW:
2233
 
      file_log->open_slow_log(sys_var_slow_log_path.value);
2234
 
      break;
2235
 
    case QUERY_LOG_GENERAL:
2236
 
      file_log->open_query_log(sys_var_general_log_path.value);
2237
 
      break;
2238
 
    default:
2239
 
      assert(0);
2240
 
    }
2241
 
  }
2242
 
 
2243
 
  logger.unlock();
2244
 
  pthread_mutex_unlock(&LOCK_global_system_variables);
2245
 
 
2246
 
err:
2247
 
  return result;
2248
 
}
2249
 
 
2250
 
 
2251
 
static bool sys_update_general_log_path(THD *thd, set_var * var)
2252
 
{
2253
 
  return update_sys_var_str_path(thd, &sys_var_general_log_path,
2254
 
                                 var, ".log", opt_log, QUERY_LOG_GENERAL);
2255
 
}
2256
 
 
2257
 
 
2258
 
static void sys_default_general_log_path(THD *thd,
2259
 
                                         enum_var_type type __attribute__((unused)))
2260
 
{
2261
 
  (void) update_sys_var_str_path(thd, &sys_var_general_log_path,
2262
 
                                 0, ".log", opt_log, QUERY_LOG_GENERAL);
2263
 
}
2264
 
 
2265
 
 
2266
 
static bool sys_update_slow_log_path(THD *thd, set_var * var)
2267
 
{
2268
 
  return update_sys_var_str_path(thd, &sys_var_slow_log_path,
2269
 
                                 var, "-slow.log", opt_slow_log,
2270
 
                                 QUERY_LOG_SLOW);
2271
 
}
2272
 
 
2273
 
 
2274
 
static void sys_default_slow_log_path(THD *thd,
2275
 
                                      enum_var_type type __attribute__((unused)))
2276
 
{
2277
 
  (void) update_sys_var_str_path(thd, &sys_var_slow_log_path,
2278
 
                                 0, "-slow.log", opt_slow_log,
2279
 
                                 QUERY_LOG_SLOW);
2280
 
}
2281
 
 
2282
 
 
2283
 
bool sys_var_log_output::update(THD *thd __attribute__((unused)),
2284
 
                                set_var *var)
2285
 
{
2286
 
  pthread_mutex_lock(&LOCK_global_system_variables);
2287
 
  logger.lock_exclusive();
2288
 
  logger.init_slow_log(var->save_result.ulong_value);
2289
 
  logger.init_general_log(var->save_result.ulong_value);
2290
 
  *value= var->save_result.ulong_value;
2291
 
  logger.unlock();
2292
 
  pthread_mutex_unlock(&LOCK_global_system_variables);
2293
 
  return 0;
2294
 
}
2295
 
 
2296
 
 
2297
 
void sys_var_log_output::set_default(THD *thd __attribute__((unused)),
2298
 
                                     enum_var_type type __attribute__((unused)))
2299
 
{
2300
 
  pthread_mutex_lock(&LOCK_global_system_variables);
2301
 
  logger.lock_exclusive();
2302
 
  logger.init_slow_log(LOG_FILE);
2303
 
  logger.init_general_log(LOG_FILE);
2304
 
  *value= LOG_FILE;
2305
 
  logger.unlock();
2306
 
  pthread_mutex_unlock(&LOCK_global_system_variables);
2307
 
}
2308
 
 
2309
 
 
2310
 
uchar *sys_var_log_output::value_ptr(THD *thd,
2311
 
                                     enum_var_type type __attribute__((unused)),
2312
 
                                     LEX_STRING *base __attribute__((unused)))
2313
 
{
2314
 
  char buff[256];
2315
 
  String tmp(buff, sizeof(buff), &my_charset_latin1);
2316
 
  ulong length;
2317
 
  ulong val= *value;
2318
 
 
2319
 
  tmp.length(0);
2320
 
  for (uint i= 0; val; val>>= 1, i++)
2321
 
  {
2322
 
    if (val & 1)
2323
 
    {
2324
 
      tmp.append(log_output_typelib.type_names[i],
2325
 
                 log_output_typelib.type_lengths[i]);
2326
 
      tmp.append(',');
2327
 
    }
2328
 
  }
2329
 
 
2330
 
  if ((length= tmp.length()))
2331
 
    length--;
2332
 
  return (uchar*) thd->strmake(tmp.ptr(), length);
2333
 
}
2334
 
 
2335
 
 
2336
 
/*****************************************************************************
2337
 
  Functions to handle SET NAMES and SET CHARACTER SET
2338
 
*****************************************************************************/
2339
 
 
2340
 
int set_var_collation_client::check(THD *thd __attribute__((unused)))
2341
 
{
2342
 
  /* Currently, UCS-2 cannot be used as a client character set */
2343
 
  if (character_set_client->mbminlen > 1)
2344
 
  {
2345
 
    my_error(ER_WRONG_VALUE_FOR_VAR, MYF(0), "character_set_client",
2346
 
             character_set_client->csname);
2347
 
    return 1;
2348
 
  }
2349
 
  return 0;
2350
 
}
2351
 
 
2352
 
int set_var_collation_client::update(THD *thd)
2353
 
{
2354
 
  thd->variables.character_set_client= character_set_client;
2355
 
  thd->variables.character_set_results= character_set_results;
2356
 
  thd->variables.collation_connection= collation_connection;
2357
 
  thd->update_charset();
2358
 
  thd->protocol_text.init(thd);
2359
 
  return 0;
2360
 
}
2361
 
 
2362
1478
/****************************************************************************/
2363
1479
 
2364
 
bool sys_var_timestamp::update(THD *thd,  set_var *var)
 
1480
bool sys_var_timestamp::update(Session *session,  set_var *var)
2365
1481
{
2366
 
  thd->set_time((time_t) var->save_result.uint64_t_value);
 
1482
  session->set_time((time_t) var->save_result.uint64_t_value);
2367
1483
  return 0;
2368
1484
}
2369
1485
 
2370
1486
 
2371
 
void sys_var_timestamp::set_default(THD *thd,
2372
 
                                    enum_var_type type __attribute__((unused)))
2373
 
{
2374
 
  thd->user_time=0;
2375
 
}
2376
 
 
2377
 
 
2378
 
uchar *sys_var_timestamp::value_ptr(THD *thd,
2379
 
                                    enum_var_type type __attribute__((unused)),
2380
 
                                    LEX_STRING *base __attribute__((unused)))
2381
 
{
2382
 
  thd->sys_var_tmp.long_value= (long) thd->start_time;
2383
 
  return (uchar*) &thd->sys_var_tmp.long_value;
2384
 
}
2385
 
 
2386
 
 
2387
 
bool sys_var_last_insert_id::update(THD *thd, set_var *var)
2388
 
{
2389
 
  thd->first_successful_insert_id_in_prev_stmt=
 
1487
void sys_var_timestamp::set_default(Session *session, enum_var_type)
 
1488
{
 
1489
  session->user_time=0;
 
1490
}
 
1491
 
 
1492
 
 
1493
unsigned char *sys_var_timestamp::value_ptr(Session *session, enum_var_type,
 
1494
                                            const LEX_STRING *)
 
1495
{
 
1496
  session->sys_var_tmp.int32_t_value= (int32_t) session->start_time;
 
1497
  return (unsigned char*) &session->sys_var_tmp.int32_t_value;
 
1498
}
 
1499
 
 
1500
 
 
1501
bool sys_var_last_insert_id::update(Session *session, set_var *var)
 
1502
{
 
1503
  session->first_successful_insert_id_in_prev_stmt=
2390
1504
    var->save_result.uint64_t_value;
2391
1505
  return 0;
2392
1506
}
2393
1507
 
2394
1508
 
2395
 
uchar *sys_var_last_insert_id::value_ptr(THD *thd,
2396
 
                                         enum_var_type type __attribute__((unused)),
2397
 
                                         LEX_STRING *base __attribute__((unused)))
 
1509
unsigned char *sys_var_last_insert_id::value_ptr(Session *session,
 
1510
                                                 enum_var_type,
 
1511
                                                 const LEX_STRING *)
2398
1512
{
2399
1513
  /*
2400
1514
    this tmp var makes it robust againt change of type of
2401
1515
    read_first_successful_insert_id_in_prev_stmt().
2402
1516
  */
2403
 
  thd->sys_var_tmp.uint64_t_value= 
2404
 
    thd->read_first_successful_insert_id_in_prev_stmt();
2405
 
  return (uchar*) &thd->sys_var_tmp.uint64_t_value;
2406
 
}
2407
 
 
2408
 
 
2409
 
bool sys_var_insert_id::update(THD *thd, set_var *var)
2410
 
{
2411
 
  thd->force_one_auto_inc_interval(var->save_result.uint64_t_value);
2412
 
  return 0;
2413
 
}
2414
 
 
2415
 
 
2416
 
uchar *sys_var_insert_id::value_ptr(THD *thd,
2417
 
                                    enum_var_type type __attribute__((unused)),
2418
 
                                    LEX_STRING *base __attribute__((unused)))
2419
 
{
2420
 
  thd->sys_var_tmp.uint64_t_value=
2421
 
    thd->auto_inc_intervals_forced.minimum();
2422
 
  return (uchar*) &thd->sys_var_tmp.uint64_t_value;
2423
 
}
2424
 
 
2425
 
 
2426
 
bool sys_var_rand_seed1::update(THD *thd, set_var *var)
2427
 
{
2428
 
  thd->rand.seed1= (ulong) var->save_result.uint64_t_value;
2429
 
  return 0;
2430
 
}
2431
 
 
2432
 
bool sys_var_rand_seed2::update(THD *thd, set_var *var)
2433
 
{
2434
 
  thd->rand.seed2= (ulong) var->save_result.uint64_t_value;
2435
 
  return 0;
2436
 
}
2437
 
 
2438
 
 
2439
 
bool sys_var_thd_time_zone::check(THD *thd, set_var *var)
 
1517
  session->sys_var_tmp.uint64_t_value=
 
1518
    session->read_first_successful_insert_id_in_prev_stmt();
 
1519
  return (unsigned char*) &session->sys_var_tmp.uint64_t_value;
 
1520
}
 
1521
 
 
1522
 
 
1523
bool sys_var_session_time_zone::check(Session *session, set_var *var)
2440
1524
{
2441
1525
  char buff[MAX_TIME_ZONE_NAME_LENGTH];
2442
 
  String str(buff, sizeof(buff), &my_charset_latin1);
 
1526
  String str(buff, sizeof(buff), &my_charset_utf8_general_ci);
2443
1527
  String *res= var->value->val_str(&str);
2444
1528
 
2445
 
  if (!(var->save_result.time_zone= my_tz_find(thd, res)))
 
1529
  if (!(var->save_result.time_zone= my_tz_find(session, res)))
2446
1530
  {
2447
1531
    my_error(ER_UNKNOWN_TIME_ZONE, MYF(0), res ? res->c_ptr() : "NULL");
2448
1532
    return 1;
2451
1535
}
2452
1536
 
2453
1537
 
2454
 
bool sys_var_thd_time_zone::update(THD *thd, set_var *var)
 
1538
bool sys_var_session_time_zone::update(Session *session, set_var *var)
2455
1539
{
2456
1540
  /* We are using Time_zone object found during check() phase. */
2457
1541
  if (var->type == OPT_GLOBAL)
2461
1545
    pthread_mutex_unlock(&LOCK_global_system_variables);
2462
1546
  }
2463
1547
  else
2464
 
    thd->variables.time_zone= var->save_result.time_zone;
 
1548
    session->variables.time_zone= var->save_result.time_zone;
2465
1549
  return 0;
2466
1550
}
2467
1551
 
2468
1552
 
2469
 
uchar *sys_var_thd_time_zone::value_ptr(THD *thd, enum_var_type type,
2470
 
                                        LEX_STRING *base __attribute__((unused)))
 
1553
unsigned char *sys_var_session_time_zone::value_ptr(Session *session,
 
1554
                                                    enum_var_type type,
 
1555
                                                    const LEX_STRING *)
2471
1556
{
2472
 
  /* 
 
1557
  /*
2473
1558
    We can use ptr() instead of c_ptr() here because String contaning
2474
1559
    time zone name is guaranteed to be zero ended.
2475
1560
  */
2476
1561
  if (type == OPT_GLOBAL)
2477
 
    return (uchar *)(global_system_variables.time_zone->get_name()->ptr());
 
1562
    return (unsigned char *)(global_system_variables.time_zone->get_name()->ptr());
2478
1563
  else
2479
1564
  {
2480
1565
    /*
2485
1570
      timezone). If it's the global value which was used we can't replicate
2486
1571
      (binlog code stores session value only).
2487
1572
    */
2488
 
    thd->time_zone_used= 1;
2489
 
    return (uchar *)(thd->variables.time_zone->get_name()->ptr());
 
1573
    return (unsigned char *)(session->variables.time_zone->get_name()->ptr());
2490
1574
  }
2491
1575
}
2492
1576
 
2493
1577
 
2494
 
void sys_var_thd_time_zone::set_default(THD *thd, enum_var_type type)
 
1578
void sys_var_session_time_zone::set_default(Session *session, enum_var_type type)
2495
1579
{
2496
1580
 pthread_mutex_lock(&LOCK_global_system_variables);
2497
1581
 if (type == OPT_GLOBAL)
2498
1582
 {
2499
1583
   if (default_tz_name)
2500
1584
   {
2501
 
     String str(default_tz_name, &my_charset_latin1);
 
1585
     String str(default_tz_name, &my_charset_utf8_general_ci);
2502
1586
     /*
2503
1587
       We are guaranteed to find this time zone since its existence
2504
1588
       is checked during start-up.
2505
1589
     */
2506
 
     global_system_variables.time_zone= my_tz_find(thd, &str);
 
1590
     global_system_variables.time_zone= my_tz_find(session, &str);
2507
1591
   }
2508
1592
   else
2509
1593
     global_system_variables.time_zone= my_tz_SYSTEM;
2510
1594
 }
2511
1595
 else
2512
 
   thd->variables.time_zone= global_system_variables.time_zone;
 
1596
   session->variables.time_zone= global_system_variables.time_zone;
2513
1597
 pthread_mutex_unlock(&LOCK_global_system_variables);
2514
1598
}
2515
1599
 
2516
1600
 
2517
 
bool sys_var_max_user_conn::check(THD *thd, set_var *var)
2518
 
{
2519
 
  if (var->type == OPT_GLOBAL)
2520
 
    return sys_var_thd::check(thd, var);
2521
 
  else
2522
 
  {
2523
 
    /*
2524
 
      Per-session values of max_user_connections can't be set directly.
2525
 
      May be we should have a separate error message for this?
2526
 
    */
2527
 
    my_error(ER_GLOBAL_VARIABLE, MYF(0), name);
2528
 
    return true;
2529
 
  }
2530
 
}
2531
 
 
2532
 
bool sys_var_max_user_conn::update(THD *thd __attribute__((unused)),
2533
 
                                   set_var *var)
2534
 
{
2535
 
  assert(var->type == OPT_GLOBAL);
2536
 
  pthread_mutex_lock(&LOCK_global_system_variables);
2537
 
  max_user_connections= (uint)var->save_result.uint64_t_value;
2538
 
  pthread_mutex_unlock(&LOCK_global_system_variables);
2539
 
  return 0;
2540
 
}
2541
 
 
2542
 
 
2543
 
void sys_var_max_user_conn::set_default(THD *thd __attribute__((unused)),
2544
 
                                        enum_var_type type __attribute__((unused)))
2545
 
{
2546
 
  assert(type == OPT_GLOBAL);
2547
 
  pthread_mutex_lock(&LOCK_global_system_variables);
2548
 
  max_user_connections= (ulong) option_limits->def_value;
2549
 
  pthread_mutex_unlock(&LOCK_global_system_variables);
2550
 
}
2551
 
 
2552
 
 
2553
 
uchar *sys_var_max_user_conn::value_ptr(THD *thd, enum_var_type type,
2554
 
                                        LEX_STRING *base __attribute__((unused)))
2555
 
{
2556
 
  if (type != OPT_GLOBAL &&
2557
 
      thd->user_connect && thd->user_connect->user_resources.user_conn)
2558
 
    return (uchar*) &(thd->user_connect->user_resources.user_conn);
2559
 
  return (uchar*) &(max_user_connections);
2560
 
}
2561
 
 
2562
 
 
2563
 
bool sys_var_thd_lc_time_names::check(THD *thd __attribute__((unused)),
2564
 
                                      set_var *var)
 
1601
bool sys_var_session_lc_time_names::check(Session *, set_var *var)
2565
1602
{
2566
1603
  MY_LOCALE *locale_match;
2567
1604
 
2568
1605
  if (var->value->result_type() == INT_RESULT)
2569
1606
  {
2570
 
    if (!(locale_match= my_locale_by_number((uint) var->value->val_int())))
 
1607
    if (!(locale_match= my_locale_by_number((uint32_t) var->value->val_int())))
2571
1608
    {
2572
1609
      char buf[20];
2573
1610
      int10_to_str((int) var->value->val_int(), buf, -10);
2577
1614
  }
2578
1615
  else // STRING_RESULT
2579
1616
  {
2580
 
    char buff[6]; 
2581
 
    String str(buff, sizeof(buff), &my_charset_latin1), *res;
 
1617
    char buff[6];
 
1618
    String str(buff, sizeof(buff), &my_charset_utf8_general_ci), *res;
2582
1619
    if (!(res=var->value->val_str(&str)))
2583
1620
    {
2584
 
      my_error(ER_WRONG_VALUE_FOR_VAR, MYF(0), name, "NULL");
 
1621
      my_error(ER_WRONG_VALUE_FOR_VAR, MYF(0), name.c_str(), "NULL");
2585
1622
      return 1;
2586
1623
    }
2587
1624
    const char *locale_str= res->c_ptr();
2598
1635
}
2599
1636
 
2600
1637
 
2601
 
bool sys_var_thd_lc_time_names::update(THD *thd, set_var *var)
 
1638
bool sys_var_session_lc_time_names::update(Session *session, set_var *var)
2602
1639
{
2603
1640
  if (var->type == OPT_GLOBAL)
2604
1641
    global_system_variables.lc_time_names= var->save_result.locale_value;
2605
1642
  else
2606
 
    thd->variables.lc_time_names= var->save_result.locale_value;
 
1643
    session->variables.lc_time_names= var->save_result.locale_value;
2607
1644
  return 0;
2608
1645
}
2609
1646
 
2610
1647
 
2611
 
uchar *sys_var_thd_lc_time_names::value_ptr(THD *thd,
2612
 
                                            enum_var_type type,
2613
 
                                            LEX_STRING *base __attribute__((unused)))
 
1648
unsigned char *sys_var_session_lc_time_names::value_ptr(Session *session,
 
1649
                                                        enum_var_type type,
 
1650
                                                        const LEX_STRING *)
2614
1651
{
2615
1652
  return type == OPT_GLOBAL ?
2616
 
                 (uchar *) global_system_variables.lc_time_names->name :
2617
 
                 (uchar *) thd->variables.lc_time_names->name;
 
1653
                 (unsigned char *) global_system_variables.lc_time_names->name :
 
1654
                 (unsigned char *) session->variables.lc_time_names->name;
2618
1655
}
2619
1656
 
2620
1657
 
2621
 
void sys_var_thd_lc_time_names::set_default(THD *thd, enum_var_type type)
 
1658
void sys_var_session_lc_time_names::set_default(Session *session, enum_var_type type)
2622
1659
{
2623
1660
  if (type == OPT_GLOBAL)
2624
1661
    global_system_variables.lc_time_names= my_default_lc_time_names;
2625
1662
  else
2626
 
    thd->variables.lc_time_names= global_system_variables.lc_time_names;
 
1663
    session->variables.lc_time_names= global_system_variables.lc_time_names;
2627
1664
}
2628
1665
 
2629
1666
/*
2635
1672
    This is used for handling long_query_time
2636
1673
*/
2637
1674
 
2638
 
bool sys_var_microseconds::update(THD *thd, set_var *var)
 
1675
bool sys_var_microseconds::update(Session *session, set_var *var)
2639
1676
{
2640
1677
  double num= var->value->val_real();
2641
1678
  int64_t microseconds;
2651
1688
    pthread_mutex_unlock(&LOCK_global_system_variables);
2652
1689
  }
2653
1690
  else
2654
 
    thd->variables.*offset= microseconds;
 
1691
    session->variables.*offset= microseconds;
2655
1692
  return 0;
2656
1693
}
2657
1694
 
2658
1695
 
2659
 
void sys_var_microseconds::set_default(THD *thd, enum_var_type type)
 
1696
void sys_var_microseconds::set_default(Session *session, enum_var_type type)
2660
1697
{
2661
1698
  int64_t microseconds= (int64_t) (option_limits->def_value * 1000000.0);
2662
1699
  if (type == OPT_GLOBAL)
2666
1703
    pthread_mutex_unlock(&LOCK_global_system_variables);
2667
1704
  }
2668
1705
  else
2669
 
    thd->variables.*offset= microseconds;
2670
 
}
2671
 
 
2672
 
 
2673
 
uchar *sys_var_microseconds::value_ptr(THD *thd, enum_var_type type,
2674
 
                                          LEX_STRING *base __attribute__((unused)))
2675
 
{
2676
 
  thd->tmp_double_value= (double) ((type == OPT_GLOBAL) ?
2677
 
                                   global_system_variables.*offset :
2678
 
                                   thd->variables.*offset) / 1000000.0;
2679
 
  return (uchar*) &thd->tmp_double_value;
2680
 
}
2681
 
 
 
1706
    session->variables.*offset= microseconds;
 
1707
}
2682
1708
 
2683
1709
/*
2684
 
  Functions to update thd->options bits
 
1710
  Functions to update session->options bits
2685
1711
*/
2686
1712
 
2687
 
static bool set_option_bit(THD *thd, set_var *var)
 
1713
static bool set_option_bit(Session *session, set_var *var)
2688
1714
{
2689
 
  sys_var_thd_bit *sys_var= ((sys_var_thd_bit*) var->var);
2690
 
  if ((var->save_result.ulong_value != 0) == sys_var->reverse)
2691
 
    thd->options&= ~sys_var->bit_flag;
 
1715
  sys_var_session_bit *sys_var= ((sys_var_session_bit*) var->var);
 
1716
  if ((var->save_result.uint32_t_value != 0) == sys_var->reverse)
 
1717
    session->options&= ~sys_var->bit_flag;
2692
1718
  else
2693
 
    thd->options|= sys_var->bit_flag;
 
1719
    session->options|= sys_var->bit_flag;
2694
1720
  return 0;
2695
1721
}
2696
1722
 
2697
1723
 
2698
 
static bool set_option_autocommit(THD *thd, set_var *var)
 
1724
static bool set_option_autocommit(Session *session, set_var *var)
2699
1725
{
2700
1726
  /* The test is negative as the flag we use is NOT autocommit */
2701
1727
 
2702
 
  uint64_t org_options= thd->options;
 
1728
  uint64_t org_options= session->options;
2703
1729
 
2704
 
  if (var->save_result.ulong_value != 0)
2705
 
    thd->options&= ~((sys_var_thd_bit*) var->var)->bit_flag;
 
1730
  if (var->save_result.uint32_t_value != 0)
 
1731
    session->options&= ~((sys_var_session_bit*) var->var)->bit_flag;
2706
1732
  else
2707
 
    thd->options|= ((sys_var_thd_bit*) var->var)->bit_flag;
 
1733
    session->options|= ((sys_var_session_bit*) var->var)->bit_flag;
2708
1734
 
2709
 
  if ((org_options ^ thd->options) & OPTION_NOT_AUTOCOMMIT)
 
1735
  if ((org_options ^ session->options) & OPTION_NOT_AUTOCOMMIT)
2710
1736
  {
2711
1737
    if ((org_options & OPTION_NOT_AUTOCOMMIT))
2712
1738
    {
2713
1739
      /* We changed to auto_commit mode */
2714
 
      thd->options&= ~(uint64_t) (OPTION_BEGIN | OPTION_KEEP_LOG);
2715
 
      thd->transaction.all.modified_non_trans_table= false;
2716
 
      thd->server_status|= SERVER_STATUS_AUTOCOMMIT;
2717
 
      if (ha_commit(thd))
 
1740
      session->options&= ~(uint64_t) (OPTION_BEGIN | OPTION_KEEP_LOG);
 
1741
      session->transaction.all.modified_non_trans_table= false;
 
1742
      session->server_status|= SERVER_STATUS_AUTOCOMMIT;
 
1743
      if (ha_commit(session))
2718
1744
        return 1;
2719
1745
    }
2720
1746
    else
2721
1747
    {
2722
 
      thd->transaction.all.modified_non_trans_table= false;
2723
 
      thd->server_status&= ~SERVER_STATUS_AUTOCOMMIT;
 
1748
      session->transaction.all.modified_non_trans_table= false;
 
1749
      session->server_status&= ~SERVER_STATUS_AUTOCOMMIT;
2724
1750
    }
2725
1751
  }
2726
1752
  return 0;
2727
1753
}
2728
1754
 
2729
 
static int check_log_update(THD *thd __attribute__((unused)),
2730
 
                            set_var *var __attribute__((unused)))
2731
 
{
2732
 
  return 0;
2733
 
}
2734
 
 
2735
 
static bool set_log_update(THD *thd __attribute__((unused)),
2736
 
                           set_var *var __attribute__((unused)))
2737
 
{
2738
 
  /*
2739
 
    The update log is not supported anymore since 5.0.
2740
 
    See sql/mysqld.cc/, comments in function init_server_components() for an
2741
 
    explaination of the different warnings we send below
2742
 
  */
2743
 
 
2744
 
  if (opt_sql_bin_update)
2745
 
  {
2746
 
    push_warning(thd, DRIZZLE_ERROR::WARN_LEVEL_NOTE,
2747
 
                 ER_UPDATE_LOG_DEPRECATED_TRANSLATED,
2748
 
                 ER(ER_UPDATE_LOG_DEPRECATED_TRANSLATED));
2749
 
  }
2750
 
  else
2751
 
    push_warning(thd, DRIZZLE_ERROR::WARN_LEVEL_NOTE,
2752
 
                 ER_UPDATE_LOG_DEPRECATED_IGNORED,
2753
 
                 ER(ER_UPDATE_LOG_DEPRECATED_IGNORED));
2754
 
  set_option_bit(thd, var);
2755
 
  return 0;
2756
 
}
2757
 
 
2758
 
 
2759
 
static int check_pseudo_thread_id(THD *thd __attribute__((unused)),
2760
 
                                  set_var *var)
 
1755
static int check_pseudo_thread_id(Session *, set_var *var)
2761
1756
{
2762
1757
  var->save_result.uint64_t_value= var->value->val_int();
2763
1758
  return 0;
2764
1759
}
2765
1760
 
2766
 
static uchar *get_warning_count(THD *thd)
 
1761
static unsigned char *get_warning_count(Session *session)
2767
1762
{
2768
 
  thd->sys_var_tmp.long_value=
2769
 
    (thd->warn_count[(uint) DRIZZLE_ERROR::WARN_LEVEL_NOTE] +
2770
 
     thd->warn_count[(uint) DRIZZLE_ERROR::WARN_LEVEL_ERROR] +
2771
 
     thd->warn_count[(uint) DRIZZLE_ERROR::WARN_LEVEL_WARN]);
2772
 
  return (uchar*) &thd->sys_var_tmp.long_value;
 
1763
  session->sys_var_tmp.uint32_t_value=
 
1764
    (session->warn_count[(uint32_t) DRIZZLE_ERROR::WARN_LEVEL_NOTE] +
 
1765
     session->warn_count[(uint32_t) DRIZZLE_ERROR::WARN_LEVEL_ERROR] +
 
1766
     session->warn_count[(uint32_t) DRIZZLE_ERROR::WARN_LEVEL_WARN]);
 
1767
  return (unsigned char*) &session->sys_var_tmp.uint32_t_value;
2773
1768
}
2774
1769
 
2775
 
static uchar *get_error_count(THD *thd)
 
1770
static unsigned char *get_error_count(Session *session)
2776
1771
{
2777
 
  thd->sys_var_tmp.long_value= 
2778
 
    thd->warn_count[(uint) DRIZZLE_ERROR::WARN_LEVEL_ERROR];
2779
 
  return (uchar*) &thd->sys_var_tmp.long_value;
 
1772
  session->sys_var_tmp.uint32_t_value=
 
1773
    session->warn_count[(uint32_t) DRIZZLE_ERROR::WARN_LEVEL_ERROR];
 
1774
  return (unsigned char*) &session->sys_var_tmp.uint32_t_value;
2780
1775
}
2781
1776
 
2782
1777
 
2785
1780
 
2786
1781
  This is necessary because if the user does not specify a temporary
2787
1782
  directory via the command line, one is chosen based on the environment
2788
 
  or system defaults.  But we can't just always use mysql_tmpdir, because
 
1783
  or system defaults.  But we can't just always use drizzle_tmpdir, because
2789
1784
  that is actually a call to my_tmpdir() which cycles among possible
2790
1785
  temporary directories.
2791
1786
 
2792
 
  @param thd            thread handle
 
1787
  @param session                thread handle
2793
1788
 
2794
1789
  @retval
2795
1790
    ptr         pointer to NUL-terminated string
2796
1791
*/
2797
 
static uchar *get_tmpdir(THD *thd __attribute__((unused)))
 
1792
static unsigned char *get_tmpdir(Session *)
2798
1793
{
2799
 
  if (opt_mysql_tmpdir)
2800
 
    return (uchar *)opt_mysql_tmpdir;
2801
 
  return (uchar*)mysql_tmpdir;
 
1794
  assert(drizzle_tmpdir);
 
1795
  return (unsigned char*)drizzle_tmpdir;
2802
1796
}
2803
1797
 
2804
1798
/****************************************************************************
2821
1815
    ptr         pointer to option structure
2822
1816
*/
2823
1817
 
2824
 
static struct my_option *find_option(struct my_option *opt, const char *name) 
 
1818
static struct my_option *find_option(struct my_option *opt, const char *name)
2825
1819
{
2826
 
  uint length=strlen(name);
 
1820
  uint32_t length=strlen(name);
2827
1821
  for (; opt->name; opt++)
2828
1822
  {
2829
1823
    if (!getopt_compare_strings(opt->name, name, length) &&
2840
1834
}
2841
1835
 
2842
1836
 
2843
 
/**
2844
 
  Return variable name and length for hashing of variables.
2845
 
*/
2846
 
 
2847
 
static uchar *get_sys_var_length(const sys_var *var, size_t *length,
2848
 
                                 bool first __attribute__((unused)))
2849
 
{
2850
 
  *length= var->name_length;
2851
 
  return (uchar*) var->name;
2852
 
}
2853
 
 
2854
 
 
2855
1837
/*
2856
1838
  Add variables to the dynamic hash of system variables
2857
 
  
 
1839
 
2858
1840
  SYNOPSIS
2859
1841
    mysql_add_sys_var_chain()
2860
1842
    first       Pointer to first system variable to add
2861
1843
    long_opt    (optional)command line arguments may be tied for limit checks.
2862
 
  
 
1844
 
2863
1845
  RETURN VALUES
2864
1846
    0           SUCCESS
2865
1847
    otherwise   FAILURE
2869
1851
int mysql_add_sys_var_chain(sys_var *first, struct my_option *long_options)
2870
1852
{
2871
1853
  sys_var *var;
2872
 
  
2873
1854
  /* A write lock should be held on LOCK_system_variables_hash */
2874
 
  
2875
 
  for (var= first; var; var= var->next)
 
1855
 
 
1856
  for (var= first; var; var= var->getNext())
2876
1857
  {
2877
 
    var->name_length= strlen(var->name);
2878
 
    /* this fails if there is a conflicting variable name. see HASH_UNIQUE */
2879
 
    if (my_hash_insert(&system_variable_hash, (uchar*) var))
2880
 
      goto error;
 
1858
 
 
1859
    /* this fails if there is a conflicting variable name. */
 
1860
    if (system_variable_hash.add(var))
 
1861
    {
 
1862
      return 1;
 
1863
    } 
2881
1864
    if (long_options)
2882
 
      var->option_limits= find_option(long_options, var->name);
 
1865
      var->setOptionLimits(find_option(long_options, var->getName().c_str()));
2883
1866
  }
2884
1867
  return 0;
2885
1868
 
2886
 
error:
2887
 
  for (; first != var; first= first->next)
2888
 
    hash_delete(&system_variable_hash, (uchar*) first);
2889
 
  return 1;
2890
1869
}
2891
 
 
2892
 
 
 
1870
 
 
1871
 
2893
1872
/*
2894
1873
  Remove variables to the dynamic hash of system variables
2895
 
   
 
1874
 
2896
1875
  SYNOPSIS
2897
1876
    mysql_del_sys_var_chain()
2898
1877
    first       Pointer to first system variable to remove
2899
 
   
 
1878
 
2900
1879
  RETURN VALUES
2901
1880
    0           SUCCESS
2902
1881
    otherwise   FAILURE
2903
1882
*/
2904
 
 
 
1883
 
2905
1884
int mysql_del_sys_var_chain(sys_var *first)
2906
1885
{
2907
1886
  int result= 0;
2908
 
 
 
1887
 
2909
1888
  /* A write lock should be held on LOCK_system_variables_hash */
2910
 
   
2911
 
  for (sys_var *var= first; var; var= var->next)
2912
 
    result|= hash_delete(&system_variable_hash, (uchar*) var);
 
1889
  for (sys_var *var= first; var; var= var->getNext())
 
1890
  {
 
1891
    system_variable_hash.remove(var);
 
1892
  }
2913
1893
 
2914
1894
  return result;
2915
1895
}
2916
 
 
2917
 
 
2918
 
static int show_cmp(SHOW_VAR *a, SHOW_VAR *b)
2919
 
{
2920
 
  return strcmp(a->name, b->name);
2921
 
}
2922
 
 
2923
 
 
 
1896
 
 
1897
 
 
1898
 
2924
1899
/*
2925
1900
  Constructs an array of system variables for display to the user.
2926
 
  
 
1901
 
2927
1902
  SYNOPSIS
2928
1903
    enumerate_sys_vars()
2929
 
    thd         current thread
 
1904
    session         current thread
2930
1905
    sorted      If TRUE, the system variables should be sorted
2931
 
  
 
1906
 
2932
1907
  RETURN VALUES
2933
1908
    pointer     Array of SHOW_VAR elements for display
2934
1909
    NULL        FAILURE
2935
1910
*/
2936
1911
 
2937
 
SHOW_VAR* enumerate_sys_vars(THD *thd, bool sorted)
 
1912
SHOW_VAR* enumerate_sys_vars(Session *session, bool)
2938
1913
{
2939
 
  int count= system_variable_hash.records, i;
2940
1914
  int fixed_count= fixed_show_vars.elements;
2941
 
  int size= sizeof(SHOW_VAR) * (count + fixed_count + 1);
2942
 
  SHOW_VAR *result= (SHOW_VAR*) thd->alloc(size);
 
1915
  int size= sizeof(SHOW_VAR) * (system_variable_hash.size() + fixed_count + 1);
 
1916
  SHOW_VAR *result= (SHOW_VAR*) session->alloc(size);
2943
1917
 
2944
1918
  if (result)
2945
1919
  {
2946
1920
    SHOW_VAR *show= result + fixed_count;
2947
1921
    memcpy(result, fixed_show_vars.buffer, fixed_count * sizeof(SHOW_VAR));
2948
1922
 
2949
 
    for (i= 0; i < count; i++)
 
1923
    drizzled::Registry<sys_var *>::const_iterator iter;
 
1924
    for(iter= system_variable_hash.begin();
 
1925
        iter != system_variable_hash.end();
 
1926
        iter++)
2950
1927
    {
2951
 
      sys_var *var= (sys_var*) hash_element(&system_variable_hash, i);
2952
 
      show->name= var->name;
 
1928
      sys_var *var= *iter;
 
1929
      show->name= var->getName().c_str();
2953
1930
      show->value= (char*) var;
2954
1931
      show->type= SHOW_SYS;
2955
1932
      show++;
2956
1933
    }
2957
1934
 
2958
 
    /* sort into order */
2959
 
    if (sorted)
2960
 
      my_qsort(result, count + fixed_count, sizeof(SHOW_VAR),
2961
 
               (qsort_cmp) show_cmp);
2962
 
    
2963
1935
    /* make last element empty */
2964
1936
    memset(show, 0, sizeof(SHOW_VAR));
2965
1937
  }
2967
1939
}
2968
1940
 
2969
1941
 
 
1942
NAMED_LIST::NAMED_LIST(I_List<NAMED_LIST> *links, const char *name_arg,
 
1943
                       uint32_t name_length_arg, unsigned char* data_arg)
 
1944
    :data(data_arg)
 
1945
{
 
1946
  name.assign(name_arg, name_length_arg);
 
1947
  links->push_back(this);
 
1948
}
 
1949
 
 
1950
 
 
1951
bool NAMED_LIST::cmp(const char *name_cmp, uint32_t length)
 
1952
{
 
1953
  return length == name.length() && !name.compare(name_cmp);
 
1954
}
 
1955
 
 
1956
 
2970
1957
/*
2971
1958
  Initialize the system variables
2972
 
  
 
1959
 
2973
1960
  SYNOPSIS
2974
1961
    set_var_init()
2975
 
  
 
1962
 
2976
1963
  RETURN VALUES
2977
1964
    0           SUCCESS
2978
1965
    otherwise   FAILURE
2980
1967
 
2981
1968
int set_var_init()
2982
1969
{
2983
 
  uint count= 0;
2984
 
  
2985
 
  for (sys_var *var=vars.first; var; var= var->next, count++) {};
 
1970
  uint32_t count= 0;
 
1971
 
 
1972
  for (sys_var *var= vars.first; var; var= var->getNext(), count++) {};
2986
1973
 
2987
1974
  if (my_init_dynamic_array(&fixed_show_vars, sizeof(SHOW_VAR),
2988
1975
                            FIXED_VARS_SIZE + 64, 64))
2991
1978
  fixed_show_vars.elements= FIXED_VARS_SIZE;
2992
1979
  memcpy(fixed_show_vars.buffer, fixed_vars, sizeof(fixed_vars));
2993
1980
 
2994
 
  if (hash_init(&system_variable_hash, system_charset_info, count, 0,
2995
 
                0, (hash_get_key) get_sys_var_length, 0, HASH_UNIQUE))
2996
 
    goto error;
2997
 
 
2998
 
  vars.last->next= NULL;
 
1981
  vars.last->setNext(NULL);
2999
1982
  if (mysql_add_sys_var_chain(vars.first, my_long_options))
3000
1983
    goto error;
3001
1984
 
3009
1992
 
3010
1993
void set_var_free()
3011
1994
{
3012
 
  hash_free(&system_variable_hash);
3013
1995
  delete_dynamic(&fixed_show_vars);
3014
1996
}
3015
1997
 
3016
1998
 
3017
1999
/*
3018
2000
  Add elements to the dynamic list of read-only system variables.
3019
 
  
 
2001
 
3020
2002
  SYNOPSIS
3021
2003
    mysql_append_static_vars()
3022
2004
    show_vars   Pointer to start of array
3023
2005
    count       Number of elements
3024
 
  
 
2006
 
3025
2007
  RETURN VALUES
3026
2008
    0           SUCCESS
3027
2009
    otherwise   FAILURE
3028
2010
*/
3029
 
int mysql_append_static_vars(const SHOW_VAR *show_vars, uint count)
 
2011
int mysql_append_static_vars(const SHOW_VAR *show_vars, uint32_t count)
3030
2012
{
3031
2013
  for (; count > 0; count--, show_vars++)
3032
 
    if (insert_dynamic(&fixed_show_vars, (uchar*) show_vars))
 
2014
    if (insert_dynamic(&fixed_show_vars, (unsigned char*) show_vars))
3033
2015
      return 1;
3034
2016
  return 0;
3035
2017
}
3049
2031
    0           Unknown variable (error message is given)
3050
2032
*/
3051
2033
 
3052
 
sys_var *intern_find_sys_var(const char *str, uint length, bool no_error)
 
2034
sys_var *intern_find_sys_var(const char *str, uint32_t, bool no_error)
3053
2035
{
3054
 
  sys_var *var;
3055
 
 
3056
2036
  /*
3057
2037
    This function is only called from the sql_plugin.cc.
3058
2038
    A lock on LOCK_system_variable_hash should be held
3059
2039
  */
3060
 
  var= (sys_var*) hash_search(&system_variable_hash,
3061
 
                              (uchar*) str, length ? length : strlen(str));
3062
 
  if (!(var || no_error))
3063
 
    my_error(ER_UNKNOWN_SYSTEM_VARIABLE, MYF(0), (char*) str);
 
2040
  sys_var *result= system_variable_hash.find(str);
 
2041
  if (result == NULL)
 
2042
  {
 
2043
    if (no_error)
 
2044
    {
 
2045
      return NULL;
 
2046
    }
 
2047
    else
 
2048
    {
 
2049
      my_error(ER_UNKNOWN_SYSTEM_VARIABLE, MYF(0), (char*) str);
 
2050
      return NULL;
 
2051
    }
 
2052
  }
3064
2053
 
3065
 
  return var;
 
2054
  return result;
3066
2055
}
3067
2056
 
3068
2057
 
3075
2064
  This should ensure that in all normal cases none all or variables are
3076
2065
  updated.
3077
2066
 
3078
 
  @param THD            Thread id
 
2067
  @param Session                Thread id
3079
2068
  @param var_list       List of variables to update
3080
2069
 
3081
2070
  @retval
3086
2075
    -1  ERROR, message not sent
3087
2076
*/
3088
2077
 
3089
 
int sql_set_variables(THD *thd, List<set_var_base> *var_list)
 
2078
int sql_set_variables(Session *session, List<set_var_base> *var_list)
3090
2079
{
3091
2080
  int error;
3092
2081
  List_iterator_fast<set_var_base> it(*var_list);
3094
2083
  set_var_base *var;
3095
2084
  while ((var=it++))
3096
2085
  {
3097
 
    if ((error= var->check(thd)))
 
2086
    if ((error= var->check(session)))
3098
2087
      goto err;
3099
2088
  }
3100
 
  if (!(error= test(thd->is_error())))
 
2089
  if (!(error= test(session->is_error())))
3101
2090
  {
3102
2091
    it.rewind();
3103
2092
    while ((var= it++))
3104
 
      error|= var->update(thd);         // Returns 0, -1 or 1
 
2093
      error|= var->update(session);         // Returns 0, -1 or 1
3105
2094
  }
3106
2095
 
3107
2096
err:
3108
 
  free_underlaid_joins(thd, &thd->lex->select_lex);
 
2097
  free_underlaid_joins(session, &session->lex->select_lex);
3109
2098
  return(error);
3110
2099
}
3111
2100
 
3112
2101
 
3113
 
/**
3114
 
  Say if all variables set by a SET support the ONE_SHOT keyword
3115
 
  (currently, only character set and collation do; later timezones
3116
 
  will).
3117
 
 
3118
 
  @param var_list       List of variables to update
3119
 
 
3120
 
  @note
3121
 
    It has a "not_" because it makes faster tests (no need to "!")
3122
 
 
3123
 
  @retval
3124
 
    0   all variables of the list support ONE_SHOT
3125
 
  @retval
3126
 
    1   at least one does not support ONE_SHOT
3127
 
*/
3128
 
 
3129
 
bool not_all_support_one_shot(List<set_var_base> *var_list)
3130
 
{
3131
 
  List_iterator_fast<set_var_base> it(*var_list);
3132
 
  set_var_base *var;
3133
 
  while ((var= it++))
3134
 
  {
3135
 
    if (var->no_support_one_shot())
3136
 
      return 1;
3137
 
  }
3138
 
  return 0;
3139
 
}
3140
 
 
3141
 
 
3142
2102
/*****************************************************************************
3143
2103
  Functions to handle SET mysql_internal_variable=const_expr
3144
2104
*****************************************************************************/
3145
2105
 
3146
 
int set_var::check(THD *thd)
 
2106
int set_var::check(Session *session)
3147
2107
{
3148
2108
  if (var->is_readonly())
3149
2109
  {
3150
 
    my_error(ER_INCORRECT_GLOBAL_LOCAL_VAR, MYF(0), var->name, "read only");
 
2110
    my_error(ER_INCORRECT_GLOBAL_LOCAL_VAR, MYF(0), var->getName().c_str(), "read only");
3151
2111
    return -1;
3152
2112
  }
3153
2113
  if (var->check_type(type))
3154
2114
  {
3155
2115
    int err= type == OPT_GLOBAL ? ER_LOCAL_VARIABLE : ER_GLOBAL_VARIABLE;
3156
 
    my_error(err, MYF(0), var->name);
 
2116
    my_error(err, MYF(0), var->getName().c_str());
3157
2117
    return -1;
3158
2118
  }
3159
2119
  /* value is a NULL pointer if we are using SET ... = DEFAULT */
3161
2121
  {
3162
2122
    if (var->check_default(type))
3163
2123
    {
3164
 
      my_error(ER_NO_DEFAULT, MYF(0), var->name);
 
2124
      my_error(ER_NO_DEFAULT, MYF(0), var->getName().c_str());
3165
2125
      return -1;
3166
2126
    }
3167
2127
    return 0;
3168
2128
  }
3169
2129
 
3170
2130
  if ((!value->fixed &&
3171
 
       value->fix_fields(thd, &value)) || value->check_cols(1))
 
2131
       value->fix_fields(session, &value)) || value->check_cols(1))
3172
2132
    return -1;
3173
2133
  if (var->check_update_type(value->result_type()))
3174
2134
  {
3175
 
    my_error(ER_WRONG_TYPE_FOR_VAR, MYF(0), var->name);
 
2135
    my_error(ER_WRONG_TYPE_FOR_VAR, MYF(0), var->getName().c_str());
3176
2136
    return -1;
3177
2137
  }
3178
 
  return var->check(thd, this) ? -1 : 0;
 
2138
  return var->check(session, this) ? -1 : 0;
3179
2139
}
3180
2140
 
3181
2141
/**
3182
2142
  Update variable
3183
2143
 
3184
 
  @param   thd    thread handler
 
2144
  @param   session    thread handler
3185
2145
  @returns 0|1    ok or ERROR
3186
2146
 
3187
2147
  @note ERROR can be only due to abnormal operations involving
3190
2150
  Consider set_var::check() method if there is a need to return
3191
2151
  an error due to logics.
3192
2152
*/
3193
 
int set_var::update(THD *thd)
 
2153
int set_var::update(Session *session)
3194
2154
{
3195
 
  if (!value)
3196
 
    var->set_default(thd, type);
3197
 
  else if (var->update(thd, this))
 
2155
  if (! value)
 
2156
    var->set_default(session, type);
 
2157
  else if (var->update(session, this))
3198
2158
    return -1;                          // should never happen
3199
 
  if (var->after_update)
3200
 
    (*var->after_update)(thd, type);
 
2159
  if (var->getAfterUpdateTrigger())
 
2160
    (*var->getAfterUpdateTrigger())(session, type);
3201
2161
  return 0;
3202
2162
}
3203
2163
 
3204
 
 
3205
2164
/*****************************************************************************
3206
2165
  Functions to handle SET @user_variable=const_expr
3207
2166
*****************************************************************************/
3208
2167
 
3209
 
int set_var_user::check(THD *thd)
 
2168
int set_var_user::check(Session *session)
3210
2169
{
3211
2170
  /*
3212
2171
    Item_func_set_user_var can't substitute something else on its place =>
3213
2172
    0 can be passed as last argument (reference on item)
3214
2173
  */
3215
 
  return (user_var_item->fix_fields(thd, (Item**) 0) ||
 
2174
  return (user_var_item->fix_fields(session, (Item**) 0) ||
3216
2175
          user_var_item->check(0)) ? -1 : 0;
3217
2176
}
3218
2177
 
3219
2178
 
3220
 
int set_var_user::update(THD *thd __attribute__((unused)))
 
2179
int set_var_user::update(Session *)
3221
2180
{
3222
2181
  if (user_var_item->update())
3223
2182
  {
3234
2193
 
3235
2194
/* Based upon sys_var::check_enum() */
3236
2195
 
3237
 
bool sys_var_thd_storage_engine::check(THD *thd, set_var *var)
 
2196
bool sys_var_session_storage_engine::check(Session *session, set_var *var)
3238
2197
{
3239
2198
  char buff[STRING_BUFFER_USUAL_SIZE];
3240
2199
  const char *value;
3241
 
  String str(buff, sizeof(buff), &my_charset_latin1), *res;
 
2200
  String str(buff, sizeof(buff), &my_charset_utf8_general_ci), *res;
3242
2201
 
3243
 
  var->save_result.plugin= NULL;
 
2202
  var->save_result.storage_engine= NULL;
3244
2203
  if (var->value->result_type() == STRING_RESULT)
3245
2204
  {
3246
2205
    LEX_STRING engine_name;
3247
 
    handlerton *hton;
 
2206
    StorageEngine *engine;
3248
2207
    if (!(res=var->value->val_str(&str)) ||
3249
2208
        !(engine_name.str= (char *)res->ptr()) ||
3250
2209
        !(engine_name.length= res->length()) ||
3251
 
        !(var->save_result.plugin= ha_resolve_by_name(thd, &engine_name)) ||
3252
 
        !(hton= plugin_data(var->save_result.plugin, handlerton *)) ||
3253
 
        ha_checktype(thd, ha_legacy_type(hton), 1, 0) != hton)
 
2210
              !(var->save_result.storage_engine=
 
2211
            ha_resolve_by_name(session, &engine_name)) ||
 
2212
        !(engine= var->save_result.storage_engine))
3254
2213
    {
3255
2214
      value= res ? res->c_ptr() : "NULL";
3256
2215
      goto err;
3265
2224
}
3266
2225
 
3267
2226
 
3268
 
uchar *sys_var_thd_storage_engine::value_ptr(THD *thd, enum_var_type type,
3269
 
                                             LEX_STRING *base __attribute__((unused)))
 
2227
unsigned char *sys_var_session_storage_engine::value_ptr(Session *session,
 
2228
                                                         enum_var_type type,
 
2229
                                                         const LEX_STRING *)
3270
2230
{
3271
 
  uchar* result;
3272
 
  handlerton *hton;
3273
 
  LEX_STRING *engine_name;
3274
 
  plugin_ref plugin= thd->variables.*offset;
3275
 
  if (type == OPT_GLOBAL)
3276
 
    plugin= my_plugin_lock(thd, &(global_system_variables.*offset));
3277
 
  hton= plugin_data(plugin, handlerton*);
3278
 
  engine_name= &hton2plugin[hton->slot]->name;
3279
 
  result= (uchar *) thd->strmake(engine_name->str, engine_name->length);
3280
 
  if (type == OPT_GLOBAL)
3281
 
    plugin_unlock(thd, plugin);
 
2231
  unsigned char* result;
 
2232
  string engine_name;
 
2233
  StorageEngine *engine= session->variables.*offset;
 
2234
  if (type == OPT_GLOBAL)
 
2235
    engine= global_system_variables.*offset;
 
2236
  engine_name= engine->getName();
 
2237
  result= (unsigned char *) session->strmake(engine_name.c_str(),
 
2238
                                             engine_name.size());
3282
2239
  return result;
3283
2240
}
3284
2241
 
3285
2242
 
3286
 
void sys_var_thd_storage_engine::set_default(THD *thd, enum_var_type type)
 
2243
void sys_var_session_storage_engine::set_default(Session *session, enum_var_type type)
3287
2244
{
3288
 
  plugin_ref old_value, new_value, *value;
 
2245
  StorageEngine *old_value, *new_value, **value;
3289
2246
  if (type == OPT_GLOBAL)
3290
2247
  {
3291
2248
    value= &(global_system_variables.*offset);
3292
 
    new_value= ha_lock_engine(NULL, myisam_hton);
 
2249
    new_value= myisam_engine;
3293
2250
  }
3294
2251
  else
3295
2252
  {
3296
 
    value= &(thd->variables.*offset);
3297
 
    new_value= my_plugin_lock(NULL, &(global_system_variables.*offset));
 
2253
    value= &(session->variables.*offset);
 
2254
    new_value= global_system_variables.*offset;
3298
2255
  }
3299
2256
  assert(new_value);
3300
2257
  old_value= *value;
3301
2258
  *value= new_value;
3302
 
  plugin_unlock(NULL, old_value);
3303
2259
}
3304
2260
 
3305
2261
 
3306
 
bool sys_var_thd_storage_engine::update(THD *thd, set_var *var)
 
2262
bool sys_var_session_storage_engine::update(Session *session, set_var *var)
3307
2263
{
3308
 
  plugin_ref *value= &(global_system_variables.*offset), old_value;
 
2264
  StorageEngine **value= &(global_system_variables.*offset), *old_value;
3309
2265
   if (var->type != OPT_GLOBAL)
3310
 
     value= &(thd->variables.*offset);
 
2266
     value= &(session->variables.*offset);
3311
2267
  old_value= *value;
3312
 
  if (old_value != var->save_result.plugin)
 
2268
  if (old_value != var->save_result.storage_engine)
3313
2269
  {
3314
 
    *value= my_plugin_lock(NULL, &var->save_result.plugin);
3315
 
    plugin_unlock(NULL, old_value);
 
2270
    *value= var->save_result.storage_engine;
3316
2271
  }
3317
2272
  return 0;
3318
2273
}
3319
2274
 
3320
2275
bool
3321
 
sys_var_thd_optimizer_switch::
3322
 
symbolic_mode_representation(THD *thd, uint64_t val, LEX_STRING *rep)
 
2276
sys_var_session_optimizer_switch::
 
2277
symbolic_mode_representation(Session *session, uint32_t val, LEX_STRING *rep)
3323
2278
{
3324
2279
  char buff[STRING_BUFFER_USUAL_SIZE*8];
3325
 
  String tmp(buff, sizeof(buff), &my_charset_latin1);
 
2280
  String tmp(buff, sizeof(buff), &my_charset_utf8_general_ci);
3326
2281
 
3327
2282
  tmp.length(0);
3328
2283
 
3329
 
  for (uint i= 0; val; val>>= 1, i++)
 
2284
  for (uint32_t i= 0; val; val>>= 1, i++)
3330
2285
  {
3331
2286
    if (val & 1)
3332
2287
    {
3339
2294
  if (tmp.length())
3340
2295
    tmp.length(tmp.length() - 1); /* trim the trailing comma */
3341
2296
 
3342
 
  rep->str= thd->strmake(tmp.ptr(), tmp.length());
 
2297
  rep->str= session->strmake(tmp.ptr(), tmp.length());
3343
2298
 
3344
2299
  rep->length= rep->str ? tmp.length() : 0;
3345
2300
 
3347
2302
}
3348
2303
 
3349
2304
 
3350
 
uchar *sys_var_thd_optimizer_switch::value_ptr(THD *thd, enum_var_type type,
3351
 
                                               LEX_STRING *base __attribute__((unused)))
 
2305
unsigned char *sys_var_session_optimizer_switch::value_ptr(Session *session,
 
2306
                                                           enum_var_type type,
 
2307
                                                           const LEX_STRING *)
3352
2308
{
3353
2309
  LEX_STRING opts;
3354
 
  uint64_t val= ((type == OPT_GLOBAL) ? global_system_variables.*offset :
3355
 
                  thd->variables.*offset);
3356
 
  (void) symbolic_mode_representation(thd, val, &opts);
3357
 
  return (uchar *) opts.str;
 
2310
  uint32_t val= ((type == OPT_GLOBAL) ? global_system_variables.*offset :
 
2311
                  session->variables.*offset);
 
2312
  (void) symbolic_mode_representation(session, val, &opts);
 
2313
  return (unsigned char *) opts.str;
3358
2314
}
3359
2315
 
3360
2316
 
3361
 
void sys_var_thd_optimizer_switch::set_default(THD *thd, enum_var_type type)
 
2317
void sys_var_session_optimizer_switch::set_default(Session *session, enum_var_type type)
3362
2318
{
3363
2319
  if (type == OPT_GLOBAL)
3364
2320
    global_system_variables.*offset= 0;
3365
2321
  else
3366
 
    thd->variables.*offset= global_system_variables.*offset;
 
2322
    session->variables.*offset= global_system_variables.*offset;
3367
2323
}
3368
2324
 
3369
2325
 
3371
2327
  Named list handling
3372
2328
****************************************************************************/
3373
2329
 
3374
 
uchar* find_named(I_List<NAMED_LIST> *list, const char *name, uint length,
 
2330
unsigned char* find_named(I_List<NAMED_LIST> *list, const char *name, uint32_t length,
3375
2331
                NAMED_LIST **found)
3376
2332
{
3377
2333
  I_List_iterator<NAMED_LIST> it(*list);
3390
2346
 
3391
2347
 
3392
2348
void delete_elements(I_List<NAMED_LIST> *list,
3393
 
                     void (*free_element)(const char *name, uchar*))
 
2349
                     void (*free_element)(const char *name, unsigned char*))
3394
2350
{
3395
2351
  NAMED_LIST *element;
3396
2352
  while ((element= list->get()))
3397
2353
  {
3398
 
    (*free_element)(element->name, element->data);
 
2354
    (*free_element)(element->name.c_str(), element->data);
3399
2355
    delete element;
3400
2356
  }
3401
2357
  return;
3404
2360
 
3405
2361
/* Key cache functions */
3406
2362
 
3407
 
static KEY_CACHE *create_key_cache(const char *name, uint length)
 
2363
static KEY_CACHE *create_key_cache(const char *name, uint32_t length)
3408
2364
{
3409
2365
  KEY_CACHE *key_cache;
3410
 
  
3411
 
  if ((key_cache= (KEY_CACHE*) my_malloc(sizeof(KEY_CACHE),
3412
 
                                             MYF(MY_ZEROFILL | MY_WME))))
 
2366
 
 
2367
  if ((key_cache= (KEY_CACHE*) malloc(sizeof(KEY_CACHE))))
3413
2368
  {
3414
 
    if (!new NAMED_LIST(&key_caches, name, length, (uchar*) key_cache))
 
2369
    memset(key_cache, 0, sizeof(KEY_CACHE));
 
2370
    if (!new NAMED_LIST(&key_caches, name, length, (unsigned char*) key_cache))
3415
2371
    {
3416
 
      my_free((char*) key_cache, MYF(0));
 
2372
      free((char*) key_cache);
3417
2373
      key_cache= 0;
3418
2374
    }
3419
2375
    else
3433
2389
}
3434
2390
 
3435
2391
 
3436
 
KEY_CACHE *get_or_create_key_cache(const char *name, uint length)
 
2392
KEY_CACHE *get_or_create_key_cache(const char *name, uint32_t length)
3437
2393
{
3438
2394
  LEX_STRING key_cache_name;
3439
2395
  KEY_CACHE *key_cache;
3448
2404
}
3449
2405
 
3450
2406
 
3451
 
void free_key_cache(const char *name __attribute__((unused)),
3452
 
                    KEY_CACHE *key_cache)
 
2407
void free_key_cache(const char *, KEY_CACHE *key_cache)
3453
2408
{
3454
2409
  ha_end_key_cache(key_cache);
3455
 
  my_free((char*) key_cache, MYF(0));
 
2410
  free((char*) key_cache);
3456
2411
}
3457
2412
 
3458
2413
 
3464
2419
  while ((element= it++))
3465
2420
  {
3466
2421
    KEY_CACHE *key_cache= (KEY_CACHE *) element->data;
3467
 
    func(element->name, key_cache);
 
2422
    func(element->name.c_str(), key_cache);
3468
2423
  }
3469
2424
  return 0;
3470
2425
}
3471
2426
 
3472
 
 
3473
 
bool sys_var_opt_readonly::update(THD *thd, set_var *var)
3474
 
{
3475
 
  bool result;
3476
 
 
3477
 
  /* Prevent self dead-lock */
3478
 
  if (thd->locked_tables || thd->active_transaction())
3479
 
  {
3480
 
    my_error(ER_LOCK_OR_ACTIVE_TRANSACTION, MYF(0));
3481
 
    return(true);
3482
 
  }
3483
 
 
3484
 
  if (thd->global_read_lock)
3485
 
  {
3486
 
    /*
3487
 
      This connection already holds the global read lock.
3488
 
      This can be the case with:
3489
 
      - FLUSH TABLES WITH READ LOCK
3490
 
      - SET GLOBAL READ_ONLY = 1
3491
 
    */
3492
 
    result= sys_var_bool_ptr::update(thd, var);
3493
 
    return(result);
3494
 
  }
3495
 
 
3496
 
  /*
3497
 
    Perform a 'FLUSH TABLES WITH READ LOCK'.
3498
 
    This is a 3 step process:
3499
 
    - [1] lock_global_read_lock()
3500
 
    - [2] close_cached_tables()
3501
 
    - [3] make_global_read_lock_block_commit()
3502
 
    [1] prevents new connections from obtaining tables locked for write.
3503
 
    [2] waits until all existing connections close their tables.
3504
 
    [3] prevents transactions from being committed.
3505
 
  */
3506
 
 
3507
 
  if (lock_global_read_lock(thd))
3508
 
    return(true);
3509
 
 
3510
 
  /*
3511
 
    This call will be blocked by any connection holding a READ or WRITE lock.
3512
 
    Ideally, we want to wait only for pending WRITE locks, but since:
3513
 
    con 1> LOCK TABLE T FOR READ;
3514
 
    con 2> LOCK TABLE T FOR WRITE; (blocked by con 1)
3515
 
    con 3> SET GLOBAL READ ONLY=1; (blocked by con 2)
3516
 
    can cause to wait on a read lock, it's required for the client application
3517
 
    to unlock everything, and acceptable for the server to wait on all locks.
3518
 
  */
3519
 
  if ((result= close_cached_tables(thd, NULL, false, true, true)) == true)
3520
 
    goto end_with_read_lock;
3521
 
 
3522
 
  if ((result= make_global_read_lock_block_commit(thd)) == true)
3523
 
    goto end_with_read_lock;
3524
 
 
3525
 
  /* Change the opt_readonly system variable, safe because the lock is held */
3526
 
  result= sys_var_bool_ptr::update(thd, var);
3527
 
 
3528
 
end_with_read_lock:
3529
 
  /* Release the lock */
3530
 
  unlock_global_read_lock(thd);
3531
 
  return(result);
3532
 
}
3533
 
 
3534
2427
/****************************************************************************
3535
2428
  Used templates
3536
2429
****************************************************************************/