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("VERSION", plugin::TableFunction::NUMBER);
37
add_field("IS_NAME_LOCKED", plugin::TableFunction::BOOLEAN);
38
add_field("ROWS", plugin::TableFunction::NUMBER);
39
add_field("AVG_ROW_LENGTH", plugin::TableFunction::NUMBER);
40
add_field("TABLE_SIZE", plugin::TableFunction::NUMBER);
41
add_field("AUTO_INCREMENT", plugin::TableFunction::NUMBER);
44
table_cache_dictionary::TableCache::Generator::Generator(drizzled::Field **arg) :
45
drizzled::plugin::TableFunction::Generator(arg),
48
pthread_mutex_lock(&LOCK_open); /* Optionally lock for remove tables from open_cahe if not in use */
50
drizzled::HASH *open_cache=
53
for (uint32_t idx= 0; idx < open_cache->records; idx++ )
55
table= (Table*) hash_element(open_cache, idx);
56
table_list.push_back(table);
58
std::sort(table_list.begin(), table_list.end(), Table::compare);
61
table_cache_dictionary::TableCache::Generator::~Generator()
63
pthread_mutex_unlock(&LOCK_open); /* Optionally lock for remove tables from open_cahe if not in use */
66
bool table_cache_dictionary::TableCache::Generator::nextCore()
70
table_list_iterator++;
75
table_list_iterator= table_list.begin();
78
if (table_list_iterator == table_list.end())
81
table= *table_list_iterator;
86
bool table_cache_dictionary::TableCache::Generator::next()
88
while (not nextCore())
90
if (table_list_iterator != table_list.end())
99
bool table_cache_dictionary::TableCache::Generator::populate()
109
void table_cache_dictionary::TableCache::Generator::fill()
113
--replace_column 1 # 4 # 5 # 6 # 8 # 9 #
117
if (table->getSession())
118
push(table->getSession()->getSessionId());
120
push(static_cast<int64_t>(0));
124
push(table->getShare()->getSchemaName(arg));
127
push(table->getShare()->getTableName(arg));
130
push(static_cast<int64_t>(table->getShare()->version));
132
/* IS_NAME_LOCKED 5 */
133
push(table->getShare()->isNameLock());
136
push(static_cast<uint64_t>(table->getCursor().records()));
138
/* AVG_ROW_LENGTH 7 */
139
push(table->getCursor().rowSize());
142
push(table->getCursor().tableSize());
144
/* AUTO_INCREMENT 9 */
145
push(table->getCursor().getNextInsertId());