drizzle
C++ MySQL-protocol-compatible database server
Loading...
Searching...
No Matches
schema_dictionary/tables.cc
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, Inc.
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#include <drizzled/table_proto.h>
25
26using namespace std;
27using namespace drizzled;
28
29static const string STANDARD("STANDARD");
30static const string TEMPORARY("TEMPORARY");
31static const string INTERNAL("INTERNAL");
32static const string FUNCTION("FUNCTION");
33
34
35static const string VARCHAR("VARCHAR");
36static const string DOUBLE("DOUBLE");
37static const string BLOB("BLOB");
38static const string ENUM("ENUM");
39static const string INTEGER("INTEGER");
40static const string BIGINT("BIGINT");
41static const string DECIMAL("DECIMAL");
42static const string DATE("DATE");
43static const string TIMESTAMP("TIMESTAMP");
44static const string DATETIME("DATETIME");
45
46TablesTool::TablesTool() :
47 plugin::TableFunction("DATA_DICTIONARY", "TABLES")
48{
49 add_field("TABLE_SCHEMA", plugin::TableFunction::STRING, MAXIMUM_IDENTIFIER_LENGTH, false);
50 add_field("TABLE_NAME", plugin::TableFunction::STRING, MAXIMUM_IDENTIFIER_LENGTH, false);
51 add_field("TABLE_TYPE");
52 add_field("TABLE_ARCHETYPE");
53 add_field("ENGINE");
54 add_field("ROW_FORMAT", 10);
55 add_field("TABLE_COLLATION");
56 add_field("TABLE_CREATION_TIME");
57 add_field("TABLE_UPDATE_TIME");
58 add_field("TABLE_COMMENT", plugin::TableFunction::STRING,
59 TABLE_COMMENT_MAXLEN, true);
60 add_field("AUTO_INCREMENT", plugin::TableFunction::NUMBER, 0, false);
61 add_field("TABLE_UUID", plugin::TableFunction::STRING, 36, true);
62 add_field("TABLE_VERSION", plugin::TableFunction::NUMBER, 0, true);
63 add_field("IS_REPLICATED", plugin::TableFunction::BOOLEAN, 0, false);
64 add_field("TABLE_DEFINER", plugin::TableFunction::STRING, 64, true);
65}
66
67TablesTool::Generator::Generator(Field **arg) :
68 plugin::TableFunction::Generator(arg),
69 all_tables_generator(getSession())
70{
71}
72
73bool TablesTool::Generator::nextTable()
74{
75 drizzled::message::table::shared_ptr table_ptr;
76 while ((table_ptr= all_tables_generator))
77 {
78 table_message.CopyFrom(*table_ptr);
79 return true;
80 }
81
82 return false;
83}
84
85bool TablesTool::Generator::populate()
86{
87 if (nextTable())
88 {
89 fill();
90 return true;
91 }
92
93 return false;
94}
95
97{
98
102
103 /* TABLE_SCHEMA */
104 push(getTableMessage().schema());
105
106 /* TABLE_NAME */
107 push(getTableMessage().name());
108
109 /* TABLE_TYPE */
110 if (drizzled::identifier::Table::isView(getTableMessage().type()))
111 {
112 push("VIEW");
113 }
114 else
115 {
116 push("BASE");
117 }
118
119 /* TABLE_ARCHETYPE */
120 {
121 switch (getTableMessage().type())
122 {
123 default:
124 case message::Table::STANDARD:
125 push(STANDARD);
126 break;
127 case message::Table::TEMPORARY:
128 push(TEMPORARY);
129 break;
130 case message::Table::INTERNAL:
131 push(INTERNAL);
132 break;
133 case message::Table::FUNCTION:
134 push(FUNCTION);
135 break;
136 }
137 }
138
139 /* ENGINE */
140 const drizzled::message::Engine &engine= getTableMessage().engine();
141 push(engine.name());
142
143 /* ROW_FORMAT */
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");
158
159 /* TABLE_COLLATION */
160 push(getTableMessage().options().collation());
161
162 /* TABLE_CREATION_TIME */
163 time_t time_arg= getTableMessage().creation_timestamp();
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 */
172 time_arg= getTableMessage().update_timestamp();
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
177 /* TABLE_COMMENT */
178 if (getTableMessage().options().has_comment())
179 {
180 push(getTableMessage().options().comment());
181 }
182 else
183 {
184 push();
185 }
186
187 /* AUTO_INCREMENT */
188 push(getTableMessage().options().auto_increment_value());
189
190 /* TABLE_UUID */
191 push(getTableMessage().uuid());
192
193 /* TABLE_VERSION */
194 push(getTableMessage().version());
195
196 /* IS_REPLICATED */
197 push(message::is_replicated(getTableMessage()));
198
199 /* _DEFINER */
200 if (message::has_definer(getTableMessage()))
201 {
202 push(message::definer(getTableMessage()));
203 }
204 else
205 {
206 push();
207 }
208}
Convert from decimal to binary representation.
Definition common_fwd.h:215
TODO: Rename this file - func.h is stupid.
STL namespace.