00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #include <config.h>
00022 #include <plugin/schema_dictionary/dictionary.h>
00023
00024 using namespace std;
00025 using namespace drizzled;
00026
00027
00028 ColumnsTool::ColumnsTool() :
00029 DataDictionary("COLUMNS")
00030 {
00031 add_field("TABLE_SCHEMA");
00032 add_field("TABLE_NAME");
00033
00034 add_field("COLUMN_NAME");
00035 add_field("COLUMN_TYPE");
00036 add_field("ORDINAL_POSITION", plugin::TableFunction::NUMBER, 0, false);
00037 add_field("COLUMN_DEFAULT", plugin::TableFunction::VARBINARY, 65535, true);
00038 add_field("COLUMN_DEFAULT_IS_NULL", plugin::TableFunction::BOOLEAN, 0, false);
00039 add_field("COLUMN_DEFAULT_UPDATE");
00040 add_field("IS_SIGNED", plugin::TableFunction::BOOLEAN, 0, true);
00041 add_field("IS_AUTO_INCREMENT", plugin::TableFunction::BOOLEAN, 0, false);
00042 add_field("IS_NULLABLE", plugin::TableFunction::BOOLEAN, 0, false);
00043 add_field("IS_INDEXED", plugin::TableFunction::BOOLEAN, 0, false);
00044 add_field("IS_USED_IN_PRIMARY", plugin::TableFunction::BOOLEAN, 0, false);
00045 add_field("IS_UNIQUE", plugin::TableFunction::BOOLEAN, 0, false);
00046 add_field("IS_MULTI", plugin::TableFunction::BOOLEAN, 0, false);
00047 add_field("IS_FIRST_IN_MULTI", plugin::TableFunction::BOOLEAN, 0, false);
00048 add_field("INDEXES_FOUND_IN", plugin::TableFunction::NUMBER, 0, false);
00049 add_field("DATA_TYPE");
00050 add_field("DATA_ARCHETYPE");
00051 add_field("CHARACTER_MAXIMUM_LENGTH", plugin::TableFunction::NUMBER);
00052 add_field("CHARACTER_OCTET_LENGTH", plugin::TableFunction::NUMBER);
00053 add_field("NUMERIC_PRECISION", plugin::TableFunction::NUMBER);
00054 add_field("NUMERIC_SCALE", plugin::TableFunction::NUMBER);
00055
00056 add_field("ENUM_VALUES", plugin::TableFunction::STRING, 1024, true);
00057
00058 add_field("COLLATION_NAME");
00059
00060 add_field("COLUMN_COMMENT", plugin::TableFunction::STRING, 1024, true);
00061 }
00062
00063
00064 ColumnsTool::Generator::Generator(Field **arg) :
00065 DataDictionary::Generator(arg),
00066 field_generator(getSession())
00067 {
00068 }
00069
00070 bool ColumnsTool::Generator::populate()
00071 {
00072 drizzled::generator::FieldPair field_pair;
00073
00074 while (!!(field_pair= field_generator))
00075 {
00076 const drizzled::message::Table *table_message= field_pair.first;
00077 int32_t field_iterator= field_pair.second;
00078 const message::Table::Field &column(table_message->field(field_pair.second));
00079
00080
00081 push(table_message->schema());
00082
00083
00084 push(table_message->name());
00085
00086
00087 push(column.name());
00088
00089
00090 push(drizzled::message::type(column.type()));
00091
00092
00093 push(static_cast<int64_t>(field_iterator));
00094
00095
00096 if (column.options().has_default_value())
00097 {
00098 push(column.options().default_value());
00099 }
00100 else if (column.options().has_default_bin_value())
00101 {
00102 push(column.options().default_bin_value().c_str(), column.options().default_bin_value().length());
00103 }
00104 else if (column.options().has_default_expression())
00105 {
00106 push(column.options().default_expression());
00107 }
00108 else
00109 {
00110 push();
00111 }
00112
00113
00114 push(column.options().default_null());
00115
00116
00117 push(column.options().update_expression());
00118
00119
00120 if (drizzled::message::is_numeric(column))
00121 {
00122 push(true);
00123 }
00124 else
00125 {
00126 push();
00127 }
00128
00129
00130 push(column.numeric_options().is_autoincrement());
00131
00132
00133 push(not column.constraints().is_notnull());
00134
00135
00136 bool is_indexed= false;
00137 bool is_primary= false;
00138 bool is_unique= false;
00139 bool is_multi= false;
00140 bool is_multi_first= false;
00141 int64_t indexes_found_in= 0;
00142 for (int32_t x= 0; x < table_message->indexes_size() ; x++)
00143 {
00144 const drizzled::message::Table::Index &index(table_message->indexes(x));
00145
00146 for (int32_t y= 0; y < index.index_part_size() ; y++)
00147 {
00148 const drizzled::message::Table::Index::IndexPart &index_part(index.index_part(y));
00149
00150 if (static_cast<int32_t>(index_part.fieldnr()) == field_iterator)
00151 {
00152 indexes_found_in++;
00153 is_indexed= true;
00154
00155 if (index.is_primary())
00156 is_primary= true;
00157
00158 if (index.is_unique())
00159 is_unique= true;
00160
00161 if (index.index_part_size() > 1)
00162 {
00163 is_multi= true;
00164
00165 if (y == 0)
00166 is_multi_first= true;
00167 }
00168 }
00169 }
00170 }
00171
00172 push(is_indexed);
00173 push(is_primary);
00174 push(is_unique);
00175 push(is_multi);
00176 push(is_multi_first);
00177 push(indexes_found_in);
00178
00179
00180 push(drizzled::message::type(column));
00181
00182
00183 push(drizzled::message::type(column.type()));
00184
00185
00186 push(static_cast<int64_t>(column.string_options().length()));
00187
00188
00189 push(static_cast<int64_t>(column.string_options().length()) * 4);
00190
00191
00192 push(static_cast<int64_t>(column.numeric_options().precision()));
00193
00194
00195 push(static_cast<int64_t>(column.numeric_options().scale()));
00196
00197
00198 if (column.type() == drizzled::message::Table::Field::ENUM)
00199 {
00200 string destination;
00201 size_t num_field_values= column.enumeration_values().field_value_size();
00202 for (size_t x= 0; x < num_field_values; ++x)
00203 {
00204 const string &type= column.enumeration_values().field_value(x);
00205
00206 if (x != 0)
00207 destination.push_back(',');
00208
00209 destination.push_back('\'');
00210 destination.append(type);
00211 destination.push_back('\'');
00212 }
00213 push(destination);
00214 }
00215 else
00216 {
00217 push();
00218 }
00219
00220
00221 push(column.string_options().collation());
00222
00223
00224 if (column.has_comment())
00225 {
00226 push(column.comment());
00227 }
00228 else
00229 {
00230 push();
00231 }
00232
00233 return true;
00234 }
00235
00236 return false;
00237 }