66
66
#include <drizzled/item/null.h>
67
67
#include <drizzled/item/float.h>
69
74
extern const CHARSET_INFO *character_set_filesystem;
70
75
extern I_List<NAMED_LIST> key_caches;
71
76
extern size_t my_thread_stack_size;
73
78
static DYNAMIC_ARRAY fixed_show_vars;
74
static HASH system_variable_hash;
79
static map<const string, sys_var *> system_variable_hash;
75
80
extern char *opt_drizzle_tmpdir;
77
82
const char *bool_type_names[]= { "OFF", "ON", NULL };
446
451
{"thread_stack", (char*) &my_thread_stack_size, SHOW_INT},
450
454
bool sys_var::check(Session *, set_var *var)
452
456
var->save_result.uint64_t_value= var->value->val_int();
2087
Return variable name and length for hashing of variables.
2090
static unsigned char *get_sys_var_length(const sys_var *var, size_t *length,
2093
*length= var->name_length;
2094
return (unsigned char*) var->name;
2099
2091
Add variables to the dynamic hash of system variables
2112
2104
int mysql_add_sys_var_chain(sys_var *first, struct my_option *long_options)
2116
2107
/* A write lock should be held on LOCK_system_variables_hash */
2118
2109
for (var= first; var; var= var->next)
2120
var->name_length= strlen(var->name);
2121
/* this fails if there is a conflicting variable name. see HASH_UNIQUE */
2122
if (my_hash_insert(&system_variable_hash, (unsigned char*) var))
2111
/* Make a temp string to hold this and then make it lower so that matching
2112
* happens case-insensitive.
2114
string var_name(var->name);
2115
transform(var_name.begin(), var_name.end(), var_name.begin(), ::tolower);
2116
var->name_length= var_name.length();
2118
/* this fails if there is a conflicting variable name. */
2119
if (system_variable_hash.count(var_name) == 0)
2121
system_variable_hash[var_name]= var;
2125
for (; first != var; first= first->next)
2128
* This is slightly expensive, since we have to do the transform
2129
* _again_ but should rarely happen unless there is a pretty
2130
* major problem in the code
2132
var_name= first->name;
2133
transform(var_name.begin(), var_name.end(),
2134
var_name.begin(), ::tolower);
2135
system_variable_hash.erase(var_name);
2124
2139
if (long_options)
2125
2140
var->option_limits= find_option(long_options, var->name);
2130
for (; first != var; first= first->next)
2131
hash_delete(&system_variable_hash, (unsigned char*) first);
2148
2159
int mysql_del_sys_var_chain(sys_var *first)
2152
2164
/* A write lock should be held on LOCK_system_variables_hash */
2154
2165
for (sys_var *var= first; var; var= var->next)
2155
result|= hash_delete(&system_variable_hash, (unsigned char*) var);
2167
var_name= var->name;
2168
transform(var_name.begin(), var_name.end(),
2169
var_name.begin(), ::tolower);
2170
result|= system_variable_hash.erase(var_name);
2161
static int show_cmp(SHOW_VAR *a, SHOW_VAR *b)
2163
return strcmp(a->name, b->name);
2168
2179
Constructs an array of system variables for display to the user.
2180
SHOW_VAR* enumerate_sys_vars(Session *session, bool sorted)
2191
SHOW_VAR* enumerate_sys_vars(Session *session, bool)
2182
int count= system_variable_hash.records, i;
2183
2193
int fixed_count= fixed_show_vars.elements;
2184
int size= sizeof(SHOW_VAR) * (count + fixed_count + 1);
2194
int size= sizeof(SHOW_VAR) * (system_variable_hash.size() + fixed_count + 1);
2185
2195
SHOW_VAR *result= (SHOW_VAR*) session->alloc(size);
2189
2199
SHOW_VAR *show= result + fixed_count;
2190
2200
memcpy(result, fixed_show_vars.buffer, fixed_count * sizeof(SHOW_VAR));
2192
for (i= 0; i < count; i++)
2202
map<string, sys_var *>::iterator iter;
2203
for(iter= system_variable_hash.begin();
2204
iter != system_variable_hash.end();
2194
sys_var *var= (sys_var*) hash_element(&system_variable_hash, i);
2207
sys_var *var= (*iter).second;
2195
2208
show->name= var->name;
2196
2209
show->value= (char*) var;
2197
2210
show->type= SHOW_SYS;
2201
/* sort into order */
2203
my_qsort(result, count + fixed_count, sizeof(SHOW_VAR),
2204
(qsort_cmp) show_cmp);
2206
2214
/* make last element empty */
2207
2215
memset(show, 0, sizeof(SHOW_VAR));
2249
2257
fixed_show_vars.elements= FIXED_VARS_SIZE;
2250
2258
memcpy(fixed_show_vars.buffer, fixed_vars, sizeof(fixed_vars));
2252
if (hash_init(&system_variable_hash, system_charset_info, count, 0,
2253
0, (hash_get_key) get_sys_var_length, 0, HASH_UNIQUE))
2256
2260
vars.last->next= NULL;
2257
2261
if (mysql_add_sys_var_chain(vars.first, my_long_options))
2307
2310
0 Unknown variable (error message is given)
2310
sys_var *intern_find_sys_var(const char *str, uint32_t length, bool no_error)
2313
sys_var *intern_find_sys_var(const char *str, uint32_t, bool no_error)
2315
2316
This function is only called from the sql_plugin.cc.
2316
2317
A lock on LOCK_system_variable_hash should be held
2318
var= (sys_var*) hash_search(&system_variable_hash,
2319
(unsigned char*) str, length ? length : strlen(str));
2320
if (!(var || no_error))
2319
string lower_var(str);
2320
transform(lower_var.begin(), lower_var.end(), lower_var.begin(), ::tolower);
2321
map<string, sys_var *>::iterator result_iter=
2322
system_variable_hash.find(lower_var);
2323
if (result_iter == system_variable_hash.end() && (!no_error))
2321
2324
my_error(ER_UNKNOWN_SYSTEM_VARIABLE, MYF(0), (char*) str);
2326
return (*result_iter).second;