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/table_cache_dictionary/dictionary.h"
24
#include "drizzled/pthread_globals.h"
25
#include "drizzled/my_hash.h"
27
using namespace drizzled;
30
table_cache_dictionary::TableCache::TableCache() :
31
plugin::TableFunction("DATA_DICTIONARY", "TABLE_CACHE")
33
add_field("SESSION_ID", plugin::TableFunction::NUMBER);
34
add_field("TABLE_SCHEMA");
35
add_field("TABLE_NAME");
36
add_field("ARCHETYPE");
38
add_field("VERSION", plugin::TableFunction::NUMBER);
39
add_field("IS_NAME_LOCKED", plugin::TableFunction::BOOLEAN);
40
add_field("ROWS", plugin::TableFunction::NUMBER);
41
add_field("AVG_ROW_LENGTH", plugin::TableFunction::NUMBER);
42
add_field("TABLE_SIZE", plugin::TableFunction::NUMBER);
43
add_field("AUTO_INCREMENT", plugin::TableFunction::NUMBER);
46
table_cache_dictionary::TableCache::Generator::Generator(drizzled::Field **arg) :
47
drizzled::plugin::TableFunction::Generator(arg),
50
pthread_mutex_lock(&LOCK_open); /* Optionally lock for remove tables from open_cahe if not in use */
52
drizzled::HASH *open_cache=
55
for (uint32_t idx= 0; idx < open_cache->records; idx++ )
57
table= (Table*) hash_element(open_cache, idx);
58
table_list.push_back(table);
60
std::sort(table_list.begin(), table_list.end(), Table::compare);
63
table_cache_dictionary::TableCache::Generator::~Generator()
65
pthread_mutex_unlock(&LOCK_open); /* Optionally lock for remove tables from open_cahe if not in use */
68
bool table_cache_dictionary::TableCache::Generator::nextCore()
72
table_list_iterator++;
77
table_list_iterator= table_list.begin();
80
if (table_list_iterator == table_list.end())
83
table= *table_list_iterator;
88
bool table_cache_dictionary::TableCache::Generator::next()
90
while (not nextCore())
92
if (table_list_iterator != table_list.end())
101
bool table_cache_dictionary::TableCache::Generator::populate()
111
void table_cache_dictionary::TableCache::Generator::fill()
115
--replace_column 1 # 6 # 8 # 9 # 10 # 11 #
119
if (table->getSession())
120
push(table->getSession()->getSessionId());
122
push(static_cast<int64_t>(0));
125
push(table->getShare()->getSchemaName());
128
push(table->getShare()->getTableName());
131
push(table->getShare()->getTableTypeAsString());
134
push(table->getEngine()->getName());
137
push(static_cast<int64_t>(table->getShare()->version));
139
/* IS_NAME_LOCKED 7 */
140
push(table->getShare()->isNameLock());
143
push(static_cast<uint64_t>(table->getCursor().records()));
145
/* AVG_ROW_LENGTH 9 */
146
push(table->getCursor().rowSize());
149
push(table->getCursor().tableSize());
151
/* AUTO_INCREMENT 11 */
152
push(table->getCursor().getNextInsertId());