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 |
*
|
|
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 |
||
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"); |
|
51 |
add_field("ENGINE"); |
|
52 |
add_field("ROW_FORMAT", 10); |
|
53 |
add_field("TABLE_COLLATION"); |
|
1340.1.4
by Brian Aker
A first pass through adding a timestamp to our proto. |
54 |
add_field("TABLE_CREATION_TIME"); |
55 |
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 |
56 |
add_field("TABLE_COMMENT", plugin::TableFunction::STRING, 2048, true); |
1273.13.18
by Brian Aker
Update code, first pass through cleaner method for recursing through |
57 |
}
|
58 |
||
59 |
TablesTool::Generator::Generator(Field **arg) : |
|
1643.3.1
by Brian Aker
Move schema listing logic out. |
60 |
plugin::TableFunction::Generator(arg), |
1643.3.5
by Brian Aker
Addd an "all_tables" generator to loop through all tables. |
61 |
all_tables_generator(getSession()) |
62 |
{
|
|
1273.13.18
by Brian Aker
Update code, first pass through cleaner method for recursing through |
63 |
}
|
64 |
||
65 |
bool TablesTool::Generator::nextTable() |
|
66 |
{
|
|
1643.3.5
by Brian Aker
Addd an "all_tables" generator to loop through all tables. |
67 |
const drizzled::message::Table *table_ptr; |
68 |
while ((table_ptr= all_tables_generator)) |
|
1273.13.18
by Brian Aker
Update code, first pass through cleaner method for recursing through |
69 |
{
|
1643.3.5
by Brian Aker
Addd an "all_tables" generator to loop through all tables. |
70 |
table_message.CopyFrom(*table_ptr); |
71 |
return true; |
|
1273.13.18
by Brian Aker
Update code, first pass through cleaner method for recursing through |
72 |
}
|
73 |
||
1643.3.5
by Brian Aker
Addd an "all_tables" generator to loop through all tables. |
74 |
return false; |
1273.13.18
by Brian Aker
Update code, first pass through cleaner method for recursing through |
75 |
}
|
76 |
||
1273.13.21
by Brian Aker
Fix interface (we no longer need Fields passed around). |
77 |
bool TablesTool::Generator::populate() |
1273.13.18
by Brian Aker
Update code, first pass through cleaner method for recursing through |
78 |
{
|
1643.3.5
by Brian Aker
Addd an "all_tables" generator to loop through all tables. |
79 |
if (nextTable()) |
80 |
{
|
|
81 |
fill(); |
|
82 |
return true; |
|
83 |
}
|
|
84 |
||
85 |
return false; |
|
1273.13.18
by Brian Aker
Update code, first pass through cleaner method for recursing through |
86 |
}
|
87 |
||
1273.13.66
by Brian Aker
Modify return type for COLUMNS type. |
88 |
void TablesTool::Generator::pushType(message::Table::Field::FieldType type) |
89 |
{
|
|
90 |
switch (type) |
|
91 |
{
|
|
92 |
default: |
|
93 |
case message::Table::Field::VARCHAR: |
|
94 |
push(VARCHAR); |
|
95 |
break; |
|
96 |
case message::Table::Field::DOUBLE: |
|
97 |
push(DOUBLE); |
|
98 |
break; |
|
99 |
case message::Table::Field::BLOB: |
|
100 |
push(BLOB); |
|
101 |
break; |
|
102 |
case message::Table::Field::ENUM: |
|
103 |
push(ENUM); |
|
104 |
break; |
|
105 |
case message::Table::Field::INTEGER: |
|
106 |
push(INTEGER); |
|
107 |
break; |
|
108 |
case message::Table::Field::BIGINT: |
|
109 |
push(BIGINT); |
|
110 |
break; |
|
111 |
case message::Table::Field::DECIMAL: |
|
112 |
push(DECIMAL); |
|
113 |
break; |
|
114 |
case message::Table::Field::DATE: |
|
115 |
push(DATE); |
|
116 |
break; |
|
117 |
case message::Table::Field::TIMESTAMP: |
|
118 |
push(TIMESTAMP); |
|
119 |
break; |
|
120 |
case message::Table::Field::DATETIME: |
|
121 |
push(DATETIME); |
|
122 |
break; |
|
123 |
}
|
|
124 |
}
|
|
125 |
||
1273.13.18
by Brian Aker
Update code, first pass through cleaner method for recursing through |
126 |
void TablesTool::Generator::fill() |
127 |
{
|
|
128 |
||
1340.1.4
by Brian Aker
A first pass through adding a timestamp to our proto. |
129 |
/**
|
130 |
@note use --replace-column
|
|
131 |
*/
|
|
132 |
||
1273.13.18
by Brian Aker
Update code, first pass through cleaner method for recursing through |
133 |
/* TABLE_SCHEMA */
|
1643.3.5
by Brian Aker
Addd an "all_tables" generator to loop through all tables. |
134 |
push(getTableMessage().schema()); |
1273.13.18
by Brian Aker
Update code, first pass through cleaner method for recursing through |
135 |
|
136 |
/* TABLE_NAME */
|
|
1643.3.5
by Brian Aker
Addd an "all_tables" generator to loop through all tables. |
137 |
push(getTableMessage().name()); |
1273.13.11
by Brian Aker
First pass through tables. |
138 |
|
139 |
/* TABLE_TYPE */
|
|
140 |
{
|
|
1643.3.5
by Brian Aker
Addd an "all_tables" generator to loop through all tables. |
141 |
switch (getTableMessage().type()) |
1273.13.11
by Brian Aker
First pass through tables. |
142 |
{
|
143 |
default: |
|
144 |
case message::Table::STANDARD: |
|
1273.13.45
by Brian Aker
Update for test split. |
145 |
push(STANDARD); |
1273.13.11
by Brian Aker
First pass through tables. |
146 |
break; |
147 |
case message::Table::TEMPORARY: |
|
1273.13.45
by Brian Aker
Update for test split. |
148 |
push(TEMPORARY); |
1273.13.11
by Brian Aker
First pass through tables. |
149 |
break; |
150 |
case message::Table::INTERNAL: |
|
1273.13.45
by Brian Aker
Update for test split. |
151 |
push(INTERNAL); |
1273.13.11
by Brian Aker
First pass through tables. |
152 |
break; |
153 |
case message::Table::FUNCTION: |
|
1273.13.45
by Brian Aker
Update for test split. |
154 |
push(FUNCTION); |
1273.13.11
by Brian Aker
First pass through tables. |
155 |
break; |
156 |
}
|
|
157 |
}
|
|
158 |
||
159 |
/* ENGINE */
|
|
1643.3.5
by Brian Aker
Addd an "all_tables" generator to loop through all tables. |
160 |
push(getTableMessage().engine().name()); |
1273.13.11
by Brian Aker
First pass through tables. |
161 |
|
162 |
/* ROW_FORMAT */
|
|
1638.2.1
by Stewart Smith
remove unused row_type from table proto (although referenced in a bunch of places) |
163 |
push("DEFAULT"); |
1273.13.11
by Brian Aker
First pass through tables. |
164 |
|
165 |
/* TABLE_COLLATION */
|
|
1643.3.5
by Brian Aker
Addd an "all_tables" generator to loop through all tables. |
166 |
push(getTableMessage().options().collation()); |
1273.13.11
by Brian Aker
First pass through tables. |
167 |
|
1340.1.4
by Brian Aker
A first pass through adding a timestamp to our proto. |
168 |
/* TABLE_CREATION_TIME */
|
1643.3.5
by Brian Aker
Addd an "all_tables" generator to loop through all tables. |
169 |
time_t time_arg= getTableMessage().creation_timestamp(); |
1340.1.4
by Brian Aker
A first pass through adding a timestamp to our proto. |
170 |
char buffer[40]; |
171 |
struct tm tm_buffer; |
|
172 |
||
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_UPDATE_TIME */
|
|
1643.3.5
by Brian Aker
Addd an "all_tables" generator to loop through all tables. |
178 |
time_arg= getTableMessage().update_timestamp(); |
1340.1.4
by Brian Aker
A first pass through adding a timestamp to our proto. |
179 |
localtime_r(&time_arg, &tm_buffer); |
180 |
strftime(buffer, sizeof(buffer), "%a %b %d %H:%M:%S %Y", &tm_buffer); |
|
181 |
push(buffer); |
|
182 |
||
1273.13.11
by Brian Aker
First pass through tables. |
183 |
/* TABLE_COMMENT */
|
1643.3.5
by Brian Aker
Addd an "all_tables" generator to loop through all tables. |
184 |
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 |
185 |
{
|
1643.3.5
by Brian Aker
Addd an "all_tables" generator to loop through all tables. |
186 |
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 |
187 |
}
|
188 |
else
|
|
189 |
{
|
|
190 |
push(); |
|
191 |
}
|
|
1273.13.11
by Brian Aker
First pass through tables. |
192 |
}
|