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
ShowIndexes::ShowIndexes() :
30
plugin::TableFunction("DATA_DICTIONARY", "SHOW_INDEXES")
33
add_field("Unique", plugin::TableFunction::BOOLEAN, 0, false);
34
add_field("Key_name");
35
add_field("Seq_in_index", plugin::TableFunction::NUMBER, 0, false);
36
add_field("Column_name");
39
ShowIndexes::Generator::Generator(Field **arg) :
40
plugin::TableFunction::Generator(arg),
41
is_tables_primed(false),
42
is_index_primed(false),
43
is_index_part_primed(false),
45
index_part_iterator(0)
47
statement::Select *select= static_cast<statement::Select *>(getSession().lex->statement);
49
if (not select->getShowTable().empty() && not select->getShowSchema().empty())
51
table_name.append(select->getShowTable().c_str());
52
TableIdentifier identifier(select->getShowSchema().c_str(), select->getShowTable().c_str());
54
is_tables_primed= plugin::StorageEngine::getTableDefinition(getSession(),
60
bool ShowIndexes::Generator::nextIndexCore()
62
if (isIndexesPrimed())
68
if (not isTablesPrimed())
72
is_index_primed= true;
75
if (index_iterator >= getTableProto().indexes_size())
78
index= getTableProto().indexes(index_iterator);
83
bool ShowIndexes::Generator::nextIndex()
85
while (not nextIndexCore())
93
bool ShowIndexes::Generator::nextIndexPartsCore()
95
if (is_index_part_primed)
97
index_part_iterator++;
101
if (not isIndexesPrimed())
104
index_part_iterator= 0;
105
is_index_part_primed= true;
108
if (index_part_iterator >= getIndex().index_part_size())
111
index_part= getIndex().index_part(index_part_iterator);
117
bool ShowIndexes::Generator::nextIndexParts()
119
while (not nextIndexPartsCore())
123
is_index_part_primed= false;
131
bool ShowIndexes::Generator::populate()
133
if (not nextIndexParts())
141
void ShowIndexes::Generator::fill()
144
push(getTableName());
147
push(getIndex().is_unique());
150
push(getIndex().name());
153
push(static_cast<int64_t>(index_part_iterator + 1));
156
push(getTableProto().field(getIndexPart().fieldnr()).name());