1
/* - mode: c; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
* vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
4
* Copyright (C) 2009 Sun Microsystems
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; either version 2 of the License, or
9
* (at your option) any later version.
11
* This program is distributed in the hope that it will be useful,
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
* GNU General Public License for more details.
16
* You should have received a copy of the GNU General Public License
17
* along with this program; if not, write to the Free Software
18
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
23
* Implementation of helper methods for I_S tables.
27
#include "drizzled/session.h"
28
#include "drizzled/show.h"
29
#include "drizzled/sql_base.h"
30
#include "drizzled/plugin/client.h"
31
#include "drizzled/join_table.h"
32
#include "drizzled/global_charset_info.h"
33
#include "drizzled/pthread_globals.h"
34
#include "drizzled/internal/m_string.h"
35
#include "plugin/myisam/myisam.h" // needed for dflt_key_cache
36
#include "helper_methods.h"
43
using namespace drizzled;
45
static inline void make_upper(char *buf)
48
*buf= my_toupper(system_charset_info, *buf);
51
bool show_status_array(Session *session,
54
enum enum_var_type value_type,
55
struct system_status_var *status_var,
56
const char *prefix, Table *table,
58
plugin::InfoSchemaTable *schema_table)
60
MY_ALIGNED_BYTE_ARRAY(buff_data, SHOW_VAR_FUNC_BUFF_SIZE, int64_t);
61
char * const buff= (char *) &buff_data;
63
/* the variable name should not be longer than 64 characters */
68
prefix_end= strncpy(name_buffer, prefix, sizeof(name_buffer)-1);
69
prefix_end+= strlen(prefix);
73
len=name_buffer + sizeof(name_buffer) - prefix_end;
75
for (; variables->name; variables++)
77
strncpy(prefix_end, variables->name, len);
78
name_buffer[sizeof(name_buffer)-1]=0; /* Safety */
81
if var->type is SHOW_FUNC, call the function.
82
Repeat as necessary, if new var is again SHOW_FUNC
84
for (var=variables; var->type == SHOW_FUNC; var= &tmp)
85
((mysql_show_var_func)((st_show_var_func_container *)var->value)->func)(&tmp, buff);
87
SHOW_TYPE show_type=var->type;
88
if (show_type == SHOW_ARRAY)
90
show_status_array(session, wild, (SHOW_VAR *) var->value, value_type,
91
status_var, name_buffer, table, false, schema_table);
95
if (!(wild && wild[0] && wild_case_compare(system_charset_info,
98
char *value=var->value;
99
const char *pos, *end; // We assign a lot of const's
100
pthread_mutex_lock(&LOCK_global_system_variables);
102
if (show_type == SHOW_SYS)
104
show_type= ((sys_var*) value)->show_type();
105
value= (char*) ((sys_var*) value)->value_ptr(session, value_type,
111
note that value may be == buff. All SHOW_xxx code below
112
should still work in this case
115
case SHOW_DOUBLE_STATUS:
116
value= ((char *) status_var + (ulong) value);
119
/* 6 is the default precision for '%f' in sprintf() */
120
end= buff + internal::my_fcvt(*(double *) value, 6, buff, NULL);
122
case SHOW_LONG_STATUS:
123
value= ((char *) status_var + (ulong) value);
126
end= internal::int10_to_str(*(long*) value, buff, 10);
128
case SHOW_LONGLONG_STATUS:
129
value= ((char *) status_var + (uint64_t) value);
132
end= internal::int64_t10_to_str(*(int64_t*) value, buff, 10);
136
stringstream ss (stringstream::in);
137
ss << *(size_t*) value;
139
string str= ss.str();
140
strncpy(buff, str.c_str(), str.length());
141
end= buff+ str.length();
145
end= internal::int64_t10_to_str((int64_t) *(ha_rows*) value, buff, 10);
148
end+= sprintf(buff,"%s", *(bool*) value ? "ON" : "OFF");
151
end+= sprintf(buff,"%s", *(bool*) value ? "ON" : "OFF");
154
case SHOW_INT_NOFLUSH: // the difference lies in refresh_status()
155
end= internal::int10_to_str((long) *(uint32_t*) value, buff, 10);
161
end= strchr(pos, '\0');
166
if (!(pos= *(char**) value))
168
end= strchr(pos, '\0');
171
case SHOW_KEY_CACHE_LONG:
172
value= (char*) dflt_key_cache + (ulong)value;
173
end= internal::int10_to_str(*(long*) value, buff, 10);
175
case SHOW_KEY_CACHE_LONGLONG:
176
value= (char*) dflt_key_cache + (ulong)value;
177
end= internal::int64_t10_to_str(*(int64_t*) value, buff, 10);
180
break; // Return empty string
181
case SHOW_SYS: // Cannot happen
186
table->restoreRecordAsDefault();
187
table->setWriteSet(0);
188
table->setWriteSet(1);
189
table->setWriteSet(2);
190
table->field[0]->store(name_buffer, strlen(name_buffer),
191
system_charset_info);
192
table->field[1]->store(pos, (uint32_t) (end - pos), system_charset_info);
193
table->field[1]->set_notnull();
195
pthread_mutex_unlock(&LOCK_global_system_variables);
197
schema_table->addRow(table->record[0], table->s->reclength);
205
void store_key_column_usage(Table *table,
207
LEX_STRING *table_name,
208
const char *key_name,
210
const char *con_type,
214
const CHARSET_INFO * const cs= system_charset_info;
215
/* set the appropriate bits in the write bitset */
216
table->setWriteSet(1);
217
table->setWriteSet(2);
218
table->setWriteSet(4);
219
table->setWriteSet(5);
220
table->setWriteSet(6);
221
table->setWriteSet(7);
222
table->field[1]->store(db_name->str, db_name->length, cs);
223
table->field[2]->store(key_name, key_len, cs);
224
table->field[4]->store(db_name->str, db_name->length, cs);
225
table->field[5]->store(table_name->str, table_name->length, cs);
226
table->field[6]->store(con_type, con_len, cs);
227
table->field[7]->store((int64_t) idx, true);
231
* Function object used for deleting the memory allocated
232
* for the columns contained with the vector of columns.
238
inline void operator()(const T *ptr) const
244
void clearColumns(vector<const drizzled::plugin::ColumnInfo *> &cols)
246
for_each(cols.begin(), cols.end(), DeleteColumns());