1
/* - mode: c; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
* vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
4
* Copyright (C) 2010 Sun Microsystems
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/schema_dictionary/dictionary.h"
25
using namespace drizzled;
28
ColumnsTool::ColumnsTool() :
31
add_field("TABLE_SCHEMA");
32
add_field("TABLE_NAME");
34
add_field("COLUMN_NAME");
35
add_field("COLUMN_TYPE");
36
add_field("ORDINAL_POSITION", plugin::TableFunction::NUMBER);
37
add_field("COLUMN_DEFAULT", plugin::TableFunction::VARBINARY, 65535, true);
38
add_field("COLUMN_DEFAULT_IS_NULL", plugin::TableFunction::BOOLEAN);
39
add_field("COLUMN_DEFAULT_UPDATE");
40
add_field("IS_NULLABLE", plugin::TableFunction::BOOLEAN);
41
add_field("IS_INDEXED", plugin::TableFunction::BOOLEAN);
42
add_field("IS_USED_IN_PRIMARY", plugin::TableFunction::BOOLEAN);
43
add_field("IS_UNIQUE", plugin::TableFunction::BOOLEAN);
44
add_field("IS_MULTI", plugin::TableFunction::BOOLEAN);
45
add_field("IS_FIRST_IN_MULTI", plugin::TableFunction::BOOLEAN);
46
add_field("INDEXES_FOUND_IN", plugin::TableFunction::NUMBER);
47
add_field("DATA_TYPE");
49
add_field("CHARACTER_MAXIMUM_LENGTH", plugin::TableFunction::NUMBER);
50
add_field("CHARACTER_OCTET_LENGTH", plugin::TableFunction::NUMBER);
51
add_field("NUMERIC_PRECISION", plugin::TableFunction::NUMBER);
52
add_field("NUMERIC_SCALE", plugin::TableFunction::NUMBER);
54
add_field("COLLATION_NAME");
56
add_field("COLUMN_COMMENT", 1024);
60
ColumnsTool::Generator::Generator(Field **arg) :
61
TablesTool::Generator(arg),
63
is_columns_primed(false)
68
bool ColumnsTool::Generator::nextColumnCore()
70
if (is_columns_primed)
76
if (not isTablesPrimed())
80
is_columns_primed= true;
83
if (column_iterator >= getTableProto().field_size())
86
column= getTableProto().field(column_iterator);
92
bool ColumnsTool::Generator::nextColumn()
94
while (not nextColumnCore())
98
is_columns_primed= false;
104
bool ColumnsTool::Generator::populate()
107
if (not nextColumn())
115
void ColumnsTool::Generator::fill()
118
push(getTableProto().schema());
121
push(getTableProto().name());
127
pushType(column.type());
129
/* ORDINAL_POSITION */
130
push(static_cast<int64_t>(column_iterator));
133
if (column.options().has_default_value())
134
push(column.options().default_value());
135
else if (column.options().has_default_bin_value())
136
push(column.options().default_bin_value().c_str(), column.options().default_bin_value().length());
140
/* COLUMN_DEFAULT_IS_NULL */
141
push(column.options().default_null());
143
/* COLUMN_DEFAULT_UPDATE */
144
push(column.options().update_value());
147
push(column.constraints().is_nullable());
149
/* IS_INDEXED, IS_USED_IN_PRIMARY, IS_UNIQUE, IS_MULTI, IS_FIRST_IN_MULTI, INDEXES_FOUND_IN */
150
bool is_indexed= false;
151
bool is_primary= false;
152
bool is_unique= false;
153
bool is_multi= false;
154
bool is_multi_first= false;
155
int64_t indexes_found_in= 0;
156
for (int32_t x= 0; x < getTableProto().indexes_size() ; x++)
158
drizzled::message::Table::Index index=
159
getTableProto().indexes(x);
161
for (int32_t y= 0; y < index.index_part_size() ; y++)
163
drizzled::message::Table::Index::IndexPart index_part=
166
if (static_cast<int32_t>(index_part.fieldnr()) == column_iterator)
171
if (index.is_primary())
174
if (index.is_unique())
177
if (index.index_part_size() > 1)
182
is_multi_first= true;
187
/* ...IS_INDEXED, IS_USED_IN_PRIMARY, IS_UNIQUE, IS_MULTI, IS_FIRST_IN_MULTI, INDEXES_FOUND_IN */
192
push(is_multi_first);
193
push(indexes_found_in);
196
pushType(column.type());
198
/* "CHARACTER_MAXIMUM_LENGTH" */
199
push(static_cast<int64_t>(column.string_options().length()));
201
/* "CHARACTER_OCTET_LENGTH" */
202
push(static_cast<int64_t>(column.string_options().length()) * 4);
204
/* "NUMERIC_PRECISION" */
205
push(static_cast<int64_t>(column.numeric_options().precision()));
207
/* "NUMERIC_SCALE" */
208
push(static_cast<int64_t>(column.numeric_options().scale()));
210
/* "COLLATION_NAME" */
211
push(column.string_options().collation());
213
/* "COLUMN_COMMENT" */
214
push(column.comment());