37
37
using namespace std;
39
static inline void make_upper(char *buf)
42
*buf= my_toupper(system_charset_info, *buf);
45
static bool show_status_array(Session *session, const char *wild,
47
enum enum_var_type value_type,
48
struct system_status_var *status_var,
49
const char *prefix, Table *table,
52
MY_ALIGNED_BYTE_ARRAY(buff_data, SHOW_VAR_FUNC_BUFF_SIZE, int64_t);
53
char * const buff= (char *) &buff_data;
55
/* the variable name should not be longer than 64 characters */
60
prefix_end= strncpy(name_buffer, prefix, sizeof(name_buffer)-1);
61
prefix_end+= strlen(prefix);
65
len=name_buffer + sizeof(name_buffer) - prefix_end;
67
for (; variables->name; variables++)
69
strncpy(prefix_end, variables->name, len);
70
name_buffer[sizeof(name_buffer)-1]=0; /* Safety */
72
make_upper(name_buffer);
75
if var->type is SHOW_FUNC, call the function.
76
Repeat as necessary, if new var is again SHOW_FUNC
78
for (var=variables; var->type == SHOW_FUNC; var= &tmp)
79
((mysql_show_var_func)((st_show_var_func_container *)var->value)->func)(&tmp, buff);
81
SHOW_TYPE show_type=var->type;
82
if (show_type == SHOW_ARRAY)
84
show_status_array(session, wild, (SHOW_VAR *) var->value, value_type,
85
status_var, name_buffer, table, ucase_names);
89
if (!(wild && wild[0] && wild_case_compare(system_charset_info,
92
char *value=var->value;
93
const char *pos, *end; // We assign a lot of const's
94
pthread_mutex_lock(&LOCK_global_system_variables);
96
if (show_type == SHOW_SYS)
98
show_type= ((sys_var*) value)->show_type();
99
value= (char*) ((sys_var*) value)->value_ptr(session, value_type,
105
note that value may be == buff. All SHOW_xxx code below
106
should still work in this case
109
case SHOW_DOUBLE_STATUS:
110
value= ((char *) status_var + (ulong) value);
113
/* 6 is the default precision for '%f' in sprintf() */
114
end= buff + my_fcvt(*(double *) value, 6, buff, NULL);
116
case SHOW_LONG_STATUS:
117
value= ((char *) status_var + (ulong) value);
120
end= int10_to_str(*(long*) value, buff, 10);
122
case SHOW_LONGLONG_STATUS:
123
value= ((char *) status_var + (uint64_t) value);
126
end= int64_t10_to_str(*(int64_t*) value, buff, 10);
130
stringstream ss (stringstream::in);
131
ss << *(size_t*) value;
133
string str= ss.str();
134
strncpy(buff, str.c_str(), str.length());
135
end= buff+ str.length();
139
end= int64_t10_to_str((int64_t) *(ha_rows*) value, buff, 10);
142
end+= sprintf(buff,"%s", *(bool*) value ? "ON" : "OFF");
145
end+= sprintf(buff,"%s", *(bool*) value ? "ON" : "OFF");
148
case SHOW_INT_NOFLUSH: // the difference lies in refresh_status()
149
end= int10_to_str((long) *(uint32_t*) value, buff, 10);
153
SHOW_COMP_OPTION tmp_option= *(SHOW_COMP_OPTION *)value;
154
pos= show_comp_option_name[(int) tmp_option];
155
end= strchr(pos, '\0');
162
end= strchr(pos, '\0');
167
if (!(pos= *(char**) value))
169
end= strchr(pos, '\0');
172
case SHOW_KEY_CACHE_LONG:
173
value= (char*) dflt_key_cache + (ulong)value;
174
end= int10_to_str(*(long*) value, buff, 10);
176
case SHOW_KEY_CACHE_LONGLONG:
177
value= (char*) dflt_key_cache + (ulong)value;
178
end= int64_t10_to_str(*(int64_t*) value, buff, 10);
181
break; // Return empty string
182
case SHOW_SYS: // Cannot happen
187
table->restoreRecordAsDefault();
188
table->field[0]->store(name_buffer, strlen(name_buffer),
189
system_charset_info);
190
table->field[1]->store(pos, (uint32_t) (end - pos), system_charset_info);
191
table->field[1]->set_notnull();
193
pthread_mutex_unlock(&LOCK_global_system_variables);
195
if (schema_table_store_record(session, table))
39
204
int CharSetISMethods::fillTable(Session *session, TableList *tables, COND *)
41
206
CHARSET_INFO **cs;
953
int StatusISMethods::fillTable(Session *session, TableList *tables, COND *)
955
LEX *lex= session->lex;
956
const char *wild= lex->wild ? lex->wild->ptr() : NULL;
958
STATUS_VAR *tmp1, tmp;
959
const string schema_table_name= tables->schema_table->getTableName();
960
enum enum_var_type option_type;
961
bool upper_case_names= (schema_table_name.compare("STATUS") != 0);
963
if (schema_table_name.compare("STATUS") == 0)
965
option_type= lex->option_type;
966
if (option_type == OPT_GLOBAL)
969
tmp1= session->initial_status_var;
971
else if (schema_table_name.compare("GLOBAL_STATUS") == 0)
973
option_type= OPT_GLOBAL;
978
option_type= OPT_SESSION;
979
tmp1= &session->status_var;
982
pthread_mutex_lock(&LOCK_status);
983
if (option_type == OPT_GLOBAL)
984
calc_sum_of_all_status(&tmp);
985
res= show_status_array(session, wild,
986
getFrontOfStatusVars(),
987
option_type, tmp1, "", tables->table,
989
pthread_mutex_unlock(&LOCK_status);
788
993
static bool store_constraints(Session *session, Table *table, LEX_STRING *db_name,
789
994
LEX_STRING *table_name, const char *key_name,
790
995
uint32_t key_len, const char *con_type, uint32_t con_len)
1326
int VariablesISMethods::fillTable(Session *session, TableList *tables, COND *)
1329
LEX *lex= session->lex;
1330
const char *wild= lex->wild ? lex->wild->ptr() : NULL;
1331
const string schema_table_name= tables->schema_table->getTableName();
1332
enum enum_var_type option_type= OPT_SESSION;
1333
bool upper_case_names= (schema_table_name.compare("VARIABLES") != 0);
1334
bool sorted_vars= (schema_table_name.compare("VARIABLES") == 0);
1336
if (lex->option_type == OPT_GLOBAL ||
1337
schema_table_name.compare("GLOBAL_VARIABLES") == 0)
1339
option_type= OPT_GLOBAL;
1342
pthread_rwlock_rdlock(&LOCK_system_variables_hash);
1343
res= show_status_array(session, wild, enumerate_sys_vars(session, sorted_vars),
1344
option_type, NULL, "", tables->table, upper_case_names);
1345
pthread_rwlock_unlock(&LOCK_system_variables_hash);