~drizzle-trunk/drizzle/development

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
#include <drizzled/statement/show.h>
33
#include <drizzled/statement/show_errors.h>
34
#include <drizzled/statement/show_warnings.h>
2234.1.4 by Olaf van der Spek
Refactor includes
35
#include <drizzled/sql_lex.h>
2239.1.9 by Olaf van der Spek
Refactor includes
36
#include <drizzled/table_ident.h>
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
2318.6.31 by Olaf van der Spek
Refactor
48
namespace drizzled {
1 by brian
clean slate
49
2318.6.31 by Olaf van der Spek
Refactor
50
inline const char* str_or_nil(const char *str)
322.2.2 by Mats Kindahl
Hiding THD::proc_info field and providing a setter and getter.
51
{
52
  return str ? str : "<nil>";
53
}
1 by brian
clean slate
54
2154.2.2 by Brian Aker
Reduce include files for show command.
55
int wild_case_compare(const charset_info_st * const cs, const char *str, const char *wildstr)
1 by brian
clean slate
56
{
2194.3.1 by Olaf van der Spek
Remove register keyword
57
  int flag;
1273.13.61 by Brian Aker
Fixes a memory leak. sql_string() sucks.
58
1 by brian
clean slate
59
  while (*wildstr)
60
  {
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
61
    while (*wildstr && *wildstr != internal::wild_many && *wildstr != internal::wild_one)
1 by brian
clean slate
62
    {
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
63
      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
64
        wildstr++;
2170.1.1 by Brian Aker
Merge with trunk.
65
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
      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.
67
        return (1);
1 by brian
clean slate
68
    }
2170.1.1 by Brian Aker
Merge with trunk.
69
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
70
    if (! *wildstr )
71
      return (*str != 0);
2170.1.1 by Brian Aker
Merge with trunk.
72
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
73
    if (*wildstr++ == internal::wild_one)
1 by brian
clean slate
74
    {
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
75
      if (! *str++)
76
        return (1);	/* One char; skip */
1 by brian
clean slate
77
    }
78
    else
79
    {						/* Found '*' */
1067.3.1 by Padraig O'Sullivan
Extracted the CHARACTER_SET I_S table into the I_S plugin.
80
      if (! *wildstr)
81
        return (0);		/* '*' as last char: OK */
2170.1.1 by Brian Aker
Merge with trunk.
82
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
83
      flag=(*wildstr != internal::wild_many && *wildstr != internal::wild_one);
1 by brian
clean slate
84
      do
85
      {
1067.3.1 by Padraig O'Sullivan
Extracted the CHARACTER_SET I_S table into the I_S plugin.
86
        if (flag)
87
        {
88
          char cmp;
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
89
          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.
90
            cmp= wildstr[1];
2170.1.1 by Brian Aker
Merge with trunk.
91
1067.3.1 by Padraig O'Sullivan
Extracted the CHARACTER_SET I_S table into the I_S plugin.
92
          cmp= my_toupper(cs, cmp);
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
          while (*str && my_toupper(cs, *str) != cmp)
95
            str++;
2170.1.1 by Brian Aker
Merge with trunk.
96
1067.3.1 by Padraig O'Sullivan
Extracted the CHARACTER_SET I_S table into the I_S plugin.
97
          if (! *str)
98
            return (1);
99
        }
2170.1.1 by Brian Aker
Merge with trunk.
100
1067.3.1 by Padraig O'Sullivan
Extracted the CHARACTER_SET I_S table into the I_S plugin.
101
        if (wild_case_compare(cs, str, wildstr) == 0)
102
          return (0);
2170.1.1 by Brian Aker
Merge with trunk.
103
1067.3.1 by Padraig O'Sullivan
Extracted the CHARACTER_SET I_S table into the I_S plugin.
104
      } while (*str++);
2170.1.1 by Brian Aker
Merge with trunk.
105
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
106
      return (1);
1 by brian
clean slate
107
    }
108
  }
1273.13.61 by Brian Aker
Fixes a memory leak. sql_string() sucks.
109
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
110
  return (*str != '\0');
1 by brian
clean slate
111
}
112
113
/*
114
  Get the quote character for displaying an identifier.
115
116
  SYNOPSIS
117
    get_quote_char_for_identifier()
118
119
  IMPLEMENTATION
120
    Force quoting in the following cases:
121
      - name is empty (for one, it is possible when we use this function for
122
        quoting user and host names for DEFINER clause);
123
      - name is a keyword;
124
      - name includes a special character;
125
    Otherwise identifier is quoted only if the option OPTION_QUOTE_SHOW_CREATE
126
    is set.
127
128
  RETURN
129
    EOF	  No quote character is needed
130
    #	  Quote character
131
*/
132
1014.3.4 by Brian Aker
Remove dead session calls.
133
int get_quote_char_for_identifier()
1 by brian
clean slate
134
{
352.2.1 by Harrison Fisk
Fix for bugs 259843 and 256482
135
  return '`';
1 by brian
clean slate
136
}
137
2096.1.7 by Brian Aker
Shrink parser code, push C out to function call.
138
namespace show {
139
2318.6.31 by Olaf van der Spek
Refactor
140
bool buildSchemas(Session *session)
2096.1.9 by Brian Aker
Merge in additional show.
141
{
2227.4.8 by Olaf van der Spek
Session::lex()
142
  session->lex().sql_command= SQLCOM_SELECT;
143
  session->lex().statement= new statement::Show(session);
2096.1.9 by Brian Aker
Merge in additional show.
144
145
  std::string column_name= "Database";
2227.4.8 by Olaf van der Spek
Session::lex()
146
  if (session->lex().wild)
2096.1.9 by Brian Aker
Merge in additional show.
147
  {
148
    column_name.append(" (");
2227.4.8 by Olaf van der Spek
Session::lex()
149
    column_name.append(session->lex().wild->ptr());
2096.1.9 by Brian Aker
Merge in additional show.
150
    column_name.append(")");
151
  }
152
2318.9.1 by Olaf van der Spek
Refactor Item::set_name() calls
153
  if (prepare_new_schema_table(session, session->lex(), session->lex().current_select->where ? "SCHEMAS" : "SHOW_SCHEMAS"))
154
    return false;
2096.1.9 by Brian Aker
Merge in additional show.
155
2227.4.8 by Olaf van der Spek
Session::lex()
156
  Item_field *my_field= new Item_field(&session->lex().current_select->context, NULL, NULL, "SCHEMA_NAME");
2096.1.9 by Brian Aker
Merge in additional show.
157
  my_field->is_autogenerated_name= false;
2318.9.1 by Olaf van der Spek
Refactor Item::set_name() calls
158
  my_field->set_name(column_name);
2096.1.9 by Brian Aker
Merge in additional show.
159
2318.6.31 by Olaf van der Spek
Refactor
160
  session->add_item_to_list(my_field);
161
  session->add_order_to_list(my_field, true);
2096.1.9 by Brian Aker
Merge in additional show.
162
  return true;
163
}
164
2096.1.10 by Brian Aker
More shuffle of show into functions.
165
bool buildTables(Session *session, const char *ident)
166
{
2227.4.8 by Olaf van der Spek
Session::lex()
167
  session->lex().sql_command= SQLCOM_SELECT;
2096.1.10 by Brian Aker
More shuffle of show into functions.
168
169
  drizzled::statement::Show *select= new statement::Show(session);
2227.4.8 by Olaf van der Spek
Session::lex()
170
  session->lex().statement= select;
2096.1.10 by Brian Aker
More shuffle of show into functions.
171
172
  std::string column_name= "Tables_in_";
173
2269.1.7 by Olaf van der Spek
Use util::string::ptr
174
  util::string::ptr schema(session->schema());
2096.1.10 by Brian Aker
More shuffle of show into functions.
175
  if (ident)
176
  {
177
    identifier::Schema identifier(ident);
178
    column_name.append(ident);
2227.4.8 by Olaf van der Spek
Session::lex()
179
    session->lex().select_lex.db= const_cast<char *>(ident);
2096.1.10 by Brian Aker
More shuffle of show into functions.
180
    if (not plugin::StorageEngine::doesSchemaExist(identifier))
181
    {
2159.2.8 by Brian Aker
Merge in fixes for error messages with privs.
182
      my_error(ER_BAD_DB_ERROR, identifier);
2096.1.10 by Brian Aker
More shuffle of show into functions.
183
    }
184
    select->setShowPredicate(ident, "");
185
  }
186
  else if (schema and not schema->empty())
187
  {
188
    column_name.append(*schema);
189
    select->setShowPredicate(*schema, "");
190
  }
191
  else
192
  {
193
    my_error(ER_NO_DB_ERROR, MYF(0));
194
    return false;
195
  }
196
197
2227.4.8 by Olaf van der Spek
Session::lex()
198
  if (session->lex().wild)
2096.1.10 by Brian Aker
More shuffle of show into functions.
199
  {
200
    column_name.append(" (");
2227.4.8 by Olaf van der Spek
Session::lex()
201
    column_name.append(session->lex().wild->ptr());
2096.1.10 by Brian Aker
More shuffle of show into functions.
202
    column_name.append(")");
203
  }
204
2227.4.9 by Olaf van der Spek
Session::lex()
205
  if (prepare_new_schema_table(session, session->lex(), "SHOW_TABLES"))
2096.1.10 by Brian Aker
More shuffle of show into functions.
206
    return false;
207
2227.4.8 by Olaf van der Spek
Session::lex()
208
  Item_field *my_field= new Item_field(&session->lex().current_select->context, NULL, NULL, "TABLE_NAME");
2096.1.10 by Brian Aker
More shuffle of show into functions.
209
  my_field->is_autogenerated_name= false;
2318.9.1 by Olaf van der Spek
Refactor Item::set_name() calls
210
  my_field->set_name(column_name);
2096.1.10 by Brian Aker
More shuffle of show into functions.
211
2318.6.31 by Olaf van der Spek
Refactor
212
  session->add_item_to_list(my_field);
213
  session->add_order_to_list(my_field, true);
2096.1.10 by Brian Aker
More shuffle of show into functions.
214
  return true;
215
}
216
217
bool buildTemporaryTables(Session *session)
218
{
2227.4.8 by Olaf van der Spek
Session::lex()
219
  session->lex().sql_command= SQLCOM_SELECT;
220
  session->lex().statement= new statement::Show(session);
2096.1.10 by Brian Aker
More shuffle of show into functions.
221
2227.4.9 by Olaf van der Spek
Session::lex()
222
  if (prepare_new_schema_table(session, session->lex(), "SHOW_TEMPORARY_TABLES"))
2096.1.10 by Brian Aker
More shuffle of show into functions.
223
    return false;
224
2318.6.31 by Olaf van der Spek
Refactor
225
  session->add_item_to_list( new Item_field(&session->lex().current_select->context, NULL, NULL, "*"));
226
  session->lex().current_select->with_wild++;
2096.1.10 by Brian Aker
More shuffle of show into functions.
227
  return true;
228
}
229
230
bool buildTableStatus(Session *session, const char *ident)
231
{
2227.4.8 by Olaf van der Spek
Session::lex()
232
  session->lex().sql_command= SQLCOM_SELECT;
2096.1.10 by Brian Aker
More shuffle of show into functions.
233
  drizzled::statement::Show *select= new statement::Show(session);
2227.4.8 by Olaf van der Spek
Session::lex()
234
  session->lex().statement= select;
2096.1.10 by Brian Aker
More shuffle of show into functions.
235
236
  std::string column_name= "Tables_in_";
237
2269.1.7 by Olaf van der Spek
Use util::string::ptr
238
  util::string::ptr schema(session->schema());
2096.1.10 by Brian Aker
More shuffle of show into functions.
239
  if (ident)
240
  {
2227.4.8 by Olaf van der Spek
Session::lex()
241
    session->lex().select_lex.db= const_cast<char *>(ident);
2096.1.10 by Brian Aker
More shuffle of show into functions.
242
243
    identifier::Schema identifier(ident);
244
    if (not plugin::StorageEngine::doesSchemaExist(identifier))
245
    {
2159.2.8 by Brian Aker
Merge in fixes for error messages with privs.
246
      my_error(ER_BAD_DB_ERROR, identifier);
2096.1.10 by Brian Aker
More shuffle of show into functions.
247
    }
248
249
    select->setShowPredicate(ident, "");
250
  }
251
  else if (schema)
252
  {
253
    select->setShowPredicate(*schema, "");
254
  }
255
  else
256
  {
257
    my_error(ER_NO_DB_ERROR, MYF(0));
258
    return false;
259
  }
260
2227.4.9 by Olaf van der Spek
Session::lex()
261
  if (prepare_new_schema_table(session, session->lex(), "SHOW_TABLE_STATUS"))
2096.1.10 by Brian Aker
More shuffle of show into functions.
262
    return false;
263
2318.6.31 by Olaf van der Spek
Refactor
264
  session->add_item_to_list( new Item_field(&session->lex().current_select->context, NULL, NULL, "*"));
265
  session->lex().current_select->with_wild++;
2096.1.10 by Brian Aker
More shuffle of show into functions.
266
  return true;
267
}
268
2371.1.2 by Brian Aker
Remove the typedef on lexkey
269
bool buildEngineStatus(Session *session, lex_string_t)
2131.3.1 by Andrew Hutchings
Add error telling the user to use data_dictionary for SHOW engine_name STATUS
270
{
2227.4.8 by Olaf van der Spek
Session::lex()
271
  session->lex().sql_command= SQLCOM_SELECT;
2131.3.1 by Andrew Hutchings
Add error telling the user to use data_dictionary for SHOW engine_name STATUS
272
  drizzled::statement::Show *select= new statement::Show(session);
2227.4.8 by Olaf van der Spek
Session::lex()
273
  session->lex().statement= select;
2131.3.1 by Andrew Hutchings
Add error telling the user to use data_dictionary for SHOW engine_name STATUS
274
275
  my_error(ER_USE_DATA_DICTIONARY);
276
  return false;
277
}
278
2096.1.12 by Brian Aker
Additional show to functions.
279
bool buildColumns(Session *session, const char *schema_ident, Table_ident *table_ident)
280
{
2227.4.8 by Olaf van der Spek
Session::lex()
281
  session->lex().sql_command= SQLCOM_SELECT;
2096.1.12 by Brian Aker
Additional show to functions.
282
283
  drizzled::statement::Show *select= new statement::Show(session);
2227.4.8 by Olaf van der Spek
Session::lex()
284
  session->lex().statement= select;
2096.1.12 by Brian Aker
Additional show to functions.
285
2269.1.7 by Olaf van der Spek
Use util::string::ptr
286
  util::string::ptr schema(session->schema());
2096.1.12 by Brian Aker
Additional show to functions.
287
  if (schema_ident)
288
  {
289
    select->setShowPredicate(schema_ident, table_ident->table.str);
290
  }
291
  else if (table_ident->db.str)
292
  {
293
    select->setShowPredicate(table_ident->db.str, table_ident->table.str);
294
  }
295
  else if (schema)
296
  {
297
    select->setShowPredicate(*schema, table_ident->table.str);
298
  }
299
  else
300
  {
301
    my_error(ER_NO_DB_ERROR, MYF(0));
302
    return false;
303
  }
304
305
  {
2318.9.1 by Olaf van der Spek
Refactor Item::set_name() calls
306
    drizzled::identifier::Table identifier(select->getShowSchema(), table_ident->table.str);
2096.1.12 by Brian Aker
Additional show to functions.
307
    if (not plugin::StorageEngine::doesTableExist(*session, identifier))
308
    {
2140.1.3 by Brian Aker
Merge in error message fix for just one type of error for unknown table.
309
      my_error(ER_TABLE_UNKNOWN, identifier);
2096.1.12 by Brian Aker
Additional show to functions.
310
    }
311
  }
312
2227.4.9 by Olaf van der Spek
Session::lex()
313
  if (prepare_new_schema_table(session, session->lex(), "SHOW_COLUMNS"))
2096.1.12 by Brian Aker
Additional show to functions.
314
    return false;
315
2318.6.31 by Olaf van der Spek
Refactor
316
  session->add_item_to_list( new Item_field(&session->lex().current_select->context, NULL, NULL, "*"));
317
  session->lex().current_select->with_wild++;
2096.1.12 by Brian Aker
Additional show to functions.
318
  return true;
319
}
320
2137.1.12 by Brian Aker
Remove current_session in building the error count.
321
void buildSelectWarning(Session *session)
322
{
2137.1.13 by Brian Aker
Fix bad error in warnings/errors.
323
  (void) create_select_for_variable(session, "warning_count");
2227.4.8 by Olaf van der Spek
Session::lex()
324
  session->lex().statement= new statement::Show(session);
2137.1.12 by Brian Aker
Remove current_session in building the error count.
325
}
326
327
void buildSelectError(Session *session)
328
{
329
  (void) create_select_for_variable(session, "error_count");
2227.4.8 by Olaf van der Spek
Session::lex()
330
  session->lex().statement= new statement::Show(session);
2137.1.12 by Brian Aker
Remove current_session in building the error count.
331
}
332
333
void buildWarnings(Session *session)
2096.1.13 by Brian Aker
Last of format style show commands removed from parser.
334
{
2227.4.8 by Olaf van der Spek
Session::lex()
335
  session->lex().statement= new statement::ShowWarnings(session);
2096.1.13 by Brian Aker
Last of format style show commands removed from parser.
336
}
337
2137.1.12 by Brian Aker
Remove current_session in building the error count.
338
void buildErrors(Session *session)
2096.1.13 by Brian Aker
Last of format style show commands removed from parser.
339
{
2227.4.8 by Olaf van der Spek
Session::lex()
340
  session->lex().statement= new statement::ShowErrors(session);
2096.1.13 by Brian Aker
Last of format style show commands removed from parser.
341
}
342
2096.1.12 by Brian Aker
Additional show to functions.
343
bool buildIndex(Session *session, const char *schema_ident, Table_ident *table_ident)
344
{
2227.4.8 by Olaf van der Spek
Session::lex()
345
  session->lex().sql_command= SQLCOM_SELECT;
2096.1.12 by Brian Aker
Additional show to functions.
346
  drizzled::statement::Show *select= new statement::Show(session);
2227.4.8 by Olaf van der Spek
Session::lex()
347
  session->lex().statement= select;
2096.1.12 by Brian Aker
Additional show to functions.
348
2269.1.7 by Olaf van der Spek
Use util::string::ptr
349
  util::string::ptr schema(session->schema());
2096.1.12 by Brian Aker
Additional show to functions.
350
  if (schema_ident)
351
  {
352
    select->setShowPredicate(schema_ident, table_ident->table.str);
353
  }
354
  else if (table_ident->db.str)
355
  {
356
    select->setShowPredicate(table_ident->db.str, table_ident->table.str);
357
  }
358
  else if (schema)
359
  {
360
    select->setShowPredicate(*schema, table_ident->table.str);
361
  }
362
  else
363
  {
364
    my_error(ER_NO_DB_ERROR, MYF(0));
365
    return false;
366
  }
367
368
  {
2318.9.1 by Olaf van der Spek
Refactor Item::set_name() calls
369
    drizzled::identifier::Table identifier(select->getShowSchema(), table_ident->table.str);
2096.1.12 by Brian Aker
Additional show to functions.
370
    if (not plugin::StorageEngine::doesTableExist(*session, identifier))
371
    {
2140.1.3 by Brian Aker
Merge in error message fix for just one type of error for unknown table.
372
      my_error(ER_TABLE_UNKNOWN, identifier);
2096.1.12 by Brian Aker
Additional show to functions.
373
    }
374
  }
375
2227.4.9 by Olaf van der Spek
Session::lex()
376
  if (prepare_new_schema_table(session, session->lex(), "SHOW_INDEXES"))
2096.1.12 by Brian Aker
Additional show to functions.
377
    return false;
378
2318.6.31 by Olaf van der Spek
Refactor
379
  session->add_item_to_list(new Item_field(&session->lex().current_select->context, NULL, NULL, "*"));
380
  session->lex().current_select->with_wild++;
2096.1.12 by Brian Aker
Additional show to functions.
381
  return true;
382
}
383
384
bool buildStatus(Session *session, const drizzled::sql_var_t is_global)
385
{
2227.4.8 by Olaf van der Spek
Session::lex()
386
  session->lex().sql_command= SQLCOM_SELECT;
387
  session->lex().statement= new statement::Show(session);
2096.1.12 by Brian Aker
Additional show to functions.
388
2318.9.1 by Olaf van der Spek
Refactor Item::set_name() calls
389
  if (prepare_new_schema_table(session, session->lex(), is_global == OPT_GLOBAL ? "GLOBAL_STATUS" : "SESSION_STATUS"))
390
    return false;
2096.1.12 by Brian Aker
Additional show to functions.
391
2227.4.8 by Olaf van der Spek
Session::lex()
392
  Item_field *my_field= new Item_field(&session->lex().current_select->context, NULL, NULL, "VARIABLE_NAME");
2096.1.12 by Brian Aker
Additional show to functions.
393
  my_field->is_autogenerated_name= false;
2318.9.1 by Olaf van der Spek
Refactor Item::set_name() calls
394
  my_field->set_name("Variable_name");
2318.6.31 by Olaf van der Spek
Refactor
395
  session->add_item_to_list(my_field);
2227.4.8 by Olaf van der Spek
Session::lex()
396
  my_field= new Item_field(&session->lex().current_select->context, NULL, NULL, "VARIABLE_VALUE");
2096.1.12 by Brian Aker
Additional show to functions.
397
  my_field->is_autogenerated_name= false;
2318.9.1 by Olaf van der Spek
Refactor Item::set_name() calls
398
  my_field->set_name("Value");
2318.6.31 by Olaf van der Spek
Refactor
399
  session->add_item_to_list(my_field);
2096.1.12 by Brian Aker
Additional show to functions.
400
  return true;
401
}
402
403
bool buildCreateTable(Session *session, Table_ident *ident)
404
{
2227.4.8 by Olaf van der Spek
Session::lex()
405
  session->lex().sql_command= SQLCOM_SELECT;
2096.1.12 by Brian Aker
Additional show to functions.
406
  statement::Show *select= new statement::Show(session);
2227.4.8 by Olaf van der Spek
Session::lex()
407
  session->lex().statement= select;
2096.1.12 by Brian Aker
Additional show to functions.
408
2227.4.8 by Olaf van der Spek
Session::lex()
409
  if (session->lex().statement == NULL)
2096.1.12 by Brian Aker
Additional show to functions.
410
    return false;
411
2227.4.9 by Olaf van der Spek
Session::lex()
412
  if (prepare_new_schema_table(session, session->lex(), "TABLE_SQL_DEFINITION"))
2096.1.12 by Brian Aker
Additional show to functions.
413
    return false;
414
2269.1.7 by Olaf van der Spek
Use util::string::ptr
415
  util::string::ptr schema(session->schema());
2096.1.12 by Brian Aker
Additional show to functions.
416
  if (ident->db.str)
417
  {
418
    select->setShowPredicate(ident->db.str, ident->table.str);
419
  }
420
  else if (schema)
421
  {
422
    select->setShowPredicate(*schema, ident->table.str);
423
  }
424
  else
425
  {
426
    my_error(ER_NO_DB_ERROR, MYF(0));
427
    return false;
428
  }
429
2227.4.8 by Olaf van der Spek
Session::lex()
430
  Item_field *my_field= new Item_field(&session->lex().current_select->context, NULL, NULL, "TABLE_NAME");
2096.1.12 by Brian Aker
Additional show to functions.
431
  my_field->is_autogenerated_name= false;
2318.9.1 by Olaf van der Spek
Refactor Item::set_name() calls
432
  my_field->set_name("Table");
2318.6.31 by Olaf van der Spek
Refactor
433
  session->add_item_to_list(my_field);
2227.4.8 by Olaf van der Spek
Session::lex()
434
  my_field= new Item_field(&session->lex().current_select->context, NULL, NULL, "TABLE_SQL_DEFINITION");
2096.1.12 by Brian Aker
Additional show to functions.
435
  my_field->is_autogenerated_name= false;
2318.9.1 by Olaf van der Spek
Refactor Item::set_name() calls
436
  my_field->set_name("Create Table");
2318.6.31 by Olaf van der Spek
Refactor
437
  session->add_item_to_list(my_field);
2096.1.12 by Brian Aker
Additional show to functions.
438
  return true;
439
}
440
441
bool buildProcesslist(Session *session)
442
{
2227.4.8 by Olaf van der Spek
Session::lex()
443
  session->lex().sql_command= SQLCOM_SELECT;
444
  session->lex().statement= new statement::Show(session);
2096.1.12 by Brian Aker
Additional show to functions.
445
2227.4.9 by Olaf van der Spek
Session::lex()
446
  if (prepare_new_schema_table(session, session->lex(), "PROCESSLIST"))
2096.1.12 by Brian Aker
Additional show to functions.
447
    return false;
448
2318.6.31 by Olaf van der Spek
Refactor
449
  session->add_item_to_list( new Item_field(&session->lex().current_select->context, NULL, NULL, "*"));
450
  session->lex().current_select->with_wild++;
2096.1.12 by Brian Aker
Additional show to functions.
451
  return true;
452
}
453
2096.1.11 by Brian Aker
Additional show to function.
454
bool buildVariables(Session *session, const drizzled::sql_var_t is_global)
455
{
2227.4.8 by Olaf van der Spek
Session::lex()
456
  session->lex().sql_command= SQLCOM_SELECT;
457
  session->lex().statement= new statement::Show(session);
2096.1.11 by Brian Aker
Additional show to function.
458
459
  if (is_global == OPT_GLOBAL)
460
  {
2227.4.9 by Olaf van der Spek
Session::lex()
461
    if (prepare_new_schema_table(session, session->lex(), "GLOBAL_VARIABLES"))
2096.1.11 by Brian Aker
Additional show to function.
462
      return false;
463
  }
464
  else
465
  {
2227.4.9 by Olaf van der Spek
Session::lex()
466
    if (prepare_new_schema_table(session, session->lex(), "SESSION_VARIABLES"))
2096.1.11 by Brian Aker
Additional show to function.
467
      return false;
468
  }
469
2227.4.8 by Olaf van der Spek
Session::lex()
470
  Item_field *my_field= new Item_field(&session->lex().current_select->context, NULL, NULL, "VARIABLE_NAME");
2096.1.11 by Brian Aker
Additional show to function.
471
  my_field->is_autogenerated_name= false;
2318.9.1 by Olaf van der Spek
Refactor Item::set_name() calls
472
  my_field->set_name("Variable_name");
2318.6.31 by Olaf van der Spek
Refactor
473
  session->add_item_to_list(my_field);
2227.4.8 by Olaf van der Spek
Session::lex()
474
  my_field= new Item_field(&session->lex().current_select->context, NULL, NULL, "VARIABLE_VALUE");
2096.1.11 by Brian Aker
Additional show to function.
475
  my_field->is_autogenerated_name= false;
2318.9.1 by Olaf van der Spek
Refactor Item::set_name() calls
476
  my_field->set_name("Value");
2096.1.11 by Brian Aker
Additional show to function.
477
2318.6.31 by Olaf van der Spek
Refactor
478
  session->add_item_to_list(my_field);
2096.1.11 by Brian Aker
Additional show to function.
479
  return true;
480
}
481
2371.1.2 by Brian Aker
Remove the typedef on lexkey
482
bool buildCreateSchema(Session *session, lex_string_t &ident)
2096.1.8 by Brian Aker
Move show create schema into function.
483
{
2227.4.8 by Olaf van der Spek
Session::lex()
484
  session->lex().sql_command= SQLCOM_SELECT;
2096.1.8 by Brian Aker
Move show create schema into function.
485
  drizzled::statement::Show *select= new statement::Show(session);
2227.4.8 by Olaf van der Spek
Session::lex()
486
  session->lex().statement= select;
2096.1.8 by Brian Aker
Move show create schema into function.
487
2227.4.9 by Olaf van der Spek
Session::lex()
488
  if (prepare_new_schema_table(session, session->lex(), "SCHEMA_SQL_DEFINITION"))
2096.1.8 by Brian Aker
Move show create schema into function.
489
    return false;
490
2269.1.7 by Olaf van der Spek
Use util::string::ptr
491
  util::string::ptr schema(session->schema());
2096.1.8 by Brian Aker
Move show create schema into function.
492
  if (ident.str)
493
  {
494
    select->setShowPredicate(ident.str);
495
  }
496
  else if (schema)
497
  {
498
    select->setShowPredicate(*schema);
499
  }
500
  else
501
  {
502
    my_error(ER_NO_DB_ERROR, MYF(0));
503
    return false;
504
  }
505
2227.4.8 by Olaf van der Spek
Session::lex()
506
  Item_field *my_field= new Item_field(&session->lex().current_select->context, NULL, NULL, "SCHEMA_NAME");
2096.1.8 by Brian Aker
Move show create schema into function.
507
  my_field->is_autogenerated_name= false;
2318.9.1 by Olaf van der Spek
Refactor Item::set_name() calls
508
  my_field->set_name("Database");
2318.6.31 by Olaf van der Spek
Refactor
509
  session->add_item_to_list(my_field);
2318.9.1 by Olaf van der Spek
Refactor Item::set_name() calls
510
2227.4.8 by Olaf van der Spek
Session::lex()
511
  my_field= new Item_field(&session->lex().current_select->context, NULL, NULL, "SCHEMA_SQL_DEFINITION");
2096.1.8 by Brian Aker
Move show create schema into function.
512
  my_field->is_autogenerated_name= false;
2318.9.1 by Olaf van der Spek
Refactor Item::set_name() calls
513
  my_field->set_name("Create Database");
2318.6.31 by Olaf van der Spek
Refactor
514
  session->add_item_to_list(my_field);
2096.1.8 by Brian Aker
Move show create schema into function.
515
  return true;
516
}
517
2096.1.7 by Brian Aker
Shrink parser code, push C out to function call.
518
bool buildDescribe(Session *session, Table_ident *ident)
519
{
2227.4.8 by Olaf van der Spek
Session::lex()
520
  session->lex().lock_option= TL_READ;
2227.4.9 by Olaf van der Spek
Session::lex()
521
  init_select(&session->lex());
2227.4.8 by Olaf van der Spek
Session::lex()
522
  session->lex().current_select->parsing_place= SELECT_LIST;
523
  session->lex().sql_command= SQLCOM_SELECT;
2096.1.7 by Brian Aker
Shrink parser code, push C out to function call.
524
  drizzled::statement::Show *select= new statement::Show(session);
2227.4.8 by Olaf van der Spek
Session::lex()
525
  session->lex().statement= select;
526
  session->lex().select_lex.db= 0;
2096.1.7 by Brian Aker
Shrink parser code, push C out to function call.
527
2269.1.7 by Olaf van der Spek
Use util::string::ptr
528
  util::string::ptr schema(session->schema());
2096.1.7 by Brian Aker
Shrink parser code, push C out to function call.
529
  if (ident->db.str)
530
  {
531
    select->setShowPredicate(ident->db.str, ident->table.str);
532
  }
533
  else if (schema)
534
  {
535
    select->setShowPredicate(*schema, ident->table.str);
536
  }
537
  else
538
  {
539
    my_error(ER_NO_DB_ERROR, MYF(0));
540
    return false;
541
  }
542
543
  {
2318.9.1 by Olaf van der Spek
Refactor Item::set_name() calls
544
    drizzled::identifier::Table identifier(select->getShowSchema(), ident->table.str);
2096.1.7 by Brian Aker
Shrink parser code, push C out to function call.
545
    if (not plugin::StorageEngine::doesTableExist(*session, identifier))
546
    {
2140.1.3 by Brian Aker
Merge in error message fix for just one type of error for unknown table.
547
      my_error(ER_TABLE_UNKNOWN, identifier);
2096.1.7 by Brian Aker
Shrink parser code, push C out to function call.
548
    }
549
  }
550
2227.4.9 by Olaf van der Spek
Session::lex()
551
  if (prepare_new_schema_table(session, session->lex(), "SHOW_COLUMNS"))
2096.1.7 by Brian Aker
Shrink parser code, push C out to function call.
552
  {
553
    return false;
554
  }
2318.6.31 by Olaf van der Spek
Refactor
555
  session->add_item_to_list( new Item_field(&session->lex().current_select->context, NULL, NULL, "*"));
556
  session->lex().current_select->with_wild++;
2096.1.7 by Brian Aker
Shrink parser code, push C out to function call.
557
  return true;
558
}
559
2318.6.31 by Olaf van der Spek
Refactor
560
}
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
561
} /* namespace drizzled */