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 |
||
1273.14.5
by Monty Taylor
Merged trunk. |
21 |
#include "config.h" |
1273.13.49
by Brian Aker
Does not work (compile issue in plugin). |
22 |
#include "plugin/schema_dictionary/dictionary.h" |
1660.1.1
by Brian Aker
Merge in move identifier work. |
23 |
#include "drizzled/identifier.h" |
1273.13.18
by Brian Aker
Update code, first pass through cleaner method for recursing through |
24 |
|
1273.13.5
by Brian Aker
Additional definitions. |
25 |
using namespace std; |
26 |
using namespace drizzled; |
|
27 |
||
1273.13.45
by Brian Aker
Update for test split. |
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 |
||
1273.13.66
by Brian Aker
Modify return type for COLUMNS type. |
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 |
||
1273.13.7
by Brian Aker
Updates to the classes (first pass). |
45 |
TablesTool::TablesTool() : |
1643.3.1
by Brian Aker
Move schema listing logic out. |
46 |
plugin::TableFunction("DATA_DICTIONARY", "TABLES") |
1273.13.18
by Brian Aker
Update code, first pass through cleaner method for recursing through |
47 |
{
|
48 |
add_field("TABLE_SCHEMA"); |
|
49 |
add_field("TABLE_NAME"); |
|
50 |
add_field("TABLE_TYPE"); |
|
1802.12.1
by Brian Aker
This solves bug lp:654905 |
51 |
add_field("TABLE_ARCHETYPE"); |
1273.13.18
by Brian Aker
Update code, first pass through cleaner method for recursing through |
52 |
add_field("ENGINE"); |
53 |
add_field("ROW_FORMAT", 10); |
|
54 |
add_field("TABLE_COLLATION"); |
|
1340.1.4
by Brian Aker
A first pass through adding a timestamp to our proto. |
55 |
add_field("TABLE_CREATION_TIME"); |
56 |
add_field("TABLE_UPDATE_TIME"); |
|
1567.1.1
by Brian Aker
This fixes bug 586009, increases the size of the log files so that the UNION |
57 |
add_field("TABLE_COMMENT", plugin::TableFunction::STRING, 2048, true); |
1802.5.1
by Andrew Hutchings
Adds auto_increment to data_dictionary.tables and drizzledump (when connecting to a Drizzle server) |
58 |
add_field("AUTO_INCREMENT", plugin::TableFunction::NUMBER, 0, false); |
1802.12.1
by Brian Aker
This solves bug lp:654905 |
59 |
add_field("TABLE_UUID", plugin::TableFunction::STRING, 36, true); |
60 |
add_field("TABLE_VERSION", plugin::TableFunction::NUMBER, 0, true); |
|
1273.13.18
by Brian Aker
Update code, first pass through cleaner method for recursing through |
61 |
}
|
62 |
||
63 |
TablesTool::Generator::Generator(Field **arg) : |
|
1643.3.1
by Brian Aker
Move schema listing logic out. |
64 |
plugin::TableFunction::Generator(arg), |
1643.3.5
by Brian Aker
Addd an "all_tables" generator to loop through all tables. |
65 |
all_tables_generator(getSession()) |
66 |
{
|
|
1273.13.18
by Brian Aker
Update code, first pass through cleaner method for recursing through |
67 |
}
|
68 |
||
69 |
bool TablesTool::Generator::nextTable() |
|
70 |
{
|
|
1938.4.2
by Brian Aker
Fix style issue around table for message (though this is imperfect,...) |
71 |
drizzled::message::table::shared_ptr table_ptr; |
1643.3.5
by Brian Aker
Addd an "all_tables" generator to loop through all tables. |
72 |
while ((table_ptr= all_tables_generator)) |
1273.13.18
by Brian Aker
Update code, first pass through cleaner method for recursing through |
73 |
{
|
1643.3.5
by Brian Aker
Addd an "all_tables" generator to loop through all tables. |
74 |
table_message.CopyFrom(*table_ptr); |
75 |
return true; |
|
1273.13.18
by Brian Aker
Update code, first pass through cleaner method for recursing through |
76 |
}
|
77 |
||
1643.3.5
by Brian Aker
Addd an "all_tables" generator to loop through all tables. |
78 |
return false; |
1273.13.18
by Brian Aker
Update code, first pass through cleaner method for recursing through |
79 |
}
|
80 |
||
1273.13.21
by Brian Aker
Fix interface (we no longer need Fields passed around). |
81 |
bool TablesTool::Generator::populate() |
1273.13.18
by Brian Aker
Update code, first pass through cleaner method for recursing through |
82 |
{
|
1643.3.5
by Brian Aker
Addd an "all_tables" generator to loop through all tables. |
83 |
if (nextTable()) |
84 |
{
|
|
85 |
fill(); |
|
86 |
return true; |
|
87 |
}
|
|
88 |
||
89 |
return false; |
|
1273.13.18
by Brian Aker
Update code, first pass through cleaner method for recursing through |
90 |
}
|
91 |
||
92 |
void TablesTool::Generator::fill() |
|
93 |
{
|
|
94 |
||
1340.1.4
by Brian Aker
A first pass through adding a timestamp to our proto. |
95 |
/**
|
96 |
@note use --replace-column
|
|
97 |
*/
|
|
98 |
||
1273.13.18
by Brian Aker
Update code, first pass through cleaner method for recursing through |
99 |
/* TABLE_SCHEMA */
|
1643.3.5
by Brian Aker
Addd an "all_tables" generator to loop through all tables. |
100 |
push(getTableMessage().schema()); |
1273.13.18
by Brian Aker
Update code, first pass through cleaner method for recursing through |
101 |
|
102 |
/* TABLE_NAME */
|
|
1643.3.5
by Brian Aker
Addd an "all_tables" generator to loop through all tables. |
103 |
push(getTableMessage().name()); |
1273.13.11
by Brian Aker
First pass through tables. |
104 |
|
105 |
/* TABLE_TYPE */
|
|
1802.12.1
by Brian Aker
This solves bug lp:654905 |
106 |
if (drizzled::TableIdentifier::isView(getTableMessage().type())) |
107 |
{
|
|
108 |
push("VIEW"); |
|
109 |
}
|
|
110 |
else
|
|
111 |
{
|
|
112 |
push("BASE"); |
|
113 |
}
|
|
114 |
||
115 |
/* TABLE_ARCHETYPE */
|
|
1273.13.11
by Brian Aker
First pass through tables. |
116 |
{
|
1643.3.5
by Brian Aker
Addd an "all_tables" generator to loop through all tables. |
117 |
switch (getTableMessage().type()) |
1273.13.11
by Brian Aker
First pass through tables. |
118 |
{
|
119 |
default: |
|
120 |
case message::Table::STANDARD: |
|
1273.13.45
by Brian Aker
Update for test split. |
121 |
push(STANDARD); |
1273.13.11
by Brian Aker
First pass through tables. |
122 |
break; |
123 |
case message::Table::TEMPORARY: |
|
1273.13.45
by Brian Aker
Update for test split. |
124 |
push(TEMPORARY); |
1273.13.11
by Brian Aker
First pass through tables. |
125 |
break; |
126 |
case message::Table::INTERNAL: |
|
1273.13.45
by Brian Aker
Update for test split. |
127 |
push(INTERNAL); |
1273.13.11
by Brian Aker
First pass through tables. |
128 |
break; |
129 |
case message::Table::FUNCTION: |
|
1273.13.45
by Brian Aker
Update for test split. |
130 |
push(FUNCTION); |
1273.13.11
by Brian Aker
First pass through tables. |
131 |
break; |
132 |
}
|
|
133 |
}
|
|
134 |
||
135 |
/* ENGINE */
|
|
2082.2.1
by Andrew Hutchings
If ROW_FORMAT was specified then actually show it in data_dictionary.tables |
136 |
const drizzled::message::Engine &engine= getTableMessage().engine(); |
137 |
push(engine.name()); |
|
1273.13.11
by Brian Aker
First pass through tables. |
138 |
|
139 |
/* ROW_FORMAT */
|
|
2082.2.1
by Andrew Hutchings
If ROW_FORMAT was specified then actually show it in data_dictionary.tables |
140 |
bool row_format_sent= false; |
141 |
for (ssize_t it= 0; it < engine.options_size(); it++) |
|
142 |
{
|
|
143 |
const drizzled::message::Engine::Option &opt= engine.options(it); |
|
144 |
if (opt.name().compare("ROW_FORMAT") == 0) |
|
145 |
{
|
|
146 |
row_format_sent= true; |
|
147 |
push(opt.state()); |
|
148 |
break; |
|
149 |
}
|
|
150 |
}
|
|
151 |
||
152 |
if (not row_format_sent) |
|
153 |
push("DEFAULT"); |
|
1273.13.11
by Brian Aker
First pass through tables. |
154 |
|
155 |
/* TABLE_COLLATION */
|
|
1643.3.5
by Brian Aker
Addd an "all_tables" generator to loop through all tables. |
156 |
push(getTableMessage().options().collation()); |
1273.13.11
by Brian Aker
First pass through tables. |
157 |
|
1340.1.4
by Brian Aker
A first pass through adding a timestamp to our proto. |
158 |
/* TABLE_CREATION_TIME */
|
1643.3.5
by Brian Aker
Addd an "all_tables" generator to loop through all tables. |
159 |
time_t time_arg= getTableMessage().creation_timestamp(); |
1340.1.4
by Brian Aker
A first pass through adding a timestamp to our proto. |
160 |
char buffer[40]; |
161 |
struct tm tm_buffer; |
|
162 |
||
163 |
localtime_r(&time_arg, &tm_buffer); |
|
164 |
strftime(buffer, sizeof(buffer), "%a %b %d %H:%M:%S %Y", &tm_buffer); |
|
165 |
push(buffer); |
|
166 |
||
167 |
/* TABLE_UPDATE_TIME */
|
|
1643.3.5
by Brian Aker
Addd an "all_tables" generator to loop through all tables. |
168 |
time_arg= getTableMessage().update_timestamp(); |
1340.1.4
by Brian Aker
A first pass through adding a timestamp to our proto. |
169 |
localtime_r(&time_arg, &tm_buffer); |
170 |
strftime(buffer, sizeof(buffer), "%a %b %d %H:%M:%S %Y", &tm_buffer); |
|
171 |
push(buffer); |
|
172 |
||
1273.13.11
by Brian Aker
First pass through tables. |
173 |
/* TABLE_COMMENT */
|
1643.3.5
by Brian Aker
Addd an "all_tables" generator to loop through all tables. |
174 |
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 |
175 |
{
|
1643.3.5
by Brian Aker
Addd an "all_tables" generator to loop through all tables. |
176 |
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 |
177 |
}
|
178 |
else
|
|
179 |
{
|
|
180 |
push(); |
|
181 |
}
|
|
1802.5.1
by Andrew Hutchings
Adds auto_increment to data_dictionary.tables and drizzledump (when connecting to a Drizzle server) |
182 |
|
183 |
/* AUTO_INCREMENT */
|
|
184 |
push(getTableMessage().options().auto_increment_value()); |
|
1802.12.1
by Brian Aker
This solves bug lp:654905 |
185 |
|
186 |
/* TABLE_UUID */
|
|
187 |
push(getTableMessage().uuid()); |
|
188 |
||
189 |
/* TABLE_VERSION */
|
|
190 |
push(getTableMessage().version()); |
|
1273.13.11
by Brian Aker
First pass through tables. |
191 |
}
|