~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/sys_var.cc

  • Committer: Brian Aker
  • Date: 2011-11-04 21:06:16 UTC
  • mto: This revision was merged to the branch mainline in revision 2450.
  • Revision ID: brian@tangent.org-20111104210616-2at42agch94dkwb0
Additional fixes for libdrizzle.

Show diffs side-by-side

added added

removed removed

Lines of Context:
94
94
 
95
95
namespace
96
96
{
97
 
  static size_t revno= DRIZZLE7_VC_REVNO;
98
 
  static size_t release_id= DRIZZLE7_RELEASE_ID;
 
97
static size_t revno= DRIZZLE7_VC_REVNO;
 
98
static size_t release_id= DRIZZLE7_RELEASE_ID;
99
99
}
100
100
 
101
101
const char *bool_type_names[]= { "OFF", "ON", NULL };
104
104
  array_elements(bool_type_names)-1, "", bool_type_names, NULL
105
105
};
106
106
 
107
 
static bool set_option_bit(Session*, set_var*);
108
 
static bool set_option_autocommit(Session*, set_var*);
109
 
static int  check_pseudo_thread_id(Session*, set_var*);
110
 
static int check_tx_isolation(Session*, set_var*);
111
 
static void fix_tx_isolation(Session*, sql_var_t);
112
 
static int check_completion_type(Session*, set_var*);
113
 
static void fix_max_join_size(Session*, sql_var_t);
114
 
static void fix_session_mem_root(Session*, sql_var_t);
115
 
void throw_bounds_warning(Session*, bool fixed, bool unsignd, const std::string &name, int64_t);
116
 
static unsigned char *get_error_count(Session*);
117
 
static unsigned char *get_warning_count(Session*);
118
 
static unsigned char *get_tmpdir(Session*);
 
107
static bool set_option_bit(Session *session, set_var *var);
 
108
static bool set_option_autocommit(Session *session, set_var *var);
 
109
static int  check_pseudo_thread_id(Session *session, set_var *var);
 
110
static int check_tx_isolation(Session *session, set_var *var);
 
111
static void fix_tx_isolation(Session *session, sql_var_t type);
 
112
static int check_completion_type(Session *session, set_var *var);
 
113
static void fix_completion_type(Session *session, sql_var_t type);
 
114
static void fix_max_join_size(Session *session, sql_var_t type);
 
115
static void fix_session_mem_root(Session *session, sql_var_t type);
 
116
static void fix_server_id(Session *session, sql_var_t type);
 
117
void throw_bounds_warning(Session *session, bool fixed, bool unsignd, const std::string &name, int64_t val);
 
118
static unsigned char *get_error_count(Session *session);
 
119
static unsigned char *get_warning_count(Session *session);
 
120
static unsigned char *get_tmpdir(Session *session);
119
121
 
120
122
/*
121
123
  Variable definition list
127
129
  it in the constructor (see sys_var class for details).
128
130
*/
129
131
static sys_var_session_uint64_t
130
 
sys_auto_increment_increment("auto_increment_increment", &drizzle_system_variables::auto_increment_increment);
 
132
sys_auto_increment_increment("auto_increment_increment",
 
133
                             &drizzle_system_variables::auto_increment_increment);
131
134
static sys_var_session_uint64_t
132
 
sys_auto_increment_offset("auto_increment_offset", &drizzle_system_variables::auto_increment_offset);
 
135
sys_auto_increment_offset("auto_increment_offset",
 
136
                          &drizzle_system_variables::auto_increment_offset);
133
137
 
134
138
static sys_var_fs_path sys_basedir("basedir", basedir);
135
139
static sys_var_fs_path sys_pid_file("pid_file", pid_file);
136
140
static sys_var_fs_path sys_plugin_dir("plugin_dir", plugin_dir);
137
141
 
138
 
static sys_var_size_t_ptr sys_thread_stack_size("thread_stack", &my_thread_stack_size);
 
142
static sys_var_size_t_ptr sys_thread_stack_size("thread_stack",
 
143
                                                      &my_thread_stack_size);
139
144
static sys_var_constrained_value_readonly<uint32_t> sys_back_log("back_log", back_log);
140
145
 
141
 
static sys_var_session_uint64_t sys_bulk_insert_buff_size("bulk_insert_buffer_size", &drizzle_system_variables::bulk_insert_buff_size);
142
 
static sys_var_session_uint32_t sys_completion_type("completion_type", &drizzle_system_variables::completion_type, check_completion_type);
 
146
static sys_var_session_uint64_t sys_bulk_insert_buff_size("bulk_insert_buffer_size",
 
147
                                                          &drizzle_system_variables::bulk_insert_buff_size);
 
148
static sys_var_session_uint32_t sys_completion_type("completion_type",
 
149
                                                    &drizzle_system_variables::completion_type,
 
150
                                                    check_completion_type,
 
151
                                                    fix_completion_type);
143
152
static sys_var_collation_sv
144
153
sys_collation_server("collation_server", &drizzle_system_variables::collation_server, &default_charset_info);
145
 
static sys_var_fs_path sys_datadir("datadir", getDataHome());
146
 
 
147
 
static sys_var_session_uint64_t sys_join_buffer_size("join_buffer_size", &drizzle_system_variables::join_buff_size);
148
 
static sys_var_session_uint32_t sys_max_allowed_packet("max_allowed_packet", &drizzle_system_variables::max_allowed_packet);
149
 
static sys_var_session_uint64_t sys_max_error_count("max_error_count", &drizzle_system_variables::max_error_count);
150
 
static sys_var_session_uint64_t sys_max_heap_table_size("max_heap_table_size", &drizzle_system_variables::max_heap_table_size);
151
 
static sys_var_session_uint64_t sys_pseudo_thread_id("pseudo_thread_id", &drizzle_system_variables::pseudo_thread_id, 0, check_pseudo_thread_id);
152
 
static sys_var_session_ha_rows  sys_max_join_size("max_join_size", &drizzle_system_variables::max_join_size, fix_max_join_size);
153
 
static sys_var_session_uint64_t sys_max_seeks_for_key("max_seeks_for_key", &drizzle_system_variables::max_seeks_for_key);
154
 
static sys_var_session_uint64_t sys_max_length_for_sort_data("max_length_for_sort_data", &drizzle_system_variables::max_length_for_sort_data);
155
 
static sys_var_session_size_t   sys_max_sort_length("max_sort_length", &drizzle_system_variables::max_sort_length);
156
 
static sys_var_uint64_t_ptr     sys_max_write_lock_count("max_write_lock_count", &max_write_lock_count);
157
 
static sys_var_session_uint64_t sys_min_examined_row_limit("min_examined_row_limit", &drizzle_system_variables::min_examined_row_limit);
158
 
 
159
 
static sys_var_session_bool sys_optimizer_prune_level("optimizer_prune_level", &drizzle_system_variables::optimizer_prune_level);
160
 
static sys_var_session_uint32_t sys_optimizer_search_depth("optimizer_search_depth", &drizzle_system_variables::optimizer_search_depth);
161
 
 
162
 
static sys_var_session_uint64_t sys_preload_buff_size("preload_buffer_size", &drizzle_system_variables::preload_buff_size);
163
 
static sys_var_session_uint32_t sys_read_buff_size("read_buffer_size", &drizzle_system_variables::read_buff_size);
164
 
static sys_var_session_uint32_t sys_read_rnd_buff_size("read_rnd_buffer_size", &drizzle_system_variables::read_rnd_buff_size);
165
 
static sys_var_session_uint32_t sys_div_precincrement("div_precision_increment", &drizzle_system_variables::div_precincrement);
166
 
 
167
 
static sys_var_session_size_t   sys_range_alloc_block_size("range_alloc_block_size", &drizzle_system_variables::range_alloc_block_size);
168
 
 
169
 
static sys_var_session_bool sys_replicate_query("replicate_query", &drizzle_system_variables::replicate_query);
170
 
 
171
 
static sys_var_session_uint32_t sys_query_alloc_block_size("query_alloc_block_size", &drizzle_system_variables::query_alloc_block_size, NULL, fix_session_mem_root);
172
 
static sys_var_session_uint32_t sys_query_prealloc_size("query_prealloc_size", &drizzle_system_variables::query_prealloc_size, NULL, fix_session_mem_root);
 
154
static sys_var_fs_path       sys_datadir("datadir", getDataHome());
 
155
 
 
156
static sys_var_session_uint64_t sys_join_buffer_size("join_buffer_size",
 
157
                                                     &drizzle_system_variables::join_buff_size);
 
158
static sys_var_session_uint32_t sys_max_allowed_packet("max_allowed_packet",
 
159
                                                       &drizzle_system_variables::max_allowed_packet);
 
160
static sys_var_session_uint64_t sys_max_error_count("max_error_count",
 
161
                                                  &drizzle_system_variables::max_error_count);
 
162
static sys_var_session_uint64_t sys_max_heap_table_size("max_heap_table_size",
 
163
                                                        &drizzle_system_variables::max_heap_table_size);
 
164
static sys_var_session_uint64_t sys_pseudo_thread_id("pseudo_thread_id",
 
165
                                              &drizzle_system_variables::pseudo_thread_id,
 
166
                                              0, check_pseudo_thread_id);
 
167
static sys_var_session_ha_rows  sys_max_join_size("max_join_size",
 
168
                                                  &drizzle_system_variables::max_join_size,
 
169
                                                  fix_max_join_size);
 
170
static sys_var_session_uint64_t sys_max_seeks_for_key("max_seeks_for_key",
 
171
                                                      &drizzle_system_variables::max_seeks_for_key);
 
172
static sys_var_session_uint64_t   sys_max_length_for_sort_data("max_length_for_sort_data",
 
173
                                                               &drizzle_system_variables::max_length_for_sort_data);
 
174
static sys_var_session_size_t   sys_max_sort_length("max_sort_length",
 
175
                                                    &drizzle_system_variables::max_sort_length);
 
176
static sys_var_uint64_t_ptr     sys_max_write_lock_count("max_write_lock_count",
 
177
                                                 &max_write_lock_count);
 
178
static sys_var_session_uint64_t sys_min_examined_row_limit("min_examined_row_limit",
 
179
                                                           &drizzle_system_variables::min_examined_row_limit);
 
180
 
 
181
/* these two cannot be static */
 
182
static sys_var_session_bool sys_optimizer_prune_level("optimizer_prune_level",
 
183
                                                      &drizzle_system_variables::optimizer_prune_level);
 
184
static sys_var_session_uint32_t sys_optimizer_search_depth("optimizer_search_depth",
 
185
                                                           &drizzle_system_variables::optimizer_search_depth);
 
186
 
 
187
static sys_var_session_uint64_t sys_preload_buff_size("preload_buffer_size",
 
188
                                                      &drizzle_system_variables::preload_buff_size);
 
189
static sys_var_session_uint32_t sys_read_buff_size("read_buffer_size",
 
190
                                                   &drizzle_system_variables::read_buff_size);
 
191
static sys_var_session_uint32_t sys_read_rnd_buff_size("read_rnd_buffer_size",
 
192
                                                       &drizzle_system_variables::read_rnd_buff_size);
 
193
static sys_var_session_uint32_t sys_div_precincrement("div_precision_increment",
 
194
                                                      &drizzle_system_variables::div_precincrement);
 
195
 
 
196
static sys_var_session_size_t   sys_range_alloc_block_size("range_alloc_block_size",
 
197
                                                           &drizzle_system_variables::range_alloc_block_size);
 
198
 
 
199
static sys_var_session_bool sys_replicate_query("replicate_query",
 
200
                                                &drizzle_system_variables::replicate_query);
 
201
 
 
202
static sys_var_session_uint32_t sys_query_alloc_block_size("query_alloc_block_size",
 
203
                                                           &drizzle_system_variables::query_alloc_block_size,
 
204
                                                           NULL, fix_session_mem_root);
 
205
static sys_var_session_uint32_t sys_query_prealloc_size("query_prealloc_size",
 
206
                                                        &drizzle_system_variables::query_prealloc_size,
 
207
                                                        NULL, fix_session_mem_root);
173
208
static sys_var_readonly sys_tmpdir("tmpdir", OPT_GLOBAL, SHOW_CHAR, get_tmpdir);
174
209
 
175
 
static sys_var_fs_path sys_secure_file_priv("secure_file_priv", secure_file_priv);
176
 
static sys_var_const_str_ptr sys_scheduler("scheduler", (char**)&opt_scheduler);
177
 
 
178
 
static sys_var_uint32_t_ptr  sys_server_id("server_id", &server_id);
 
210
static sys_var_fs_path sys_secure_file_priv("secure_file_priv",
 
211
                                            secure_file_priv);
 
212
 
 
213
static sys_var_const_str_ptr sys_scheduler("scheduler",
 
214
                                           (char**)&opt_scheduler);
 
215
 
 
216
static sys_var_uint32_t_ptr  sys_server_id("server_id", &server_id,
 
217
                                           fix_server_id);
179
218
 
180
219
static sys_var_const_string sys_server_uuid("server_uuid", server_uuid);
181
220
 
182
 
static sys_var_session_size_t   sys_sort_buffer("sort_buffer_size", &drizzle_system_variables::sortbuff_size);
183
 
 
184
 
static sys_var_size_t_ptr_readonly sys_transaction_message_threshold("transaction_message_threshold", &transaction_message_threshold);
185
 
 
186
 
static sys_var_session_storage_engine sys_storage_engine("storage_engine", &drizzle_system_variables::storage_engine);
187
 
static sys_var_size_t_ptr       sys_table_def_size("table_definition_cache", &table_def_size);
188
 
static sys_var_uint64_t_ptr     sys_table_cache_size("table_open_cache", &table_cache_size);
189
 
static sys_var_uint64_t_ptr     sys_table_lock_wait_timeout("table_lock_wait_timeout", &table_lock_wait_timeout);
 
221
static sys_var_session_size_t   sys_sort_buffer("sort_buffer_size",
 
222
                                                &drizzle_system_variables::sortbuff_size);
 
223
 
 
224
static sys_var_size_t_ptr_readonly sys_transaction_message_threshold("transaction_message_threshold",
 
225
                                                                &transaction_message_threshold);
 
226
 
 
227
static sys_var_session_storage_engine sys_storage_engine("storage_engine",
 
228
                                       &drizzle_system_variables::storage_engine);
 
229
static sys_var_size_t_ptr       sys_table_def_size("table_definition_cache",
 
230
                                             &table_def_size);
 
231
static sys_var_uint64_t_ptr     sys_table_cache_size("table_open_cache",
 
232
                                             &table_cache_size);
 
233
static sys_var_uint64_t_ptr     sys_table_lock_wait_timeout("table_lock_wait_timeout",
 
234
                                                    &table_lock_wait_timeout);
190
235
static sys_var_session_enum     sys_tx_isolation("tx_isolation",
191
236
                                             &drizzle_system_variables::tx_isolation,
192
237
                                             &tx_isolation_typelib,
197
242
static sys_var_bool_ptr  sys_timed_mutexes("timed_mutexes", &internal::timed_mutexes);
198
243
static sys_var_const_str  sys_version("version", version().c_str());
199
244
 
200
 
static sys_var_const_str sys_version_comment("version_comment", COMPILATION_COMMENT);
201
 
static sys_var_const_str sys_version_compile_machine("version_compile_machine", HOST_CPU);
202
 
static sys_var_const_str sys_version_compile_os("version_compile_os", HOST_OS);
203
 
static sys_var_const_str sys_version_compile_vendor("version_compile_vendor", HOST_VENDOR);
 
245
static sys_var_const_str        sys_version_comment("version_comment",
 
246
                                            COMPILATION_COMMENT);
 
247
static sys_var_const_str        sys_version_compile_machine("version_compile_machine",
 
248
                                                      HOST_CPU);
 
249
static sys_var_const_str        sys_version_compile_os("version_compile_os",
 
250
                                                 HOST_OS);
 
251
static sys_var_const_str        sys_version_compile_vendor("version_compile_vendor",
 
252
                                                 HOST_VENDOR);
204
253
 
205
254
/* Variables that are bits in Session */
206
255
 
207
 
sys_var_session_bit sys_autocommit("autocommit", 0, set_option_autocommit, OPTION_NOT_AUTOCOMMIT, 1);
208
 
static sys_var_session_bit sys_big_selects("sql_big_selects", 0, set_option_bit, OPTION_BIG_SELECTS);
209
 
static sys_var_session_bit sys_sql_warnings("sql_warnings", 0, set_option_bit, OPTION_WARNINGS);
210
 
static sys_var_session_bit sys_sql_notes("sql_notes", 0, set_option_bit, OPTION_SQL_NOTES);
211
 
static sys_var_session_bit sys_buffer_results("sql_buffer_result", 0, set_option_bit, OPTION_BUFFER_RESULT);
212
 
static sys_var_session_bit sys_foreign_key_checks("foreign_key_checks", 0, set_option_bit, OPTION_NO_FOREIGN_KEY_CHECKS, 1);
213
 
static sys_var_session_bit sys_unique_checks("unique_checks", 0, set_option_bit, OPTION_RELAXED_UNIQUE_CHECKS, 1);
 
256
sys_var_session_bit sys_autocommit("autocommit", 0,
 
257
                               set_option_autocommit,
 
258
                               OPTION_NOT_AUTOCOMMIT,
 
259
                               1);
 
260
static sys_var_session_bit      sys_big_selects("sql_big_selects", 0,
 
261
                                        set_option_bit,
 
262
                                        OPTION_BIG_SELECTS);
 
263
static sys_var_session_bit      sys_sql_warnings("sql_warnings", 0,
 
264
                                         set_option_bit,
 
265
                                         OPTION_WARNINGS);
 
266
static sys_var_session_bit      sys_sql_notes("sql_notes", 0,
 
267
                                         set_option_bit,
 
268
                                         OPTION_SQL_NOTES);
 
269
static sys_var_session_bit      sys_buffer_results("sql_buffer_result", 0,
 
270
                                           set_option_bit,
 
271
                                           OPTION_BUFFER_RESULT);
 
272
static sys_var_session_bit      sys_foreign_key_checks("foreign_key_checks", 0,
 
273
                                               set_option_bit,
 
274
                                               OPTION_NO_FOREIGN_KEY_CHECKS, 1);
 
275
static sys_var_session_bit      sys_unique_checks("unique_checks", 0,
 
276
                                          set_option_bit,
 
277
                                          OPTION_RELAXED_UNIQUE_CHECKS, 1);
214
278
/* Local state variables */
215
279
 
216
 
static sys_var_session_ha_rows  sys_select_limit("sql_select_limit", &drizzle_system_variables::select_limit);
 
280
static sys_var_session_ha_rows  sys_select_limit("sql_select_limit",
 
281
                                                 &drizzle_system_variables::select_limit);
217
282
static sys_var_timestamp sys_timestamp("timestamp");
218
283
static sys_var_last_insert_id
219
284
sys_last_insert_id("last_insert_id");
237
302
  statement-based logging mode: t will be different on master and
238
303
  slave).
239
304
*/
240
 
static sys_var_readonly sys_error_count("error_count", OPT_SESSION, SHOW_INT, get_error_count);
241
 
static sys_var_readonly sys_warning_count("warning_count", OPT_SESSION, SHOW_INT, get_warning_count);
 
305
static sys_var_readonly sys_error_count("error_count",
 
306
                                        OPT_SESSION,
 
307
                                        SHOW_INT,
 
308
                                        get_error_count);
 
309
static sys_var_readonly sys_warning_count("warning_count",
 
310
                                          OPT_SESSION,
 
311
                                          SHOW_INT,
 
312
                                          get_warning_count);
242
313
 
243
 
sys_var_session_uint64_t sys_group_concat_max_len("group_concat_max_len", &drizzle_system_variables::group_concat_max_len);
 
314
sys_var_session_uint64_t sys_group_concat_max_len("group_concat_max_len",
 
315
                                                  &drizzle_system_variables::group_concat_max_len);
244
316
 
245
317
/* Global read-only variable containing hostname */
246
318
static sys_var_const_string sys_hostname("hostname", getServerHostname());
254
326
{
255
327
  if (check_func)
256
328
  {
257
 
    int res= (*check_func)(session, var);
258
 
    if (res < 0)
 
329
    int res;
 
330
    if ((res=(*check_func)(session, var)) < 0)
259
331
      my_error(ER_WRONG_VALUE_FOR_VAR, MYF(0), getName().c_str(), var->value->str_value.ptr());
260
332
    return res;
261
333
  }
265
337
 
266
338
bool sys_var_str::check(Session *session, set_var *var)
267
339
{
268
 
  if (not check_func)
 
340
  if (!check_func)
269
341
    return 0;
270
342
 
271
 
  int res= (*check_func)(session, var);
272
 
  if (res < 0)
 
343
  int res;
 
344
  if ((res=(*check_func)(session, var)) < 0)
273
345
    my_error(ER_WRONG_VALUE_FOR_VAR, MYF(0), getName().c_str(), var->value->str_value.ptr());
274
346
  return res;
275
347
}
276
348
 
277
349
bool sys_var_std_string::check(Session *session, set_var *var)
278
350
{
279
 
  if (not check_func)
 
351
  if (check_func == NULL)
 
352
  {
280
353
    return false;
 
354
  }
281
355
 
282
 
  if ((*check_func)(session, var))
 
356
  int res= (*check_func)(session, var);
 
357
  if (res != 0)
283
358
  {
284
359
    my_error(ER_WRONG_VALUE_FOR_VAR, MYF(0), getName().c_str(), var->value->str_value.ptr());
285
360
    return true;
329
404
static void fix_tx_isolation(Session *session, sql_var_t type)
330
405
{
331
406
  if (type == OPT_SESSION)
332
 
    session->session_tx_isolation= (enum_tx_isolation) session->variables.tx_isolation;
 
407
    session->session_tx_isolation= ((enum_tx_isolation)
 
408
                                    session->variables.tx_isolation);
333
409
}
334
410
 
 
411
static void fix_completion_type(Session *, sql_var_t) {}
 
412
 
335
413
static int check_completion_type(Session *, set_var *var)
336
414
{
337
415
  int64_t val= var->value->val_int();
352
430
}
353
431
 
354
432
 
 
433
static void fix_server_id(Session *, sql_var_t)
 
434
{
 
435
}
 
436
 
355
437
void throw_bounds_warning(Session *session, bool fixed, bool unsignd, const std::string &name, int64_t val)
356
438
{
357
439
  if (not fixed)
546
628
 }
547
629
 
548
630
 
549
 
unsigned char *sys_var_session_uint32_t::value_ptr(Session *session, sql_var_t type)
 
631
unsigned char *sys_var_session_uint32_t::value_ptr(Session *session,
 
632
                                                sql_var_t type,
 
633
                                                const lex_string_t *)
550
634
{
551
 
  return type == OPT_GLOBAL
552
 
    ? (unsigned char*) &(global_system_variables.*offset)
553
 
    : (unsigned char*) &(session->variables.*offset);
 
635
  if (type == OPT_GLOBAL)
 
636
    return (unsigned char*) &(global_system_variables.*offset);
 
637
  return (unsigned char*) &(session->variables.*offset);
554
638
}
555
639
 
556
640
 
596
680
}
597
681
 
598
682
 
599
 
unsigned char *sys_var_session_ha_rows::value_ptr(Session *session, sql_var_t type)
 
683
unsigned char *sys_var_session_ha_rows::value_ptr(Session *session,
 
684
                                                  sql_var_t type,
 
685
                                                  const lex_string_t *)
600
686
{
601
 
  return type == OPT_GLOBAL
602
 
    ? (unsigned char*) &(global_system_variables.*offset)
603
 
    : (unsigned char*) &(session->variables.*offset);
 
687
  if (type == OPT_GLOBAL)
 
688
    return (unsigned char*) &(global_system_variables.*offset);
 
689
  return (unsigned char*) &(session->variables.*offset);
604
690
}
605
691
 
606
692
bool sys_var_session_uint64_t::check(Session *session, set_var *var)
652
738
}
653
739
 
654
740
 
655
 
unsigned char *sys_var_session_uint64_t::value_ptr(Session *session, sql_var_t type)
 
741
unsigned char *sys_var_session_uint64_t::value_ptr(Session *session,
 
742
                                                   sql_var_t type,
 
743
                                                   const lex_string_t *)
656
744
{
657
 
  return type == OPT_GLOBAL
658
 
    ? (unsigned char*) &(global_system_variables.*offset)
659
 
    : (unsigned char*) &(session->variables.*offset);
 
745
  if (type == OPT_GLOBAL)
 
746
    return (unsigned char*) &(global_system_variables.*offset);
 
747
  return (unsigned char*) &(session->variables.*offset);
660
748
}
661
749
 
662
750
bool sys_var_session_size_t::check(Session *session, set_var *var)
705
793
}
706
794
 
707
795
 
708
 
unsigned char *sys_var_session_size_t::value_ptr(Session *session, sql_var_t type)
 
796
unsigned char *sys_var_session_size_t::value_ptr(Session *session,
 
797
                                                 sql_var_t type,
 
798
                                                 const lex_string_t *)
709
799
{
710
 
  return type == OPT_GLOBAL
711
 
    ? (unsigned char*) &(global_system_variables.*offset) 
712
 
    : (unsigned char*) &(session->variables.*offset);
 
800
  if (type == OPT_GLOBAL)
 
801
    return (unsigned char*) &(global_system_variables.*offset);
 
802
  return (unsigned char*) &(session->variables.*offset);
713
803
}
714
804
 
715
805
bool sys_var_session_bool::check(Session *session, set_var *var)
737
827
}
738
828
 
739
829
 
740
 
unsigned char *sys_var_session_bool::value_ptr(Session *session, sql_var_t type)
 
830
unsigned char *sys_var_session_bool::value_ptr(Session *session,
 
831
                                               sql_var_t type,
 
832
                                               const lex_string_t *)
741
833
{
742
 
  return type == OPT_GLOBAL
743
 
    ? (unsigned char*) &(global_system_variables.*offset)
744
 
    : (unsigned char*) &(session->variables.*offset);
 
834
  if (type == OPT_GLOBAL)
 
835
    return (unsigned char*) &(global_system_variables.*offset);
 
836
  return (unsigned char*) &(session->variables.*offset);
745
837
}
746
838
 
747
839
 
748
 
bool sys_var::check_enum(Session *, set_var *var, const TYPELIB *enum_names)
 
840
bool sys_var::check_enum(Session *,
 
841
                         set_var *var, const TYPELIB *enum_names)
749
842
{
750
843
  char buff[STRING_BUFFER_USUAL_SIZE];
751
844
  const char *value;
795
888
  If type is not given, return local value if exists, else global.
796
889
*/
797
890
 
798
 
Item *sys_var::item(Session *session, sql_var_t var_type)
 
891
Item *sys_var::item(Session *session, sql_var_t var_type, const lex_string_t *base)
799
892
{
800
893
  if (check_type(var_type))
801
894
  {
802
895
    if (var_type != OPT_DEFAULT)
803
896
    {
804
 
      my_error(ER_INCORRECT_GLOBAL_LOCAL_VAR, MYF(0), name.c_str(), var_type == OPT_GLOBAL ? "SESSION" : "GLOBAL");
 
897
      my_error(ER_INCORRECT_GLOBAL_LOCAL_VAR, MYF(0),
 
898
               name.c_str(), var_type == OPT_GLOBAL ? "SESSION" : "GLOBAL");
805
899
      return 0;
806
900
    }
807
901
    /* As there was no local variable, return the global value */
808
902
    var_type= OPT_GLOBAL;
809
903
  }
810
 
  boost::mutex::scoped_lock lock(session->catalog().systemVariableLock());
811
 
  switch (show_type()) 
812
 
  {
 
904
  switch (show_type()) {
813
905
  case SHOW_LONG:
814
906
  case SHOW_INT:
815
907
  {
816
 
    uint32_t value= *(uint*) value_ptr(session, var_type);
 
908
    uint32_t value;
 
909
    boost::mutex::scoped_lock scopedLock(session->catalog().systemVariableLock());
 
910
    value= *(uint*) value_ptr(session, var_type, base);
 
911
 
817
912
    return new Item_uint((uint64_t) value);
818
913
  }
819
914
  case SHOW_LONGLONG:
820
915
  {
821
 
    int64_t value= *(int64_t*) value_ptr(session, var_type);
 
916
    int64_t value;
 
917
    boost::mutex::scoped_lock scopedLock(session->catalog().systemVariableLock());
 
918
    value= *(int64_t*) value_ptr(session, var_type, base);
 
919
 
822
920
    return new Item_int(value);
823
921
  }
824
922
  case SHOW_DOUBLE:
825
923
  {
826
 
    double value= *(double*) value_ptr(session, var_type);
 
924
    double value;
 
925
    {
 
926
      boost::mutex::scoped_lock scopedLock(session->catalog().systemVariableLock());
 
927
      value= *(double*) value_ptr(session, var_type, base);
 
928
    }
 
929
 
827
930
    /* 6, as this is for now only used with microseconds */
828
931
    return new Item_float(value, 6);
829
932
  }
830
933
  case SHOW_HA_ROWS:
831
934
  {
832
 
    ha_rows value= *(ha_rows*) value_ptr(session, var_type);
 
935
    ha_rows value;
 
936
    boost::mutex::scoped_lock scopedLock(session->catalog().systemVariableLock());
 
937
    value= *(ha_rows*) value_ptr(session, var_type, base);
 
938
 
833
939
    return new Item_int((uint64_t) value);
834
940
  }
835
941
  case SHOW_SIZE:
836
942
  {
837
 
    size_t value= *(size_t*) value_ptr(session, var_type);
 
943
    size_t value;
 
944
    boost::mutex::scoped_lock scopedLock(session->catalog().systemVariableLock());
 
945
    value= *(size_t*) value_ptr(session, var_type, base);
 
946
 
838
947
    return new Item_int((uint64_t) value);
839
948
  }
840
949
  case SHOW_MY_BOOL:
841
950
  {
842
 
    int32_t value= *(bool*) value_ptr(session, var_type);
843
 
    return new Item_int(value, 1);
 
951
    int32_t value;
 
952
    boost::mutex::scoped_lock scopedLock(session->catalog().systemVariableLock());
 
953
    value= *(bool*) value_ptr(session, var_type, base);
 
954
    return new Item_int(value,1);
844
955
  }
845
956
  case SHOW_CHAR_PTR:
846
957
  {
847
 
    if (const char *str= *(char**) value_ptr(session, var_type))
 
958
    Item *tmp;
 
959
    boost::mutex::scoped_lock scopedLock(session->catalog().systemVariableLock());
 
960
    char *str= *(char**) value_ptr(session, var_type, base);
 
961
    if (str)
848
962
    {
849
963
      uint32_t length= strlen(str);
850
 
      return new Item_string(session->mem.strdup(str, length), length, system_charset_info, DERIVATION_SYSCONST);
851
 
    }
852
 
    Item* tmp= new Item_null();
853
 
    tmp->collation.set(system_charset_info, DERIVATION_SYSCONST);
 
964
      tmp= new Item_string(session->mem.strdup(str, length), length, system_charset_info, DERIVATION_SYSCONST);
 
965
    }
 
966
    else
 
967
    {
 
968
      tmp= new Item_null();
 
969
      tmp->collation.set(system_charset_info, DERIVATION_SYSCONST);
 
970
    }
 
971
 
854
972
    return tmp;
855
973
  }
856
974
  case SHOW_CHAR:
857
975
  {
858
 
    if (const char* str= (char*) value_ptr(session, var_type))
 
976
    boost::mutex::scoped_lock scopedLock(session->catalog().systemVariableLock());
 
977
    if (const char* str= (char*) value_ptr(session, var_type, base))
859
978
      return new Item_string(str_ref(str), system_charset_info, DERIVATION_SYSCONST);
860
979
    Item* tmp= new Item_null();
861
980
    tmp->collation.set(system_charset_info, DERIVATION_SYSCONST);
887
1006
}
888
1007
 
889
1008
 
890
 
unsigned char *sys_var_session_enum::value_ptr(Session *session, sql_var_t type)
 
1009
unsigned char *sys_var_session_enum::value_ptr(Session *session,
 
1010
                                               sql_var_t type,
 
1011
                                               const lex_string_t *)
891
1012
{
892
 
  uint32_t tmp= type == OPT_GLOBAL ? global_system_variables.*offset : session->variables.*offset;
 
1013
  uint32_t tmp= ((type == OPT_GLOBAL) ?
 
1014
              global_system_variables.*offset :
 
1015
              session->variables.*offset);
893
1016
  return (unsigned char*) enum_names->type_names[tmp];
894
1017
}
895
1018
 
896
1019
bool sys_var_session_bit::check(Session *session, set_var *var)
897
1020
{
898
 
  return check_enum(session, var, &bool_typelib) || (check_func && (*check_func)(session, var));
 
1021
  return (check_enum(session, var, &bool_typelib) ||
 
1022
          (check_func && (*check_func)(session, var)));
899
1023
}
900
1024
 
901
1025
bool sys_var_session_bit::update(Session *session, set_var *var)
902
1026
{
903
 
  return (*update_func)(session, var);
 
1027
  int res= (*update_func)(session, var);
 
1028
  return res;
904
1029
}
905
1030
 
906
1031
 
907
 
unsigned char *sys_var_session_bit::value_ptr(Session *session, sql_var_t)
 
1032
unsigned char *sys_var_session_bit::value_ptr(Session *session, sql_var_t,
 
1033
                                              const lex_string_t *)
908
1034
{
909
1035
  /*
910
1036
    If reverse is 0 (default) return 1 if bit is set.
911
1037
    If reverse is 1, return 0 if bit is set
912
1038
  */
913
 
  session->sys_var_tmp.bool_value= (session->options & bit_flag) ? !reverse : reverse;
 
1039
  session->sys_var_tmp.bool_value= ((session->options & bit_flag) ?
 
1040
                                   !reverse : reverse);
914
1041
  return (unsigned char*) &session->sys_var_tmp.bool_value;
915
1042
}
916
1043
 
967
1094
}
968
1095
 
969
1096
 
970
 
unsigned char *sys_var_collation_sv::value_ptr(Session *session, sql_var_t type)
 
1097
unsigned char *sys_var_collation_sv::value_ptr(Session *session,
 
1098
                                               sql_var_t type,
 
1099
                                               const lex_string_t *)
971
1100
{
972
 
  const charset_info_st *cs= type == OPT_GLOBAL ? global_system_variables.*offset : session->variables.*offset;
 
1101
  const charset_info_st *cs= ((type == OPT_GLOBAL) ?
 
1102
                           global_system_variables.*offset :
 
1103
                           session->variables.*offset);
973
1104
  return cs ? (unsigned char*) cs->name : (unsigned char*) "NULL";
974
1105
}
975
1106
 
988
1119
}
989
1120
 
990
1121
 
991
 
unsigned char *sys_var_timestamp::value_ptr(Session *session, sql_var_t)
 
1122
unsigned char *sys_var_timestamp::value_ptr(Session *session, sql_var_t,
 
1123
                                            const lex_string_t *)
992
1124
{
993
1125
  session->sys_var_tmp.int32_t_value= (int32_t) session->times.getCurrentTimestampEpoch();
994
1126
  return (unsigned char*) &session->sys_var_tmp.int32_t_value;
1002
1134
}
1003
1135
 
1004
1136
 
1005
 
unsigned char *sys_var_last_insert_id::value_ptr(Session *session, sql_var_t)
 
1137
unsigned char *sys_var_last_insert_id::value_ptr(Session *session,
 
1138
                                                 sql_var_t,
 
1139
                                                 const lex_string_t *)
1006
1140
{
1007
1141
  /*
1008
1142
    this tmp var makes it robust againt change of type of
1053
1187
}
1054
1188
 
1055
1189
 
1056
 
unsigned char *sys_var_session_lc_time_names::value_ptr(Session *session, sql_var_t type)
 
1190
unsigned char *sys_var_session_lc_time_names::value_ptr(Session *session,
 
1191
                                                        sql_var_t type,
 
1192
                                                        const lex_string_t *)
1057
1193
{
1058
 
  return type == OPT_GLOBAL 
1059
 
    ? (unsigned char *) global_system_variables.lc_time_names->name 
1060
 
    : (unsigned char *) session->variables.lc_time_names->name;
 
1194
  return type == OPT_GLOBAL ?
 
1195
                 (unsigned char *) global_system_variables.lc_time_names->name :
 
1196
                 (unsigned char *) session->variables.lc_time_names->name;
1061
1197
}
1062
1198
 
1063
1199
 
1158
1294
  else
1159
1295
    session->options|= ((sys_var_session_bit*) var->var)->bit_flag;
1160
1296
 
1161
 
  return not success;
 
1297
  if (not success)
 
1298
    return true;
 
1299
 
 
1300
  return 0;
1162
1301
}
1163
1302
 
1164
1303
static int check_pseudo_thread_id(Session *, set_var *var)
1421
1560
 Functions to handle table_type
1422
1561
****************************************************************************/
1423
1562
 
1424
 
unsigned char *sys_var_session_storage_engine::value_ptr(Session *session, sql_var_t type)
 
1563
unsigned char *sys_var_session_storage_engine::value_ptr(Session *session,
 
1564
                                                         sql_var_t type,
 
1565
                                                         const lex_string_t *)
1425
1566
{
1426
 
  plugin::StorageEngine *engine= type == OPT_GLOBAL
1427
 
    ? global_system_variables.*offset
1428
 
    : session->variables.*offset;
1429
 
  return (unsigned char *) session->mem.strdup(engine->getName());
 
1567
  plugin::StorageEngine *engine= session->variables.*offset;
 
1568
  if (type == OPT_GLOBAL)
 
1569
    engine= global_system_variables.*offset;
 
1570
  string engine_name= engine->getName();
 
1571
  return (unsigned char *) session->mem.strdup(engine_name);
1430
1572
}
1431
1573
 
1432
1574