1
/* - mode: c; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
* vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
4
* Copyright (C) 2010 Sun Microsystems, Inc.
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
22
#include "plugin/schema_dictionary/dictionary.h"
23
#include "drizzled/identifier.h"
26
using namespace drizzled;
28
static const string STANDARD("STANDARD");
29
static const string TEMPORARY("TEMPORARY");
30
static const string INTERNAL("INTERNAL");
31
static const string FUNCTION("FUNCTION");
34
static const string VARCHAR("VARCHAR");
35
static const string DOUBLE("DOUBLE");
36
static const string BLOB("BLOB");
37
static const string ENUM("ENUM");
38
static const string INTEGER("INTEGER");
39
static const string BIGINT("BIGINT");
40
static const string DECIMAL("DECIMAL");
41
static const string DATE("DATE");
42
static const string TIMESTAMP("TIMESTAMP");
43
static const string DATETIME("DATETIME");
45
TablesTool::TablesTool() :
46
plugin::TableFunction("DATA_DICTIONARY", "TABLES")
48
add_field("TABLE_SCHEMA");
49
add_field("TABLE_NAME");
50
add_field("TABLE_TYPE");
51
add_field("TABLE_ARCHETYPE");
53
add_field("ROW_FORMAT", 10);
54
add_field("TABLE_COLLATION");
55
add_field("TABLE_CREATION_TIME");
56
add_field("TABLE_UPDATE_TIME");
57
add_field("TABLE_COMMENT", plugin::TableFunction::STRING, 2048, true);
58
add_field("AUTO_INCREMENT", plugin::TableFunction::NUMBER, 0, false);
59
add_field("TABLE_UUID", plugin::TableFunction::STRING, 36, true);
60
add_field("TABLE_VERSION", plugin::TableFunction::NUMBER, 0, true);
63
TablesTool::Generator::Generator(Field **arg) :
64
plugin::TableFunction::Generator(arg),
65
all_tables_generator(getSession())
69
bool TablesTool::Generator::nextTable()
71
drizzled::message::table::shared_ptr table_ptr;
72
while ((table_ptr= all_tables_generator))
74
table_message.CopyFrom(*table_ptr);
81
bool TablesTool::Generator::populate()
92
void TablesTool::Generator::fill()
96
@note use --replace-column
100
push(getTableMessage().schema());
103
push(getTableMessage().name());
106
if (drizzled::identifier::Table::isView(getTableMessage().type()))
115
/* TABLE_ARCHETYPE */
117
switch (getTableMessage().type())
120
case message::Table::STANDARD:
123
case message::Table::TEMPORARY:
126
case message::Table::INTERNAL:
129
case message::Table::FUNCTION:
136
const drizzled::message::Engine &engine= getTableMessage().engine();
140
bool row_format_sent= false;
141
for (ssize_t it= 0; it < engine.options_size(); it++)
143
const drizzled::message::Engine::Option &opt= engine.options(it);
144
if (opt.name().compare("ROW_FORMAT") == 0)
146
row_format_sent= true;
152
if (not row_format_sent)
155
/* TABLE_COLLATION */
156
push(getTableMessage().options().collation());
158
/* TABLE_CREATION_TIME */
159
time_t time_arg= getTableMessage().creation_timestamp();
163
localtime_r(&time_arg, &tm_buffer);
164
strftime(buffer, sizeof(buffer), "%a %b %d %H:%M:%S %Y", &tm_buffer);
167
/* TABLE_UPDATE_TIME */
168
time_arg= getTableMessage().update_timestamp();
169
localtime_r(&time_arg, &tm_buffer);
170
strftime(buffer, sizeof(buffer), "%a %b %d %H:%M:%S %Y", &tm_buffer);
174
if (getTableMessage().options().has_comment())
176
push(getTableMessage().options().comment());
184
push(getTableMessage().options().auto_increment_value());
187
push(getTableMessage().uuid());
190
push(getTableMessage().version());