~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to plugin/schema_dictionary/tables.cc

  • Committer: Brian Aker
  • Date: 2010-05-26 21:49:18 UTC
  • mto: This revision was merged to the branch mainline in revision 1568.
  • Revision ID: brian@gaz-20100526214918-8kdibq48e9lnyr6t
This fixes bug 586009, increases the size of the log files so that the UNION
test doesn't hit Innodb's default limit. Increases the size of the initial
Innodb data file, and fixes one case where an empty string on error was
causing a crash on OSX.

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
63
  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
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
    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;
67
102
}
68
103
 
69
104
bool TablesTool::Generator::nextTable()
70
105
{
71
 
  drizzled::message::table::shared_ptr table_ptr;
72
 
  while ((table_ptr= all_tables_generator))
 
106
  while (not nextTableCore())
73
107
  {
74
 
    table_message.CopyFrom(*table_ptr);
75
 
    return true;
 
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;
76
116
  }
77
117
 
78
 
  return false;
 
118
  return true;
79
119
}
80
120
 
81
121
bool TablesTool::Generator::populate()
82
122
{
83
 
  if (nextTable())
84
 
  {
85
 
    fill();
86
 
    return true;
87
 
  }
88
 
 
89
 
  return false;
 
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
  }
90
196
}
91
197
 
92
198
void TablesTool::Generator::fill()
97
203
  */
98
204
 
99
205
  /* TABLE_SCHEMA */
100
 
  push(getTableMessage().schema());
 
206
  push(table_proto.schema());
101
207
 
102
208
  /* TABLE_NAME */
103
 
  push(getTableMessage().name());
 
209
  push(table_proto.name());
104
210
 
105
211
  /* 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())
 
212
  {
 
213
    switch (table_proto.type())
118
214
    {
119
215
    default:
120
216
    case message::Table::STANDARD:
133
229
  }
134
230
 
135
231
  /* ENGINE */
136
 
  push(getTableMessage().engine().name());
 
232
  push(table_proto.engine().name());
137
233
 
138
234
  /* ROW_FORMAT */
139
 
  push("DEFAULT");
 
235
  pushRow(table_proto.options().row_type());
140
236
 
141
237
  /* TABLE_COLLATION */
142
 
  push(getTableMessage().options().collation());
 
238
  push(table_proto.options().collation());
143
239
 
144
240
  /* TABLE_CREATION_TIME */
145
 
  time_t time_arg= getTableMessage().creation_timestamp();
 
241
  time_t time_arg= table_proto.creation_timestamp();
146
242
  char buffer[40];
147
243
  struct tm tm_buffer;
148
244
 
151
247
  push(buffer);
152
248
 
153
249
  /* TABLE_UPDATE_TIME */
154
 
  time_arg= getTableMessage().update_timestamp();
 
250
  time_arg= table_proto.update_timestamp();
155
251
  localtime_r(&time_arg, &tm_buffer);
156
252
  strftime(buffer, sizeof(buffer), "%a %b %d %H:%M:%S %Y", &tm_buffer);
157
253
  push(buffer);
158
254
 
159
255
  /* TABLE_COMMENT */
160
 
  if (getTableMessage().options().has_comment())
 
256
  if (table_proto.options().has_comment())
161
257
  {
162
 
    push(getTableMessage().options().comment());
 
258
    push(table_proto.options().comment());
163
259
  }
164
260
  else
165
261
  {
166
262
    push();
167
263
  }
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());
177
264
}