~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to plugin/show_dictionary/show_indexes.cc

  • Committer: Brian Aker
  • Date: 2010-12-18 18:24:57 UTC
  • mfrom: (1999.6.3 trunk)
  • Revision ID: brian@tangent.org-20101218182457-yi1wd0so2hml1k1w
Merge in Lee's copyright header fix

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* - mode: c; c-basic-offset: 2; indent-tabs-mode: nil; -*-
 
2
 *  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
 
3
 *
 
4
 *  Copyright (C) 2010 Brian Aker
 
5
 *
 
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.
 
10
 *
 
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.
 
15
 *
 
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
 
19
 */
 
20
 
 
21
#include "config.h"
 
22
#include "plugin/show_dictionary/dictionary.h"
 
23
#include "drizzled/identifier.h"
 
24
 
 
25
 
 
26
using namespace std;
 
27
using namespace drizzled;
 
28
 
 
29
ShowIndexes::ShowIndexes() :
 
30
  show_dictionary::Show("SHOW_INDEXES")
 
31
{
 
32
  add_field("Table");
 
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");
 
37
}
 
38
 
 
39
ShowIndexes::Generator::Generator(Field **arg) :
 
40
  show_dictionary::Show::Generator(arg),
 
41
  is_tables_primed(false),
 
42
  is_index_primed(false),
 
43
  is_index_part_primed(false),
 
44
  index_iterator(0),
 
45
  index_part_iterator(0)
 
46
{
 
47
  statement::Show *select= static_cast<statement::Show *>(getSession().lex->statement);
 
48
 
 
49
  if (not select->getShowTable().empty() && not select->getShowSchema().empty())
 
50
  {
 
51
    table_name.append(select->getShowTable().c_str());
 
52
    TableIdentifier identifier(select->getShowSchema().c_str(), select->getShowTable().c_str());
 
53
 
 
54
    is_tables_primed= plugin::StorageEngine::getTableDefinition(getSession(),
 
55
                                                                identifier,
 
56
                                                                table_proto);
 
57
  }
 
58
}
 
59
 
 
60
bool ShowIndexes::Generator::nextIndexCore()
 
61
{
 
62
  if (isIndexesPrimed())
 
63
  {
 
64
    index_iterator++;
 
65
  }
 
66
  else
 
67
  {
 
68
    if (not isTablesPrimed())
 
69
      return false;
 
70
 
 
71
    index_iterator= 0;
 
72
    is_index_primed= true;
 
73
  }
 
74
 
 
75
  if (index_iterator >= getTableProto().indexes_size())
 
76
    return false;
 
77
 
 
78
  index= getTableProto().indexes(index_iterator);
 
79
 
 
80
  return true;
 
81
}
 
82
 
 
83
bool ShowIndexes::Generator::nextIndex()
 
84
{
 
85
  while (not nextIndexCore())
 
86
  {
 
87
    return false;
 
88
  }
 
89
 
 
90
  return true;
 
91
}
 
92
 
 
93
bool ShowIndexes::Generator::nextIndexPartsCore()
 
94
{
 
95
  if (is_index_part_primed)
 
96
  {
 
97
    index_part_iterator++;
 
98
  }
 
99
  else
 
100
  {
 
101
    if (not isIndexesPrimed())
 
102
      return false;
 
103
 
 
104
    index_part_iterator= 0;
 
105
    is_index_part_primed= true;
 
106
  }
 
107
 
 
108
  if (index_part_iterator >= getIndex().index_part_size())
 
109
    return false;
 
110
 
 
111
  index_part= getIndex().index_part(index_part_iterator);
 
112
 
 
113
  return true;
 
114
}
 
115
 
 
116
 
 
117
bool ShowIndexes::Generator::nextIndexParts()
 
118
{
 
119
  while (not nextIndexPartsCore())
 
120
  {
 
121
    if (not nextIndex())
 
122
      return false;
 
123
    is_index_part_primed= false;
 
124
  }
 
125
 
 
126
  return true;
 
127
}
 
128
 
 
129
 
 
130
 
 
131
bool ShowIndexes::Generator::populate()
 
132
{
 
133
  if (not nextIndexParts())
 
134
    return false;
 
135
 
 
136
  fill();
 
137
 
 
138
  return true;
 
139
}
 
140
 
 
141
void ShowIndexes::Generator::fill()
 
142
{
 
143
  /* Table */
 
144
  push(getTableName());
 
145
 
 
146
  /* Unique */
 
147
  push(getIndex().is_unique());
 
148
 
 
149
  /* Key_name */
 
150
  push(getIndex().name());
 
151
 
 
152
  /* Seq_in_index */
 
153
  push(static_cast<int64_t>(index_part_iterator + 1));
 
154
 
 
155
  /* Column_name */
 
156
  push(getTableProto().field(getIndexPart().fieldnr()).name());
 
157
}