1150
inline void make_upper(char *buf)
1153
*buf= my_toupper(system_charset_info, *buf);
1156
static bool show_status_array(Session *session, const char *wild,
1157
SHOW_VAR *variables,
1158
enum enum_var_type value_type,
1159
struct system_status_var *status_var,
1160
const char *prefix, Table *table,
1163
MY_ALIGNED_BYTE_ARRAY(buff_data, SHOW_VAR_FUNC_BUFF_SIZE, int64_t);
1164
char * const buff= (char *) &buff_data;
1166
/* the variable name should not be longer than 64 characters */
1167
char name_buffer[64];
1171
prefix_end= strncpy(name_buffer, prefix, sizeof(name_buffer)-1);
1172
prefix_end+= strlen(prefix);
1176
len=name_buffer + sizeof(name_buffer) - prefix_end;
1178
for (; variables->name; variables++)
1180
strncpy(prefix_end, variables->name, len);
1181
name_buffer[sizeof(name_buffer)-1]=0; /* Safety */
1183
make_upper(name_buffer);
1186
if var->type is SHOW_FUNC, call the function.
1187
Repeat as necessary, if new var is again SHOW_FUNC
1189
for (var=variables; var->type == SHOW_FUNC; var= &tmp)
1190
((mysql_show_var_func)((st_show_var_func_container *)var->value)->func)(&tmp, buff);
1192
SHOW_TYPE show_type=var->type;
1193
if (show_type == SHOW_ARRAY)
1195
show_status_array(session, wild, (SHOW_VAR *) var->value, value_type,
1196
status_var, name_buffer, table, ucase_names);
1200
if (!(wild && wild[0] && wild_case_compare(system_charset_info,
1201
name_buffer, wild)))
1203
char *value=var->value;
1204
const char *pos, *end; // We assign a lot of const's
1205
pthread_mutex_lock(&LOCK_global_system_variables);
1207
if (show_type == SHOW_SYS)
1209
show_type= ((sys_var*) value)->show_type();
1210
value= (char*) ((sys_var*) value)->value_ptr(session, value_type,
1216
note that value may be == buff. All SHOW_xxx code below
1217
should still work in this case
1219
switch (show_type) {
1220
case SHOW_DOUBLE_STATUS:
1221
value= ((char *) status_var + (ulong) value);
1224
/* 6 is the default precision for '%f' in sprintf() */
1225
end= buff + my_fcvt(*(double *) value, 6, buff, NULL);
1227
case SHOW_LONG_STATUS:
1228
value= ((char *) status_var + (ulong) value);
1231
end= int10_to_str(*(long*) value, buff, 10);
1233
case SHOW_LONGLONG_STATUS:
1234
value= ((char *) status_var + (uint64_t) value);
1237
end= int64_t10_to_str(*(int64_t*) value, buff, 10);
1241
stringstream ss (stringstream::in);
1242
ss << *(size_t*) value;
1244
string str= ss.str();
1245
strncpy(buff, str.c_str(), str.length());
1246
end= buff+ str.length();
1250
end= int64_t10_to_str((int64_t) *(ha_rows*) value, buff, 10);
1253
end+= sprintf(buff,"%s", *(bool*) value ? "ON" : "OFF");
1256
end+= sprintf(buff,"%s", *(bool*) value ? "ON" : "OFF");
1259
case SHOW_INT_NOFLUSH: // the difference lies in refresh_status()
1260
end= int10_to_str((long) *(uint32_t*) value, buff, 10);
1264
SHOW_COMP_OPTION tmp_option= *(SHOW_COMP_OPTION *)value;
1265
pos= show_comp_option_name[(int) tmp_option];
1266
end= strchr(pos, '\0');
1273
end= strchr(pos, '\0');
1278
if (!(pos= *(char**) value))
1280
end= strchr(pos, '\0');
1283
case SHOW_KEY_CACHE_LONG:
1284
value= (char*) dflt_key_cache + (ulong)value;
1285
end= int10_to_str(*(long*) value, buff, 10);
1287
case SHOW_KEY_CACHE_LONGLONG:
1288
value= (char*) dflt_key_cache + (ulong)value;
1289
end= int64_t10_to_str(*(int64_t*) value, buff, 10);
1292
break; // Return empty string
1293
case SHOW_SYS: // Cannot happen
1298
table->restoreRecordAsDefault();
1299
table->field[0]->store(name_buffer, strlen(name_buffer),
1300
system_charset_info);
1301
table->field[1]->store(pos, (uint32_t) (end - pos), system_charset_info);
1302
table->field[1]->set_notnull();
1304
pthread_mutex_unlock(&LOCK_global_system_variables);
1306
if (schema_table_store_record(session, table))
1316
1155
/* collect status for all running threads */
1318
1157
void calc_sum_of_all_status(STATUS_VAR *to)
1778
1613
static int schema_tables_add(Session *session, vector<LEX_STRING*> &files, const char *wild)
1780
InfoSchemaTable *tmp_schema_table= schema_tables;
1782
for (; tmp_schema_table->getTableName().length() != 0; tmp_schema_table++)
1784
if (tmp_schema_table->isHidden())
1789
const string &schema_table_name= tmp_schema_table->getTableName();
1791
if (wild && wild_case_compare(files_charset_info, schema_table_name.c_str(), wild))
1796
LEX_STRING *file_name= 0;
1797
file_name= session->make_lex_string(file_name, schema_table_name.c_str(),
1798
schema_table_name.length(), true);
1799
if (file_name == NULL)
1804
files.push_back(file_name);
1807
1615
vector<InfoSchemaTable *>::iterator iter= find_if(all_schema_tables.begin(),
1808
1616
all_schema_tables.end(),
1809
1617
AddSchemaTable(session, files, wild));
1811
1619
if (iter != all_schema_tables.end())
2578
int VariablesISMethods::fillTable(Session *session, TableList *tables, COND *)
2581
LEX *lex= session->lex;
2582
const char *wild= lex->wild ? lex->wild->ptr() : NULL;
2583
const string schema_table_name= tables->schema_table->getTableName();
2584
enum enum_var_type option_type= OPT_SESSION;
2585
bool upper_case_names= (schema_table_name.compare("VARIABLES") != 0);
2586
bool sorted_vars= (schema_table_name.compare("VARIABLES") == 0);
2588
if (lex->option_type == OPT_GLOBAL ||
2589
schema_table_name.compare("GLOBAL_VARIABLES") == 0)
2591
option_type= OPT_GLOBAL;
2594
pthread_rwlock_rdlock(&LOCK_system_variables_hash);
2595
res= show_status_array(session, wild, enumerate_sys_vars(session, sorted_vars),
2596
option_type, NULL, "", tables->table, upper_case_names);
2597
pthread_rwlock_unlock(&LOCK_system_variables_hash);
2602
int StatusISMethods::fillTable(Session *session, TableList *tables, COND *)
2604
LEX *lex= session->lex;
2605
const char *wild= lex->wild ? lex->wild->ptr() : NULL;
2607
STATUS_VAR *tmp1, tmp;
2608
const string schema_table_name= tables->schema_table->getTableName();
2609
enum enum_var_type option_type;
2610
bool upper_case_names= (schema_table_name.compare("STATUS") != 0);
2612
if (schema_table_name.compare("STATUS") == 0)
2614
option_type= lex->option_type;
2615
if (option_type == OPT_GLOBAL)
2618
tmp1= session->initial_status_var;
2620
else if (schema_table_name.compare("GLOBAL_STATUS") == 0)
2622
option_type= OPT_GLOBAL;
2627
option_type= OPT_SESSION;
2628
tmp1= &session->status_var;
2631
pthread_mutex_lock(&LOCK_status);
2632
if (option_type == OPT_GLOBAL)
2633
calc_sum_of_all_status(&tmp);
2634
res= show_status_array(session, wild,
2635
(SHOW_VAR *) all_status_vars.front(),
2636
option_type, tmp1, "", tables->table,
2638
pthread_mutex_unlock(&LOCK_status);
2643
2388
class FindSchemaTableByName : public unary_function<InfoSchemaTable *, bool>
2645
2390
const char *table_name;
2996
2734
session->no_warnings_for_error= 0;
2997
2735
return(result);
3000
ColumnInfo variables_fields_info[]=
3002
ColumnInfo("VARIABLE_NAME", 64, DRIZZLE_TYPE_VARCHAR, 0, 0, "Variable_name",
3004
ColumnInfo("VARIABLE_VALUE", 16300, DRIZZLE_TYPE_VARCHAR, 0, 1, "Value", SKIP_OPEN_TABLE),
3009
static StatusISMethods status_methods;
3010
static VariablesISMethods variables_methods;
3012
static InfoSchemaTable global_stat_table("GLOBAL_STATUS",
3013
variables_fields_info,
3014
-1, -1, false, false, 0,
3016
static InfoSchemaTable global_var_table("GLOBAL_VARIABLES",
3017
variables_fields_info,
3018
-1, -1, false, false, 0,
3019
&variables_methods);
3020
static InfoSchemaTable sess_stat_table("SESSION_STATUS",
3021
variables_fields_info,
3022
-1, -1, false, false, 0,
3024
static InfoSchemaTable sess_var_table("SESSION_VARIABLES",
3025
variables_fields_info,
3026
-1, -1, false, false, 0,
3027
&variables_methods);
3028
static InfoSchemaTable status_table("STATUS",
3029
variables_fields_info,
3030
-1, -1, true, false, 0,
3032
static InfoSchemaTable var_table("VARIABLES",
3033
variables_fields_info,
3034
-1, -1, true, false, 0,
3035
&variables_methods);
3037
InfoSchemaTable schema_tables[]=