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 #include <drizzled/statement/select.h>
00024
00025 using namespace std;
00026 using namespace drizzled;
00027
00028 IndexPartsTool::IndexPartsTool() :
00029 IndexesTool("INDEX_PARTS")
00030 {
00031 add_field("TABLE_SCHEMA");
00032 add_field("TABLE_NAME");
00033 add_field("INDEX_NAME");
00034 add_field("COLUMN_NAME");
00035 add_field("COLUMN_NUMBER", plugin::TableFunction::NUMBER, 0, false);
00036 add_field("SEQUENCE_IN_INDEX", plugin::TableFunction::NUMBER, 0, false);
00037 add_field("COMPARE_LENGTH", plugin::TableFunction::NUMBER, 0, true);
00038 add_field("IS_ORDER_REVERSE", plugin::TableFunction::BOOLEAN, 0, false);
00039 add_field("IS_USED_IN_PRIMARY", plugin::TableFunction::BOOLEAN, 0, false);
00040 add_field("IS_UNIQUE", plugin::TableFunction::BOOLEAN, 0, false);
00041 add_field("IS_NULLABLE", plugin::TableFunction::BOOLEAN, 0, false);
00042 }
00043
00044 IndexPartsTool::Generator::Generator(Field **arg) :
00045 IndexesTool::Generator(arg),
00046 index_part_iterator(0),
00047 is_index_part_primed(false)
00048 {
00049 }
00050
00051
00052 bool IndexPartsTool::Generator::nextIndexPartsCore()
00053 {
00054 if (is_index_part_primed)
00055 {
00056 index_part_iterator++;
00057 }
00058 else
00059 {
00060 if (not isIndexesPrimed())
00061 return false;
00062
00063 index_part_iterator= 0;
00064 is_index_part_primed= true;
00065 }
00066
00067 if (index_part_iterator >= getIndex().index_part_size())
00068 return false;
00069
00070 index_part= getIndex().index_part(index_part_iterator);
00071
00072 return true;
00073 }
00074
00075 bool IndexPartsTool::Generator::nextIndexParts()
00076 {
00077 while (not nextIndexPartsCore())
00078 {
00079 if (not nextIndex())
00080 return false;
00081 is_index_part_primed= false;
00082 }
00083
00084 return true;
00085 }
00086
00087 bool IndexPartsTool::Generator::populate()
00088 {
00089 if (not nextIndexParts())
00090 return false;
00091
00092 fill();
00093
00094 return true;
00095 }
00096
00097 void IndexPartsTool::Generator::fill()
00098 {
00099 const message::Table::Field &field= getTableProto().field(index_part.fieldnr());
00100
00101
00102 push(getTableProto().schema());
00103
00104
00105 push(getTableProto().name());
00106
00107
00108 push(getIndex().name());
00109
00110
00111 push(field.name());
00112
00113
00114 push(static_cast<int64_t>(index_part.fieldnr()));
00115
00116
00117 push(static_cast<int64_t>(index_part_iterator));
00118
00119
00120 if ((field.type() == message::Table::Field::VARCHAR or
00121 field.type() == message::Table::Field::BLOB) and
00122 (index_part.has_compare_length()) and
00123 (index_part.compare_length() != field.string_options().length()))
00124 {
00125 push(static_cast<int64_t>(index_part.compare_length()));
00126 }
00127 else
00128 push();
00129
00130
00131 push(index_part.in_reverse_order());
00132
00133
00134 push(getIndex().is_primary());
00135
00136
00137 push(getIndex().is_unique());
00138
00139
00140 push(getIndex().options().null_part_key());
00141 }