~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to plugin/schema_dictionary/index_parts.cc

  • Committer: Brian Aker
  • Date: 2010-02-11 22:56:25 UTC
  • Revision ID: brian@gaz-20100211225625-63v3e79p78blva2u
Remove WEIGHT_STRING() from parser (where it does not belong). If someone
wants to they can reimplement this as a straight function.

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 Sun Microsystems
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/schema_dictionary/dictionary.h"
23
 
#include "drizzled/statement/select.h"
24
 
 
25
 
using namespace std;
26
 
using namespace drizzled;
27
 
 
28
 
IndexPartsTool::IndexPartsTool() :
29
 
  IndexesTool("INDEX_PARTS")
30
 
{
31
 
  add_field("TABLE_SCHEMA");
32
 
  add_field("TABLE_NAME");
33
 
  add_field("INDEX_NAME");
34
 
  add_field("COLUMN_NAME");
35
 
  add_field("COLUMN_NUMBER", plugin::TableFunction::NUMBER);
36
 
  add_field("SEQUENCE_IN_INDEX", plugin::TableFunction::NUMBER);
37
 
  add_field("COMPARE_LENGTH", plugin::TableFunction::NUMBER);
38
 
  add_field("IS_ORDER_REVERSE", plugin::TableFunction::BOOLEAN);
39
 
  add_field("IS_USED_IN_PRIMARY", plugin::TableFunction::BOOLEAN);
40
 
  add_field("IS_UNIQUE", plugin::TableFunction::BOOLEAN);
41
 
  add_field("IS_NULLABLE", plugin::TableFunction::BOOLEAN);
42
 
}
43
 
 
44
 
IndexPartsTool::Generator::Generator(Field **arg) :
45
 
  IndexesTool::Generator(arg),
46
 
  index_part_iterator(0),
47
 
  is_index_part_primed(false)
48
 
{
49
 
  Session *session= current_session;
50
 
  drizzled::statement::Select *select= static_cast<statement::Select *>(session->lex->statement);
51
 
 
52
 
  setSchemaPredicate(select->getShowSchema());
53
 
  setTablePredicate(select->getShowTable());
54
 
}
55
 
 
56
 
 
57
 
bool IndexPartsTool::Generator::nextIndexPartsCore()
58
 
{
59
 
  if (is_index_part_primed)
60
 
  {
61
 
    index_part_iterator++;
62
 
  }
63
 
  else
64
 
  {
65
 
    if (not isIndexesPrimed())
66
 
      return false;
67
 
 
68
 
    index_part_iterator= 0;
69
 
    is_index_part_primed= true;
70
 
  }
71
 
 
72
 
  if (index_part_iterator >= getIndex().index_part_size())
73
 
    return false;
74
 
 
75
 
  index_part= getIndex().index_part(index_part_iterator);
76
 
 
77
 
  return true;
78
 
}
79
 
 
80
 
bool IndexPartsTool::Generator::nextIndexParts()
81
 
{
82
 
  while (not nextIndexPartsCore())
83
 
  {
84
 
    if (not nextIndex())
85
 
      return false;
86
 
    is_index_part_primed= false;
87
 
  }
88
 
 
89
 
  return true;
90
 
}
91
 
 
92
 
bool IndexPartsTool::Generator::populate()
93
 
{
94
 
  if (not nextIndexParts())
95
 
    return false;
96
 
 
97
 
  fill();
98
 
 
99
 
  return true;
100
 
}
101
 
 
102
 
void IndexPartsTool::Generator::fill()
103
 
{
104
 
  /* TABLE_SCHEMA */
105
 
  push(schema_name());
106
 
 
107
 
  /* TABLE_NAME */
108
 
  push(table_name());
109
 
 
110
 
  /* INDEX_NAME */
111
 
  push(getIndex().name());
112
 
 
113
 
  /* COLUMN_NAME */
114
 
  push(getTableProto().field(index_part.fieldnr()).name());
115
 
 
116
 
  /* COLUMN_NUMBER */
117
 
  push(static_cast<int64_t>(index_part.fieldnr()));
118
 
 
119
 
  /* SEQUENCE_IN_INDEX  */
120
 
  push(static_cast<int64_t>(index_part_iterator));
121
 
 
122
 
  /* COMPARE_LENGTH */
123
 
  push(static_cast<int64_t>(index_part.compare_length()));
124
 
 
125
 
  /* IS_ORDER_REVERSE */
126
 
  push(index_part.in_reverse_order());
127
 
 
128
 
  /* IS_USED_IN_PRIMARY */
129
 
  push(getIndex().is_primary());
130
 
 
131
 
  /* IS_UNIQUE */
132
 
  push(getIndex().is_unique());
133
 
 
134
 
  /* IS_NULLABLE */
135
 
  push(getIndex().options().null_part_key());
136
 
}