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
00023 #include <plugin/show_dictionary/dictionary.h>
00024 #include <drizzled/pthread_globals.h>
00025
00026 using namespace drizzled;
00027 using namespace std;
00028
00029 ShowTableStatus::ShowTableStatus() :
00030 show_dictionary::Show("SHOW_TABLE_STATUS")
00031 {
00032 add_field("Session", plugin::TableFunction::NUMBER, 0, false);
00033 add_field("Schema");
00034 add_field("Name");
00035 add_field("Type");
00036 add_field("Engine");
00037 add_field("Version");
00038 add_field("Rows");
00039 add_field("Avg_row_length");
00040 add_field("Table_size");
00041 add_field("Auto_increment");
00042 }
00043
00044 ShowTableStatus::Generator::Generator(drizzled::Field **arg) :
00045 show_dictionary::Show::Generator(arg),
00046 is_primed(false),
00047 scopedLock(table::Cache::singleton().mutex())
00048 {
00049 if (not isShowQuery())
00050 return;
00051
00052 statement::Show& select= static_cast<statement::Show&>(statement());
00053
00054 schema_predicate.append(select.getShowSchema());
00055
00056 util::string::const_shared_ptr schema(getSession().schema());
00057 if (schema_predicate.empty() and schema)
00058 {
00059 schema_predicate.append(*schema);
00060 }
00061
00062 if (not schema_predicate.empty())
00063 {
00064 table::CacheMap &open_cache(table::getCache());
00065
00066 for (table::CacheMap::const_iterator iter= open_cache.begin();
00067 iter != open_cache.end();
00068 iter++)
00069 {
00070 table_list.push_back(iter->second);
00071 }
00072
00073 for (drizzled::Table *tmp_table= getSession().getTemporaryTables(); tmp_table; tmp_table= tmp_table->getNext())
00074 {
00075 if (tmp_table->getShare())
00076 {
00077 table_list.push_back(tmp_table);
00078 }
00079 }
00080 std::sort(table_list.begin(), table_list.end(), Table::compare);
00081 }
00082 }
00083
00084 ShowTableStatus::Generator::~Generator()
00085 {
00086 }
00087
00088 bool ShowTableStatus::Generator::nextCore()
00089 {
00090 if (is_primed)
00091 {
00092 table_list_iterator++;
00093 }
00094 else
00095 {
00096 is_primed= true;
00097 table_list_iterator= table_list.begin();
00098 }
00099
00100 if (table_list_iterator == table_list.end())
00101 return false;
00102
00103 table= *table_list_iterator;
00104
00105 if (checkSchemaName())
00106 return false;
00107
00108 return true;
00109 }
00110
00111 bool ShowTableStatus::Generator::next()
00112 {
00113 while (not nextCore())
00114 {
00115 if (table_list_iterator != table_list.end())
00116 continue;
00117
00118 return false;
00119 }
00120
00121 return true;
00122 }
00123
00124 bool ShowTableStatus::Generator::checkSchemaName()
00125 {
00126 if (not schema_predicate.empty() && schema_predicate.compare(schema_name()))
00127 return true;
00128
00129 return false;
00130 }
00131
00132 const char *ShowTableStatus::Generator::schema_name()
00133 {
00134 return table->getShare()->getSchemaName();
00135 }
00136
00137 bool ShowTableStatus::Generator::populate()
00138 {
00139 if (not next())
00140 return false;
00141
00142 fill();
00143
00144 return true;
00145 }
00146
00147 void ShowTableStatus::Generator::fill()
00148 {
00154
00155 if (table->getSession())
00156 push(table->getSession()->getSessionId());
00157 else
00158 push(static_cast<int64_t>(0));
00159
00160
00161 push(table->getShare()->getSchemaName());
00162
00163
00164 push(table->getShare()->getTableName());
00165
00166
00167 push(table->getShare()->getTableTypeAsString());
00168
00169
00170 push(table->getEngine()->getName());
00171
00172
00173 push(static_cast<int64_t>(table->getShare()->getVersion()));
00174
00175
00176 push(static_cast<uint64_t>(table->getCursor().records()));
00177
00178
00179 push(table->getCursor().rowSize());
00180
00181
00182 push(table->getCursor().tableSize());
00183
00184
00185 bool session_set= false;
00186 if (table->in_use == NULL)
00187 {
00188 table->in_use= &getSession();
00189 session_set= true;
00190 }
00191
00192 table->getCursor().info(HA_STATUS_AUTO);
00193 push(table->getCursor().getAutoIncrement());
00194
00195 if (session_set)
00196 table->in_use= NULL;
00197 }