~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to plugin/schema_dictionary/tables.cc

  • Committer: brian
  • Date: 2008-06-25 05:29:13 UTC
  • Revision ID: brian@localhost.localdomain-20080625052913-6upwo0jsrl4lnapl
clean slate

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/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
 
 
34
 
static const string VARCHAR("VARCHAR");
35
 
static const string DOUBLE("DOUBLE");
36
 
static const string BLOB("BLOB");
37
 
static const string ENUM("ENUM");
38
 
static const string INTEGER("INTEGER");
39
 
static const string BIGINT("BIGINT");
40
 
static const string DECIMAL("DECIMAL");
41
 
static const string DATE("DATE");
42
 
static const string TIMESTAMP("TIMESTAMP");
43
 
static const string DATETIME("DATETIME");
44
 
 
45
 
TablesTool::TablesTool() :
46
 
  plugin::TableFunction("DATA_DICTIONARY", "TABLES")
47
 
{
48
 
  add_field("TABLE_SCHEMA");
49
 
  add_field("TABLE_NAME");
50
 
  add_field("TABLE_TYPE");
51
 
  add_field("TABLE_ARCHETYPE");
52
 
  add_field("ENGINE");
53
 
  add_field("ROW_FORMAT", 10);
54
 
  add_field("TABLE_COLLATION");
55
 
  add_field("TABLE_CREATION_TIME");
56
 
  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);
61
 
}
62
 
 
63
 
TablesTool::Generator::Generator(Field **arg) :
64
 
  plugin::TableFunction::Generator(arg),
65
 
  all_tables_generator(getSession())
66
 
{
67
 
}
68
 
 
69
 
bool TablesTool::Generator::nextTable()
70
 
{
71
 
  drizzled::message::table::shared_ptr table_ptr;
72
 
  while ((table_ptr= all_tables_generator))
73
 
  {
74
 
    table_message.CopyFrom(*table_ptr);
75
 
    return true;
76
 
  }
77
 
 
78
 
  return false;
79
 
}
80
 
 
81
 
bool TablesTool::Generator::populate()
82
 
{
83
 
  if (nextTable())
84
 
  {
85
 
    fill();
86
 
    return true;
87
 
  }
88
 
 
89
 
  return false;
90
 
}
91
 
 
92
 
void TablesTool::Generator::fill()
93
 
{
94
 
 
95
 
  /**
96
 
    @note use --replace-column
97
 
  */
98
 
 
99
 
  /* TABLE_SCHEMA */
100
 
  push(getTableMessage().schema());
101
 
 
102
 
  /* TABLE_NAME */
103
 
  push(getTableMessage().name());
104
 
 
105
 
  /* 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())
118
 
    {
119
 
    default:
120
 
    case message::Table::STANDARD:
121
 
      push(STANDARD);
122
 
      break;
123
 
    case message::Table::TEMPORARY:
124
 
      push(TEMPORARY);
125
 
      break;
126
 
    case message::Table::INTERNAL:
127
 
      push(INTERNAL);
128
 
      break;
129
 
    case message::Table::FUNCTION:
130
 
      push(FUNCTION);
131
 
      break;
132
 
    }
133
 
  }
134
 
 
135
 
  /* ENGINE */
136
 
  push(getTableMessage().engine().name());
137
 
 
138
 
  /* ROW_FORMAT */
139
 
  push("DEFAULT");
140
 
 
141
 
  /* TABLE_COLLATION */
142
 
  push(getTableMessage().options().collation());
143
 
 
144
 
  /* TABLE_CREATION_TIME */
145
 
  time_t time_arg= getTableMessage().creation_timestamp();
146
 
  char buffer[40];
147
 
  struct tm tm_buffer;
148
 
 
149
 
  localtime_r(&time_arg, &tm_buffer);
150
 
  strftime(buffer, sizeof(buffer), "%a %b %d %H:%M:%S %Y", &tm_buffer);
151
 
  push(buffer);
152
 
 
153
 
  /* TABLE_UPDATE_TIME */
154
 
  time_arg= getTableMessage().update_timestamp();
155
 
  localtime_r(&time_arg, &tm_buffer);
156
 
  strftime(buffer, sizeof(buffer), "%a %b %d %H:%M:%S %Y", &tm_buffer);
157
 
  push(buffer);
158
 
 
159
 
  /* 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());
177
 
}