1
/* - mode: c; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
* vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
4
* Copyright (C) 2010 Brian Aker
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/show_dictionary/dictionary.h"
23
#include "drizzled/identifier.h"
27
using namespace drizzled;
29
static const string VARCHAR("VARCHAR");
30
/* VARBINARY already defined elsewhere */
31
static const string VARBIN("VARBINARY");
32
static const string DOUBLE("DOUBLE");
33
static const string BLOB("BLOB");
34
static const string TEXT("TEXT");
35
static const string ENUM("ENUM");
36
static const string INTEGER("INTEGER");
37
static const string BIGINT("BIGINT");
38
static const string DECIMAL("DECIMAL");
39
static const string DATE("DATE");
40
static const string TIMESTAMP("TIMESTAMP");
41
static const string DATETIME("DATETIME");
43
ShowColumns::ShowColumns() :
44
plugin::TableFunction("DATA_DICTIONARY", "SHOW_COLUMNS")
48
add_field("Null", plugin::TableFunction::BOOLEAN, 0 , false);
50
add_field("Default_is_NULL", plugin::TableFunction::BOOLEAN, 0, false);
51
add_field("On_Update");
54
ShowColumns::Generator::Generator(Field **arg) :
55
plugin::TableFunction::Generator(arg),
56
is_tables_primed(false),
57
is_columns_primed(false),
60
statement::Select *select= static_cast<statement::Select *>(getSession().lex->statement);
62
if (not select->getShowTable().empty() && not select->getShowSchema().empty())
64
table_name.append(select->getShowTable().c_str());
65
TableIdentifier identifier(select->getShowSchema().c_str(), select->getShowTable().c_str());
67
is_tables_primed= plugin::StorageEngine::getTableDefinition(getSession(),
73
bool ShowColumns::Generator::nextColumnCore()
75
if (is_columns_primed)
81
if (not isTablesPrimed())
85
is_columns_primed= true;
88
if (column_iterator >= getTableProto().field_size())
91
column= getTableProto().field(column_iterator);
97
bool ShowColumns::Generator::nextColumn()
99
while (not nextColumnCore())
107
bool ShowColumns::Generator::populate()
110
if (not nextColumn())
118
void ShowColumns::Generator::pushType(message::Table::Field::FieldType type, const string collation)
123
case message::Table::Field::VARCHAR:
124
push(collation.compare("binary") ? VARCHAR : VARBIN);
126
case message::Table::Field::DOUBLE:
129
case message::Table::Field::BLOB:
130
push(collation.compare("binary") ? TEXT : BLOB);
132
case message::Table::Field::ENUM:
135
case message::Table::Field::INTEGER:
138
case message::Table::Field::BIGINT:
141
case message::Table::Field::DECIMAL:
144
case message::Table::Field::DATE:
147
case message::Table::Field::TIMESTAMP:
150
case message::Table::Field::DATETIME:
157
void ShowColumns::Generator::fill()
163
pushType(column.type(), column.string_options().collation());
166
push(column.constraints().is_nullable());
169
if (column.options().has_default_value())
170
push(column.options().default_value());
171
else if (column.options().has_default_expression())
172
push(column.options().default_expression());
174
push(column.options().default_bin_value());
176
/* Default_is_NULL */
177
push(column.options().default_null());
180
push(column.options().update_expression());