~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to plugin/data_engine/tables.cc

Remove PLUGIN and MODULES.

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 "plugin/data_engine/schemas.h"
 
22
 
 
23
extern size_t build_table_filename(char *buff, size_t bufflen, const char *db, const char *table_name, bool is_tmp);
 
24
 
 
25
using namespace std;
 
26
using namespace drizzled;
 
27
 
 
28
TablesTool::TablesTool() :
 
29
  SchemasTool("TABLES")
 
30
{
 
31
  add_field("TABLE_SCHEMA");
 
32
  add_field("TABLE_NAME");
 
33
  add_field("TABLE_TYPE");
 
34
  add_field("ENGINE");
 
35
  add_field("ROW_FORMAT", 10);
 
36
  add_field("TABLE_COLLATION");
 
37
  add_field("TABLE_COMMENT", 2048);
 
38
}
 
39
 
 
40
TablesTool::Generator::Generator(Field **arg) :
 
41
  SchemasTool::Generator(arg),
 
42
  is_tables_primed(false)
 
43
{
 
44
}
 
45
 
 
46
bool TablesTool::Generator::nextTableCore()
 
47
{
 
48
  if (is_tables_primed)
 
49
  {
 
50
    table_iterator++;
 
51
  }
 
52
  else
 
53
  {
 
54
    if (not isSchemaPrimed())
 
55
     return false;
 
56
 
 
57
    table_names.clear();
 
58
    plugin::StorageEngine::getTableNames(schema_name(), table_names);
 
59
    table_iterator= table_names.begin();
 
60
    is_tables_primed= true;
 
61
  }
 
62
 
 
63
  if (table_iterator == table_names.end())
 
64
    return false;
 
65
 
 
66
  table_proto.Clear();
 
67
  {
 
68
    Session *session= current_session;
 
69
    char path[FN_REFLEN];
 
70
    build_table_filename(path, sizeof(path), schema_name().c_str(), table_name().c_str(), false);
 
71
    plugin::StorageEngine::getTableDefinition(*session,
 
72
                                             path,
 
73
                                             schema_name().c_str(),
 
74
                                             table_name().c_str(),
 
75
                                             false,
 
76
                                             &table_proto);
 
77
  }
 
78
 
 
79
  return true;
 
80
}
 
81
 
 
82
bool TablesTool::Generator::nextTable()
 
83
{
 
84
  while (not nextTableCore())
 
85
  {
 
86
    if (not nextSchema())
 
87
      return false;
 
88
    is_tables_primed= false;
 
89
  }
 
90
 
 
91
  return true;
 
92
}
 
93
 
 
94
bool TablesTool::Generator::populate()
 
95
{
 
96
  if (not nextTable())
 
97
    return false;
 
98
 
 
99
  fill();
 
100
 
 
101
  return true;
 
102
}
 
103
 
 
104
void TablesTool::Generator::fill()
 
105
{
 
106
 
 
107
  /* TABLE_SCHEMA */
 
108
  push(schema_name());
 
109
 
 
110
  /* TABLE_NAME */
 
111
  push(table_name());
 
112
 
 
113
  /* TABLE_TYPE */
 
114
  {
 
115
    const char *str;
 
116
 
 
117
    switch (table_proto.type())
 
118
    {
 
119
    default:
 
120
    case message::Table::STANDARD:
 
121
      str= "STANDARD";
 
122
      break;
 
123
    case message::Table::TEMPORARY:
 
124
      str= "TEMPORARY";
 
125
      break;
 
126
    case message::Table::INTERNAL:
 
127
      str= "INTERNAL";
 
128
      break;
 
129
    case message::Table::FUNCTION:
 
130
      str= "FUNCTION";
 
131
      break;
 
132
    }
 
133
    push(str);
 
134
  }
 
135
 
 
136
  /* ENGINE */
 
137
  push(table_proto.engine().name());
 
138
 
 
139
  /* ROW_FORMAT */
 
140
  {
 
141
    const char *str;
 
142
 
 
143
    switch (table_proto.options().row_type())
 
144
    {
 
145
    default:
 
146
    case message::Table::TableOptions::ROW_TYPE_DEFAULT:
 
147
      str= "DEFAULT";
 
148
      break;
 
149
    case message::Table::TableOptions::ROW_TYPE_FIXED:
 
150
      str= "FIXED";
 
151
      break;
 
152
    case message::Table::TableOptions::ROW_TYPE_DYNAMIC:
 
153
      str= "DYNAMIC";
 
154
      break;
 
155
    case message::Table::TableOptions::ROW_TYPE_COMPRESSED:
 
156
      str= "COMPRESSED";
 
157
      break;
 
158
    case message::Table::TableOptions::ROW_TYPE_REDUNDANT:
 
159
      str= "REDUNDANT";
 
160
      break;
 
161
    case message::Table::TableOptions::ROW_TYPE_COMPACT:
 
162
      str= "COMPACT";
 
163
      break;
 
164
    case message::Table::TableOptions::ROW_TYPE_PAGE:
 
165
      str= "PAGE";
 
166
      break;
 
167
    }
 
168
    message::Table::TableOptions options= table_proto.options();
 
169
 
 
170
    push(str);
 
171
  }
 
172
 
 
173
  /* TABLE_COLLATION */
 
174
  push(table_proto.options().collation());
 
175
 
 
176
  /* TABLE_COMMENT */
 
177
  push(table_proto.options().comment());
 
178
}