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.
26
#include "drizzled/server_includes.h"
27
#include "drizzled/session.h"
28
#include "drizzled/show.h"
29
#include "drizzled/tztime.h"
31
#include "helper_methods.h"
36
using namespace drizzled;
40
* Vectors of columns for the tables I_S table.
42
static vector<const plugin::ColumnInfo *> *columns= NULL;
45
* Methods for the tables I_S table.
47
static plugin::InfoSchemaMethods *methods= NULL;
52
static plugin::InfoSchemaTable *tbls_table= NULL;
55
* Populate the vectors of columns for the I_S table.
57
* @return a pointer to a std::vector of Columns.
59
vector<const plugin::ColumnInfo *> *TablesIS::createColumns()
63
columns= new vector<const plugin::ColumnInfo *>;
67
clearColumns(*columns);
70
columns->push_back(new plugin::ColumnInfo("TABLE_CATALOG",
78
columns->push_back(new plugin::ColumnInfo("TABLE_SCHEMA",
86
columns->push_back(new plugin::ColumnInfo("TABLE_NAME",
94
columns->push_back(new plugin::ColumnInfo("TABLE_TYPE",
102
columns->push_back(new plugin::ColumnInfo("ENGINE",
104
DRIZZLE_TYPE_VARCHAR,
110
columns->push_back(new plugin::ColumnInfo("VERSION",
111
MY_INT64_NUM_DECIMAL_DIGITS,
112
DRIZZLE_TYPE_LONGLONG,
114
(MY_I_S_MAYBE_NULL | MY_I_S_UNSIGNED),
118
columns->push_back(new plugin::ColumnInfo("ROW_FORMAT",
120
DRIZZLE_TYPE_VARCHAR,
126
columns->push_back(new plugin::ColumnInfo("TABLE_ROWS",
127
MY_INT64_NUM_DECIMAL_DIGITS,
128
DRIZZLE_TYPE_LONGLONG,
130
(MY_I_S_MAYBE_NULL | MY_I_S_UNSIGNED),
134
columns->push_back(new plugin::ColumnInfo("AVG_ROW_LENGTH",
135
MY_INT64_NUM_DECIMAL_DIGITS,
136
DRIZZLE_TYPE_LONGLONG,
138
(MY_I_S_MAYBE_NULL | MY_I_S_UNSIGNED),
142
columns->push_back(new plugin::ColumnInfo("DATA_LENGTH",
143
MY_INT64_NUM_DECIMAL_DIGITS,
144
DRIZZLE_TYPE_LONGLONG,
146
(MY_I_S_MAYBE_NULL | MY_I_S_UNSIGNED),
150
columns->push_back(new plugin::ColumnInfo("MAX_DATA_LENGTH",
151
MY_INT64_NUM_DECIMAL_DIGITS,
152
DRIZZLE_TYPE_LONGLONG,
154
(MY_I_S_MAYBE_NULL | MY_I_S_UNSIGNED),
158
columns->push_back(new plugin::ColumnInfo("INDEX_LENGTH",
159
MY_INT64_NUM_DECIMAL_DIGITS,
160
DRIZZLE_TYPE_LONGLONG,
162
(MY_I_S_MAYBE_NULL | MY_I_S_UNSIGNED),
166
columns->push_back(new plugin::ColumnInfo("DATA_FREE",
167
MY_INT64_NUM_DECIMAL_DIGITS,
168
DRIZZLE_TYPE_LONGLONG,
170
(MY_I_S_MAYBE_NULL | MY_I_S_UNSIGNED),
174
columns->push_back(new plugin::ColumnInfo("AUTO_INCREMENT",
175
MY_INT64_NUM_DECIMAL_DIGITS,
176
DRIZZLE_TYPE_LONGLONG,
178
(MY_I_S_MAYBE_NULL | MY_I_S_UNSIGNED),
182
columns->push_back(new plugin::ColumnInfo("CREATE_TIME",
184
DRIZZLE_TYPE_DATETIME,
190
columns->push_back(new plugin::ColumnInfo("UPDATE_TIME",
192
DRIZZLE_TYPE_DATETIME,
198
columns->push_back(new plugin::ColumnInfo("CHECK_TIME",
200
DRIZZLE_TYPE_DATETIME,
206
columns->push_back(new plugin::ColumnInfo("TABLE_COLLATION",
208
DRIZZLE_TYPE_VARCHAR,
214
columns->push_back(new plugin::ColumnInfo("CHECKSUM",
215
MY_INT64_NUM_DECIMAL_DIGITS,
216
DRIZZLE_TYPE_LONGLONG,
218
(MY_I_S_MAYBE_NULL | MY_I_S_UNSIGNED),
222
columns->push_back(new plugin::ColumnInfo("CREATE_OPTIONS",
224
DRIZZLE_TYPE_VARCHAR,
230
columns->push_back(new plugin::ColumnInfo("TABLE_COMMENT",
231
TABLE_COMMENT_MAXLEN,
232
DRIZZLE_TYPE_VARCHAR,
242
* Initialize the I_S table.
244
* @return a pointer to an I_S table
246
plugin::InfoSchemaTable *TablesIS::getTable()
248
columns= createColumns();
252
methods= new TablesISMethods();
255
if (tbls_table == NULL)
257
tbls_table= new plugin::InfoSchemaTable("TABLES",
268
* Delete memory allocated for the table, columns and methods.
270
void TablesIS::cleanup()
272
clearColumns(*columns);
278
int TablesISMethods::processTable(Session *session,
283
LEX_STRING *table_name) const
285
const char *tmp_buff= NULL;
287
const CHARSET_INFO * const cs= system_charset_info;
289
table->restoreRecordAsDefault();
290
table->field[1]->store(db_name->str, db_name->length, cs);
291
table->field[2]->store(table_name->str, table_name->length, cs);
295
there was errors during opening tables
297
const char *error= session->is_error() ? session->main_da.message() : "";
298
if (tables->schema_table)
300
table->field[3]->store(STRING_WITH_LEN("SYSTEM VIEW"), cs);
304
table->field[3]->store(STRING_WITH_LEN("BASE Table"), cs);
306
table->field[20]->store(error, strlen(error), cs);
307
session->clear_error();
311
char option_buff[400];
313
Table *show_table= tables->table;
314
TableShare *share= show_table->s;
315
Cursor *cursor= show_table->cursor;
316
drizzled::plugin::StorageEngine *tmp_db_type= share->db_type();
318
if (share->tmp_table == SYSTEM_TMP_TABLE)
320
table->field[3]->store(STRING_WITH_LEN("SYSTEM VIEW"), cs);
322
else if (share->tmp_table)
324
table->field[3]->store(STRING_WITH_LEN("LOCAL TEMPORARY"), cs);
328
table->field[3]->store(STRING_WITH_LEN("BASE Table"), cs);
331
for (int i= 4; i < 20; i++)
333
if (i == 7 || (i > 12 && i < 17) || i == 18)
337
table->field[i]->set_notnull();
339
const string &engine_name= drizzled::plugin::StorageEngine::resolveName(tmp_db_type);
340
table->field[4]->store(engine_name.c_str(), engine_name.size(), cs);
341
table->field[5]->store((int64_t) 0, true);
345
if (share->db_create_options & HA_OPTION_PACK_KEYS)
347
ptr= strcpy(ptr," pack_keys=1")+12;
349
if (share->db_create_options & HA_OPTION_NO_PACK_KEYS)
351
ptr= strcpy(ptr," pack_keys=0")+12;
353
if (share->row_type != ROW_TYPE_DEFAULT)
355
ptr+= sprintf(ptr, " row_format=%s", ha_row_type[(uint32_t)share->row_type]);
357
if (share->block_size)
359
ptr= strcpy(ptr, " block_size=")+12;
360
ptr= int64_t10_to_str(share->block_size, ptr, 10);
363
table->field[19]->store(option_buff+1,
364
(ptr == option_buff ? 0 :
365
(uint32_t) (ptr-option_buff)-1), cs);
367
tmp_buff= (share->table_charset ?
368
share->table_charset->name : "default");
369
table->field[17]->store(tmp_buff, strlen(tmp_buff), cs);
371
if (share->hasComment())
372
table->field[20]->store(share->getComment(),
373
share->getCommentLength(), cs);
377
cursor->info(HA_STATUS_VARIABLE |
381
enum row_type row_type = cursor->get_row_type();
384
case ROW_TYPE_NOT_USED:
385
case ROW_TYPE_DEFAULT:
386
tmp_buff= ((share->db_options_in_use &
387
HA_OPTION_COMPRESS_RECORD) ? "Compressed" :
388
(share->db_options_in_use & HA_OPTION_PACK_RECORD) ?
389
"Dynamic" : "Fixed");
394
case ROW_TYPE_DYNAMIC:
397
case ROW_TYPE_COMPRESSED:
398
tmp_buff= "Compressed";
400
case ROW_TYPE_REDUNDANT:
401
tmp_buff= "Redundant";
403
case ROW_TYPE_COMPACT:
410
table->field[6]->store(tmp_buff, strlen(tmp_buff), cs);
411
if (! tables->schema_table)
413
table->field[7]->store((int64_t) cursor->stats.records, true);
414
table->field[7]->set_notnull();
416
table->field[8]->store((int64_t) cursor->stats.mean_rec_length, true);
417
table->field[9]->store((int64_t) cursor->stats.data_file_length, true);
418
if (cursor->stats.max_data_file_length)
420
table->field[10]->store((int64_t) cursor->stats.max_data_file_length,
423
table->field[11]->store((int64_t) cursor->stats.index_file_length, true);
424
table->field[12]->store((int64_t) cursor->stats.delete_length, true);
425
if (show_table->found_next_number_field)
427
table->field[13]->store((int64_t) cursor->stats.auto_increment_value, true);
428
table->field[13]->set_notnull();
430
if (cursor->stats.create_time)
432
session->variables.time_zone->gmt_sec_to_TIME(&time,
433
(time_t) cursor->stats.create_time);
434
table->field[14]->store_time(&time, DRIZZLE_TIMESTAMP_DATETIME);
435
table->field[14]->set_notnull();
437
if (cursor->stats.update_time)
439
session->variables.time_zone->gmt_sec_to_TIME(&time,
440
(time_t) cursor->stats.update_time);
441
table->field[15]->store_time(&time, DRIZZLE_TIMESTAMP_DATETIME);
442
table->field[15]->set_notnull();
444
if (cursor->stats.check_time)
446
session->variables.time_zone->gmt_sec_to_TIME(&time,
447
(time_t) cursor->stats.check_time);
448
table->field[16]->store_time(&time, DRIZZLE_TIMESTAMP_DATETIME);
449
table->field[16]->set_notnull();
451
if (cursor->ha_table_flags() & (ulong) HA_HAS_CHECKSUM)
453
table->field[18]->store((int64_t) cursor->checksum(), true);
454
table->field[18]->set_notnull();
458
return (schema_table_store_record(session, table));