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
* tables I_S table methods.
27
#include "drizzled/session.h"
28
#include "drizzled/show.h"
29
#include "drizzled/tztime.h"
30
#include "drizzled/internal/m_string.h"
32
#include "helper_methods.h"
37
using namespace drizzled;
41
* Vectors of columns for the tables I_S table.
43
static vector<const plugin::ColumnInfo *> *columns= NULL;
46
* Methods for the tables I_S table.
48
static plugin::InfoSchemaMethods *methods= NULL;
53
static plugin::InfoSchemaTable *tbls_table= NULL;
56
* Populate the vectors of columns for the I_S table.
58
* @return a pointer to a std::vector of Columns.
60
vector<const plugin::ColumnInfo *> *TablesIS::createColumns()
64
columns= new vector<const plugin::ColumnInfo *>;
68
clearColumns(*columns);
71
columns->push_back(new plugin::ColumnInfo("TABLE_CATALOG",
78
columns->push_back(new plugin::ColumnInfo("TABLE_SCHEMA",
85
columns->push_back(new plugin::ColumnInfo("TABLE_NAME",
92
columns->push_back(new plugin::ColumnInfo("TABLE_TYPE",
99
columns->push_back(new plugin::ColumnInfo("ENGINE",
101
DRIZZLE_TYPE_VARCHAR,
106
columns->push_back(new plugin::ColumnInfo("VERSION",
107
MY_INT64_NUM_DECIMAL_DIGITS,
108
DRIZZLE_TYPE_LONGLONG,
110
(MY_I_S_MAYBE_NULL | MY_I_S_UNSIGNED),
113
columns->push_back(new plugin::ColumnInfo("ROW_FORMAT",
115
DRIZZLE_TYPE_VARCHAR,
120
columns->push_back(new plugin::ColumnInfo("TABLE_ROWS",
121
MY_INT64_NUM_DECIMAL_DIGITS,
122
DRIZZLE_TYPE_LONGLONG,
124
(MY_I_S_MAYBE_NULL | MY_I_S_UNSIGNED),
127
columns->push_back(new plugin::ColumnInfo("AVG_ROW_LENGTH",
128
MY_INT64_NUM_DECIMAL_DIGITS,
129
DRIZZLE_TYPE_LONGLONG,
131
(MY_I_S_MAYBE_NULL | MY_I_S_UNSIGNED),
134
columns->push_back(new plugin::ColumnInfo("DATA_LENGTH",
135
MY_INT64_NUM_DECIMAL_DIGITS,
136
DRIZZLE_TYPE_LONGLONG,
138
(MY_I_S_MAYBE_NULL | MY_I_S_UNSIGNED),
141
columns->push_back(new plugin::ColumnInfo("MAX_DATA_LENGTH",
142
MY_INT64_NUM_DECIMAL_DIGITS,
143
DRIZZLE_TYPE_LONGLONG,
145
(MY_I_S_MAYBE_NULL | MY_I_S_UNSIGNED),
148
columns->push_back(new plugin::ColumnInfo("INDEX_LENGTH",
149
MY_INT64_NUM_DECIMAL_DIGITS,
150
DRIZZLE_TYPE_LONGLONG,
152
(MY_I_S_MAYBE_NULL | MY_I_S_UNSIGNED),
155
columns->push_back(new plugin::ColumnInfo("DATA_FREE",
156
MY_INT64_NUM_DECIMAL_DIGITS,
157
DRIZZLE_TYPE_LONGLONG,
159
(MY_I_S_MAYBE_NULL | MY_I_S_UNSIGNED),
162
columns->push_back(new plugin::ColumnInfo("AUTO_INCREMENT",
163
MY_INT64_NUM_DECIMAL_DIGITS,
164
DRIZZLE_TYPE_LONGLONG,
166
(MY_I_S_MAYBE_NULL | MY_I_S_UNSIGNED),
169
columns->push_back(new plugin::ColumnInfo("CREATE_TIME",
171
DRIZZLE_TYPE_DATETIME,
176
columns->push_back(new plugin::ColumnInfo("UPDATE_TIME",
178
DRIZZLE_TYPE_DATETIME,
183
columns->push_back(new plugin::ColumnInfo("CHECK_TIME",
185
DRIZZLE_TYPE_DATETIME,
190
columns->push_back(new plugin::ColumnInfo("TABLE_COLLATION",
192
DRIZZLE_TYPE_VARCHAR,
197
columns->push_back(new plugin::ColumnInfo("CHECKSUM",
198
MY_INT64_NUM_DECIMAL_DIGITS,
199
DRIZZLE_TYPE_LONGLONG,
201
(MY_I_S_MAYBE_NULL | MY_I_S_UNSIGNED),
204
columns->push_back(new plugin::ColumnInfo("CREATE_OPTIONS",
206
DRIZZLE_TYPE_VARCHAR,
211
columns->push_back(new plugin::ColumnInfo("TABLE_COMMENT",
212
TABLE_COMMENT_MAXLEN,
213
DRIZZLE_TYPE_VARCHAR,
218
columns->push_back(new plugin::ColumnInfo("PLUGIN_NAME",
220
DRIZZLE_TYPE_VARCHAR,
229
* Initialize the I_S table.
231
* @return a pointer to an I_S table
233
plugin::InfoSchemaTable *TablesIS::getTable()
235
columns= createColumns();
239
methods= new TablesISMethods();
242
if (tbls_table == NULL)
244
tbls_table= new plugin::InfoSchemaTable("OLD_TABLES",
255
* Delete memory allocated for the table, columns and methods.
257
void TablesIS::cleanup()
259
clearColumns(*columns);
265
int TablesISMethods::processTable(plugin::InfoSchemaTable *store_table,
271
LEX_STRING *table_name)
273
const char *tmp_buff= NULL;
275
const CHARSET_INFO * const cs= system_charset_info;
277
table->restoreRecordAsDefault();
278
table->setWriteSet(1);
279
table->setWriteSet(2);
280
table->setWriteSet(3);
281
table->setWriteSet(4);
282
table->setWriteSet(5);
283
table->setWriteSet(6);
284
table->setWriteSet(7);
285
table->setWriteSet(8);
286
table->setWriteSet(9);
287
table->setWriteSet(11);
288
table->setWriteSet(12);
289
table->setWriteSet(13);
290
table->setWriteSet(14);
291
table->setWriteSet(15);
292
table->setWriteSet(16);
293
table->setWriteSet(17);
294
table->setWriteSet(18);
295
table->setWriteSet(19);
296
table->setWriteSet(20);
297
table->setWriteSet(21);
298
table->field[1]->store(db_name->str, db_name->length, cs);
299
table->field[2]->store(table_name->str, table_name->length, cs);
304
there was errors during opening tables
306
const char *error= session->is_error() ? session->main_da.message() : "";
307
table->field[3]->store(STRING_WITH_LEN("BASE Table"), cs);
308
table->field[20]->store(error, strlen(error), cs);
309
session->clear_error();
313
char option_buff[400];
315
Table *show_table= tables->table;
316
TableShare *share= show_table->s;
317
Cursor *cursor= show_table->cursor;
318
drizzled::plugin::StorageEngine *tmp_db_type= share->db_type();
320
if (share->tmp_table == SYSTEM_TMP_TABLE)
322
table->field[3]->store(STRING_WITH_LEN("SYSTEM VIEW"), cs);
324
else if (share->tmp_table)
326
table->field[3]->store(STRING_WITH_LEN("LOCAL TEMPORARY"), cs);
330
table->field[3]->store(STRING_WITH_LEN("BASE Table"), cs);
333
for (int i= 4; i < 20; i++)
335
if (i == 7 || (i > 12 && i < 17) || i == 18)
339
table->field[i]->set_notnull();
341
const string &engine_name= drizzled::plugin::StorageEngine::resolveName(tmp_db_type);
342
table->field[4]->store(engine_name.c_str(), engine_name.size(), cs);
343
table->field[5]->store((int64_t) 0, true);
347
if (share->db_create_options & HA_OPTION_PACK_KEYS)
349
ptr= strcpy(ptr," pack_keys=1")+12;
351
if (share->db_create_options & HA_OPTION_NO_PACK_KEYS)
353
ptr= strcpy(ptr," pack_keys=0")+12;
355
if (share->row_type != ROW_TYPE_DEFAULT)
357
ptr+= sprintf(ptr, " row_format=%s", ha_row_type[(uint32_t)share->row_type]);
359
if (share->block_size)
361
ptr= strcpy(ptr, " block_size=")+12;
362
ptr= int64_t10_to_str(share->block_size, ptr, 10);
365
table->field[19]->store(option_buff+1,
366
(ptr == option_buff ? 0 :
367
(uint32_t) (ptr-option_buff)-1), cs);
369
tmp_buff= (share->table_charset ?
370
share->table_charset->name : "default");
371
table->field[17]->store(tmp_buff, strlen(tmp_buff), cs);
373
if (share->hasComment())
374
table->field[20]->store(share->getComment(),
375
share->getCommentLength(), cs);
377
drizzled::plugin::InfoSchemaTable *tmp_table=
378
drizzled::plugin::InfoSchemaTable::getTable(table_name->str);
380
if (tmp_table != NULL)
382
const std::string &plugin_name= tmp_table->getPluginName();
384
if (! plugin_name.empty())
386
table->field[21]->set_notnull();
387
table->field[21]->store(plugin_name.c_str(), plugin_name.size(), cs);
393
cursor->info(HA_STATUS_VARIABLE |
397
enum row_type row_type = cursor->get_row_type();
400
case ROW_TYPE_NOT_USED:
401
case ROW_TYPE_DEFAULT:
402
tmp_buff= ((share->db_options_in_use &
403
HA_OPTION_COMPRESS_RECORD) ? "Compressed" :
404
(share->db_options_in_use & HA_OPTION_PACK_RECORD) ?
405
"Dynamic" : "Fixed");
410
case ROW_TYPE_DYNAMIC:
413
case ROW_TYPE_COMPRESSED:
414
tmp_buff= "Compressed";
416
case ROW_TYPE_REDUNDANT:
417
tmp_buff= "Redundant";
419
case ROW_TYPE_COMPACT:
426
table->field[6]->store(tmp_buff, strlen(tmp_buff), cs);
427
table->field[7]->store((int64_t) cursor->stats.records, true);
428
table->field[7]->set_notnull();
429
table->field[8]->store((int64_t) cursor->stats.mean_rec_length, true);
430
table->field[9]->store((int64_t) cursor->stats.data_file_length, true);
431
if (cursor->stats.max_data_file_length)
433
table->field[10]->store((int64_t) cursor->stats.max_data_file_length,
436
table->field[11]->store((int64_t) cursor->stats.index_file_length, true);
437
table->field[12]->store((int64_t) cursor->stats.delete_length, true);
438
if (show_table->found_next_number_field)
440
table->field[13]->store((int64_t) cursor->stats.auto_increment_value, true);
441
table->field[13]->set_notnull();
443
if (cursor->stats.create_time)
445
session->variables.time_zone->gmt_sec_to_TIME(&time,
446
(time_t) cursor->stats.create_time);
447
table->field[14]->store_time(&time, DRIZZLE_TIMESTAMP_DATETIME);
448
table->field[14]->set_notnull();
450
if (cursor->stats.update_time)
452
session->variables.time_zone->gmt_sec_to_TIME(&time,
453
(time_t) cursor->stats.update_time);
454
table->field[15]->store_time(&time, DRIZZLE_TIMESTAMP_DATETIME);
455
table->field[15]->set_notnull();
457
if (cursor->stats.check_time)
459
session->variables.time_zone->gmt_sec_to_TIME(&time,
460
(time_t) cursor->stats.check_time);
461
table->field[16]->store_time(&time, DRIZZLE_TIMESTAMP_DATETIME);
462
table->field[16]->set_notnull();
464
if (cursor->getEngine()->check_flag(HTON_BIT_HAS_CHECKSUM))
466
table->field[18]->store((int64_t) cursor->checksum(), true);
467
table->field[18]->set_notnull();
471
store_table->addRow(table->record[0], table->s->reclength);