~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
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/table_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
 
static const string DEFAULT("DEFAULT");
34
 
static const string FIXED("FIXED");
35
 
static const string DYNAMIC("DYNAMIC");
36
 
static const string COMPRESSED("COMPRESSED");
37
 
static const string REDUNDANT("REDUNDANT");
38
 
static const string COMPACT("COMPACT");
39
 
static const string PAGE("PAGE");
40
 
 
41
 
static const string VARCHAR("VARCHAR");
42
 
static const string DOUBLE("DOUBLE");
43
 
static const string BLOB("BLOB");
44
 
static const string ENUM("ENUM");
45
 
static const string INTEGER("INTEGER");
46
 
static const string BIGINT("BIGINT");
47
 
static const string DECIMAL("DECIMAL");
48
 
static const string DATE("DATE");
49
 
static const string TIMESTAMP("TIMESTAMP");
50
 
static const string DATETIME("DATETIME");
51
 
 
52
 
TablesTool::TablesTool() :
53
 
  SchemasTool("TABLES")
54
 
{
55
 
  add_field("TABLE_SCHEMA");
56
 
  add_field("TABLE_NAME");
57
 
  add_field("TABLE_TYPE");
58
 
  add_field("ENGINE");
59
 
  add_field("ROW_FORMAT", 10);
60
 
  add_field("TABLE_COLLATION");
61
 
  add_field("TABLE_CREATION_TIME");
62
 
  add_field("TABLE_UPDATE_TIME");
63
 
  add_field("TABLE_COMMENT", 2048);
64
 
}
65
 
 
66
 
TablesTool::Generator::Generator(Field **arg) :
67
 
  SchemasTool::Generator(arg),
68
 
  is_tables_primed(false)
69
 
{
70
 
}
71
 
 
72
 
bool TablesTool::Generator::nextTableCore()
73
 
{
74
 
  if (is_tables_primed)
75
 
  {
76
 
    table_iterator++;
77
 
  }
78
 
  else
79
 
  {
80
 
    if (not isSchemaPrimed())
81
 
     return false;
82
 
 
83
 
    table_names.clear();
84
 
    SchemaIdentifier identifier(schema_name());
85
 
    plugin::StorageEngine::getTableNames(getSession(), identifier, table_names);
86
 
    table_iterator= table_names.begin();
87
 
    is_tables_primed= true;
88
 
  }
89
 
 
90
 
  if (table_iterator == table_names.end())
91
 
    return false;
92
 
 
93
 
  table_proto.Clear();
94
 
  {
95
 
    TableIdentifier identifier(schema_name().c_str(), table_name().c_str());
96
 
    plugin::StorageEngine::getTableDefinition(getSession(),
97
 
                                             identifier,
98
 
                                             table_proto);
99
 
  }
100
 
 
101
 
  return true;
102
 
}
103
 
 
104
 
bool TablesTool::Generator::nextTable()
105
 
{
106
 
  while (not nextTableCore())
107
 
  {
108
 
 
109
 
    if (is_tables_primed && table_iterator != table_names.end())
110
 
      continue;
111
 
 
112
 
    if (not nextSchema())
113
 
      return false;
114
 
 
115
 
    is_tables_primed= false;
116
 
  }
117
 
 
118
 
  return true;
119
 
}
120
 
 
121
 
bool TablesTool::Generator::populate()
122
 
{
123
 
  if (not nextTable())
124
 
    return false;
125
 
 
126
 
  fill();
127
 
 
128
 
  return true;
129
 
}
130
 
 
131
 
void TablesTool::Generator::pushRow(message::Table::TableOptions::RowType type)
132
 
{
133
 
  switch (type)
134
 
  {
135
 
  default:
136
 
  case message::Table::TableOptions::ROW_TYPE_DEFAULT:
137
 
    push(DEFAULT);
138
 
    break;
139
 
  case message::Table::TableOptions::ROW_TYPE_FIXED:
140
 
    push(FIXED);
141
 
    break;
142
 
  case message::Table::TableOptions::ROW_TYPE_DYNAMIC:
143
 
    push(DYNAMIC);
144
 
    break;
145
 
  case message::Table::TableOptions::ROW_TYPE_COMPRESSED:
146
 
    push(COMPRESSED);
147
 
    break;
148
 
  case message::Table::TableOptions::ROW_TYPE_REDUNDANT:
149
 
    push(REDUNDANT);
150
 
    break;
151
 
  case message::Table::TableOptions::ROW_TYPE_COMPACT:
152
 
    push(COMPACT);
153
 
    break;
154
 
  case message::Table::TableOptions::ROW_TYPE_PAGE:
155
 
    push(PAGE);
156
 
    break;
157
 
  }
158
 
}
159
 
 
160
 
void TablesTool::Generator::pushType(message::Table::Field::FieldType type)
161
 
{
162
 
  switch (type)
163
 
  {
164
 
  default:
165
 
  case message::Table::Field::VARCHAR:
166
 
    push(VARCHAR);
167
 
    break;
168
 
  case message::Table::Field::DOUBLE:
169
 
    push(DOUBLE);
170
 
    break;
171
 
  case message::Table::Field::BLOB:
172
 
    push(BLOB);
173
 
    break;
174
 
  case message::Table::Field::ENUM:
175
 
    push(ENUM);
176
 
    break;
177
 
  case message::Table::Field::INTEGER:
178
 
    push(INTEGER);
179
 
    break;
180
 
  case message::Table::Field::BIGINT:
181
 
    push(BIGINT);
182
 
    break;
183
 
  case message::Table::Field::DECIMAL:
184
 
    push(DECIMAL);
185
 
    break;
186
 
  case message::Table::Field::DATE:
187
 
    push(DATE);
188
 
    break;
189
 
  case message::Table::Field::TIMESTAMP:
190
 
    push(TIMESTAMP);
191
 
    break;
192
 
  case message::Table::Field::DATETIME:
193
 
    push(DATETIME);
194
 
    break;
195
 
  }
196
 
}
197
 
 
198
 
void TablesTool::Generator::fill()
199
 
{
200
 
 
201
 
  /**
202
 
    @note use --replace-column
203
 
  */
204
 
 
205
 
  /* TABLE_SCHEMA */
206
 
  push(table_proto.schema());
207
 
 
208
 
  /* TABLE_NAME */
209
 
  push(table_proto.name());
210
 
 
211
 
  /* TABLE_TYPE */
212
 
  {
213
 
    switch (table_proto.type())
214
 
    {
215
 
    default:
216
 
    case message::Table::STANDARD:
217
 
      push(STANDARD);
218
 
      break;
219
 
    case message::Table::TEMPORARY:
220
 
      push(TEMPORARY);
221
 
      break;
222
 
    case message::Table::INTERNAL:
223
 
      push(INTERNAL);
224
 
      break;
225
 
    case message::Table::FUNCTION:
226
 
      push(FUNCTION);
227
 
      break;
228
 
    }
229
 
  }
230
 
 
231
 
  /* ENGINE */
232
 
  push(table_proto.engine().name());
233
 
 
234
 
  /* ROW_FORMAT */
235
 
  pushRow(table_proto.options().row_type());
236
 
 
237
 
  /* TABLE_COLLATION */
238
 
  push(table_proto.options().collation());
239
 
 
240
 
  /* TABLE_CREATION_TIME */
241
 
  time_t time_arg= table_proto.creation_timestamp();
242
 
  char buffer[40];
243
 
  struct tm tm_buffer;
244
 
 
245
 
  localtime_r(&time_arg, &tm_buffer);
246
 
  strftime(buffer, sizeof(buffer), "%a %b %d %H:%M:%S %Y", &tm_buffer);
247
 
  push(buffer);
248
 
 
249
 
  /* TABLE_UPDATE_TIME */
250
 
  time_arg= table_proto.update_timestamp();
251
 
  localtime_r(&time_arg, &tm_buffer);
252
 
  strftime(buffer, sizeof(buffer), "%a %b %d %H:%M:%S %Y", &tm_buffer);
253
 
  push(buffer);
254
 
 
255
 
  /* TABLE_COMMENT */
256
 
  push(table_proto.options().comment());
257
 
}