~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to plugin/schema_dictionary/tables.cc

  • Committer: Brian Aker
  • Date: 2010-02-14 02:02:48 UTC
  • mfrom: (1273.13.64 fix_is)
  • Revision ID: brian@gaz-20100214020248-bhovaejhz9fmer3q
MergeĀ inĀ data_dictionary.

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