~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to plugin/info_schema/info_schema_methods.cc

Merging in Padraig's final I_S plugin work.

Show diffs side-by-side

added added

removed removed

Lines of Context:
36
36
 
37
37
using namespace std;
38
38
 
 
39
static inline void make_upper(char *buf)
 
40
{
 
41
  for (; *buf; buf++)
 
42
    *buf= my_toupper(system_charset_info, *buf);
 
43
}
 
44
 
 
45
static bool show_status_array(Session *session, const char *wild,
 
46
                              SHOW_VAR *variables,
 
47
                              enum enum_var_type value_type,
 
48
                              struct system_status_var *status_var,
 
49
                              const char *prefix, Table *table,
 
50
                              bool ucase_names)
 
51
{
 
52
  MY_ALIGNED_BYTE_ARRAY(buff_data, SHOW_VAR_FUNC_BUFF_SIZE, int64_t);
 
53
  char * const buff= (char *) &buff_data;
 
54
  char *prefix_end;
 
55
  /* the variable name should not be longer than 64 characters */
 
56
  char name_buffer[64];
 
57
  int len;
 
58
  SHOW_VAR tmp, *var;
 
59
 
 
60
  prefix_end= strncpy(name_buffer, prefix, sizeof(name_buffer)-1);
 
61
  prefix_end+= strlen(prefix);
 
62
 
 
63
  if (*prefix)
 
64
    *prefix_end++= '_';
 
65
  len=name_buffer + sizeof(name_buffer) - prefix_end;
 
66
 
 
67
  for (; variables->name; variables++)
 
68
  {
 
69
    strncpy(prefix_end, variables->name, len);
 
70
    name_buffer[sizeof(name_buffer)-1]=0;       /* Safety */
 
71
    if (ucase_names)
 
72
      make_upper(name_buffer);
 
73
 
 
74
    /*
 
75
      if var->type is SHOW_FUNC, call the function.
 
76
      Repeat as necessary, if new var is again SHOW_FUNC
 
77
    */
 
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);
 
80
 
 
81
    SHOW_TYPE show_type=var->type;
 
82
    if (show_type == SHOW_ARRAY)
 
83
    {
 
84
      show_status_array(session, wild, (SHOW_VAR *) var->value, value_type,
 
85
                        status_var, name_buffer, table, ucase_names);
 
86
    }
 
87
    else
 
88
    {
 
89
      if (!(wild && wild[0] && wild_case_compare(system_charset_info,
 
90
                                                 name_buffer, wild)))
 
91
      {
 
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);
 
95
 
 
96
        if (show_type == SHOW_SYS)
 
97
        {
 
98
          show_type= ((sys_var*) value)->show_type();
 
99
          value= (char*) ((sys_var*) value)->value_ptr(session, value_type,
 
100
                                                       &null_lex_str);
 
101
        }
 
102
 
 
103
        pos= end= buff;
 
104
        /*
 
105
          note that value may be == buff. All SHOW_xxx code below
 
106
          should still work in this case
 
107
        */
 
108
        switch (show_type) {
 
109
        case SHOW_DOUBLE_STATUS:
 
110
          value= ((char *) status_var + (ulong) value);
 
111
          /* fall through */
 
112
        case SHOW_DOUBLE:
 
113
          /* 6 is the default precision for '%f' in sprintf() */
 
114
          end= buff + my_fcvt(*(double *) value, 6, buff, NULL);
 
115
          break;
 
116
        case SHOW_LONG_STATUS:
 
117
          value= ((char *) status_var + (ulong) value);
 
118
          /* fall through */
 
119
        case SHOW_LONG:
 
120
          end= int10_to_str(*(long*) value, buff, 10);
 
121
          break;
 
122
        case SHOW_LONGLONG_STATUS:
 
123
          value= ((char *) status_var + (uint64_t) value);
 
124
          /* fall through */
 
125
        case SHOW_LONGLONG:
 
126
          end= int64_t10_to_str(*(int64_t*) value, buff, 10);
 
127
          break;
 
128
        case SHOW_SIZE:
 
129
          {
 
130
            stringstream ss (stringstream::in);
 
131
            ss << *(size_t*) value;
 
132
 
 
133
            string str= ss.str();
 
134
            strncpy(buff, str.c_str(), str.length());
 
135
            end= buff+ str.length();
 
136
          }
 
137
          break;
 
138
        case SHOW_HA_ROWS:
 
139
          end= int64_t10_to_str((int64_t) *(ha_rows*) value, buff, 10);
 
140
          break;
 
141
        case SHOW_BOOL:
 
142
          end+= sprintf(buff,"%s", *(bool*) value ? "ON" : "OFF");
 
143
          break;
 
144
        case SHOW_MY_BOOL:
 
145
          end+= sprintf(buff,"%s", *(bool*) value ? "ON" : "OFF");
 
146
          break;
 
147
        case SHOW_INT:
 
148
        case SHOW_INT_NOFLUSH: // the difference lies in refresh_status()
 
149
          end= int10_to_str((long) *(uint32_t*) value, buff, 10);
 
150
          break;
 
151
        case SHOW_HAVE:
 
152
        {
 
153
          SHOW_COMP_OPTION tmp_option= *(SHOW_COMP_OPTION *)value;
 
154
          pos= show_comp_option_name[(int) tmp_option];
 
155
          end= strchr(pos, '\0');
 
156
          break;
 
157
        }
 
158
        case SHOW_CHAR:
 
159
        {
 
160
          if (!(pos= value))
 
161
            pos= "";
 
162
          end= strchr(pos, '\0');
 
163
          break;
 
164
        }
 
165
       case SHOW_CHAR_PTR:
 
166
        {
 
167
          if (!(pos= *(char**) value))
 
168
            pos= "";
 
169
          end= strchr(pos, '\0');
 
170
          break;
 
171
        }
 
172
        case SHOW_KEY_CACHE_LONG:
 
173
          value= (char*) dflt_key_cache + (ulong)value;
 
174
          end= int10_to_str(*(long*) value, buff, 10);
 
175
          break;
 
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);
 
179
          break;
 
180
        case SHOW_UNDEF:
 
181
          break;                                        // Return empty string
 
182
        case SHOW_SYS:                                  // Cannot happen
 
183
        default:
 
184
          assert(0);
 
185
          break;
 
186
        }
 
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();
 
192
 
 
193
        pthread_mutex_unlock(&LOCK_global_system_variables);
 
194
 
 
195
        if (schema_table_store_record(session, table))
 
196
          return true;
 
197
      }
 
198
    }
 
199
  }
 
200
 
 
201
  return false;
 
202
}
 
203
 
39
204
int CharSetISMethods::fillTable(Session *session, TableList *tables, COND *)
40
205
{
41
206
  CHARSET_INFO **cs;
785
950
  return(res);
786
951
}
787
952
 
 
953
int StatusISMethods::fillTable(Session *session, TableList *tables, COND *)
 
954
{
 
955
  LEX *lex= session->lex;
 
956
  const char *wild= lex->wild ? lex->wild->ptr() : NULL;
 
957
  int res= 0;
 
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);
 
962
 
 
963
  if (schema_table_name.compare("STATUS") == 0)
 
964
  {
 
965
    option_type= lex->option_type;
 
966
    if (option_type == OPT_GLOBAL)
 
967
      tmp1= &tmp;
 
968
    else
 
969
      tmp1= session->initial_status_var;
 
970
  }
 
971
  else if (schema_table_name.compare("GLOBAL_STATUS") == 0)
 
972
  {
 
973
    option_type= OPT_GLOBAL;
 
974
    tmp1= &tmp;
 
975
  }
 
976
  else
 
977
  {
 
978
    option_type= OPT_SESSION;
 
979
    tmp1= &session->status_var;
 
980
  }
 
981
 
 
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,
 
988
                         upper_case_names);
 
989
  pthread_mutex_unlock(&LOCK_status);
 
990
  return(res);
 
991
}
 
992
 
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)
1117
1322
  }
1118
1323
  return 0;
1119
1324
}
 
1325
 
 
1326
int VariablesISMethods::fillTable(Session *session, TableList *tables, COND *)
 
1327
{
 
1328
  int res= 0;
 
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);
 
1335
 
 
1336
  if (lex->option_type == OPT_GLOBAL ||
 
1337
      schema_table_name.compare("GLOBAL_VARIABLES") == 0)
 
1338
  {
 
1339
    option_type= OPT_GLOBAL;
 
1340
  }
 
1341
 
 
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);
 
1346
  return(res);
 
1347
}
 
1348