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 IndexesTool::IndexesTool() :
00028 TablesTool("INDEXES")
00029 {
00030 add_field("TABLE_SCHEMA", plugin::TableFunction::STRING, MAXIMUM_IDENTIFIER_LENGTH, false);
00031 add_field("TABLE_NAME", plugin::TableFunction::STRING, MAXIMUM_IDENTIFIER_LENGTH, false);
00032 add_field("INDEX_NAME", plugin::TableFunction::STRING, MAXIMUM_IDENTIFIER_LENGTH, false);
00033 add_field("IS_USED_IN_PRIMARY", plugin::TableFunction::BOOLEAN, 0, false);
00034 add_field("IS_UNIQUE", plugin::TableFunction::BOOLEAN, 0, false);
00035 add_field("IS_NULLABLE", plugin::TableFunction::BOOLEAN, 0, false);
00036 add_field("KEY_LENGTH", plugin::TableFunction::NUMBER, 0, false);
00037 add_field("INDEX_TYPE");
00038 add_field("INDEX_COMMENT", plugin::TableFunction::STRING, 1024, true);
00039 }
00040
00041 IndexesTool::Generator::Generator(Field **arg) :
00042 TablesTool::Generator(arg),
00043 index_iterator(0),
00044 is_index_primed(false)
00045 {
00046 }
00047
00048 bool IndexesTool::Generator::nextIndexCore()
00049 {
00050 if (isIndexesPrimed())
00051 {
00052 index_iterator++;
00053 }
00054 else
00055 {
00056 if (not isTablesPrimed())
00057 return false;
00058
00059 index_iterator= 0;
00060 is_index_primed= true;
00061 }
00062
00063 if (index_iterator >= getTableProto().indexes_size())
00064 return false;
00065
00066 index= getTableProto().indexes(index_iterator);
00067
00068 return true;
00069 }
00070
00071 bool IndexesTool::Generator::nextIndex()
00072 {
00073 while (not nextIndexCore())
00074 {
00075 if (not nextTable())
00076 return false;
00077 is_index_primed= false;
00078 }
00079
00080 return true;
00081 }
00082
00083 bool IndexesTool::Generator::populate()
00084 {
00085 if (not nextIndex())
00086 return false;
00087
00088 fill();
00089
00090 return true;
00091 }
00092
00093 void IndexesTool::Generator::fill()
00094 {
00095
00096 push(getTableProto().schema());
00097
00098
00099 push(getTableProto().name());
00100
00101
00102 push(index.name());
00103
00104
00105 push(index.is_primary());
00106
00107
00108 push(index.is_unique());
00109
00110
00111 push(index.options().null_part_key());
00112
00113
00114 push(static_cast<uint64_t>(index.key_length()));
00115
00116
00117 push(message::type(index.type()));
00118
00119
00120 if (index.has_comment())
00121 {
00122 push(index.comment());
00123 }
00124 else
00125 {
00126 push();
00127 }
00128 }