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/information_schema_dictionary/dictionary.h>
00023
00024 using namespace std;
00025 using namespace drizzled;
00026
00027 KeyColumnUsage::KeyColumnUsage() :
00028 InformationSchema("KEY_COLUMN_USAGE")
00029 {
00030 add_field("CONSTRAINT_CATALOG", plugin::TableFunction::STRING, MAXIMUM_IDENTIFIER_LENGTH, false);
00031 add_field("CONSTRAINT_SCHEMA", plugin::TableFunction::STRING, MAXIMUM_IDENTIFIER_LENGTH, false);
00032 add_field("CONSTRAINT_NAME", plugin::TableFunction::STRING, MAXIMUM_IDENTIFIER_LENGTH, false);
00033 add_field("TABLE_CATALOG", plugin::TableFunction::STRING, MAXIMUM_IDENTIFIER_LENGTH, false);
00034 add_field("TABLE_SCHEMA", plugin::TableFunction::STRING, MAXIMUM_IDENTIFIER_LENGTH, false);
00035 add_field("TABLE_NAME", plugin::TableFunction::STRING, MAXIMUM_IDENTIFIER_LENGTH, false);
00036 add_field("COLUMN_NAME", plugin::TableFunction::STRING, MAXIMUM_IDENTIFIER_LENGTH, false);
00037 add_field("ORDINAL_POSITION", plugin::TableFunction::NUMBER, 0, false);
00038 }
00039
00040 KeyColumnUsage::Generator::Generator(drizzled::Field **arg) :
00041 InformationSchema::Generator(arg),
00042 generator(getSession()),
00043 index_iterator(0),
00044 index_part_iterator(0),
00045 fk_constraint_iterator(0),
00046 fk_constraint_column_name_iterator(0)
00047 {
00048 while (not (table_message= generator))
00049 { };
00050 }
00051
00052 bool KeyColumnUsage::Generator::populate()
00053 {
00054 if (not table_message)
00055 return false;
00056
00057 do
00058 {
00059 if (index_iterator != table_message->indexes_size())
00060 {
00061 drizzled::message::Table::Index index= table_message->indexes(index_iterator);
00062
00063 if (index.is_primary() || index.is_unique())
00064 {
00065
00066
00067 push(table_message->catalog());
00068
00069
00070 push(table_message->schema());
00071
00072
00073 push(index.name());
00074
00075
00076 push(table_message->catalog());
00077
00078
00079 push(table_message->schema());
00080
00081
00082 push(table_message->name());
00083
00084
00085 int32_t fieldnr= index.index_part(index_part_iterator).fieldnr();
00086 push(table_message->field(fieldnr).name());
00087
00088
00089 push(static_cast<int64_t>((index_part_iterator +1)));
00090
00091 if (index_part_iterator == index.index_part_size() -1)
00092 {
00093 index_iterator++;
00094 index_part_iterator= 0;
00095 }
00096 else
00097 {
00098 index_part_iterator++;
00099 }
00100
00101 return true;
00102 }
00103 }
00104
00105 if (fk_constraint_iterator != table_message->fk_constraint_size())
00106 {
00107 drizzled::message::Table::ForeignKeyConstraint foreign_key= table_message->fk_constraint(fk_constraint_iterator);
00108
00109 {
00110
00111
00112 push(table_message->catalog());
00113
00114
00115 push(table_message->schema());
00116
00117
00118 push(foreign_key.name());
00119
00120
00121 push(table_message->catalog());
00122
00123
00124 push(table_message->schema());
00125
00126
00127 push(table_message->name());
00128
00129
00130 push(foreign_key.column_names(fk_constraint_column_name_iterator));
00131
00132
00133 push(static_cast<int64_t>((fk_constraint_column_name_iterator + 1)));
00134
00135 if (fk_constraint_column_name_iterator == foreign_key.column_names_size() -1)
00136 {
00137 fk_constraint_iterator++;
00138 fk_constraint_column_name_iterator= 0;
00139 }
00140 else
00141 {
00142 fk_constraint_column_name_iterator++;
00143 }
00144
00145 return true;
00146 }
00147 }
00148
00149 index_iterator= 0;
00150 index_part_iterator= 0;
00151
00152 fk_constraint_iterator= 0;
00153 fk_constraint_column_name_iterator= 0;
00154
00155 } while ((table_message= generator));
00156
00157 return false;
00158 }