~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to plugin/info_schema/helper_methods.cc

  • Committer: Brian Aker
  • Date: 2010-01-27 18:58:12 UTC
  • Revision ID: brian@gaz-20100127185812-n62n0vwetnx8jrjy
Remove dead code.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* - mode: c; c-basic-offset: 2; indent-tabs-mode: nil; -*-
 
2
 *  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
 
3
 *
 
4
 *  Copyright (C) 2009 Sun Microsystems
 
5
 *
 
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.
 
10
 *
 
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.
 
15
 *
 
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
 
19
 */
 
20
 
 
21
/**
 
22
 * @file 
 
23
 *   Implementation of helper methods for I_S tables.
 
24
 */
 
25
 
 
26
#include "config.h"
 
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"
 
37
 
 
38
#include <vector>
 
39
#include <string>
 
40
#include <sstream>
 
41
 
 
42
using namespace std;
 
43
using namespace drizzled;
 
44
 
 
45
static inline void make_upper(char *buf)
 
46
{
 
47
  for (; *buf; buf++)
 
48
    *buf= my_toupper(system_charset_info, *buf);
 
49
}
 
50
 
 
51
bool show_status_array(Session *session, 
 
52
                       const char *wild,
 
53
                       SHOW_VAR *variables,
 
54
                       enum enum_var_type value_type,
 
55
                       struct system_status_var *status_var,
 
56
                       const char *prefix, Table *table,
 
57
                       bool ucase_names,
 
58
                       plugin::InfoSchemaTable *schema_table)
 
59
{
 
60
  MY_ALIGNED_BYTE_ARRAY(buff_data, SHOW_VAR_FUNC_BUFF_SIZE, int64_t);
 
61
  char * const buff= (char *) &buff_data;
 
62
  char *prefix_end;
 
63
  /* the variable name should not be longer than 64 characters */
 
64
  char name_buffer[64];
 
65
  int len;
 
66
  SHOW_VAR tmp, *var;
 
67
 
 
68
  prefix_end= strncpy(name_buffer, prefix, sizeof(name_buffer)-1);
 
69
  prefix_end+= strlen(prefix);
 
70
 
 
71
  if (*prefix)
 
72
    *prefix_end++= '_';
 
73
  len=name_buffer + sizeof(name_buffer) - prefix_end;
 
74
 
 
75
  for (; variables->name; variables++)
 
76
  {
 
77
    strncpy(prefix_end, variables->name, len);
 
78
    name_buffer[sizeof(name_buffer)-1]=0;       /* Safety */
 
79
    if (ucase_names)
 
80
      make_upper(name_buffer);
 
81
 
 
82
    /*
 
83
      if var->type is SHOW_FUNC, call the function.
 
84
      Repeat as necessary, if new var is again SHOW_FUNC
 
85
    */
 
86
    for (var=variables; var->type == SHOW_FUNC; var= &tmp)
 
87
      ((mysql_show_var_func)((st_show_var_func_container *)var->value)->func)(&tmp, buff);
 
88
 
 
89
    SHOW_TYPE show_type=var->type;
 
90
    if (show_type == SHOW_ARRAY)
 
91
    {
 
92
      show_status_array(session, wild, (SHOW_VAR *) var->value, value_type,
 
93
                        status_var, name_buffer, table, ucase_names, schema_table);
 
94
    }
 
95
    else
 
96
    {
 
97
      if (!(wild && wild[0] && wild_case_compare(system_charset_info,
 
98
                                                 name_buffer, wild)))
 
99
      {
 
100
        char *value=var->value;
 
101
        const char *pos, *end;                  // We assign a lot of const's
 
102
        pthread_mutex_lock(&LOCK_global_system_variables);
 
103
 
 
104
        if (show_type == SHOW_SYS)
 
105
        {
 
106
          show_type= ((sys_var*) value)->show_type();
 
107
          value= (char*) ((sys_var*) value)->value_ptr(session, value_type,
 
108
                                                       &null_lex_str);
 
109
        }
 
110
 
 
111
        pos= end= buff;
 
112
        /*
 
113
          note that value may be == buff. All SHOW_xxx code below
 
114
          should still work in this case
 
115
        */
 
116
        switch (show_type) {
 
117
        case SHOW_DOUBLE_STATUS:
 
118
          value= ((char *) status_var + (ulong) value);
 
119
          /* fall through */
 
120
        case SHOW_DOUBLE:
 
121
          /* 6 is the default precision for '%f' in sprintf() */
 
122
          end= buff + my_fcvt(*(double *) value, 6, buff, NULL);
 
123
          break;
 
124
        case SHOW_LONG_STATUS:
 
125
          value= ((char *) status_var + (ulong) value);
 
126
          /* fall through */
 
127
        case SHOW_LONG:
 
128
          end= int10_to_str(*(long*) value, buff, 10);
 
129
          break;
 
130
        case SHOW_LONGLONG_STATUS:
 
131
          value= ((char *) status_var + (uint64_t) value);
 
132
          /* fall through */
 
133
        case SHOW_LONGLONG:
 
134
          end= int64_t10_to_str(*(int64_t*) value, buff, 10);
 
135
          break;
 
136
        case SHOW_SIZE:
 
137
          {
 
138
            stringstream ss (stringstream::in);
 
139
            ss << *(size_t*) value;
 
140
 
 
141
            string str= ss.str();
 
142
            strncpy(buff, str.c_str(), str.length());
 
143
            end= buff+ str.length();
 
144
          }
 
145
          break;
 
146
        case SHOW_HA_ROWS:
 
147
          end= int64_t10_to_str((int64_t) *(ha_rows*) value, buff, 10);
 
148
          break;
 
149
        case SHOW_BOOL:
 
150
          end+= sprintf(buff,"%s", *(bool*) value ? "ON" : "OFF");
 
151
          break;
 
152
        case SHOW_MY_BOOL:
 
153
          end+= sprintf(buff,"%s", *(bool*) value ? "ON" : "OFF");
 
154
          break;
 
155
        case SHOW_INT:
 
156
        case SHOW_INT_NOFLUSH: // the difference lies in refresh_status()
 
157
          end= int10_to_str((long) *(uint32_t*) value, buff, 10);
 
158
          break;
 
159
        case SHOW_HAVE:
 
160
        {
 
161
          SHOW_COMP_OPTION tmp_option= *(SHOW_COMP_OPTION *)value;
 
162
          pos= show_comp_option_name[(int) tmp_option];
 
163
          end= strchr(pos, '\0');
 
164
          break;
 
165
        }
 
166
        case SHOW_CHAR:
 
167
        {
 
168
          if (!(pos= value))
 
169
            pos= "";
 
170
          end= strchr(pos, '\0');
 
171
          break;
 
172
        }
 
173
       case SHOW_CHAR_PTR:
 
174
        {
 
175
          if (!(pos= *(char**) value))
 
176
            pos= "";
 
177
          end= strchr(pos, '\0');
 
178
          break;
 
179
        }
 
180
        case SHOW_KEY_CACHE_LONG:
 
181
          value= (char*) dflt_key_cache + (ulong)value;
 
182
          end= int10_to_str(*(long*) value, buff, 10);
 
183
          break;
 
184
        case SHOW_KEY_CACHE_LONGLONG:
 
185
          value= (char*) dflt_key_cache + (ulong)value;
 
186
          end= int64_t10_to_str(*(int64_t*) value, buff, 10);
 
187
          break;
 
188
        case SHOW_UNDEF:
 
189
          break;                                        // Return empty string
 
190
        case SHOW_SYS:                                  // Cannot happen
 
191
        default:
 
192
          assert(0);
 
193
          break;
 
194
        }
 
195
        table->restoreRecordAsDefault();
 
196
        table->setWriteSet(0);
 
197
        table->setWriteSet(1);
 
198
        table->setWriteSet(2);
 
199
        table->field[0]->store(name_buffer, strlen(name_buffer),
 
200
                               system_charset_info);
 
201
        table->field[1]->store(pos, (uint32_t) (end - pos), system_charset_info);
 
202
        table->field[1]->set_notnull();
 
203
 
 
204
        pthread_mutex_unlock(&LOCK_global_system_variables);
 
205
 
 
206
        schema_table->addRow(table->record[0], table->s->reclength);
 
207
      }
 
208
    }
 
209
  }
 
210
 
 
211
  return false;
 
212
}
 
213
 
 
214
void store_key_column_usage(Table *table, 
 
215
                            LEX_STRING *db_name,
 
216
                            LEX_STRING *table_name, 
 
217
                            const char *key_name,
 
218
                            uint32_t key_len, 
 
219
                            const char *con_type, 
 
220
                            uint32_t con_len,
 
221
                            int64_t idx)
 
222
{
 
223
  const CHARSET_INFO * const cs= system_charset_info;
 
224
  /* set the appropriate bits in the write bitset */
 
225
  table->setWriteSet(1);
 
226
  table->setWriteSet(2);
 
227
  table->setWriteSet(4);
 
228
  table->setWriteSet(5);
 
229
  table->setWriteSet(6);
 
230
  table->setWriteSet(7);
 
231
  table->field[1]->store(db_name->str, db_name->length, cs);
 
232
  table->field[2]->store(key_name, key_len, cs);
 
233
  table->field[4]->store(db_name->str, db_name->length, cs);
 
234
  table->field[5]->store(table_name->str, table_name->length, cs);
 
235
  table->field[6]->store(con_type, con_len, cs);
 
236
  table->field[7]->store((int64_t) idx, true);
 
237
}
 
238
 
 
239
/*
 
240
 * Function object used for deleting the memory allocated
 
241
 * for the columns contained with the vector of columns.
 
242
 */
 
243
class DeleteColumns
 
244
{
 
245
public:
 
246
  template<typename T>
 
247
  inline void operator()(const T *ptr) const
 
248
  {
 
249
    delete ptr;
 
250
  }
 
251
};
 
252
 
 
253
void clearColumns(vector<const drizzled::plugin::ColumnInfo *> &cols)
 
254
{
 
255
  for_each(cols.begin(), cols.end(), DeleteColumns());
 
256
  cols.clear();
 
257
}