~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
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
{
2227.4.8 by Olaf van der Spek
Session::lex()
144
  session->lex().sql_command= SQLCOM_SELECT;
145
  session->lex().statement= new statement::Show(session);
2096.1.9 by Brian Aker
Merge in additional show.
146
147
  std::string column_name= "Database";
2227.4.8 by Olaf van der Spek
Session::lex()
148
  if (session->lex().wild)
2096.1.9 by Brian Aker
Merge in additional show.
149
  {
150
    column_name.append(" (");
2227.4.8 by Olaf van der Spek
Session::lex()
151
    column_name.append(session->lex().wild->ptr());
2096.1.9 by Brian Aker
Merge in additional show.
152
    column_name.append(")");
153
  }
154
2227.4.8 by Olaf van der Spek
Session::lex()
155
  if (session->lex().current_select->where)
2096.1.9 by Brian Aker
Merge in additional show.
156
  {
2227.4.9 by Olaf van der Spek
Session::lex()
157
    if (prepare_new_schema_table(session, session->lex(), "SCHEMAS"))
2096.1.9 by Brian Aker
Merge in additional show.
158
      return false;
159
  }
160
  else
161
  {
2227.4.9 by Olaf van der Spek
Session::lex()
162
    if (prepare_new_schema_table(session, session->lex(), "SHOW_SCHEMAS"))
2096.1.9 by Brian Aker
Merge in additional show.
163
      return false;
164
  }
165
2227.4.8 by Olaf van der Spek
Session::lex()
166
  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.
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
{
2227.4.8 by Olaf van der Spek
Session::lex()
181
  session->lex().sql_command= SQLCOM_SELECT;
2096.1.10 by Brian Aker
More shuffle of show into functions.
182
183
  drizzled::statement::Show *select= new statement::Show(session);
2227.4.8 by Olaf van der Spek
Session::lex()
184
  session->lex().statement= select;
2096.1.10 by Brian Aker
More shuffle of show into functions.
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);
2227.4.8 by Olaf van der Spek
Session::lex()
193
    session->lex().select_lex.db= const_cast<char *>(ident);
2096.1.10 by Brian Aker
More shuffle of show into functions.
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
2227.4.8 by Olaf van der Spek
Session::lex()
212
  if (session->lex().wild)
2096.1.10 by Brian Aker
More shuffle of show into functions.
213
  {
214
    column_name.append(" (");
2227.4.8 by Olaf van der Spek
Session::lex()
215
    column_name.append(session->lex().wild->ptr());
2096.1.10 by Brian Aker
More shuffle of show into functions.
216
    column_name.append(")");
217
  }
218
2227.4.9 by Olaf van der Spek
Session::lex()
219
  if (prepare_new_schema_table(session, session->lex(), "SHOW_TABLES"))
2096.1.10 by Brian Aker
More shuffle of show into functions.
220
    return false;
221
2227.4.8 by Olaf van der Spek
Session::lex()
222
  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.
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
{
2227.4.8 by Olaf van der Spek
Session::lex()
237
  session->lex().sql_command= SQLCOM_SELECT;
2096.1.10 by Brian Aker
More shuffle of show into functions.
238
2227.4.8 by Olaf van der Spek
Session::lex()
239
  session->lex().statement= new statement::Show(session);
2096.1.10 by Brian Aker
More shuffle of show into functions.
240
241
2227.4.9 by Olaf van der Spek
Session::lex()
242
  if (prepare_new_schema_table(session, session->lex(), "SHOW_TEMPORARY_TABLES"))
2096.1.10 by Brian Aker
More shuffle of show into functions.
243
    return false;
244
2227.4.8 by Olaf van der Spek
Session::lex()
245
  if (session->add_item_to_list( new Item_field(&session->lex().current_select->context, NULL, NULL, "*")))
2096.1.10 by Brian Aker
More shuffle of show into functions.
246
    return false;
247
2227.4.8 by Olaf van der Spek
Session::lex()
248
  (session->lex().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
{
2227.4.8 by Olaf van der Spek
Session::lex()
255
  session->lex().sql_command= SQLCOM_SELECT;
2096.1.10 by Brian Aker
More shuffle of show into functions.
256
  drizzled::statement::Show *select= new statement::Show(session);
2227.4.8 by Olaf van der Spek
Session::lex()
257
  session->lex().statement= select;
2096.1.10 by Brian Aker
More shuffle of show into functions.
258
259
  std::string column_name= "Tables_in_";
260
261
  util::string::const_shared_ptr schema(session->schema());
262
  if (ident)
263
  {
2227.4.8 by Olaf van der Spek
Session::lex()
264
    session->lex().select_lex.db= const_cast<char *>(ident);
2096.1.10 by Brian Aker
More shuffle of show into functions.
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
2227.4.9 by Olaf van der Spek
Session::lex()
284
  if (prepare_new_schema_table(session, session->lex(), "SHOW_TABLE_STATUS"))
2096.1.10 by Brian Aker
More shuffle of show into functions.
285
    return false;
286
2227.4.9 by Olaf van der Spek
Session::lex()
287
  if (session->add_item_to_list( new Item_field(&session->lex().current_select->context, NULL, NULL, "*")))
2096.1.10 by Brian Aker
More shuffle of show into functions.
288
    return false;
289
2227.4.8 by Olaf van der Spek
Session::lex()
290
  (session->lex().current_select->with_wild)++;
2096.1.10 by Brian Aker
More shuffle of show into functions.
291
292
  return true;
293
}
294
2131.3.1 by Andrew Hutchings
Add error telling the user to use data_dictionary for SHOW engine_name STATUS
295
bool buildEngineStatus(Session *session, LEX_STRING)
296
{
2227.4.8 by Olaf van der Spek
Session::lex()
297
  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
298
  drizzled::statement::Show *select= new statement::Show(session);
2227.4.8 by Olaf van der Spek
Session::lex()
299
  session->lex().statement= select;
2131.3.1 by Andrew Hutchings
Add error telling the user to use data_dictionary for SHOW engine_name STATUS
300
301
  my_error(ER_USE_DATA_DICTIONARY);
302
  return false;
303
}
304
2096.1.12 by Brian Aker
Additional show to functions.
305
bool buildColumns(Session *session, const char *schema_ident, Table_ident *table_ident)
306
{
2227.4.8 by Olaf van der Spek
Session::lex()
307
  session->lex().sql_command= SQLCOM_SELECT;
2096.1.12 by Brian Aker
Additional show to functions.
308
309
  drizzled::statement::Show *select= new statement::Show(session);
2227.4.8 by Olaf van der Spek
Session::lex()
310
  session->lex().statement= select;
2096.1.12 by Brian Aker
Additional show to functions.
311
312
  util::string::const_shared_ptr schema(session->schema());
313
  if (schema_ident)
314
  {
315
    select->setShowPredicate(schema_ident, table_ident->table.str);
316
  }
317
  else if (table_ident->db.str)
318
  {
319
    select->setShowPredicate(table_ident->db.str, table_ident->table.str);
320
  }
321
  else if (schema)
322
  {
323
    select->setShowPredicate(*schema, table_ident->table.str);
324
  }
325
  else
326
  {
327
    my_error(ER_NO_DB_ERROR, MYF(0));
328
    return false;
329
  }
330
331
  {
332
    drizzled::identifier::Table identifier(select->getShowSchema().c_str(), table_ident->table.str);
333
    if (not plugin::StorageEngine::doesTableExist(*session, identifier))
334
    {
2140.1.3 by Brian Aker
Merge in error message fix for just one type of error for unknown table.
335
      my_error(ER_TABLE_UNKNOWN, identifier);
2096.1.12 by Brian Aker
Additional show to functions.
336
    }
337
  }
338
2227.4.9 by Olaf van der Spek
Session::lex()
339
  if (prepare_new_schema_table(session, session->lex(), "SHOW_COLUMNS"))
2096.1.12 by Brian Aker
Additional show to functions.
340
    return false;
341
2227.4.8 by Olaf van der Spek
Session::lex()
342
  if (session->add_item_to_list( new Item_field(&session->lex().current_select->context, NULL, NULL, "*")))
2096.1.12 by Brian Aker
Additional show to functions.
343
    return false;
344
2227.4.8 by Olaf van der Spek
Session::lex()
345
  (session->lex().current_select->with_wild)++;
2096.1.12 by Brian Aker
Additional show to functions.
346
347
  return true;
348
}
349
2137.1.12 by Brian Aker
Remove current_session in building the error count.
350
void buildSelectWarning(Session *session)
351
{
2137.1.13 by Brian Aker
Fix bad error in warnings/errors.
352
  (void) create_select_for_variable(session, "warning_count");
2227.4.8 by Olaf van der Spek
Session::lex()
353
  session->lex().statement= new statement::Show(session);
2137.1.12 by Brian Aker
Remove current_session in building the error count.
354
}
355
356
void buildSelectError(Session *session)
357
{
358
  (void) create_select_for_variable(session, "error_count");
2227.4.8 by Olaf van der Spek
Session::lex()
359
  session->lex().statement= new statement::Show(session);
2137.1.12 by Brian Aker
Remove current_session in building the error count.
360
}
361
362
void buildWarnings(Session *session)
2096.1.13 by Brian Aker
Last of format style show commands removed from parser.
363
{
2227.4.8 by Olaf van der Spek
Session::lex()
364
  session->lex().statement= new statement::ShowWarnings(session);
2096.1.13 by Brian Aker
Last of format style show commands removed from parser.
365
}
366
2137.1.12 by Brian Aker
Remove current_session in building the error count.
367
void buildErrors(Session *session)
2096.1.13 by Brian Aker
Last of format style show commands removed from parser.
368
{
2227.4.8 by Olaf van der Spek
Session::lex()
369
  session->lex().statement= new statement::ShowErrors(session);
2096.1.13 by Brian Aker
Last of format style show commands removed from parser.
370
}
371
2096.1.12 by Brian Aker
Additional show to functions.
372
bool buildIndex(Session *session, const char *schema_ident, Table_ident *table_ident)
373
{
2227.4.8 by Olaf van der Spek
Session::lex()
374
  session->lex().sql_command= SQLCOM_SELECT;
2096.1.12 by Brian Aker
Additional show to functions.
375
  drizzled::statement::Show *select= new statement::Show(session);
2227.4.8 by Olaf van der Spek
Session::lex()
376
  session->lex().statement= select;
2096.1.12 by Brian Aker
Additional show to functions.
377
378
  util::string::const_shared_ptr schema(session->schema());
379
  if (schema_ident)
380
  {
381
    select->setShowPredicate(schema_ident, table_ident->table.str);
382
  }
383
  else if (table_ident->db.str)
384
  {
385
    select->setShowPredicate(table_ident->db.str, table_ident->table.str);
386
  }
387
  else if (schema)
388
  {
389
    select->setShowPredicate(*schema, table_ident->table.str);
390
  }
391
  else
392
  {
393
    my_error(ER_NO_DB_ERROR, MYF(0));
394
    return false;
395
  }
396
397
  {
398
    drizzled::identifier::Table identifier(select->getShowSchema().c_str(), table_ident->table.str);
399
    if (not plugin::StorageEngine::doesTableExist(*session, identifier))
400
    {
2140.1.3 by Brian Aker
Merge in error message fix for just one type of error for unknown table.
401
      my_error(ER_TABLE_UNKNOWN, identifier);
2096.1.12 by Brian Aker
Additional show to functions.
402
    }
403
  }
404
2227.4.9 by Olaf van der Spek
Session::lex()
405
  if (prepare_new_schema_table(session, session->lex(), "SHOW_INDEXES"))
2096.1.12 by Brian Aker
Additional show to functions.
406
    return false;
407
2227.4.8 by Olaf van der Spek
Session::lex()
408
  if (session->add_item_to_list( new Item_field(&session->lex().current_select->context, NULL, NULL, "*")))
2096.1.12 by Brian Aker
Additional show to functions.
409
    return false;
410
2227.4.8 by Olaf van der Spek
Session::lex()
411
  (session->lex().current_select->with_wild)++;
2096.1.12 by Brian Aker
Additional show to functions.
412
413
  return true;
414
}
415
416
bool buildStatus(Session *session, const drizzled::sql_var_t is_global)
417
{
2227.4.8 by Olaf van der Spek
Session::lex()
418
  session->lex().sql_command= SQLCOM_SELECT;
419
  session->lex().statement= new statement::Show(session);
2096.1.12 by Brian Aker
Additional show to functions.
420
421
  if (is_global == OPT_GLOBAL)
422
  {
2227.4.9 by Olaf van der Spek
Session::lex()
423
    if (prepare_new_schema_table(session, session->lex(), "GLOBAL_STATUS"))
2096.1.12 by Brian Aker
Additional show to functions.
424
      return false;
425
  }
426
  else
427
  {
2227.4.9 by Olaf van der Spek
Session::lex()
428
    if (prepare_new_schema_table(session, session->lex(), "SESSION_STATUS"))
2096.1.12 by Brian Aker
Additional show to functions.
429
      return false;
430
  }
431
432
  std::string key("Variable_name");
433
  std::string value("Value");
434
2227.4.8 by Olaf van der Spek
Session::lex()
435
  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.
436
  my_field->is_autogenerated_name= false;
437
  my_field->set_name(key.c_str(), key.length(), system_charset_info);
438
439
  if (session->add_item_to_list(my_field))
440
    return false;
441
2227.4.8 by Olaf van der Spek
Session::lex()
442
  my_field= new Item_field(&session->lex().current_select->context, NULL, NULL, "VARIABLE_VALUE");
2096.1.12 by Brian Aker
Additional show to functions.
443
  my_field->is_autogenerated_name= false;
444
  my_field->set_name(value.c_str(), value.length(), system_charset_info);
445
446
  if (session->add_item_to_list(my_field))
447
    return false;
448
449
  return true;
450
}
451
452
bool buildCreateTable(Session *session, Table_ident *ident)
453
{
2227.4.8 by Olaf van der Spek
Session::lex()
454
  session->lex().sql_command= SQLCOM_SELECT;
2096.1.12 by Brian Aker
Additional show to functions.
455
  statement::Show *select= new statement::Show(session);
2227.4.8 by Olaf van der Spek
Session::lex()
456
  session->lex().statement= select;
2096.1.12 by Brian Aker
Additional show to functions.
457
2227.4.8 by Olaf van der Spek
Session::lex()
458
  if (session->lex().statement == NULL)
2096.1.12 by Brian Aker
Additional show to functions.
459
    return false;
460
2227.4.9 by Olaf van der Spek
Session::lex()
461
  if (prepare_new_schema_table(session, session->lex(), "TABLE_SQL_DEFINITION"))
2096.1.12 by Brian Aker
Additional show to functions.
462
    return false;
463
464
  util::string::const_shared_ptr schema(session->schema());
465
  if (ident->db.str)
466
  {
467
    select->setShowPredicate(ident->db.str, ident->table.str);
468
  }
469
  else if (schema)
470
  {
471
    select->setShowPredicate(*schema, ident->table.str);
472
  }
473
  else
474
  {
475
    my_error(ER_NO_DB_ERROR, MYF(0));
476
    return false;
477
  }
478
479
  std::string key("Table");
480
  std::string value("Create Table");
481
2227.4.8 by Olaf van der Spek
Session::lex()
482
  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.
483
  my_field->is_autogenerated_name= false;
484
  my_field->set_name(key.c_str(), key.length(), system_charset_info);
485
486
  if (session->add_item_to_list(my_field))
487
    return false;
488
2227.4.8 by Olaf van der Spek
Session::lex()
489
  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.
490
  my_field->is_autogenerated_name= false;
491
  my_field->set_name(value.c_str(), value.length(), system_charset_info);
492
493
  if (session->add_item_to_list(my_field))
494
    return false;
495
496
  return true;
497
}
498
499
bool buildProcesslist(Session *session)
500
{
2227.4.8 by Olaf van der Spek
Session::lex()
501
  session->lex().sql_command= SQLCOM_SELECT;
502
  session->lex().statement= new statement::Show(session);
2096.1.12 by Brian Aker
Additional show to functions.
503
2227.4.9 by Olaf van der Spek
Session::lex()
504
  if (prepare_new_schema_table(session, session->lex(), "PROCESSLIST"))
2096.1.12 by Brian Aker
Additional show to functions.
505
    return false;
506
2227.4.8 by Olaf van der Spek
Session::lex()
507
  if (session->add_item_to_list( new Item_field(&session->lex().current_select->context, NULL, NULL, "*")))
2096.1.12 by Brian Aker
Additional show to functions.
508
    return false;
509
2227.4.8 by Olaf van der Spek
Session::lex()
510
  (session->lex().current_select->with_wild)++;
2096.1.12 by Brian Aker
Additional show to functions.
511
512
  return true;
513
}
514
2096.1.11 by Brian Aker
Additional show to function.
515
bool buildVariables(Session *session, const drizzled::sql_var_t is_global)
516
{
2227.4.8 by Olaf van der Spek
Session::lex()
517
  session->lex().sql_command= SQLCOM_SELECT;
518
  session->lex().statement= new statement::Show(session);
2096.1.11 by Brian Aker
Additional show to function.
519
520
  if (is_global == OPT_GLOBAL)
521
  {
2227.4.9 by Olaf van der Spek
Session::lex()
522
    if (prepare_new_schema_table(session, session->lex(), "GLOBAL_VARIABLES"))
2096.1.11 by Brian Aker
Additional show to function.
523
      return false;
524
  }
525
  else
526
  {
2227.4.9 by Olaf van der Spek
Session::lex()
527
    if (prepare_new_schema_table(session, session->lex(), "SESSION_VARIABLES"))
2096.1.11 by Brian Aker
Additional show to function.
528
      return false;
529
  }
530
531
  std::string key("Variable_name");
532
  std::string value("Value");
533
2227.4.8 by Olaf van der Spek
Session::lex()
534
  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.
535
  my_field->is_autogenerated_name= false;
536
  my_field->set_name(key.c_str(), key.length(), system_charset_info);
537
538
  if (session->add_item_to_list(my_field))
539
    return false;
540
2227.4.8 by Olaf van der Spek
Session::lex()
541
  my_field= new Item_field(&session->lex().current_select->context, NULL, NULL, "VARIABLE_VALUE");
2096.1.11 by Brian Aker
Additional show to function.
542
  my_field->is_autogenerated_name= false;
543
  my_field->set_name(value.c_str(), value.length(), system_charset_info);
544
545
  if (session->add_item_to_list(my_field))
546
    return false;
547
548
  return true;
549
}
550
2096.1.8 by Brian Aker
Move show create schema into function.
551
bool buildCreateSchema(Session *session, LEX_STRING &ident)
552
{
2227.4.8 by Olaf van der Spek
Session::lex()
553
  session->lex().sql_command= SQLCOM_SELECT;
2096.1.8 by Brian Aker
Move show create schema into function.
554
  drizzled::statement::Show *select= new statement::Show(session);
2227.4.8 by Olaf van der Spek
Session::lex()
555
  session->lex().statement= select;
2096.1.8 by Brian Aker
Move show create schema into function.
556
2227.4.9 by Olaf van der Spek
Session::lex()
557
  if (prepare_new_schema_table(session, session->lex(), "SCHEMA_SQL_DEFINITION"))
2096.1.8 by Brian Aker
Move show create schema into function.
558
    return false;
559
560
  util::string::const_shared_ptr schema(session->schema());
561
  if (ident.str)
562
  {
563
    select->setShowPredicate(ident.str);
564
  }
565
  else if (schema)
566
  {
567
    select->setShowPredicate(*schema);
568
  }
569
  else
570
  {
571
    my_error(ER_NO_DB_ERROR, MYF(0));
572
    return false;
573
  }
574
575
  std::string key("Database");
576
  std::string value("Create Database");
577
2227.4.8 by Olaf van der Spek
Session::lex()
578
  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.
579
  my_field->is_autogenerated_name= false;
580
  my_field->set_name(key.c_str(), key.length(), system_charset_info);
581
582
  if (session->add_item_to_list(my_field))
583
    return false;
584
2227.4.8 by Olaf van der Spek
Session::lex()
585
  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.
586
  my_field->is_autogenerated_name= false;
587
  my_field->set_name(value.c_str(), value.length(), system_charset_info);
588
589
  if (session->add_item_to_list(my_field))
590
    return false;
591
592
  return true;
593
}
594
2096.1.7 by Brian Aker
Shrink parser code, push C out to function call.
595
bool buildDescribe(Session *session, Table_ident *ident)
596
{
2227.4.8 by Olaf van der Spek
Session::lex()
597
  session->lex().lock_option= TL_READ;
2227.4.9 by Olaf van der Spek
Session::lex()
598
  init_select(&session->lex());
2227.4.8 by Olaf van der Spek
Session::lex()
599
  session->lex().current_select->parsing_place= SELECT_LIST;
600
  session->lex().sql_command= SQLCOM_SELECT;
2096.1.7 by Brian Aker
Shrink parser code, push C out to function call.
601
  drizzled::statement::Show *select= new statement::Show(session);
2227.4.8 by Olaf van der Spek
Session::lex()
602
  session->lex().statement= select;
603
  session->lex().select_lex.db= 0;
2096.1.7 by Brian Aker
Shrink parser code, push C out to function call.
604
605
  util::string::const_shared_ptr schema(session->schema());
606
  if (ident->db.str)
607
  {
608
    select->setShowPredicate(ident->db.str, ident->table.str);
609
  }
610
  else if (schema)
611
  {
612
    select->setShowPredicate(*schema, ident->table.str);
613
  }
614
  else
615
  {
616
    my_error(ER_NO_DB_ERROR, MYF(0));
617
    return false;
618
  }
619
620
  {
621
    drizzled::identifier::Table identifier(select->getShowSchema().c_str(), ident->table.str);
622
    if (not plugin::StorageEngine::doesTableExist(*session, identifier))
623
    {
2140.1.3 by Brian Aker
Merge in error message fix for just one type of error for unknown table.
624
      my_error(ER_TABLE_UNKNOWN, identifier);
2096.1.7 by Brian Aker
Shrink parser code, push C out to function call.
625
    }
626
  }
627
2227.4.9 by Olaf van der Spek
Session::lex()
628
  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.
629
  {
630
    return false;
631
  }
632
2227.4.9 by Olaf van der Spek
Session::lex()
633
  if (session->add_item_to_list( new Item_field(&session->lex().current_select->context, NULL, NULL, "*")))
2096.1.7 by Brian Aker
Shrink parser code, push C out to function call.
634
  {
635
    return false;
636
  }
637
2227.4.8 by Olaf van der Spek
Session::lex()
638
  (session->lex().current_select->with_wild)++;
2096.1.7 by Brian Aker
Shrink parser code, push C out to function call.
639
640
  return true;
641
}
642
643
} /* namespace drizzled */
644
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
645
} /* namespace drizzled */