~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to plugin/info_schema/helper_methods.cc

Merge trunk

Show diffs side-by-side

added added

removed removed

Lines of Context:
48
48
    *buf= my_toupper(system_charset_info, *buf);
49
49
}
50
50
 
51
 
bool show_status_array(Session *session, 
52
 
                       const char *wild,
53
 
                       SHOW_VAR *variables,
54
 
                       sql_var_t value_type,
55
 
                       struct system_status_var *status_var,
56
 
                       const char *prefix, Table *table,
57
 
                       bool ,
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
 
 
80
 
    /*
81
 
      if var->type is SHOW_FUNC, call the function.
82
 
      Repeat as necessary, if new var is again SHOW_FUNC
83
 
    */
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);
86
 
 
87
 
    SHOW_TYPE show_type=var->type;
88
 
    if (show_type == SHOW_ARRAY)
89
 
    {
90
 
      show_status_array(session, wild, (SHOW_VAR *) var->value, value_type,
91
 
                        status_var, name_buffer, table, false, schema_table);
92
 
    }
93
 
    else
94
 
    {
95
 
      if (!(wild && wild[0] && wild_case_compare(system_charset_info,
96
 
                                                 name_buffer, wild)))
97
 
      {
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);
101
 
 
102
 
        if (show_type == SHOW_SYS)
103
 
        {
104
 
          show_type= ((sys_var*) value)->show_type();
105
 
          value= (char*) ((sys_var*) value)->value_ptr(session, value_type,
106
 
                                                       &null_lex_str);
107
 
        }
108
 
 
109
 
        pos= end= buff;
110
 
        /*
111
 
          note that value may be == buff. All SHOW_xxx code below
112
 
          should still work in this case
113
 
        */
114
 
        switch (show_type) {
115
 
        case SHOW_DOUBLE_STATUS:
116
 
          value= ((char *) status_var + (ulong) value);
117
 
          /* fall through */
118
 
        case SHOW_DOUBLE:
119
 
          /* 6 is the default precision for '%f' in sprintf() */
120
 
          end= buff + internal::my_fcvt(*(double *) value, 6, buff, NULL);
121
 
          break;
122
 
        case SHOW_LONG_STATUS:
123
 
          value= ((char *) status_var + (ulong) value);
124
 
          /* fall through */
125
 
        case SHOW_LONG:
126
 
          end= internal::int10_to_str(*(long*) value, buff, 10);
127
 
          break;
128
 
        case SHOW_LONGLONG_STATUS:
129
 
          value= ((char *) status_var + (uint64_t) value);
130
 
          /* fall through */
131
 
        case SHOW_LONGLONG:
132
 
          end= internal::int64_t10_to_str(*(int64_t*) value, buff, 10);
133
 
          break;
134
 
        case SHOW_SIZE:
135
 
          {
136
 
            stringstream ss (stringstream::in);
137
 
            ss << *(size_t*) value;
138
 
 
139
 
            string str= ss.str();
140
 
            strncpy(buff, str.c_str(), str.length());
141
 
            end= buff+ str.length();
142
 
          }
143
 
          break;
144
 
        case SHOW_HA_ROWS:
145
 
          end= internal::int64_t10_to_str((int64_t) *(ha_rows*) value, buff, 10);
146
 
          break;
147
 
        case SHOW_BOOL:
148
 
          end+= sprintf(buff,"%s", *(bool*) value ? "ON" : "OFF");
149
 
          break;
150
 
        case SHOW_MY_BOOL:
151
 
          end+= sprintf(buff,"%s", *(bool*) value ? "ON" : "OFF");
152
 
          break;
153
 
        case SHOW_INT:
154
 
        case SHOW_INT_NOFLUSH: // the difference lies in refresh_status()
155
 
          end= internal::int10_to_str((long) *(uint32_t*) value, buff, 10);
156
 
          break;
157
 
        case SHOW_CHAR:
158
 
        {
159
 
          if (!(pos= value))
160
 
            pos= "";
161
 
          end= strchr(pos, '\0');
162
 
          break;
163
 
        }
164
 
       case SHOW_CHAR_PTR:
165
 
        {
166
 
          if (!(pos= *(char**) value))
167
 
            pos= "";
168
 
          end= strchr(pos, '\0');
169
 
          break;
170
 
        }
171
 
        case SHOW_KEY_CACHE_LONG:
172
 
          value= (char*) dflt_key_cache + (ulong)value;
173
 
          end= internal::int10_to_str(*(long*) value, buff, 10);
174
 
          break;
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);
178
 
          break;
179
 
        case SHOW_UNDEF:
180
 
          break;                                        // Return empty string
181
 
        case SHOW_SYS:                                  // Cannot happen
182
 
        default:
183
 
          assert(0);
184
 
          break;
185
 
        }
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();
194
 
 
195
 
        pthread_mutex_unlock(&LOCK_global_system_variables);
196
 
 
197
 
        schema_table->addRow(table->record[0], table->s->reclength);
198
 
      }
199
 
    }
200
 
  }
201
 
 
202
 
  return false;
203
 
}
204
 
 
205
51
void store_key_column_usage(Table *table, 
206
52
                            LEX_STRING *db_name,
207
53
                            LEX_STRING *table_name,