1273.13.32
by Brian Aker
Big ole patch. This covers moving information_schema to old_* table names |
1 |
/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
|
2 |
* vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
|
|
3 |
*
|
|
4 |
* Copyright (C) 2010 Monty Taylor
|
|
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; version 2 of the License.
|
|
9 |
*
|
|
10 |
* This program is distributed in the hope that it will be useful,
|
|
11 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
12 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
13 |
* GNU General Public License for more details.
|
|
14 |
*
|
|
15 |
* You should have received a copy of the GNU General Public License
|
|
16 |
* along with this program; if not, write to the Free Software
|
|
17 |
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
|
18 |
*/
|
|
19 |
||
2173.2.1
by Monty Taylor
Fixes incorrect usage of include |
20 |
#include <config.h> |
1273.13.32
by Brian Aker
Big ole patch. This covers moving information_schema to old_* table names |
21 |
|
2154.2.4
by Brian Aker
This fixes 716459 |
22 |
#include <drizzled/current_session.h> |
23 |
#include <drizzled/gettext.h> |
|
2281.5.1
by Muhammad Umair
Merged charset declarations of global_charset_info.h and charset_info.h into charset.h header file. |
24 |
#include <drizzled/charset.h> |
1273.13.32
by Brian Aker
Big ole patch. This covers moving information_schema to old_* table names |
25 |
#include <drizzled/plugin/table_function.h> |
2154.2.4
by Brian Aker
This fixes 716459 |
26 |
#include <drizzled/session.h> |
27 |
#include <drizzled/show.h> |
|
1273.13.32
by Brian Aker
Big ole patch. This covers moving information_schema to old_* table names |
28 |
#include <drizzled/table_function_container.h> |
2234.1.4
by Olaf van der Spek
Refactor includes |
29 |
#include <drizzled/sql_lex.h> |
1273.13.32
by Brian Aker
Big ole patch. This covers moving information_schema to old_* table names |
30 |
|
31 |
#include <vector> |
|
32 |
||
2234.1.4
by Olaf van der Spek
Refactor includes |
33 |
namespace drizzled { |
1273.13.32
by Brian Aker
Big ole patch. This covers moving information_schema to old_* table names |
34 |
|
35 |
static TableFunctionContainer table_functions; |
|
36 |
||
37 |
void plugin::TableFunction::init() |
|
38 |
{
|
|
2017.3.1
by Brian Aker
Merge catalog with current trunk. |
39 |
drizzled::message::table::init(proto, getTableLabel(), identifier.getSchemaName(), "FunctionEngine"); |
1273.13.32
by Brian Aker
Big ole patch. This covers moving information_schema to old_* table names |
40 |
proto.set_type(drizzled::message::Table::FUNCTION); |
1340.1.4
by Brian Aker
A first pass through adding a timestamp to our proto. |
41 |
proto.set_creation_timestamp(0); |
42 |
proto.set_update_timestamp(0); |
|
2187.7.6
by Brian Aker
This fixes the message such that the table inherits the no replication |
43 |
message::set_is_replicated(proto, false); |
2241.6.2
by Brian Aker
This adds the concept of a definer to a table definition. |
44 |
message::set_definer(proto, SYSTEM_USER); |
1273.13.32
by Brian Aker
Big ole patch. This covers moving information_schema to old_* table names |
45 |
}
|
46 |
||
47 |
bool plugin::TableFunction::addPlugin(plugin::TableFunction *tool) |
|
48 |
{
|
|
49 |
assert(tool != NULL); |
|
2227.4.5
by Olaf van der Spek
plugin::TableFunction::Generator::lex() |
50 |
table_functions.addFunction(tool); |
1273.13.32
by Brian Aker
Big ole patch. This covers moving information_schema to old_* table names |
51 |
return false; |
52 |
}
|
|
53 |
||
1966.2.9
by Brian Aker
Remove the use of "using std" from the plugin interface .cc files. |
54 |
plugin::TableFunction *plugin::TableFunction::getFunction(const std::string &arg) |
1273.13.32
by Brian Aker
Big ole patch. This covers moving information_schema to old_* table names |
55 |
{
|
56 |
return table_functions.getFunction(arg); |
|
57 |
}
|
|
58 |
||
1966.2.9
by Brian Aker
Remove the use of "using std" from the plugin interface .cc files. |
59 |
void plugin::TableFunction::getNames(const std::string &arg, |
60 |
std::set<std::string> &set_of_names) |
|
1273.13.32
by Brian Aker
Big ole patch. This covers moving information_schema to old_* table names |
61 |
{
|
62 |
table_functions.getNames(arg, set_of_names); |
|
63 |
}
|
|
64 |
||
2227.4.5
by Olaf van der Spek
plugin::TableFunction::Generator::lex() |
65 |
LEX& plugin::TableFunction::Generator::lex() |
66 |
{
|
|
2227.4.10
by Olaf van der Spek
Session::lex() |
67 |
return getSession().lex(); |
2227.4.5
by Olaf van der Spek
plugin::TableFunction::Generator::lex() |
68 |
}
|
69 |
||
2227.4.7
by Olaf van der Spek
plugin::TableFunction::Generator::statement() |
70 |
statement::Statement& plugin::TableFunction::Generator::statement() |
71 |
{
|
|
72 |
return *lex().statement; |
|
73 |
}
|
|
74 |
||
1273.13.32
by Brian Aker
Big ole patch. This covers moving information_schema to old_* table names |
75 |
plugin::TableFunction::Generator *plugin::TableFunction::generator(Field **arg) |
76 |
{
|
|
77 |
return new Generator(arg); |
|
78 |
}
|
|
79 |
||
80 |
void plugin::TableFunction::add_field(const char *label, |
|
1273.13.44
by Brian Aker
Updates/bug fix for columns. Assert now for checking that we filled in all |
81 |
uint32_t field_length) |
1273.13.32
by Brian Aker
Big ole patch. This covers moving information_schema to old_* table names |
82 |
{
|
83 |
add_field(label, TableFunction::STRING, field_length); |
|
84 |
}
|
|
85 |
||
86 |
void plugin::TableFunction::add_field(const char *label, |
|
87 |
TableFunction::ColumnType type, |
|
88 |
bool is_default_null) |
|
89 |
{
|
|
90 |
add_field(label, type, 5, is_default_null); |
|
91 |
}
|
|
92 |
||
93 |
void plugin::TableFunction::add_field(const char *label, |
|
1643.3.10
by Brian Aker
Column support, clean up of IS/DD for NULL type. |
94 |
TableFunction::ColumnType type, |
95 |
uint32_t field_length, |
|
96 |
bool is_default_null) |
|
1273.13.32
by Brian Aker
Big ole patch. This covers moving information_schema to old_* table names |
97 |
{
|
98 |
drizzled::message::Table::Field *field; |
|
99 |
drizzled::message::Table::Field::FieldOptions *field_options; |
|
100 |
drizzled::message::Table::Field::FieldConstraints *field_constraints; |
|
101 |
||
102 |
field= proto.add_field(); |
|
103 |
field->set_name(label); |
|
104 |
||
105 |
field_options= field->mutable_options(); |
|
106 |
field_constraints= field->mutable_constraints(); |
|
107 |
field_options->set_default_null(is_default_null); |
|
2064.2.1
by Brian Aker
Fixes naming conventions and issues around notnull being "true" by default. |
108 |
field_constraints->set_is_notnull(not is_default_null); |
1273.13.32
by Brian Aker
Big ole patch. This covers moving information_schema to old_* table names |
109 |
|
2227.4.5
by Olaf van der Spek
plugin::TableFunction::Generator::lex() |
110 |
switch (type) |
1273.13.32
by Brian Aker
Big ole patch. This covers moving information_schema to old_* table names |
111 |
{
|
112 |
case TableFunction::STRING: |
|
1812.5.5
by Brian Aker
Added in possibility of having a blob type returned by a TableFunction. |
113 |
{
|
114 |
drizzled::message::Table::Field::StringFieldOptions *string_field_options; |
|
115 |
if (field_length >= TABLE_FUNCTION_BLOB_SIZE) |
|
116 |
{
|
|
117 |
field->set_type(drizzled::message::Table::Field::BLOB); |
|
118 |
string_field_options= field->mutable_string_options(); |
|
119 |
string_field_options->set_collation_id(default_charset_info->number); |
|
120 |
string_field_options->set_collation(default_charset_info->name); |
|
121 |
}
|
|
122 |
else
|
|
123 |
{
|
|
124 |
field->set_type(drizzled::message::Table::Field::VARCHAR); |
|
125 |
string_field_options= field->mutable_string_options(); |
|
126 |
string_field_options->set_length(field_length); |
|
127 |
}
|
|
128 |
}
|
|
1337.1.2
by Stewart Smith
make DATA_DICTIONARY.COLUMNS.COLUMN_DEFAULT be a VARBINARY column that can be null. Add a test for binary default values as well as non-binary default values. |
129 |
break; |
130 |
case TableFunction::VARBINARY: |
|
1812.5.5
by Brian Aker
Added in possibility of having a blob type returned by a TableFunction. |
131 |
{
|
132 |
drizzled::message::Table::Field::StringFieldOptions *string_field_options; |
|
133 |
field->set_type(drizzled::message::Table::Field::VARCHAR); |
|
1337.1.2
by Stewart Smith
make DATA_DICTIONARY.COLUMNS.COLUMN_DEFAULT be a VARBINARY column that can be null. Add a test for binary default values as well as non-binary default values. |
134 |
|
1812.5.5
by Brian Aker
Added in possibility of having a blob type returned by a TableFunction. |
135 |
string_field_options= field->mutable_string_options(); |
136 |
string_field_options->set_length(field_length); |
|
137 |
string_field_options->set_collation(my_charset_bin.csname); |
|
138 |
string_field_options->set_collation_id(my_charset_bin.number); |
|
139 |
}
|
|
1273.13.32
by Brian Aker
Big ole patch. This covers moving information_schema to old_* table names |
140 |
break; |
2008.2.4
by Brian Aker
Merge in additional fixes for sign, plus alter table, plus TIME on |
141 |
case TableFunction::NUMBER: |
142 |
field->set_type(drizzled::message::Table::Field::BIGINT); |
|
143 |
break; |
|
144 |
case TableFunction::SIZE: |
|
145 |
field->set_type(drizzled::message::Table::Field::BIGINT); |
|
146 |
field_constraints->set_is_unsigned(true); |
|
1273.13.32
by Brian Aker
Big ole patch. This covers moving information_schema to old_* table names |
147 |
break; |
2023.2.2
by Brian Aker
Merge in BOOL change to BOOLEAN. |
148 |
case TableFunction::BOOLEAN: // Currently BOOLEAN always has a value |
149 |
field->set_type(drizzled::message::Table::Field::BOOLEAN); |
|
150 |
field_constraints->set_is_unsigned(true); |
|
151 |
break; |
|
1273.13.32
by Brian Aker
Big ole patch. This covers moving information_schema to old_* table names |
152 |
}
|
153 |
}
|
|
154 |
||
155 |
plugin::TableFunction::Generator::Generator(Field **arg) : |
|
1436
by Brian Aker
Move toward not having to call current_session (first pass). |
156 |
columns(arg), |
157 |
session(current_session) |
|
1273.13.32
by Brian Aker
Big ole patch. This covers moving information_schema to old_* table names |
158 |
{
|
159 |
scs= system_charset_info; |
|
160 |
}
|
|
161 |
||
1273.13.44
by Brian Aker
Updates/bug fix for columns. Assert now for checking that we filled in all |
162 |
bool plugin::TableFunction::Generator::sub_populate(uint32_t field_size) |
1273.13.32
by Brian Aker
Big ole patch. This covers moving information_schema to old_* table names |
163 |
{
|
164 |
columns_iterator= columns; |
|
2269.1.3
by Olaf van der Spek
Session Times |
165 |
bool ret= populate(); |
166 |
if (ret) |
|
2385.1.12
by Olaf van der Spek
Avoid comparison between signed and unsigned |
167 |
assert(columns_iterator == columns + field_size); |
1273.13.44
by Brian Aker
Updates/bug fix for columns. Assert now for checking that we filled in all |
168 |
return ret; |
1273.13.32
by Brian Aker
Big ole patch. This covers moving information_schema to old_* table names |
169 |
}
|
170 |
||
1302.2.1
by Monty Taylor
Fixed the OSX build issues. |
171 |
void plugin::TableFunction::Generator::push(uint64_t arg) |
172 |
{
|
|
1273.13.82
by Brian Aker
Revert OSX fix, requiring more cast. |
173 |
(*columns_iterator)->store(static_cast<int64_t>(arg), true); |
1337.1.1
by Stewart Smith
fix setting notnull for NUMBER columns in a TableFunction. |
174 |
(*columns_iterator)->set_notnull(); |
1302.2.1
by Monty Taylor
Fixed the OSX build issues. |
175 |
columns_iterator++; |
176 |
}
|
|
177 |
||
178 |
void plugin::TableFunction::Generator::push(int64_t arg) |
|
179 |
{
|
|
180 |
(*columns_iterator)->store(arg, false); |
|
1337.1.1
by Stewart Smith
fix setting notnull for NUMBER columns in a TableFunction. |
181 |
(*columns_iterator)->set_notnull(); |
1302.2.1
by Monty Taylor
Fixed the OSX build issues. |
182 |
columns_iterator++; |
183 |
}
|
|
184 |
||
1273.13.32
by Brian Aker
Big ole patch. This covers moving information_schema to old_* table names |
185 |
void plugin::TableFunction::Generator::push(const char *arg, uint32_t length) |
186 |
{
|
|
187 |
assert(columns_iterator); |
|
188 |
assert(*columns_iterator); |
|
2385.1.11
by Olaf van der Spek
Fix assert |
189 |
if (arg && not length) |
190 |
length= strlen(arg); |
|
1273.13.44
by Brian Aker
Updates/bug fix for columns. Assert now for checking that we filled in all |
191 |
|
1933.2.6
by Brian Aker
Enforce table share return lengths on string types. |
192 |
if ((*columns_iterator)->char_length() < length) |
193 |
length= (*columns_iterator)->char_length(); |
|
194 |
||
1273.13.45
by Brian Aker
Update for test split. |
195 |
(*columns_iterator)->store(arg, length, scs); |
196 |
(*columns_iterator)->set_notnull(); |
|
197 |
columns_iterator++; |
|
198 |
}
|
|
199 |
||
200 |
void plugin::TableFunction::Generator::push() |
|
201 |
{
|
|
1993.3.1
by Andrew Hutchings
Enforce TableFunction::Generator::push() should only be used on a nullable field |
202 |
/* Only accept NULLs */
|
203 |
assert((*columns_iterator)->maybe_null()); |
|
1273.13.45
by Brian Aker
Update for test split. |
204 |
(*columns_iterator)->set_null(); |
1273.13.32
by Brian Aker
Big ole patch. This covers moving information_schema to old_* table names |
205 |
columns_iterator++; |
206 |
}
|
|
207 |
||
2385.1.6
by Olaf van der Spek
Use str_ref |
208 |
void plugin::TableFunction::Generator::push(str_ref arg) |
209 |
{
|
|
210 |
push(arg.data(), arg.size()); |
|
211 |
}
|
|
212 |
||
1302.2.1
by Monty Taylor
Fixed the OSX build issues. |
213 |
void plugin::TableFunction::Generator::push(bool arg) |
214 |
{
|
|
215 |
if (arg) |
|
1660
by Brian Aker
MErge in change to do YES/NO like standard requires. |
216 |
(*columns_iterator)->store("YES", 3, scs); |
1302.2.1
by Monty Taylor
Fixed the OSX build issues. |
217 |
else
|
1660
by Brian Aker
MErge in change to do YES/NO like standard requires. |
218 |
(*columns_iterator)->store("NO", 2, scs); |
1302.2.1
by Monty Taylor
Fixed the OSX build issues. |
219 |
columns_iterator++; |
220 |
}
|
|
221 |
||
1273.13.38
by Brian Aker
Add in new show work. |
222 |
bool plugin::TableFunction::Generator::isWild(const std::string &predicate) |
223 |
{
|
|
2269.1.3
by Olaf van der Spek
Session Times |
224 |
return lex().wild ? wild_case_compare(system_charset_info, predicate.c_str(), lex().wild->ptr()) : false; |
1273.13.38
by Brian Aker
Add in new show work. |
225 |
}
|
1273.14.5
by Monty Taylor
Merged trunk. |
226 |
|
227 |
} /* namespace drizzled */ |