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
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/table_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");
33
static const string DEFAULT("DEFAULT");
34
static const string FIXED("FIXED");
35
static const string DYNAMIC("DYNAMIC");
36
static const string COMPRESSED("COMPRESSED");
37
static const string REDUNDANT("REDUNDANT");
38
static const string COMPACT("COMPACT");
39
static const string PAGE("PAGE");
41
static const string VARCHAR("VARCHAR");
42
static const string DOUBLE("DOUBLE");
43
static const string BLOB("BLOB");
44
static const string ENUM("ENUM");
45
static const string INTEGER("INTEGER");
46
static const string BIGINT("BIGINT");
47
static const string DECIMAL("DECIMAL");
48
static const string DATE("DATE");
49
static const string TIMESTAMP("TIMESTAMP");
50
static const string DATETIME("DATETIME");
52
TablesTool::TablesTool() :
55
add_field("TABLE_SCHEMA");
56
add_field("TABLE_NAME");
57
add_field("TABLE_TYPE");
59
add_field("ROW_FORMAT", 10);
60
add_field("TABLE_COLLATION");
61
add_field("TABLE_CREATION_TIME");
62
add_field("TABLE_UPDATE_TIME");
63
add_field("TABLE_COMMENT", 2048);
66
TablesTool::Generator::Generator(Field **arg) :
67
SchemasTool::Generator(arg),
68
is_tables_primed(false)
72
bool TablesTool::Generator::nextTableCore()
80
if (not isSchemaPrimed())
84
SchemaIdentifier identifier(schema_name());
85
plugin::StorageEngine::getTableNames(getSession(), identifier, table_names);
86
table_iterator= table_names.begin();
87
is_tables_primed= true;
90
if (table_iterator == table_names.end())
95
TableIdentifier identifier(schema_name().c_str(), table_name().c_str());
96
plugin::StorageEngine::getTableDefinition(getSession(),
104
bool TablesTool::Generator::nextTable()
106
while (not nextTableCore())
109
if (is_tables_primed && table_iterator != table_names.end())
112
if (not nextSchema())
115
is_tables_primed= false;
121
bool TablesTool::Generator::populate()
131
void TablesTool::Generator::pushRow(message::Table::TableOptions::RowType type)
136
case message::Table::TableOptions::ROW_TYPE_DEFAULT:
139
case message::Table::TableOptions::ROW_TYPE_FIXED:
142
case message::Table::TableOptions::ROW_TYPE_DYNAMIC:
145
case message::Table::TableOptions::ROW_TYPE_COMPRESSED:
148
case message::Table::TableOptions::ROW_TYPE_REDUNDANT:
151
case message::Table::TableOptions::ROW_TYPE_COMPACT:
154
case message::Table::TableOptions::ROW_TYPE_PAGE:
160
void TablesTool::Generator::pushType(message::Table::Field::FieldType type)
165
case message::Table::Field::VARCHAR:
168
case message::Table::Field::DOUBLE:
171
case message::Table::Field::BLOB:
174
case message::Table::Field::ENUM:
177
case message::Table::Field::INTEGER:
180
case message::Table::Field::BIGINT:
183
case message::Table::Field::DECIMAL:
186
case message::Table::Field::DATE:
189
case message::Table::Field::TIMESTAMP:
192
case message::Table::Field::DATETIME:
198
void TablesTool::Generator::fill()
202
@note use --replace-column
206
push(table_proto.schema());
209
push(table_proto.name());
213
switch (table_proto.type())
216
case message::Table::STANDARD:
219
case message::Table::TEMPORARY:
222
case message::Table::INTERNAL:
225
case message::Table::FUNCTION:
232
push(table_proto.engine().name());
235
pushRow(table_proto.options().row_type());
237
/* TABLE_COLLATION */
238
push(table_proto.options().collation());
240
/* TABLE_CREATION_TIME */
241
time_t time_arg= table_proto.creation_timestamp();
245
localtime_r(&time_arg, &tm_buffer);
246
strftime(buffer, sizeof(buffer), "%a %b %d %H:%M:%S %Y", &tm_buffer);
249
/* TABLE_UPDATE_TIME */
250
time_arg= table_proto.update_timestamp();
251
localtime_r(&time_arg, &tm_buffer);
252
strftime(buffer, sizeof(buffer), "%a %b %d %H:%M:%S %Y", &tm_buffer);
256
push(table_proto.options().comment());