~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to plugin/schema_dictionary/tables.cc

  • Committer: Brian Aker
  • Date: 2010-03-31 19:14:14 UTC
  • Revision ID: brian@gaz-20100331191414-9yv44mmpvf0tb7l1
Updated to use show schemas specific table.

Show diffs side-by-side

added added

removed removed

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