1273.13.5
by Brian Aker
Additional definitions. |
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 |
||
1273.14.5
by Monty Taylor
Merged trunk. |
21 |
#include "config.h" |
1273.13.49
by Brian Aker
Does not work (compile issue in plugin). |
22 |
#include "plugin/schema_dictionary/dictionary.h" |
1273.13.5
by Brian Aker
Additional definitions. |
23 |
|
24 |
using namespace std; |
|
25 |
using namespace drizzled; |
|
26 |
||
1273.13.17
by Brian Aker
Pass through rewrite. |
27 |
|
1273.13.7
by Brian Aker
Updates to the classes (first pass). |
28 |
ColumnsTool::ColumnsTool() : |
1861.4.6
by Brian Aker
Switched columns to use AllFields. |
29 |
DataDictionary("COLUMNS") |
1273.13.5
by Brian Aker
Additional definitions. |
30 |
{
|
1273.13.18
by Brian Aker
Update code, first pass through cleaner method for recursing through |
31 |
add_field("TABLE_SCHEMA"); |
32 |
add_field("TABLE_NAME"); |
|
1273.13.8
by Brian Aker
Second pass through the interface. |
33 |
|
1273.13.18
by Brian Aker
Update code, first pass through cleaner method for recursing through |
34 |
add_field("COLUMN_NAME"); |
1273.19.5
by Brian Aker
Remove the old columns I_S table. |
35 |
add_field("COLUMN_TYPE"); |
1643.3.10
by Brian Aker
Column support, clean up of IS/DD for NULL type. |
36 |
add_field("ORDINAL_POSITION", plugin::TableFunction::NUMBER, 0, false); |
1337.1.2
by Stewart Smith
make DATA_DICTIONARY.COLUMNS.COLUMN_DEFAULT be a VARBINARY column that can be null. Add a test for binary default values as well as non-binary default values. |
37 |
add_field("COLUMN_DEFAULT", plugin::TableFunction::VARBINARY, 65535, true); |
1643.3.10
by Brian Aker
Column support, clean up of IS/DD for NULL type. |
38 |
add_field("COLUMN_DEFAULT_IS_NULL", plugin::TableFunction::BOOLEAN, 0, false); |
1273.19.1
by Brian Aker
Update for show fields. |
39 |
add_field("COLUMN_DEFAULT_UPDATE"); |
1779.3.4
by Andrew Hutchings
Add auto_incrememnt boolean and enum values string to data_dictionary.columns |
40 |
add_field("IS_AUTO_INCREMENT", plugin::TableFunction::BOOLEAN, 0, false); |
1643.3.10
by Brian Aker
Column support, clean up of IS/DD for NULL type. |
41 |
add_field("IS_NULLABLE", plugin::TableFunction::BOOLEAN, 0, false); |
42 |
add_field("IS_INDEXED", plugin::TableFunction::BOOLEAN, 0, false); |
|
43 |
add_field("IS_USED_IN_PRIMARY", plugin::TableFunction::BOOLEAN, 0, false); |
|
44 |
add_field("IS_UNIQUE", plugin::TableFunction::BOOLEAN, 0, false); |
|
45 |
add_field("IS_MULTI", plugin::TableFunction::BOOLEAN, 0, false); |
|
46 |
add_field("IS_FIRST_IN_MULTI", plugin::TableFunction::BOOLEAN, 0, false); |
|
47 |
add_field("INDEXES_FOUND_IN", plugin::TableFunction::NUMBER, 0, false); |
|
1273.13.41
by Brian Aker
Updating from additional schemas added. |
48 |
add_field("DATA_TYPE"); |
1273.13.18
by Brian Aker
Update code, first pass through cleaner method for recursing through |
49 |
|
1273.13.32
by Brian Aker
Big ole patch. This covers moving information_schema to old_* table names |
50 |
add_field("CHARACTER_MAXIMUM_LENGTH", plugin::TableFunction::NUMBER); |
51 |
add_field("CHARACTER_OCTET_LENGTH", plugin::TableFunction::NUMBER); |
|
52 |
add_field("NUMERIC_PRECISION", plugin::TableFunction::NUMBER); |
|
53 |
add_field("NUMERIC_SCALE", plugin::TableFunction::NUMBER); |
|
1273.13.18
by Brian Aker
Update code, first pass through cleaner method for recursing through |
54 |
|
1779.3.8
by Andrew Hutchings
ok, so a varchar(65535) is a really bad idea in data_dictionary in some platforms. Doesn't need to be that long anyway, shrinked to 1024. |
55 |
add_field("ENUM_VALUES", plugin::TableFunction::STRING, 1024, true); |
1779.3.4
by Andrew Hutchings
Add auto_incrememnt boolean and enum values string to data_dictionary.columns |
56 |
|
1273.13.18
by Brian Aker
Update code, first pass through cleaner method for recursing through |
57 |
add_field("COLLATION_NAME"); |
1273.16.4
by Brian Aker
Added columsn for COLUMNS |
58 |
|
1567.1.1
by Brian Aker
This fixes bug 586009, increases the size of the log files so that the UNION |
59 |
add_field("COLUMN_COMMENT", plugin::TableFunction::STRING, 1024, true); |
1273.13.5
by Brian Aker
Additional definitions. |
60 |
}
|
1273.13.15
by Brian Aker
First pass through making columns work. |
61 |
|
1273.13.18
by Brian Aker
Update code, first pass through cleaner method for recursing through |
62 |
|
63 |
ColumnsTool::Generator::Generator(Field **arg) : |
|
1861.4.6
by Brian Aker
Switched columns to use AllFields. |
64 |
DataDictionary::Generator(arg), |
65 |
field_generator(getSession()) |
|
66 |
{
|
|
1273.13.18
by Brian Aker
Update code, first pass through cleaner method for recursing through |
67 |
}
|
68 |
||
1273.13.21
by Brian Aker
Fix interface (we no longer need Fields passed around). |
69 |
bool ColumnsTool::Generator::populate() |
1273.13.18
by Brian Aker
Update code, first pass through cleaner method for recursing through |
70 |
{
|
1861.4.6
by Brian Aker
Switched columns to use AllFields. |
71 |
drizzled::generator::FieldPair field_pair; |
72 |
||
73 |
while (!!(field_pair= field_generator)) |
|
74 |
{
|
|
75 |
const drizzled::message::Table *table_message= field_pair.first; |
|
76 |
int32_t field_iterator= field_pair.second; |
|
77 |
const message::Table::Field &column(table_message->field(field_pair.second)); |
|
78 |
||
79 |
/* TABLE_SCHEMA */
|
|
80 |
push(table_message->schema()); |
|
81 |
||
82 |
/* TABLE_NAME */
|
|
83 |
push(table_message->name()); |
|
84 |
||
85 |
/* COLUMN_NAME */
|
|
86 |
push(column.name()); |
|
87 |
||
88 |
/* COLUMN_TYPE */
|
|
89 |
push(drizzled::message::type(column.type())); |
|
90 |
||
91 |
/* ORDINAL_POSITION */
|
|
92 |
push(static_cast<int64_t>(field_iterator)); |
|
93 |
||
94 |
/* COLUMN_DEFAULT */
|
|
95 |
if (column.options().has_default_value()) |
|
96 |
{
|
|
97 |
push(column.options().default_value()); |
|
98 |
}
|
|
99 |
else if (column.options().has_default_bin_value()) |
|
100 |
{
|
|
101 |
push(column.options().default_bin_value().c_str(), column.options().default_bin_value().length()); |
|
102 |
}
|
|
103 |
else if (column.options().has_default_expression()) |
|
104 |
{
|
|
105 |
push(column.options().default_expression()); |
|
106 |
}
|
|
107 |
else
|
|
108 |
{
|
|
109 |
push(); |
|
110 |
}
|
|
111 |
||
112 |
/* COLUMN_DEFAULT_IS_NULL */
|
|
113 |
push(column.options().default_null()); |
|
114 |
||
115 |
/* COLUMN_DEFAULT_UPDATE */
|
|
116 |
push(column.options().update_expression()); |
|
117 |
||
118 |
/* IS_AUTO_INCREMENT */
|
|
119 |
push(column.numeric_options().is_autoincrement()); |
|
120 |
||
121 |
/* IS_NULLABLE */
|
|
122 |
push(column.constraints().is_nullable()); |
|
123 |
||
124 |
/* IS_INDEXED, IS_USED_IN_PRIMARY, IS_UNIQUE, IS_MULTI, IS_FIRST_IN_MULTI, INDEXES_FOUND_IN */
|
|
125 |
bool is_indexed= false; |
|
126 |
bool is_primary= false; |
|
127 |
bool is_unique= false; |
|
128 |
bool is_multi= false; |
|
129 |
bool is_multi_first= false; |
|
130 |
int64_t indexes_found_in= 0; |
|
131 |
for (int32_t x= 0; x < table_message->indexes_size() ; x++) |
|
132 |
{
|
|
133 |
const drizzled::message::Table::Index &index(table_message->indexes(x)); |
|
134 |
||
135 |
for (int32_t y= 0; y < index.index_part_size() ; y++) |
|
1309.4.2
by Brian Aker
Updates to schema dictionary for lee |
136 |
{
|
1861.4.6
by Brian Aker
Switched columns to use AllFields. |
137 |
const drizzled::message::Table::Index::IndexPart &index_part(index.index_part(y)); |
138 |
||
139 |
if (static_cast<int32_t>(index_part.fieldnr()) == field_iterator) |
|
1309.4.2
by Brian Aker
Updates to schema dictionary for lee |
140 |
{
|
1861.4.6
by Brian Aker
Switched columns to use AllFields. |
141 |
indexes_found_in++; |
142 |
is_indexed= true; |
|
143 |
||
144 |
if (index.is_primary()) |
|
145 |
is_primary= true; |
|
146 |
||
147 |
if (index.is_unique()) |
|
148 |
is_unique= true; |
|
149 |
||
150 |
if (index.index_part_size() > 1) |
|
151 |
{
|
|
152 |
is_multi= true; |
|
153 |
||
154 |
if (y == 0) |
|
155 |
is_multi_first= true; |
|
156 |
}
|
|
1309.4.2
by Brian Aker
Updates to schema dictionary for lee |
157 |
}
|
158 |
}
|
|
159 |
}
|
|
1861.4.6
by Brian Aker
Switched columns to use AllFields. |
160 |
/* ...IS_INDEXED, IS_USED_IN_PRIMARY, IS_UNIQUE, IS_MULTI, IS_FIRST_IN_MULTI, INDEXES_FOUND_IN */
|
161 |
push(is_indexed); |
|
162 |
push(is_primary); |
|
163 |
push(is_unique); |
|
164 |
push(is_multi); |
|
165 |
push(is_multi_first); |
|
166 |
push(indexes_found_in); |
|
167 |
||
168 |
/* DATATYPE */
|
|
169 |
push(drizzled::message::type(column.type())); |
|
170 |
||
171 |
/* "CHARACTER_MAXIMUM_LENGTH" */
|
|
172 |
push(static_cast<int64_t>(column.string_options().length())); |
|
173 |
||
174 |
/* "CHARACTER_OCTET_LENGTH" */
|
|
175 |
push(static_cast<int64_t>(column.string_options().length()) * 4); |
|
176 |
||
177 |
/* "NUMERIC_PRECISION" */
|
|
178 |
push(static_cast<int64_t>(column.numeric_options().precision())); |
|
179 |
||
180 |
/* "NUMERIC_SCALE" */
|
|
181 |
push(static_cast<int64_t>(column.numeric_options().scale())); |
|
182 |
||
183 |
/* "ENUM_VALUES" */
|
|
184 |
if (column.type() == drizzled::message::Table::Field::ENUM) |
|
185 |
{
|
|
186 |
string destination; |
|
187 |
size_t num_field_values= column.enumeration_values().field_value_size(); |
|
188 |
for (size_t x= 0; x < num_field_values; ++x) |
|
189 |
{
|
|
190 |
const string &type= column.enumeration_values().field_value(x); |
|
191 |
||
192 |
if (x != 0) |
|
193 |
destination.push_back(','); |
|
194 |
||
195 |
destination.push_back('\''); |
|
196 |
destination.append(type); |
|
197 |
destination.push_back('\''); |
|
198 |
}
|
|
199 |
push(destination); |
|
200 |
}
|
|
201 |
else
|
|
202 |
{
|
|
203 |
push(); |
|
204 |
}
|
|
205 |
||
206 |
/* "COLLATION_NAME" */
|
|
207 |
push(column.string_options().collation()); |
|
208 |
||
209 |
/* "COLUMN_COMMENT" */
|
|
210 |
if (column.has_comment()) |
|
211 |
{
|
|
212 |
push(column.comment()); |
|
213 |
}
|
|
214 |
else
|
|
215 |
{
|
|
216 |
push(); |
|
217 |
}
|
|
218 |
||
219 |
return true; |
|
220 |
}
|
|
221 |
||
222 |
return false; |
|
1273.13.15
by Brian Aker
First pass through making columns work. |
223 |
}
|