1
by Monty Taylor
Import upstream version 2010.03.1347 |
1 |
/* - mode: c; c-basic-offset: 2; indent-tabs-mode: nil; -*-
|
2 |
* vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
|
|
3 |
*
|
|
1.2.4
by Monty Taylor
Import upstream version 2010.12.06 |
4 |
* Copyright (C) 2010 Sun Microsystems, Inc.
|
1
by Monty Taylor
Import upstream version 2010.03.1347 |
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 |
||
1.2.9
by Monty Taylor
Import upstream version 2011.03.11 |
21 |
#include <config.h> |
22 |
#include <plugin/schema_dictionary/dictionary.h> |
|
23 |
#include <drizzled/statement/select.h> |
|
1
by Monty Taylor
Import upstream version 2010.03.1347 |
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"); |
|
1.1.1
by Monty Taylor
Import upstream version 2010.09.1802 |
35 |
add_field("COLUMN_NUMBER", plugin::TableFunction::NUMBER, 0, false); |
36 |
add_field("SEQUENCE_IN_INDEX", plugin::TableFunction::NUMBER, 0, false); |
|
1.2.1
by Monty Taylor
Import upstream version 2010.11.03 |
37 |
add_field("COMPARE_LENGTH", plugin::TableFunction::NUMBER, 0, true); |
1.1.1
by Monty Taylor
Import upstream version 2010.09.1802 |
38 |
add_field("IS_ORDER_REVERSE", plugin::TableFunction::BOOLEAN, 0, false); |
39 |
add_field("IS_USED_IN_PRIMARY", plugin::TableFunction::BOOLEAN, 0, false); |
|
40 |
add_field("IS_UNIQUE", plugin::TableFunction::BOOLEAN, 0, false); |
|
41 |
add_field("IS_NULLABLE", plugin::TableFunction::BOOLEAN, 0, false); |
|
1
by Monty Taylor
Import upstream version 2010.03.1347 |
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 |
}
|
|
50 |
||
51 |
||
52 |
bool IndexPartsTool::Generator::nextIndexPartsCore() |
|
53 |
{
|
|
54 |
if (is_index_part_primed) |
|
55 |
{
|
|
56 |
index_part_iterator++; |
|
57 |
}
|
|
58 |
else
|
|
59 |
{
|
|
60 |
if (not isIndexesPrimed()) |
|
61 |
return false; |
|
62 |
||
63 |
index_part_iterator= 0; |
|
64 |
is_index_part_primed= true; |
|
65 |
}
|
|
66 |
||
67 |
if (index_part_iterator >= getIndex().index_part_size()) |
|
68 |
return false; |
|
69 |
||
70 |
index_part= getIndex().index_part(index_part_iterator); |
|
71 |
||
72 |
return true; |
|
73 |
}
|
|
74 |
||
75 |
bool IndexPartsTool::Generator::nextIndexParts() |
|
76 |
{
|
|
77 |
while (not nextIndexPartsCore()) |
|
78 |
{
|
|
79 |
if (not nextIndex()) |
|
80 |
return false; |
|
81 |
is_index_part_primed= false; |
|
82 |
}
|
|
83 |
||
84 |
return true; |
|
85 |
}
|
|
86 |
||
87 |
bool IndexPartsTool::Generator::populate() |
|
88 |
{
|
|
89 |
if (not nextIndexParts()) |
|
90 |
return false; |
|
91 |
||
92 |
fill(); |
|
93 |
||
94 |
return true; |
|
95 |
}
|
|
96 |
||
97 |
void IndexPartsTool::Generator::fill() |
|
98 |
{
|
|
1.2.1
by Monty Taylor
Import upstream version 2010.11.03 |
99 |
const message::Table::Field &field= getTableProto().field(index_part.fieldnr()); |
100 |
||
1
by Monty Taylor
Import upstream version 2010.03.1347 |
101 |
/* TABLE_SCHEMA */
|
1.1.1
by Monty Taylor
Import upstream version 2010.09.1802 |
102 |
push(getTableProto().schema()); |
1
by Monty Taylor
Import upstream version 2010.03.1347 |
103 |
|
104 |
/* TABLE_NAME */
|
|
1.1.1
by Monty Taylor
Import upstream version 2010.09.1802 |
105 |
push(getTableProto().name()); |
1
by Monty Taylor
Import upstream version 2010.03.1347 |
106 |
|
107 |
/* INDEX_NAME */
|
|
108 |
push(getIndex().name()); |
|
109 |
||
110 |
/* COLUMN_NAME */
|
|
1.2.1
by Monty Taylor
Import upstream version 2010.11.03 |
111 |
push(field.name()); |
1
by Monty Taylor
Import upstream version 2010.03.1347 |
112 |
|
113 |
/* COLUMN_NUMBER */
|
|
114 |
push(static_cast<int64_t>(index_part.fieldnr())); |
|
115 |
||
116 |
/* SEQUENCE_IN_INDEX */
|
|
117 |
push(static_cast<int64_t>(index_part_iterator)); |
|
118 |
||
119 |
/* COMPARE_LENGTH */
|
|
1.2.1
by Monty Taylor
Import upstream version 2010.11.03 |
120 |
if ((field.type() == message::Table::Field::VARCHAR or |
121 |
field.type() == message::Table::Field::BLOB) and |
|
122 |
(index_part.has_compare_length()) and |
|
123 |
(index_part.compare_length() != field.string_options().length())) |
|
124 |
{
|
|
125 |
push(static_cast<int64_t>(index_part.compare_length())); |
|
126 |
}
|
|
127 |
else
|
|
128 |
push(); |
|
1
by Monty Taylor
Import upstream version 2010.03.1347 |
129 |
|
130 |
/* IS_ORDER_REVERSE */
|
|
131 |
push(index_part.in_reverse_order()); |
|
132 |
||
133 |
/* IS_USED_IN_PRIMARY */
|
|
134 |
push(getIndex().is_primary()); |
|
135 |
||
136 |
/* IS_UNIQUE */
|
|
137 |
push(getIndex().is_unique()); |
|
138 |
||
139 |
/* IS_NULLABLE */
|
|
140 |
push(getIndex().options().null_part_key()); |
|
141 |
}
|