~drizzle-trunk/drizzle/development

1273.13.5 by Brian Aker
Additional definitions.
1
/* - mode: c; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
 *  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
3
 *
1999.6.1 by kalebral at gmail
update Copyright strings to a more common format to help with creating the master debian copyright file
4
 *  Copyright (C) 2010 Sun Microsystems, Inc.
1273.13.5 by Brian Aker
Additional definitions.
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
2173.2.1 by Monty Taylor
Fixes incorrect usage of include
21
#include <config.h>
22
#include <plugin/schema_dictionary/dictionary.h>
23
#include <drizzled/identifier.h>
2338.2.1 by Stewart Smith
use TABLE_COMMENT_MAXLEN define in schema_dictionary instead of hard coded 2048
24
#include <drizzled/table_proto.h>
1273.13.18 by Brian Aker
Update code, first pass through cleaner method for recursing through
25
1273.13.5 by Brian Aker
Additional definitions.
26
using namespace std;
27
using namespace drizzled;
28
1273.13.45 by Brian Aker
Update for test split.
29
static const string STANDARD("STANDARD");
30
static const string TEMPORARY("TEMPORARY");
31
static const string INTERNAL("INTERNAL");
32
static const string FUNCTION("FUNCTION");
33
34
1273.13.66 by Brian Aker
Modify return type for COLUMNS type.
35
static const string VARCHAR("VARCHAR");
36
static const string DOUBLE("DOUBLE");
37
static const string BLOB("BLOB");
38
static const string ENUM("ENUM");
39
static const string INTEGER("INTEGER");
40
static const string BIGINT("BIGINT");
41
static const string DECIMAL("DECIMAL");
42
static const string DATE("DATE");
43
static const string TIMESTAMP("TIMESTAMP");
44
static const string DATETIME("DATETIME");
45
1273.13.7 by Brian Aker
Updates to the classes (first pass).
46
TablesTool::TablesTool() :
1643.3.1 by Brian Aker
Move schema listing logic out.
47
  plugin::TableFunction("DATA_DICTIONARY", "TABLES")
1273.13.18 by Brian Aker
Update code, first pass through cleaner method for recursing through
48
{
2338.2.2 by Stewart Smith
use MAXIMUM_IDENTIFIER_LENGTH for DATA_DICTIONARY.TABLES columns
49
  add_field("TABLE_SCHEMA", plugin::TableFunction::STRING, MAXIMUM_IDENTIFIER_LENGTH, false);
50
  add_field("TABLE_NAME", plugin::TableFunction::STRING, MAXIMUM_IDENTIFIER_LENGTH, false);
1273.13.18 by Brian Aker
Update code, first pass through cleaner method for recursing through
51
  add_field("TABLE_TYPE");
1802.12.1 by Brian Aker
This solves bug lp:654905
52
  add_field("TABLE_ARCHETYPE");
1273.13.18 by Brian Aker
Update code, first pass through cleaner method for recursing through
53
  add_field("ENGINE");
54
  add_field("ROW_FORMAT", 10);
55
  add_field("TABLE_COLLATION");
1340.1.4 by Brian Aker
A first pass through adding a timestamp to our proto.
56
  add_field("TABLE_CREATION_TIME");
57
  add_field("TABLE_UPDATE_TIME");
2338.2.1 by Stewart Smith
use TABLE_COMMENT_MAXLEN define in schema_dictionary instead of hard coded 2048
58
  add_field("TABLE_COMMENT", plugin::TableFunction::STRING,
59
            TABLE_COMMENT_MAXLEN, true);
1802.5.1 by Andrew Hutchings
Adds auto_increment to data_dictionary.tables and drizzledump (when connecting to a Drizzle server)
60
  add_field("AUTO_INCREMENT", plugin::TableFunction::NUMBER, 0, false);
1802.12.1 by Brian Aker
This solves bug lp:654905
61
  add_field("TABLE_UUID", plugin::TableFunction::STRING, 36, true);
62
  add_field("TABLE_VERSION", plugin::TableFunction::NUMBER, 0, true);
2187.7.6 by Brian Aker
This fixes the message such that the table inherits the no replication
63
  add_field("IS_REPLICATED", plugin::TableFunction::BOOLEAN, 0, false);
2241.6.2 by Brian Aker
This adds the concept of a definer to a table definition.
64
  add_field("TABLE_DEFINER", plugin::TableFunction::STRING, 64, true);
1273.13.18 by Brian Aker
Update code, first pass through cleaner method for recursing through
65
}
66
67
TablesTool::Generator::Generator(Field **arg) :
1643.3.1 by Brian Aker
Move schema listing logic out.
68
  plugin::TableFunction::Generator(arg),
1643.3.5 by Brian Aker
Addd an "all_tables" generator to loop through all tables.
69
  all_tables_generator(getSession())
70
{
1273.13.18 by Brian Aker
Update code, first pass through cleaner method for recursing through
71
}
72
73
bool TablesTool::Generator::nextTable()
74
{
1938.4.2 by Brian Aker
Fix style issue around table for message (though this is imperfect,...)
75
  drizzled::message::table::shared_ptr table_ptr;
1643.3.5 by Brian Aker
Addd an "all_tables" generator to loop through all tables.
76
  while ((table_ptr= all_tables_generator))
1273.13.18 by Brian Aker
Update code, first pass through cleaner method for recursing through
77
  {
1643.3.5 by Brian Aker
Addd an "all_tables" generator to loop through all tables.
78
    table_message.CopyFrom(*table_ptr);
79
    return true;
1273.13.18 by Brian Aker
Update code, first pass through cleaner method for recursing through
80
  }
81
1643.3.5 by Brian Aker
Addd an "all_tables" generator to loop through all tables.
82
  return false;
1273.13.18 by Brian Aker
Update code, first pass through cleaner method for recursing through
83
}
84
1273.13.21 by Brian Aker
Fix interface (we no longer need Fields passed around).
85
bool TablesTool::Generator::populate()
1273.13.18 by Brian Aker
Update code, first pass through cleaner method for recursing through
86
{
1643.3.5 by Brian Aker
Addd an "all_tables" generator to loop through all tables.
87
  if (nextTable())
88
  {
89
    fill();
90
    return true;
91
  }
92
93
  return false;
1273.13.18 by Brian Aker
Update code, first pass through cleaner method for recursing through
94
}
95
96
void TablesTool::Generator::fill()
97
{
98
1340.1.4 by Brian Aker
A first pass through adding a timestamp to our proto.
99
  /**
100
    @note use --replace-column
101
  */
102
1273.13.18 by Brian Aker
Update code, first pass through cleaner method for recursing through
103
  /* TABLE_SCHEMA */
1643.3.5 by Brian Aker
Addd an "all_tables" generator to loop through all tables.
104
  push(getTableMessage().schema());
1273.13.18 by Brian Aker
Update code, first pass through cleaner method for recursing through
105
106
  /* TABLE_NAME */
1643.3.5 by Brian Aker
Addd an "all_tables" generator to loop through all tables.
107
  push(getTableMessage().name());
1273.13.11 by Brian Aker
First pass through tables.
108
109
  /* TABLE_TYPE */
2087.4.2 by Brian Aker
Modify TableIdentifier to fit with the rest of the identifiers.
110
  if (drizzled::identifier::Table::isView(getTableMessage().type()))
1802.12.1 by Brian Aker
This solves bug lp:654905
111
  {
112
    push("VIEW");
113
  }
114
  else
115
  {
116
    push("BASE");
117
  }
118
119
  /* TABLE_ARCHETYPE */
1273.13.11 by Brian Aker
First pass through tables.
120
  {
1643.3.5 by Brian Aker
Addd an "all_tables" generator to loop through all tables.
121
    switch (getTableMessage().type())
1273.13.11 by Brian Aker
First pass through tables.
122
    {
123
    default:
124
    case message::Table::STANDARD:
1273.13.45 by Brian Aker
Update for test split.
125
      push(STANDARD);
1273.13.11 by Brian Aker
First pass through tables.
126
      break;
127
    case message::Table::TEMPORARY:
1273.13.45 by Brian Aker
Update for test split.
128
      push(TEMPORARY);
1273.13.11 by Brian Aker
First pass through tables.
129
      break;
130
    case message::Table::INTERNAL:
1273.13.45 by Brian Aker
Update for test split.
131
      push(INTERNAL);
1273.13.11 by Brian Aker
First pass through tables.
132
      break;
133
    case message::Table::FUNCTION:
1273.13.45 by Brian Aker
Update for test split.
134
      push(FUNCTION);
1273.13.11 by Brian Aker
First pass through tables.
135
      break;
136
    }
137
  }
138
139
  /* ENGINE */
2082.2.1 by Andrew Hutchings
If ROW_FORMAT was specified then actually show it in data_dictionary.tables
140
  const drizzled::message::Engine &engine= getTableMessage().engine();
141
  push(engine.name());
1273.13.11 by Brian Aker
First pass through tables.
142
143
  /* ROW_FORMAT */
2082.2.1 by Andrew Hutchings
If ROW_FORMAT was specified then actually show it in data_dictionary.tables
144
  bool row_format_sent= false;
145
  for (ssize_t it= 0; it < engine.options_size(); it++)
146
  {
147
    const drizzled::message::Engine::Option &opt= engine.options(it);
148
    if (opt.name().compare("ROW_FORMAT") == 0)
149
    {
150
      row_format_sent= true;
151
      push(opt.state());
152
      break;
153
    }
154
  }
155
156
  if (not row_format_sent)
157
    push("DEFAULT");
1273.13.11 by Brian Aker
First pass through tables.
158
159
  /* TABLE_COLLATION */
1643.3.5 by Brian Aker
Addd an "all_tables" generator to loop through all tables.
160
  push(getTableMessage().options().collation());
1273.13.11 by Brian Aker
First pass through tables.
161
1340.1.4 by Brian Aker
A first pass through adding a timestamp to our proto.
162
  /* TABLE_CREATION_TIME */
1643.3.5 by Brian Aker
Addd an "all_tables" generator to loop through all tables.
163
  time_t time_arg= getTableMessage().creation_timestamp();
1340.1.4 by Brian Aker
A first pass through adding a timestamp to our proto.
164
  char buffer[40];
165
  struct tm tm_buffer;
166
167
  localtime_r(&time_arg, &tm_buffer);
168
  strftime(buffer, sizeof(buffer), "%a %b %d %H:%M:%S %Y", &tm_buffer);
169
  push(buffer);
170
171
  /* TABLE_UPDATE_TIME */
1643.3.5 by Brian Aker
Addd an "all_tables" generator to loop through all tables.
172
  time_arg= getTableMessage().update_timestamp();
1340.1.4 by Brian Aker
A first pass through adding a timestamp to our proto.
173
  localtime_r(&time_arg, &tm_buffer);
174
  strftime(buffer, sizeof(buffer), "%a %b %d %H:%M:%S %Y", &tm_buffer);
175
  push(buffer);
176
1273.13.11 by Brian Aker
First pass through tables.
177
  /* TABLE_COMMENT */
1643.3.5 by Brian Aker
Addd an "all_tables" generator to loop through all tables.
178
  if (getTableMessage().options().has_comment())
1567.1.1 by Brian Aker
This fixes bug 586009, increases the size of the log files so that the UNION
179
  {
1643.3.5 by Brian Aker
Addd an "all_tables" generator to loop through all tables.
180
    push(getTableMessage().options().comment());
1567.1.1 by Brian Aker
This fixes bug 586009, increases the size of the log files so that the UNION
181
  }
182
  else
183
  {
184
    push();
185
  }
1802.5.1 by Andrew Hutchings
Adds auto_increment to data_dictionary.tables and drizzledump (when connecting to a Drizzle server)
186
187
  /* AUTO_INCREMENT */
188
  push(getTableMessage().options().auto_increment_value());
1802.12.1 by Brian Aker
This solves bug lp:654905
189
190
  /* TABLE_UUID */
191
  push(getTableMessage().uuid());
192
193
  /* TABLE_VERSION */
194
  push(getTableMessage().version());
2187.7.6 by Brian Aker
This fixes the message such that the table inherits the no replication
195
196
  /* IS_REPLICATED */
197
  push(message::is_replicated(getTableMessage()));
2241.6.2 by Brian Aker
This adds the concept of a definer to a table definition.
198
199
  /* _DEFINER */
200
  if (message::has_definer(getTableMessage()))
201
  {
202
    push(message::definer(getTableMessage()));
203
  }
204
  else
205
  {
206
    push();
207
  }
1273.13.11 by Brian Aker
First pass through tables.
208
}