1
/* - mode: c; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
* vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
4
* Copyright (C) 2010 Brian Aker
6
* This program is free software; you can redistribute it and/or modify
7
* it under the terms of the GNU General Public License as published by
8
* the Free Software Foundation; either version 2 of the License, or
9
* (at your option) any later version.
11
* This program is distributed in the hope that it will be useful,
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
* GNU General Public License for more details.
16
* You should have received a copy of the GNU General Public License
17
* along with this program; if not, write to the Free Software
18
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
23
#include "plugin/schema_dictionary/dictionary.h"
24
#include "drizzled/pthread_globals.h"
25
#include "drizzled/my_hash.h"
27
using namespace drizzled;
30
ShowTableStatus::ShowTableStatus() :
31
plugin::TableFunction("DATA_DICTIONARY", "SHOW_TABLE_STATUS")
33
add_field("Session", plugin::TableFunction::NUMBER);
40
add_field("Avg_row_length");
41
add_field("Table_size");
42
add_field("Auto_increment");
45
ShowTableStatus::Generator::Generator(drizzled::Field **arg) :
46
drizzled::plugin::TableFunction::Generator(arg),
49
Session *session= current_session;
50
statement::Select *select= static_cast<statement::Select *>(session->lex->statement);
52
schema_predicate.append(select->getShowSchema());
54
pthread_mutex_lock(&LOCK_open); /* Optionally lock for remove tables from open_cahe if not in use */
56
drizzled::HASH *open_cache=
59
for (uint32_t idx= 0; idx < open_cache->records; idx++ )
61
table= (Table*) hash_element(open_cache, idx);
62
table_list.push_back(table);
65
for (table= session->temporary_tables; table; table= table->next)
67
if (table->getShare())
69
table_list.push_back(table);
72
std::sort(table_list.begin(), table_list.end(), Table::compare);
75
ShowTableStatus::Generator::~Generator()
77
pthread_mutex_unlock(&LOCK_open); /* Optionally lock for remove tables from open_cahe if not in use */
80
bool ShowTableStatus::Generator::nextCore()
84
table_list_iterator++;
89
table_list_iterator= table_list.begin();
92
if (table_list_iterator == table_list.end())
95
table= *table_list_iterator;
97
if (checkSchemaName())
103
bool ShowTableStatus::Generator::next()
105
while (not nextCore())
107
if (table_list_iterator != table_list.end())
116
bool ShowTableStatus::Generator::checkSchemaName()
118
if (not schema_predicate.empty() && schema_predicate.compare(schema_name()))
124
const char *ShowTableStatus::Generator::schema_name()
126
return table->getShare()->getSchemaName();
129
bool ShowTableStatus::Generator::populate()
139
void ShowTableStatus::Generator::fill()
143
--replace_column 1 # 6 # 7 # 8 # 9 # 10 #
147
if (table->getSession())
148
push(table->getSession()->getSessionId());
150
push(static_cast<int64_t>(0));
153
push(table->getShare()->getSchemaName());
156
push(table->getShare()->getTableName());
159
push(table->getShare()->getTableTypeAsString());
162
push(table->getEngine()->getName());
165
push(static_cast<int64_t>(table->getShare()->version));
168
push(static_cast<uint64_t>(table->getCursor().records()));
170
/* Avg_row_length 8 */
171
push(table->getCursor().rowSize());
174
push(table->getCursor().tableSize());
176
/* Auto_increment 10 */
177
push(table->getCursor().getNextInsertId());