~ubuntu-branches/ubuntu/trusty/drizzle/trusty

« back to all changes in this revision

Viewing changes to plugin/schema_dictionary/show_table_status.cc

  • Committer: Bazaar Package Importer
  • Author(s): Monty Taylor
  • Date: 2010-10-02 14:17:48 UTC
  • mfrom: (1.1.1 upstream)
  • mto: (2.1.17 sid)
  • mto: This revision was merged to the branch mainline in revision 3.
  • Revision ID: james.westby@ubuntu.com-20101002141748-m6vbfbfjhrw1153e
Tags: 2010.09.1802-1
* New upstream release.
* Removed pid-file argument hack.
* Updated GPL-2 address to be new address.
* Directly copy in drizzledump.1 since debian doesn't have sphinx 1.0 yet.
* Link to jquery from libjs-jquery. Add it as a depend.
* Add drizzled.8 symlink to the install files.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* - mode: c; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
 
 *  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
3
 
 *
4
 
 *  Copyright (C) 2010 Brian Aker
5
 
 *
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.
10
 
 *
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.
15
 
 *
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
19
 
 */
20
 
 
21
 
#include "config.h"
22
 
 
23
 
#include "plugin/schema_dictionary/dictionary.h"
24
 
#include "drizzled/pthread_globals.h"
25
 
#include "drizzled/my_hash.h"
26
 
 
27
 
using namespace drizzled;
28
 
using namespace std;
29
 
 
30
 
ShowTableStatus::ShowTableStatus() :
31
 
  plugin::TableFunction("DATA_DICTIONARY", "SHOW_TABLE_STATUS")
32
 
{
33
 
  add_field("Session", plugin::TableFunction::NUMBER);
34
 
  add_field("Schema");
35
 
  add_field("Name");
36
 
  add_field("Type");
37
 
  add_field("Engine");
38
 
  add_field("Version");
39
 
  add_field("Rows");
40
 
  add_field("Avg_row_length");
41
 
  add_field("Table_size");
42
 
  add_field("Auto_increment");
43
 
}
44
 
 
45
 
ShowTableStatus::Generator::Generator(drizzled::Field **arg) :
46
 
  drizzled::plugin::TableFunction::Generator(arg),
47
 
  is_primed(false)
48
 
{
49
 
  Session *session= current_session;
50
 
  statement::Select *select= static_cast<statement::Select *>(session->lex->statement);
51
 
 
52
 
  schema_predicate.append(select->getShowSchema());
53
 
 
54
 
  pthread_mutex_lock(&LOCK_open); /* Optionally lock for remove tables from open_cahe if not in use */
55
 
 
56
 
  drizzled::HASH *open_cache=
57
 
    get_open_cache();
58
 
 
59
 
  for (uint32_t idx= 0; idx < open_cache->records; idx++ )
60
 
  {
61
 
    table= (Table*) hash_element(open_cache, idx);
62
 
    table_list.push_back(table);
63
 
  }
64
 
 
65
 
  for (table= session->temporary_tables; table; table= table->next)
66
 
  {
67
 
    if (table->getShare())
68
 
    {
69
 
      table_list.push_back(table);
70
 
    }
71
 
  }
72
 
  std::sort(table_list.begin(), table_list.end(), Table::compare);
73
 
}
74
 
 
75
 
ShowTableStatus::Generator::~Generator()
76
 
{
77
 
  pthread_mutex_unlock(&LOCK_open); /* Optionally lock for remove tables from open_cahe if not in use */
78
 
}
79
 
 
80
 
bool ShowTableStatus::Generator::nextCore()
81
 
{
82
 
  if (is_primed)
83
 
  {
84
 
    table_list_iterator++;
85
 
  }
86
 
  else
87
 
  {
88
 
    is_primed= true;
89
 
    table_list_iterator= table_list.begin();
90
 
  }
91
 
 
92
 
  if (table_list_iterator == table_list.end())
93
 
    return false;
94
 
 
95
 
  table= *table_list_iterator;
96
 
 
97
 
  if (checkSchemaName())
98
 
    return false;
99
 
 
100
 
  return true;
101
 
}
102
 
 
103
 
bool ShowTableStatus::Generator::next()
104
 
{
105
 
  while (not nextCore())
106
 
  {
107
 
    if (table_list_iterator != table_list.end())
108
 
      continue;
109
 
 
110
 
    return false;
111
 
  }
112
 
 
113
 
  return true;
114
 
}
115
 
 
116
 
bool ShowTableStatus::Generator::checkSchemaName()
117
 
{
118
 
  if (not schema_predicate.empty() && schema_predicate.compare(schema_name()))
119
 
    return true;
120
 
 
121
 
  return false;
122
 
}
123
 
 
124
 
const char *ShowTableStatus::Generator::schema_name()
125
 
{
126
 
  return table->getShare()->getSchemaName();
127
 
}
128
 
 
129
 
bool ShowTableStatus::Generator::populate()
130
 
{
131
 
  if (not next())
132
 
    return false;
133
 
  
134
 
  fill();
135
 
 
136
 
  return true;
137
 
}
138
 
 
139
 
void ShowTableStatus::Generator::fill()
140
 
{
141
 
  /**
142
 
    For test cases use:
143
 
    --replace_column 1 #  6 # 7 # 8 # 9 # 10 #
144
 
  */
145
 
 
146
 
  /* Session 1 */
147
 
  if (table->getSession())
148
 
    push(table->getSession()->getSessionId());
149
 
  else
150
 
    push(static_cast<int64_t>(0));
151
 
 
152
 
  /* Schema 2 */
153
 
  push(table->getShare()->getSchemaName());
154
 
 
155
 
  /* Name  3 */
156
 
  push(table->getShare()->getTableName());
157
 
 
158
 
  /* Type  4 */
159
 
  push(table->getShare()->getTableTypeAsString());
160
 
 
161
 
  /* Engine 5 */
162
 
  push(table->getEngine()->getName());
163
 
 
164
 
  /* Version 6 */
165
 
  push(static_cast<int64_t>(table->getShare()->version));
166
 
 
167
 
  /* Rows 7 */
168
 
  push(static_cast<uint64_t>(table->getCursor().records()));
169
 
 
170
 
  /* Avg_row_length 8 */
171
 
  push(table->getCursor().rowSize());
172
 
 
173
 
  /* Table_size 9 */
174
 
  push(table->getCursor().tableSize());
175
 
 
176
 
  /* Auto_increment 10 */
177
 
  push(table->getCursor().getNextInsertId());
178
 
}