1309.2.4
by Brian Aker
New version of show columns code. |
1 |
/* - mode: c; c-basic-offset: 2; indent-tabs-mode: nil; -*-
|
2 |
* vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
|
|
3 |
*
|
|
4 |
* Copyright (C) 2010 Brian Aker
|
|
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" |
|
1429.1.1
by Brian Aker
Shift show commands to their own dictionary. |
22 |
#include "plugin/show_dictionary/dictionary.h" |
1660.1.1
by Brian Aker
Merge in move identifier work. |
23 |
#include "drizzled/identifier.h" |
1753.2.1
by Andrew Hutchings
Use collation in SHOW FIELDS FROM so that it can detect the difference beween TEXT and BLOB (and VARCHAR/VARBINARY) |
24 |
#include <string> |
1309.2.4
by Brian Aker
New version of show columns code. |
25 |
|
26 |
using namespace std; |
|
27 |
using namespace drizzled; |
|
28 |
||
29 |
static const string VARCHAR("VARCHAR"); |
|
1753.2.1
by Andrew Hutchings
Use collation in SHOW FIELDS FROM so that it can detect the difference beween TEXT and BLOB (and VARCHAR/VARBINARY) |
30 |
/* VARBINARY already defined elsewhere */
|
31 |
static const string VARBIN("VARBINARY"); |
|
1309.2.4
by Brian Aker
New version of show columns code. |
32 |
static const string DOUBLE("DOUBLE"); |
33 |
static const string BLOB("BLOB"); |
|
1753.2.1
by Andrew Hutchings
Use collation in SHOW FIELDS FROM so that it can detect the difference beween TEXT and BLOB (and VARCHAR/VARBINARY) |
34 |
static const string TEXT("TEXT"); |
1309.2.4
by Brian Aker
New version of show columns code. |
35 |
static const string ENUM("ENUM"); |
36 |
static const string INTEGER("INTEGER"); |
|
37 |
static const string BIGINT("BIGINT"); |
|
38 |
static const string DECIMAL("DECIMAL"); |
|
39 |
static const string DATE("DATE"); |
|
40 |
static const string TIMESTAMP("TIMESTAMP"); |
|
41 |
static const string DATETIME("DATETIME"); |
|
42 |
||
43 |
ShowColumns::ShowColumns() : |
|
1874.2.4
by Brian Aker
Have show functions be invisible. |
44 |
show_dictionary::Show("SHOW_COLUMNS") |
1309.2.4
by Brian Aker
New version of show columns code. |
45 |
{
|
46 |
add_field("Field"); |
|
47 |
add_field("Type"); |
|
1643.3.10
by Brian Aker
Column support, clean up of IS/DD for NULL type. |
48 |
add_field("Null", plugin::TableFunction::BOOLEAN, 0 , false); |
1309.2.4
by Brian Aker
New version of show columns code. |
49 |
add_field("Default"); |
1643.3.10
by Brian Aker
Column support, clean up of IS/DD for NULL type. |
50 |
add_field("Default_is_NULL", plugin::TableFunction::BOOLEAN, 0, false); |
1309.2.4
by Brian Aker
New version of show columns code. |
51 |
add_field("On_Update"); |
52 |
}
|
|
53 |
||
54 |
ShowColumns::Generator::Generator(Field **arg) : |
|
1874.2.4
by Brian Aker
Have show functions be invisible. |
55 |
show_dictionary::Show::Generator(arg), |
1309.2.4
by Brian Aker
New version of show columns code. |
56 |
is_tables_primed(false), |
57 |
is_columns_primed(false), |
|
58 |
column_iterator(0) |
|
59 |
{
|
|
1874.2.2
by Brian Aker
What was once old, is now new again. Seperated out show from select. |
60 |
statement::Show *select= static_cast<statement::Show *>(getSession().lex->statement); |
1309.2.4
by Brian Aker
New version of show columns code. |
61 |
|
1448
by Brian Aker
Fix for bug on show tables.:w |
62 |
if (not select->getShowTable().empty() && not select->getShowSchema().empty()) |
63 |
{
|
|
64 |
table_name.append(select->getShowTable().c_str()); |
|
65 |
TableIdentifier identifier(select->getShowSchema().c_str(), select->getShowTable().c_str()); |
|
1309.2.4
by Brian Aker
New version of show columns code. |
66 |
|
1448
by Brian Aker
Fix for bug on show tables.:w |
67 |
is_tables_primed= plugin::StorageEngine::getTableDefinition(getSession(), |
68 |
identifier, |
|
69 |
table_proto); |
|
70 |
}
|
|
1309.2.4
by Brian Aker
New version of show columns code. |
71 |
}
|
72 |
||
73 |
bool ShowColumns::Generator::nextColumnCore() |
|
74 |
{
|
|
75 |
if (is_columns_primed) |
|
76 |
{
|
|
77 |
column_iterator++; |
|
78 |
}
|
|
79 |
else
|
|
80 |
{
|
|
81 |
if (not isTablesPrimed()) |
|
82 |
return false; |
|
83 |
||
84 |
column_iterator= 0; |
|
85 |
is_columns_primed= true; |
|
86 |
}
|
|
87 |
||
1910.2.15
by Brian Aker
Update so that we use shared_ptr from the cache throughout more of the |
88 |
if (column_iterator >= getTableProto()->field_size()) |
1309.2.4
by Brian Aker
New version of show columns code. |
89 |
return false; |
90 |
||
1910.2.15
by Brian Aker
Update so that we use shared_ptr from the cache throughout more of the |
91 |
column= getTableProto()->field(column_iterator); |
1309.2.4
by Brian Aker
New version of show columns code. |
92 |
|
93 |
return true; |
|
94 |
}
|
|
95 |
||
96 |
||
97 |
bool ShowColumns::Generator::nextColumn() |
|
98 |
{
|
|
99 |
while (not nextColumnCore()) |
|
100 |
{
|
|
101 |
return false; |
|
102 |
}
|
|
103 |
||
104 |
return true; |
|
105 |
}
|
|
106 |
||
107 |
bool ShowColumns::Generator::populate() |
|
108 |
{
|
|
109 |
||
110 |
if (not nextColumn()) |
|
111 |
return false; |
|
112 |
||
113 |
fill(); |
|
114 |
||
115 |
return true; |
|
116 |
}
|
|
117 |
||
1753.2.1
by Andrew Hutchings
Use collation in SHOW FIELDS FROM so that it can detect the difference beween TEXT and BLOB (and VARCHAR/VARBINARY) |
118 |
void ShowColumns::Generator::pushType(message::Table::Field::FieldType type, const string collation) |
1309.2.4
by Brian Aker
New version of show columns code. |
119 |
{
|
120 |
switch (type) |
|
121 |
{
|
|
122 |
default: |
|
123 |
case message::Table::Field::VARCHAR: |
|
1753.2.1
by Andrew Hutchings
Use collation in SHOW FIELDS FROM so that it can detect the difference beween TEXT and BLOB (and VARCHAR/VARBINARY) |
124 |
push(collation.compare("binary") ? VARCHAR : VARBIN); |
1309.2.4
by Brian Aker
New version of show columns code. |
125 |
break; |
126 |
case message::Table::Field::DOUBLE: |
|
127 |
push(DOUBLE); |
|
128 |
break; |
|
129 |
case message::Table::Field::BLOB: |
|
1753.2.1
by Andrew Hutchings
Use collation in SHOW FIELDS FROM so that it can detect the difference beween TEXT and BLOB (and VARCHAR/VARBINARY) |
130 |
push(collation.compare("binary") ? TEXT : BLOB); |
1309.2.4
by Brian Aker
New version of show columns code. |
131 |
break; |
132 |
case message::Table::Field::ENUM: |
|
133 |
push(ENUM); |
|
134 |
break; |
|
135 |
case message::Table::Field::INTEGER: |
|
136 |
push(INTEGER); |
|
137 |
break; |
|
138 |
case message::Table::Field::BIGINT: |
|
139 |
push(BIGINT); |
|
140 |
break; |
|
141 |
case message::Table::Field::DECIMAL: |
|
142 |
push(DECIMAL); |
|
143 |
break; |
|
144 |
case message::Table::Field::DATE: |
|
145 |
push(DATE); |
|
146 |
break; |
|
147 |
case message::Table::Field::TIMESTAMP: |
|
148 |
push(TIMESTAMP); |
|
149 |
break; |
|
150 |
case message::Table::Field::DATETIME: |
|
151 |
push(DATETIME); |
|
152 |
break; |
|
153 |
}
|
|
154 |
}
|
|
155 |
||
156 |
||
157 |
void ShowColumns::Generator::fill() |
|
158 |
{
|
|
159 |
/* Field */
|
|
160 |
push(column.name()); |
|
161 |
||
162 |
/* Type */
|
|
1753.2.1
by Andrew Hutchings
Use collation in SHOW FIELDS FROM so that it can detect the difference beween TEXT and BLOB (and VARCHAR/VARBINARY) |
163 |
pushType(column.type(), column.string_options().collation()); |
1309.2.4
by Brian Aker
New version of show columns code. |
164 |
|
165 |
/* Null */
|
|
166 |
push(column.constraints().is_nullable()); |
|
167 |
||
168 |
/* Default */
|
|
1638.3.2
by Stewart Smith
use default_expression and update_expression instead of default_value and update_value in the table proto for NOW() |
169 |
if (column.options().has_default_value()) |
170 |
push(column.options().default_value()); |
|
171 |
else if (column.options().has_default_expression()) |
|
172 |
push(column.options().default_expression()); |
|
173 |
else
|
|
174 |
push(column.options().default_bin_value()); |
|
1309.2.4
by Brian Aker
New version of show columns code. |
175 |
|
176 |
/* Default_is_NULL */
|
|
177 |
push(column.options().default_null()); |
|
178 |
||
179 |
/* On_Update */
|
|
1638.3.2
by Stewart Smith
use default_expression and update_expression instead of default_value and update_value in the table proto for NOW() |
180 |
push(column.options().update_expression()); |
1309.2.4
by Brian Aker
New version of show columns code. |
181 |
}
|