1063.4.5
by Padraig O'Sullivan
Fixed a stupid mistake I made in the innodb handler. Also reverted back to |
1 |
/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
|
520.4.14
by Monty Taylor
Removed korr.h and tztime.h from common_includes. Also removed the HAVE_DTRACE block and stuck it in autoconf. |
2 |
* vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
|
3 |
*
|
|
2096.1.14
by Brian Aker
Pull in more C code from parser. |
4 |
* Copyright (C) 2010 Brian Aker
|
1999.6.1
by kalebral at gmail
update Copyright strings to a more common format to help with creating the master debian copyright file |
5 |
* Copyright (C) 2008 Sun Microsystems, Inc.
|
520.4.14
by Monty Taylor
Removed korr.h and tztime.h from common_includes. Also removed the HAVE_DTRACE block and stuck it in autoconf. |
6 |
*
|
7 |
* This program is free software; you can redistribute it and/or modify
|
|
8 |
* it under the terms of the GNU General Public License as published by
|
|
9 |
* the Free Software Foundation; version 2 of the License.
|
|
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 |
*/
|
|
1
by brian
clean slate |
20 |
|
21 |
||
22 |
/* Function with list databases, tables or fields */
|
|
2173.2.1
by Monty Taylor
Fixes incorrect usage of include |
23 |
#include <config.h> |
24 |
||
25 |
#include <drizzled/data_home.h> |
|
26 |
#include <drizzled/error.h> |
|
27 |
#include <drizzled/internal/my_sys.h> |
|
28 |
#include <drizzled/plugin/storage_engine.h> |
|
29 |
#include <drizzled/session.h> |
|
30 |
#include <drizzled/show.h> |
|
31 |
#include <drizzled/sql_select.h> |
|
32 |
||
33 |
#include <drizzled/statement/show.h> |
|
34 |
#include <drizzled/statement/show_errors.h> |
|
35 |
#include <drizzled/statement/show_warnings.h> |
|
2096.1.7
by Brian Aker
Shrink parser code, push C out to function call. |
36 |
|
1241.9.28
by Monty Taylor
Removed global_charset_info.h from server_includes.h |
37 |
|
1108.4.2
by David Shrewsbury
Replace my_dir in find_files() with CachedDirectory. Renamed find_files() to find_dirs() to more accurately reflect what it is doing after removing dead code inside it. |
38 |
#include <sys/stat.h> |
584.1.13
by Monty Taylor
Split out a little more code. Removed table_list.h from common_includes. |
39 |
|
40 |
#include <string> |
|
629.4.1
by Monty Taylor
First step in support size_t sys_var stuff. |
41 |
#include <iostream> |
42 |
#include <sstream> |
|
901.1.1
by Padraig
Initial work to replace an instance of DYNAMIC_ARRAY in show.cc with STL |
43 |
#include <vector> |
44 |
#include <algorithm> |
|
629.4.1
by Monty Taylor
First step in support size_t sys_var stuff. |
45 |
|
46 |
using namespace std; |
|
1280.1.10
by Monty Taylor
Put everything in drizzled into drizzled namespace. |
47 |
|
48 |
namespace drizzled |
|
49 |
{
|
|
1
by brian
clean slate |
50 |
|
322.2.2
by Mats Kindahl
Hiding THD::proc_info field and providing a setter and getter. |
51 |
inline const char * |
52 |
str_or_nil(const char *str) |
|
53 |
{
|
|
54 |
return str ? str : "<nil>"; |
|
55 |
}
|
|
1
by brian
clean slate |
56 |
|
2154.2.2
by Brian Aker
Reduce include files for show command. |
57 |
int wild_case_compare(const charset_info_st * const cs, const char *str, const char *wildstr) |
1
by brian
clean slate |
58 |
{
|
2194.3.1
by Olaf van der Spek
Remove register keyword |
59 |
int flag; |
1273.13.61
by Brian Aker
Fixes a memory leak. sql_string() sucks. |
60 |
|
1
by brian
clean slate |
61 |
while (*wildstr) |
62 |
{
|
|
1280.1.10
by Monty Taylor
Put everything in drizzled into drizzled namespace. |
63 |
while (*wildstr && *wildstr != internal::wild_many && *wildstr != internal::wild_one) |
1
by brian
clean slate |
64 |
{
|
1280.1.10
by Monty Taylor
Put everything in drizzled into drizzled namespace. |
65 |
if (*wildstr == internal::wild_prefix && wildstr[1]) |
51.1.1
by Jay Pipes
Merged PatG's removal of various DBUG stuff with still keeping DBUG_ASSERT calls since they seem to be breaking test runs |
66 |
wildstr++; |
2170.1.1
by Brian Aker
Merge with trunk. |
67 |
|
51.1.1
by Jay Pipes
Merged PatG's removal of various DBUG stuff with still keeping DBUG_ASSERT calls since they seem to be breaking test runs |
68 |
if (my_toupper(cs, *wildstr++) != my_toupper(cs, *str++)) |
1067.3.1
by Padraig O'Sullivan
Extracted the CHARACTER_SET I_S table into the I_S plugin. |
69 |
return (1); |
1
by brian
clean slate |
70 |
}
|
2170.1.1
by Brian Aker
Merge with trunk. |
71 |
|
51.1.1
by Jay Pipes
Merged PatG's removal of various DBUG stuff with still keeping DBUG_ASSERT calls since they seem to be breaking test runs |
72 |
if (! *wildstr ) |
73 |
return (*str != 0); |
|
2170.1.1
by Brian Aker
Merge with trunk. |
74 |
|
1280.1.10
by Monty Taylor
Put everything in drizzled into drizzled namespace. |
75 |
if (*wildstr++ == internal::wild_one) |
1
by brian
clean slate |
76 |
{
|
51.1.1
by Jay Pipes
Merged PatG's removal of various DBUG stuff with still keeping DBUG_ASSERT calls since they seem to be breaking test runs |
77 |
if (! *str++) |
78 |
return (1); /* One char; skip */ |
|
1
by brian
clean slate |
79 |
}
|
80 |
else
|
|
81 |
{ /* Found '*' */ |
|
1067.3.1
by Padraig O'Sullivan
Extracted the CHARACTER_SET I_S table into the I_S plugin. |
82 |
if (! *wildstr) |
83 |
return (0); /* '*' as last char: OK */ |
|
2170.1.1
by Brian Aker
Merge with trunk. |
84 |
|
1280.1.10
by Monty Taylor
Put everything in drizzled into drizzled namespace. |
85 |
flag=(*wildstr != internal::wild_many && *wildstr != internal::wild_one); |
1
by brian
clean slate |
86 |
do
|
87 |
{
|
|
1067.3.1
by Padraig O'Sullivan
Extracted the CHARACTER_SET I_S table into the I_S plugin. |
88 |
if (flag) |
89 |
{
|
|
90 |
char cmp; |
|
1280.1.10
by Monty Taylor
Put everything in drizzled into drizzled namespace. |
91 |
if ((cmp= *wildstr) == internal::wild_prefix && wildstr[1]) |
1067.3.1
by Padraig O'Sullivan
Extracted the CHARACTER_SET I_S table into the I_S plugin. |
92 |
cmp= wildstr[1]; |
2170.1.1
by Brian Aker
Merge with trunk. |
93 |
|
1067.3.1
by Padraig O'Sullivan
Extracted the CHARACTER_SET I_S table into the I_S plugin. |
94 |
cmp= my_toupper(cs, cmp); |
2170.1.1
by Brian Aker
Merge with trunk. |
95 |
|
1067.3.1
by Padraig O'Sullivan
Extracted the CHARACTER_SET I_S table into the I_S plugin. |
96 |
while (*str && my_toupper(cs, *str) != cmp) |
97 |
str++; |
|
2170.1.1
by Brian Aker
Merge with trunk. |
98 |
|
1067.3.1
by Padraig O'Sullivan
Extracted the CHARACTER_SET I_S table into the I_S plugin. |
99 |
if (! *str) |
100 |
return (1); |
|
101 |
}
|
|
2170.1.1
by Brian Aker
Merge with trunk. |
102 |
|
1067.3.1
by Padraig O'Sullivan
Extracted the CHARACTER_SET I_S table into the I_S plugin. |
103 |
if (wild_case_compare(cs, str, wildstr) == 0) |
104 |
return (0); |
|
2170.1.1
by Brian Aker
Merge with trunk. |
105 |
|
1067.3.1
by Padraig O'Sullivan
Extracted the CHARACTER_SET I_S table into the I_S plugin. |
106 |
} while (*str++); |
2170.1.1
by Brian Aker
Merge with trunk. |
107 |
|
51.1.1
by Jay Pipes
Merged PatG's removal of various DBUG stuff with still keeping DBUG_ASSERT calls since they seem to be breaking test runs |
108 |
return (1); |
1
by brian
clean slate |
109 |
}
|
110 |
}
|
|
1273.13.61
by Brian Aker
Fixes a memory leak. sql_string() sucks. |
111 |
|
51.1.1
by Jay Pipes
Merged PatG's removal of various DBUG stuff with still keeping DBUG_ASSERT calls since they seem to be breaking test runs |
112 |
return (*str != '\0'); |
1
by brian
clean slate |
113 |
}
|
114 |
||
115 |
/*
|
|
116 |
Get the quote character for displaying an identifier.
|
|
117 |
||
118 |
SYNOPSIS
|
|
119 |
get_quote_char_for_identifier()
|
|
120 |
||
121 |
IMPLEMENTATION
|
|
122 |
Force quoting in the following cases:
|
|
123 |
- name is empty (for one, it is possible when we use this function for
|
|
124 |
quoting user and host names for DEFINER clause);
|
|
125 |
- name is a keyword;
|
|
126 |
- name includes a special character;
|
|
127 |
Otherwise identifier is quoted only if the option OPTION_QUOTE_SHOW_CREATE
|
|
128 |
is set.
|
|
129 |
||
130 |
RETURN
|
|
131 |
EOF No quote character is needed
|
|
132 |
# Quote character
|
|
133 |
*/
|
|
134 |
||
1014.3.4
by Brian Aker
Remove dead session calls. |
135 |
int get_quote_char_for_identifier() |
1
by brian
clean slate |
136 |
{
|
352.2.1
by Harrison Fisk
Fix for bugs 259843 and 256482 |
137 |
return '`'; |
1
by brian
clean slate |
138 |
}
|
139 |
||
2096.1.7
by Brian Aker
Shrink parser code, push C out to function call. |
140 |
namespace show { |
141 |
||
2096.1.9
by Brian Aker
Merge in additional show. |
142 |
bool buildScemas(Session *session) |
143 |
{
|
|
144 |
session->getLex()->sql_command= SQLCOM_SELECT; |
|
145 |
session->getLex()->statement= new statement::Show(session); |
|
146 |
||
147 |
std::string column_name= "Database"; |
|
148 |
if (session->getLex()->wild) |
|
149 |
{
|
|
150 |
column_name.append(" ("); |
|
151 |
column_name.append(session->getLex()->wild->ptr()); |
|
152 |
column_name.append(")"); |
|
153 |
}
|
|
154 |
||
155 |
if (session->getLex()->current_select->where) |
|
156 |
{
|
|
157 |
if (prepare_new_schema_table(session, session->getLex(), "SCHEMAS")) |
|
158 |
return false; |
|
159 |
}
|
|
160 |
else
|
|
161 |
{
|
|
162 |
if (prepare_new_schema_table(session, session->getLex(), "SHOW_SCHEMAS")) |
|
163 |
return false; |
|
164 |
}
|
|
165 |
||
2187.2.2
by Brian Aker
getLex() usage and fix for table_name creation during admin commands. |
166 |
Item_field *my_field= new Item_field(&session->getLex()->current_select->context, NULL, NULL, "SCHEMA_NAME"); |
2096.1.9
by Brian Aker
Merge in additional show. |
167 |
my_field->is_autogenerated_name= false; |
168 |
my_field->set_name(column_name.c_str(), column_name.length(), system_charset_info); |
|
169 |
||
170 |
if (session->add_item_to_list(my_field)) |
|
171 |
return false; |
|
172 |
||
173 |
if (session->add_order_to_list(my_field, true)) |
|
174 |
return false; |
|
175 |
||
176 |
return true; |
|
177 |
}
|
|
178 |
||
2096.1.10
by Brian Aker
More shuffle of show into functions. |
179 |
bool buildTables(Session *session, const char *ident) |
180 |
{
|
|
181 |
session->getLex()->sql_command= SQLCOM_SELECT; |
|
182 |
||
183 |
drizzled::statement::Show *select= new statement::Show(session); |
|
184 |
session->getLex()->statement= select; |
|
185 |
||
186 |
std::string column_name= "Tables_in_"; |
|
187 |
||
188 |
util::string::const_shared_ptr schema(session->schema()); |
|
189 |
if (ident) |
|
190 |
{
|
|
191 |
identifier::Schema identifier(ident); |
|
192 |
column_name.append(ident); |
|
193 |
session->getLex()->select_lex.db= const_cast<char *>(ident); |
|
194 |
if (not plugin::StorageEngine::doesSchemaExist(identifier)) |
|
195 |
{
|
|
2159.2.8
by Brian Aker
Merge in fixes for error messages with privs. |
196 |
my_error(ER_BAD_DB_ERROR, identifier); |
2096.1.10
by Brian Aker
More shuffle of show into functions. |
197 |
}
|
198 |
select->setShowPredicate(ident, ""); |
|
199 |
}
|
|
200 |
else if (schema and not schema->empty()) |
|
201 |
{
|
|
202 |
column_name.append(*schema); |
|
203 |
select->setShowPredicate(*schema, ""); |
|
204 |
}
|
|
205 |
else
|
|
206 |
{
|
|
207 |
my_error(ER_NO_DB_ERROR, MYF(0)); |
|
208 |
return false; |
|
209 |
}
|
|
210 |
||
211 |
||
212 |
if (session->getLex()->wild) |
|
213 |
{
|
|
214 |
column_name.append(" ("); |
|
215 |
column_name.append(session->getLex()->wild->ptr()); |
|
216 |
column_name.append(")"); |
|
217 |
}
|
|
218 |
||
219 |
if (prepare_new_schema_table(session, session->getLex(), "SHOW_TABLES")) |
|
220 |
return false; |
|
221 |
||
2187.2.2
by Brian Aker
getLex() usage and fix for table_name creation during admin commands. |
222 |
Item_field *my_field= new Item_field(&session->getLex()->current_select->context, NULL, NULL, "TABLE_NAME"); |
2096.1.10
by Brian Aker
More shuffle of show into functions. |
223 |
my_field->is_autogenerated_name= false; |
224 |
my_field->set_name(column_name.c_str(), column_name.length(), system_charset_info); |
|
225 |
||
226 |
if (session->add_item_to_list(my_field)) |
|
227 |
return false; |
|
228 |
||
229 |
if (session->add_order_to_list(my_field, true)) |
|
230 |
return false; |
|
231 |
||
232 |
return true; |
|
233 |
}
|
|
234 |
||
235 |
bool buildTemporaryTables(Session *session) |
|
236 |
{
|
|
237 |
session->getLex()->sql_command= SQLCOM_SELECT; |
|
238 |
||
239 |
session->getLex()->statement= new statement::Show(session); |
|
240 |
||
241 |
||
242 |
if (prepare_new_schema_table(session, session->getLex(), "SHOW_TEMPORARY_TABLES")) |
|
243 |
return false; |
|
244 |
||
2187.2.2
by Brian Aker
getLex() usage and fix for table_name creation during admin commands. |
245 |
if (session->add_item_to_list( new Item_field(&session->getLex()->current_select->context, NULL, NULL, "*"))) |
2096.1.10
by Brian Aker
More shuffle of show into functions. |
246 |
return false; |
247 |
||
2187.2.2
by Brian Aker
getLex() usage and fix for table_name creation during admin commands. |
248 |
(session->getLex()->current_select->with_wild)++; |
2096.1.10
by Brian Aker
More shuffle of show into functions. |
249 |
|
250 |
return true; |
|
251 |
}
|
|
252 |
||
253 |
bool buildTableStatus(Session *session, const char *ident) |
|
254 |
{
|
|
255 |
session->getLex()->sql_command= SQLCOM_SELECT; |
|
256 |
drizzled::statement::Show *select= new statement::Show(session); |
|
257 |
session->getLex()->statement= select; |
|
258 |
||
259 |
std::string column_name= "Tables_in_"; |
|
260 |
||
261 |
util::string::const_shared_ptr schema(session->schema()); |
|
262 |
if (ident) |
|
263 |
{
|
|
264 |
session->getLex()->select_lex.db= const_cast<char *>(ident); |
|
265 |
||
266 |
identifier::Schema identifier(ident); |
|
267 |
if (not plugin::StorageEngine::doesSchemaExist(identifier)) |
|
268 |
{
|
|
2159.2.8
by Brian Aker
Merge in fixes for error messages with privs. |
269 |
my_error(ER_BAD_DB_ERROR, identifier); |
2096.1.10
by Brian Aker
More shuffle of show into functions. |
270 |
}
|
271 |
||
272 |
select->setShowPredicate(ident, ""); |
|
273 |
}
|
|
274 |
else if (schema) |
|
275 |
{
|
|
276 |
select->setShowPredicate(*schema, ""); |
|
277 |
}
|
|
278 |
else
|
|
279 |
{
|
|
280 |
my_error(ER_NO_DB_ERROR, MYF(0)); |
|
281 |
return false; |
|
282 |
}
|
|
283 |
||
284 |
if (prepare_new_schema_table(session, session->getLex(), "SHOW_TABLE_STATUS")) |
|
285 |
return false; |
|
286 |
||
2187.2.2
by Brian Aker
getLex() usage and fix for table_name creation during admin commands. |
287 |
if (session->add_item_to_list( new Item_field(&session->getLex()->current_select-> |
2096.1.10
by Brian Aker
More shuffle of show into functions. |
288 |
context, |
289 |
NULL, NULL, "*"))) |
|
290 |
return false; |
|
291 |
||
2187.2.2
by Brian Aker
getLex() usage and fix for table_name creation during admin commands. |
292 |
(session->getLex()->current_select->with_wild)++; |
2096.1.10
by Brian Aker
More shuffle of show into functions. |
293 |
|
294 |
return true; |
|
295 |
}
|
|
296 |
||
2131.3.1
by Andrew Hutchings
Add error telling the user to use data_dictionary for SHOW engine_name STATUS |
297 |
bool buildEngineStatus(Session *session, LEX_STRING) |
298 |
{
|
|
299 |
session->getLex()->sql_command= SQLCOM_SELECT; |
|
300 |
drizzled::statement::Show *select= new statement::Show(session); |
|
301 |
session->getLex()->statement= select; |
|
302 |
||
303 |
my_error(ER_USE_DATA_DICTIONARY); |
|
304 |
return false; |
|
305 |
}
|
|
306 |
||
2096.1.12
by Brian Aker
Additional show to functions. |
307 |
bool buildColumns(Session *session, const char *schema_ident, Table_ident *table_ident) |
308 |
{
|
|
309 |
session->getLex()->sql_command= SQLCOM_SELECT; |
|
310 |
||
311 |
drizzled::statement::Show *select= new statement::Show(session); |
|
312 |
session->getLex()->statement= select; |
|
313 |
||
314 |
util::string::const_shared_ptr schema(session->schema()); |
|
315 |
if (schema_ident) |
|
316 |
{
|
|
317 |
select->setShowPredicate(schema_ident, table_ident->table.str); |
|
318 |
}
|
|
319 |
else if (table_ident->db.str) |
|
320 |
{
|
|
321 |
select->setShowPredicate(table_ident->db.str, table_ident->table.str); |
|
322 |
}
|
|
323 |
else if (schema) |
|
324 |
{
|
|
325 |
select->setShowPredicate(*schema, table_ident->table.str); |
|
326 |
}
|
|
327 |
else
|
|
328 |
{
|
|
329 |
my_error(ER_NO_DB_ERROR, MYF(0)); |
|
330 |
return false; |
|
331 |
}
|
|
332 |
||
333 |
{
|
|
334 |
drizzled::identifier::Table identifier(select->getShowSchema().c_str(), table_ident->table.str); |
|
335 |
if (not plugin::StorageEngine::doesTableExist(*session, identifier)) |
|
336 |
{
|
|
2140.1.3
by Brian Aker
Merge in error message fix for just one type of error for unknown table. |
337 |
my_error(ER_TABLE_UNKNOWN, identifier); |
2096.1.12
by Brian Aker
Additional show to functions. |
338 |
}
|
339 |
}
|
|
340 |
||
341 |
if (prepare_new_schema_table(session, session->getLex(), "SHOW_COLUMNS")) |
|
342 |
return false; |
|
343 |
||
2187.2.2
by Brian Aker
getLex() usage and fix for table_name creation during admin commands. |
344 |
if (session->add_item_to_list( new Item_field(&session->getLex()->current_select->context, NULL, NULL, "*"))) |
2096.1.12
by Brian Aker
Additional show to functions. |
345 |
return false; |
346 |
||
2187.2.2
by Brian Aker
getLex() usage and fix for table_name creation during admin commands. |
347 |
(session->getLex()->current_select->with_wild)++; |
2096.1.12
by Brian Aker
Additional show to functions. |
348 |
|
349 |
return true; |
|
350 |
}
|
|
351 |
||
2137.1.12
by Brian Aker
Remove current_session in building the error count. |
352 |
void buildSelectWarning(Session *session) |
353 |
{
|
|
2137.1.13
by Brian Aker
Fix bad error in warnings/errors. |
354 |
(void) create_select_for_variable(session, "warning_count"); |
2137.1.12
by Brian Aker
Remove current_session in building the error count. |
355 |
session->getLex()->statement= new statement::Show(session); |
356 |
}
|
|
357 |
||
358 |
void buildSelectError(Session *session) |
|
359 |
{
|
|
360 |
(void) create_select_for_variable(session, "error_count"); |
|
361 |
session->getLex()->statement= new statement::Show(session); |
|
362 |
}
|
|
363 |
||
364 |
void buildWarnings(Session *session) |
|
2096.1.13
by Brian Aker
Last of format style show commands removed from parser. |
365 |
{
|
366 |
session->getLex()->statement= new statement::ShowWarnings(session); |
|
367 |
}
|
|
368 |
||
2137.1.12
by Brian Aker
Remove current_session in building the error count. |
369 |
void buildErrors(Session *session) |
2096.1.13
by Brian Aker
Last of format style show commands removed from parser. |
370 |
{
|
371 |
session->getLex()->statement= new statement::ShowErrors(session); |
|
372 |
}
|
|
373 |
||
2096.1.12
by Brian Aker
Additional show to functions. |
374 |
bool buildIndex(Session *session, const char *schema_ident, Table_ident *table_ident) |
375 |
{
|
|
376 |
session->getLex()->sql_command= SQLCOM_SELECT; |
|
377 |
drizzled::statement::Show *select= new statement::Show(session); |
|
378 |
session->getLex()->statement= select; |
|
379 |
||
380 |
util::string::const_shared_ptr schema(session->schema()); |
|
381 |
if (schema_ident) |
|
382 |
{
|
|
383 |
select->setShowPredicate(schema_ident, table_ident->table.str); |
|
384 |
}
|
|
385 |
else if (table_ident->db.str) |
|
386 |
{
|
|
387 |
select->setShowPredicate(table_ident->db.str, table_ident->table.str); |
|
388 |
}
|
|
389 |
else if (schema) |
|
390 |
{
|
|
391 |
select->setShowPredicate(*schema, table_ident->table.str); |
|
392 |
}
|
|
393 |
else
|
|
394 |
{
|
|
395 |
my_error(ER_NO_DB_ERROR, MYF(0)); |
|
396 |
return false; |
|
397 |
}
|
|
398 |
||
399 |
{
|
|
400 |
drizzled::identifier::Table identifier(select->getShowSchema().c_str(), table_ident->table.str); |
|
401 |
if (not plugin::StorageEngine::doesTableExist(*session, identifier)) |
|
402 |
{
|
|
2140.1.3
by Brian Aker
Merge in error message fix for just one type of error for unknown table. |
403 |
my_error(ER_TABLE_UNKNOWN, identifier); |
2096.1.12
by Brian Aker
Additional show to functions. |
404 |
}
|
405 |
}
|
|
406 |
||
407 |
if (prepare_new_schema_table(session, session->getLex(), "SHOW_INDEXES")) |
|
408 |
return false; |
|
409 |
||
2187.2.2
by Brian Aker
getLex() usage and fix for table_name creation during admin commands. |
410 |
if (session->add_item_to_list( new Item_field(&session->getLex()->current_select->context, NULL, NULL, "*"))) |
2096.1.12
by Brian Aker
Additional show to functions. |
411 |
return false; |
412 |
||
2187.2.2
by Brian Aker
getLex() usage and fix for table_name creation during admin commands. |
413 |
(session->getLex()->current_select->with_wild)++; |
2096.1.12
by Brian Aker
Additional show to functions. |
414 |
|
415 |
return true; |
|
416 |
}
|
|
417 |
||
418 |
bool buildStatus(Session *session, const drizzled::sql_var_t is_global) |
|
419 |
{
|
|
420 |
session->getLex()->sql_command= SQLCOM_SELECT; |
|
421 |
session->getLex()->statement= new statement::Show(session); |
|
422 |
||
423 |
if (is_global == OPT_GLOBAL) |
|
424 |
{
|
|
425 |
if (prepare_new_schema_table(session, session->getLex(), "GLOBAL_STATUS")) |
|
426 |
return false; |
|
427 |
}
|
|
428 |
else
|
|
429 |
{
|
|
430 |
if (prepare_new_schema_table(session, session->getLex(), "SESSION_STATUS")) |
|
431 |
return false; |
|
432 |
}
|
|
433 |
||
434 |
std::string key("Variable_name"); |
|
435 |
std::string value("Value"); |
|
436 |
||
2187.2.2
by Brian Aker
getLex() usage and fix for table_name creation during admin commands. |
437 |
Item_field *my_field= new Item_field(&session->getLex()->current_select->context, NULL, NULL, "VARIABLE_NAME"); |
2096.1.12
by Brian Aker
Additional show to functions. |
438 |
my_field->is_autogenerated_name= false; |
439 |
my_field->set_name(key.c_str(), key.length(), system_charset_info); |
|
440 |
||
441 |
if (session->add_item_to_list(my_field)) |
|
442 |
return false; |
|
443 |
||
2187.2.2
by Brian Aker
getLex() usage and fix for table_name creation during admin commands. |
444 |
my_field= new Item_field(&session->getLex()->current_select->context, NULL, NULL, "VARIABLE_VALUE"); |
2096.1.12
by Brian Aker
Additional show to functions. |
445 |
my_field->is_autogenerated_name= false; |
446 |
my_field->set_name(value.c_str(), value.length(), system_charset_info); |
|
447 |
||
448 |
if (session->add_item_to_list(my_field)) |
|
449 |
return false; |
|
450 |
||
451 |
return true; |
|
452 |
}
|
|
453 |
||
454 |
bool buildCreateTable(Session *session, Table_ident *ident) |
|
455 |
{
|
|
456 |
session->getLex()->sql_command= SQLCOM_SELECT; |
|
457 |
statement::Show *select= new statement::Show(session); |
|
458 |
session->getLex()->statement= select; |
|
459 |
||
460 |
if (session->getLex()->statement == NULL) |
|
461 |
return false; |
|
462 |
||
463 |
if (prepare_new_schema_table(session, session->getLex(), "TABLE_SQL_DEFINITION")) |
|
464 |
return false; |
|
465 |
||
466 |
util::string::const_shared_ptr schema(session->schema()); |
|
467 |
if (ident->db.str) |
|
468 |
{
|
|
469 |
select->setShowPredicate(ident->db.str, ident->table.str); |
|
470 |
}
|
|
471 |
else if (schema) |
|
472 |
{
|
|
473 |
select->setShowPredicate(*schema, ident->table.str); |
|
474 |
}
|
|
475 |
else
|
|
476 |
{
|
|
477 |
my_error(ER_NO_DB_ERROR, MYF(0)); |
|
478 |
return false; |
|
479 |
}
|
|
480 |
||
481 |
std::string key("Table"); |
|
482 |
std::string value("Create Table"); |
|
483 |
||
2187.2.2
by Brian Aker
getLex() usage and fix for table_name creation during admin commands. |
484 |
Item_field *my_field= new Item_field(&session->getLex()->current_select->context, NULL, NULL, "TABLE_NAME"); |
2096.1.12
by Brian Aker
Additional show to functions. |
485 |
my_field->is_autogenerated_name= false; |
486 |
my_field->set_name(key.c_str(), key.length(), system_charset_info); |
|
487 |
||
488 |
if (session->add_item_to_list(my_field)) |
|
489 |
return false; |
|
490 |
||
2187.2.2
by Brian Aker
getLex() usage and fix for table_name creation during admin commands. |
491 |
my_field= new Item_field(&session->getLex()->current_select->context, NULL, NULL, "TABLE_SQL_DEFINITION"); |
2096.1.12
by Brian Aker
Additional show to functions. |
492 |
my_field->is_autogenerated_name= false; |
493 |
my_field->set_name(value.c_str(), value.length(), system_charset_info); |
|
494 |
||
495 |
if (session->add_item_to_list(my_field)) |
|
496 |
return false; |
|
497 |
||
498 |
return true; |
|
499 |
}
|
|
500 |
||
501 |
bool buildProcesslist(Session *session) |
|
502 |
{
|
|
503 |
session->getLex()->sql_command= SQLCOM_SELECT; |
|
504 |
session->getLex()->statement= new statement::Show(session); |
|
505 |
||
506 |
if (prepare_new_schema_table(session, session->getLex(), "PROCESSLIST")) |
|
507 |
return false; |
|
508 |
||
2187.2.2
by Brian Aker
getLex() usage and fix for table_name creation during admin commands. |
509 |
if (session->add_item_to_list( new Item_field(&session->getLex()->current_select->context, NULL, NULL, "*"))) |
2096.1.12
by Brian Aker
Additional show to functions. |
510 |
return false; |
511 |
||
2187.2.2
by Brian Aker
getLex() usage and fix for table_name creation during admin commands. |
512 |
(session->getLex()->current_select->with_wild)++; |
2096.1.12
by Brian Aker
Additional show to functions. |
513 |
|
514 |
return true; |
|
515 |
}
|
|
516 |
||
2096.1.11
by Brian Aker
Additional show to function. |
517 |
bool buildVariables(Session *session, const drizzled::sql_var_t is_global) |
518 |
{
|
|
519 |
session->getLex()->sql_command= SQLCOM_SELECT; |
|
520 |
session->getLex()->statement= new statement::Show(session); |
|
521 |
||
522 |
if (is_global == OPT_GLOBAL) |
|
523 |
{
|
|
524 |
if (prepare_new_schema_table(session, session->getLex(), "GLOBAL_VARIABLES")) |
|
525 |
return false; |
|
526 |
}
|
|
527 |
else
|
|
528 |
{
|
|
529 |
if (prepare_new_schema_table(session, session->getLex(), "SESSION_VARIABLES")) |
|
530 |
return false; |
|
531 |
}
|
|
532 |
||
533 |
std::string key("Variable_name"); |
|
534 |
std::string value("Value"); |
|
535 |
||
2187.2.2
by Brian Aker
getLex() usage and fix for table_name creation during admin commands. |
536 |
Item_field *my_field= new Item_field(&session->getLex()->current_select->context, NULL, NULL, "VARIABLE_NAME"); |
2096.1.11
by Brian Aker
Additional show to function. |
537 |
my_field->is_autogenerated_name= false; |
538 |
my_field->set_name(key.c_str(), key.length(), system_charset_info); |
|
539 |
||
540 |
if (session->add_item_to_list(my_field)) |
|
541 |
return false; |
|
542 |
||
2187.2.2
by Brian Aker
getLex() usage and fix for table_name creation during admin commands. |
543 |
my_field= new Item_field(&session->getLex()->current_select->context, NULL, NULL, "VARIABLE_VALUE"); |
2096.1.11
by Brian Aker
Additional show to function. |
544 |
my_field->is_autogenerated_name= false; |
545 |
my_field->set_name(value.c_str(), value.length(), system_charset_info); |
|
546 |
||
547 |
if (session->add_item_to_list(my_field)) |
|
548 |
return false; |
|
549 |
||
550 |
return true; |
|
551 |
}
|
|
552 |
||
2096.1.8
by Brian Aker
Move show create schema into function. |
553 |
bool buildCreateSchema(Session *session, LEX_STRING &ident) |
554 |
{
|
|
555 |
session->getLex()->sql_command= SQLCOM_SELECT; |
|
556 |
drizzled::statement::Show *select= new statement::Show(session); |
|
557 |
session->getLex()->statement= select; |
|
558 |
||
559 |
if (prepare_new_schema_table(session, session->getLex(), "SCHEMA_SQL_DEFINITION")) |
|
560 |
return false; |
|
561 |
||
562 |
util::string::const_shared_ptr schema(session->schema()); |
|
563 |
if (ident.str) |
|
564 |
{
|
|
565 |
select->setShowPredicate(ident.str); |
|
566 |
}
|
|
567 |
else if (schema) |
|
568 |
{
|
|
569 |
select->setShowPredicate(*schema); |
|
570 |
}
|
|
571 |
else
|
|
572 |
{
|
|
573 |
my_error(ER_NO_DB_ERROR, MYF(0)); |
|
574 |
return false; |
|
575 |
}
|
|
576 |
||
577 |
std::string key("Database"); |
|
578 |
std::string value("Create Database"); |
|
579 |
||
2187.2.2
by Brian Aker
getLex() usage and fix for table_name creation during admin commands. |
580 |
Item_field *my_field= new Item_field(&session->getLex()->current_select->context, NULL, NULL, "SCHEMA_NAME"); |
2096.1.8
by Brian Aker
Move show create schema into function. |
581 |
my_field->is_autogenerated_name= false; |
582 |
my_field->set_name(key.c_str(), key.length(), system_charset_info); |
|
583 |
||
584 |
if (session->add_item_to_list(my_field)) |
|
585 |
return false; |
|
586 |
||
2187.2.2
by Brian Aker
getLex() usage and fix for table_name creation during admin commands. |
587 |
my_field= new Item_field(&session->getLex()->current_select->context, NULL, NULL, "SCHEMA_SQL_DEFINITION"); |
2096.1.8
by Brian Aker
Move show create schema into function. |
588 |
my_field->is_autogenerated_name= false; |
589 |
my_field->set_name(value.c_str(), value.length(), system_charset_info); |
|
590 |
||
591 |
if (session->add_item_to_list(my_field)) |
|
592 |
return false; |
|
593 |
||
594 |
return true; |
|
595 |
}
|
|
596 |
||
2096.1.7
by Brian Aker
Shrink parser code, push C out to function call. |
597 |
bool buildDescribe(Session *session, Table_ident *ident) |
598 |
{
|
|
599 |
session->getLex()->lock_option= TL_READ; |
|
600 |
init_select(session->getLex()); |
|
601 |
session->getLex()->current_select->parsing_place= SELECT_LIST; |
|
602 |
session->getLex()->sql_command= SQLCOM_SELECT; |
|
603 |
drizzled::statement::Show *select= new statement::Show(session); |
|
604 |
session->getLex()->statement= select; |
|
605 |
session->getLex()->select_lex.db= 0; |
|
606 |
||
607 |
util::string::const_shared_ptr schema(session->schema()); |
|
608 |
if (ident->db.str) |
|
609 |
{
|
|
610 |
select->setShowPredicate(ident->db.str, ident->table.str); |
|
611 |
}
|
|
612 |
else if (schema) |
|
613 |
{
|
|
614 |
select->setShowPredicate(*schema, ident->table.str); |
|
615 |
}
|
|
616 |
else
|
|
617 |
{
|
|
618 |
my_error(ER_NO_DB_ERROR, MYF(0)); |
|
619 |
return false; |
|
620 |
}
|
|
621 |
||
622 |
{
|
|
623 |
drizzled::identifier::Table identifier(select->getShowSchema().c_str(), ident->table.str); |
|
624 |
if (not plugin::StorageEngine::doesTableExist(*session, identifier)) |
|
625 |
{
|
|
2140.1.3
by Brian Aker
Merge in error message fix for just one type of error for unknown table. |
626 |
my_error(ER_TABLE_UNKNOWN, identifier); |
2096.1.7
by Brian Aker
Shrink parser code, push C out to function call. |
627 |
}
|
628 |
}
|
|
629 |
||
630 |
if (prepare_new_schema_table(session, session->getLex(), "SHOW_COLUMNS")) |
|
631 |
{
|
|
632 |
return false; |
|
633 |
}
|
|
634 |
||
2187.2.2
by Brian Aker
getLex() usage and fix for table_name creation during admin commands. |
635 |
if (session->add_item_to_list( new Item_field(&session->getLex()->current_select-> |
2096.1.7
by Brian Aker
Shrink parser code, push C out to function call. |
636 |
context, |
637 |
NULL, NULL, "*"))) |
|
638 |
{
|
|
639 |
return false; |
|
640 |
}
|
|
641 |
||
2187.2.2
by Brian Aker
getLex() usage and fix for table_name creation during admin commands. |
642 |
(session->getLex()->current_select->with_wild)++; |
2096.1.7
by Brian Aker
Shrink parser code, push C out to function call. |
643 |
|
644 |
return true; |
|
645 |
}
|
|
646 |
||
647 |
} /* namespace drizzled */ |
|
648 |
||
1280.1.10
by Monty Taylor
Put everything in drizzled into drizzled namespace. |
649 |
} /* namespace drizzled */ |