~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to plugin/schema_dictionary/tables.cc

Merge Stewart's dead code removal

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 Sun Microsystems, Inc.
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
 
#include "plugin/schema_dictionary/dictionary.h"
23
 
#include "drizzled/identifier.h"
24
 
 
25
 
using namespace std;
26
 
using namespace drizzled;
27
 
 
28
 
static const string STANDARD("STANDARD");
29
 
static const string TEMPORARY("TEMPORARY");
30
 
static const string INTERNAL("INTERNAL");
31
 
static const string FUNCTION("FUNCTION");
32
 
 
33
 
 
34
 
static const string VARCHAR("VARCHAR");
35
 
static const string DOUBLE("DOUBLE");
36
 
static const string BLOB("BLOB");
37
 
static const string ENUM("ENUM");
38
 
static const string INTEGER("INTEGER");
39
 
static const string BIGINT("BIGINT");
40
 
static const string DECIMAL("DECIMAL");
41
 
static const string DATE("DATE");
42
 
static const string TIMESTAMP("TIMESTAMP");
43
 
static const string DATETIME("DATETIME");
44
 
 
45
 
TablesTool::TablesTool() :
46
 
  plugin::TableFunction("DATA_DICTIONARY", "TABLES")
47
 
{
48
 
  add_field("TABLE_SCHEMA");
49
 
  add_field("TABLE_NAME");
50
 
  add_field("TABLE_TYPE");
51
 
  add_field("TABLE_ARCHETYPE");
52
 
  add_field("ENGINE");
53
 
  add_field("ROW_FORMAT", 10);
54
 
  add_field("TABLE_COLLATION");
55
 
  add_field("TABLE_CREATION_TIME");
56
 
  add_field("TABLE_UPDATE_TIME");
57
 
  add_field("TABLE_COMMENT", plugin::TableFunction::STRING, 2048, true);
58
 
  add_field("AUTO_INCREMENT", plugin::TableFunction::NUMBER, 0, false);
59
 
  add_field("TABLE_UUID", plugin::TableFunction::STRING, 36, true);
60
 
  add_field("TABLE_VERSION", plugin::TableFunction::NUMBER, 0, true);
61
 
}
62
 
 
63
 
TablesTool::Generator::Generator(Field **arg) :
64
 
  plugin::TableFunction::Generator(arg),
65
 
  all_tables_generator(getSession())
66
 
{
67
 
}
68
 
 
69
 
bool TablesTool::Generator::nextTable()
70
 
{
71
 
  drizzled::message::table::shared_ptr table_ptr;
72
 
  while ((table_ptr= all_tables_generator))
73
 
  {
74
 
    table_message.CopyFrom(*table_ptr);
75
 
    return true;
76
 
  }
77
 
 
78
 
  return false;
79
 
}
80
 
 
81
 
bool TablesTool::Generator::populate()
82
 
{
83
 
  if (nextTable())
84
 
  {
85
 
    fill();
86
 
    return true;
87
 
  }
88
 
 
89
 
  return false;
90
 
}
91
 
 
92
 
void TablesTool::Generator::fill()
93
 
{
94
 
 
95
 
  /**
96
 
    @note use --replace-column
97
 
  */
98
 
 
99
 
  /* TABLE_SCHEMA */
100
 
  push(getTableMessage().schema());
101
 
 
102
 
  /* TABLE_NAME */
103
 
  push(getTableMessage().name());
104
 
 
105
 
  /* TABLE_TYPE */
106
 
  if (drizzled::identifier::Table::isView(getTableMessage().type()))
107
 
  {
108
 
    push("VIEW");
109
 
  }
110
 
  else
111
 
  {
112
 
    push("BASE");
113
 
  }
114
 
 
115
 
  /* TABLE_ARCHETYPE */
116
 
  {
117
 
    switch (getTableMessage().type())
118
 
    {
119
 
    default:
120
 
    case message::Table::STANDARD:
121
 
      push(STANDARD);
122
 
      break;
123
 
    case message::Table::TEMPORARY:
124
 
      push(TEMPORARY);
125
 
      break;
126
 
    case message::Table::INTERNAL:
127
 
      push(INTERNAL);
128
 
      break;
129
 
    case message::Table::FUNCTION:
130
 
      push(FUNCTION);
131
 
      break;
132
 
    }
133
 
  }
134
 
 
135
 
  /* ENGINE */
136
 
  const drizzled::message::Engine &engine= getTableMessage().engine();
137
 
  push(engine.name());
138
 
 
139
 
  /* ROW_FORMAT */
140
 
  bool row_format_sent= false;
141
 
  for (ssize_t it= 0; it < engine.options_size(); it++)
142
 
  {
143
 
    const drizzled::message::Engine::Option &opt= engine.options(it);
144
 
    if (opt.name().compare("ROW_FORMAT") == 0)
145
 
    {
146
 
      row_format_sent= true;
147
 
      push(opt.state());
148
 
      break;
149
 
    }
150
 
  }
151
 
 
152
 
  if (not row_format_sent)
153
 
    push("DEFAULT");
154
 
 
155
 
  /* TABLE_COLLATION */
156
 
  push(getTableMessage().options().collation());
157
 
 
158
 
  /* TABLE_CREATION_TIME */
159
 
  time_t time_arg= getTableMessage().creation_timestamp();
160
 
  char buffer[40];
161
 
  struct tm tm_buffer;
162
 
 
163
 
  localtime_r(&time_arg, &tm_buffer);
164
 
  strftime(buffer, sizeof(buffer), "%a %b %d %H:%M:%S %Y", &tm_buffer);
165
 
  push(buffer);
166
 
 
167
 
  /* TABLE_UPDATE_TIME */
168
 
  time_arg= getTableMessage().update_timestamp();
169
 
  localtime_r(&time_arg, &tm_buffer);
170
 
  strftime(buffer, sizeof(buffer), "%a %b %d %H:%M:%S %Y", &tm_buffer);
171
 
  push(buffer);
172
 
 
173
 
  /* TABLE_COMMENT */
174
 
  if (getTableMessage().options().has_comment())
175
 
  {
176
 
    push(getTableMessage().options().comment());
177
 
  }
178
 
  else
179
 
  {
180
 
    push();
181
 
  }
182
 
 
183
 
  /* AUTO_INCREMENT */
184
 
  push(getTableMessage().options().auto_increment_value());
185
 
 
186
 
  /* TABLE_UUID */
187
 
  push(getTableMessage().uuid());
188
 
 
189
 
  /* TABLE_VERSION */
190
 
  push(getTableMessage().version());
191
 
}