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/show_dictionary/dictionary.h>
00023 #include <drizzled/identifier.h>
00024 #include <string>
00025
00026 using namespace std;
00027 using namespace drizzled;
00028
00029 ShowColumns::ShowColumns() :
00030 show_dictionary::Show("SHOW_COLUMNS")
00031 {
00032 add_field("Field");
00033 add_field("Type");
00034 add_field("Null", plugin::TableFunction::BOOLEAN, 0 , false);
00035 add_field("Default");
00036 add_field("Default_is_NULL", plugin::TableFunction::BOOLEAN, 0, false);
00037 add_field("On_Update");
00038 }
00039
00040 ShowColumns::Generator::Generator(Field **arg) :
00041 show_dictionary::Show::Generator(arg),
00042 is_tables_primed(false),
00043 is_columns_primed(false),
00044 column_iterator(0)
00045 {
00046 if (not isShowQuery())
00047 return;
00048
00049 statement::Show& select= static_cast<statement::Show&>(statement());
00050
00051 if (not select.getShowTable().empty() && not select.getShowSchema().empty())
00052 {
00053 table_name.append(select.getShowTable().c_str());
00054 identifier::Table identifier(select.getShowSchema().c_str(), select.getShowTable().c_str());
00055
00056 if (not plugin::Authorization::isAuthorized(*getSession().user(),
00057 identifier, false))
00058 {
00059 drizzled::error::access(*getSession().user(), identifier);
00060 return;
00061 }
00062
00063 table_proto= plugin::StorageEngine::getTableMessage(getSession(), identifier);
00064
00065 if (table_proto)
00066 is_tables_primed= true;
00067 }
00068 }
00069
00070 bool ShowColumns::Generator::nextColumnCore()
00071 {
00072 if (is_columns_primed)
00073 {
00074 column_iterator++;
00075 }
00076 else
00077 {
00078 if (not isTablesPrimed())
00079 return false;
00080
00081 column_iterator= 0;
00082 is_columns_primed= true;
00083 }
00084
00085 if (column_iterator >= getTableProto()->field_size())
00086 return false;
00087
00088 column= getTableProto()->field(column_iterator);
00089
00090 return true;
00091 }
00092
00093
00094 bool ShowColumns::Generator::nextColumn()
00095 {
00096 while (not nextColumnCore())
00097 {
00098 return false;
00099 }
00100
00101 return true;
00102 }
00103
00104 bool ShowColumns::Generator::populate()
00105 {
00106
00107 if (not nextColumn())
00108 return false;
00109
00110 fill();
00111
00112 return true;
00113 }
00114
00115
00116 void ShowColumns::Generator::fill()
00117 {
00118
00119 push(column.name());
00120
00121
00122 push(drizzled::message::type(column));
00123
00124
00125 push(not column.constraints().is_notnull());
00126
00127
00128 if (column.options().has_default_value())
00129 push(column.options().default_value());
00130 else if (column.options().has_default_expression())
00131 push(column.options().default_expression());
00132 else
00133 push(column.options().default_bin_value());
00134
00135
00136 push(column.options().default_null());
00137
00138
00139 push(column.options().update_expression());
00140 }