~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/show.cc

  • Committer: Andrew Hutchings
  • Date: 2011-01-28 21:33:48 UTC
  • mto: (2126.1.2 build)
  • mto: This revision was merged to the branch mainline in revision 2127.
  • Revision ID: andrew@linuxjedi.co.uk-20110128213348-ypi381xo47o80ypo
Backport fix for http://bugs.mysql.com/bug.php?id=57034

Show diffs side-by-side

added added

removed removed

Lines of Context:
20
20
 
21
21
 
22
22
/* Function with list databases, tables or fields */
23
 
#include <config.h>
24
 
 
 
23
#include "config.h"
 
24
#include <drizzled/sql_select.h>
 
25
#include <drizzled/show.h>
 
26
#include <drizzled/gettext.h>
 
27
#include <drizzled/util/convert.h>
 
28
#include <drizzled/error.h>
 
29
#include <drizzled/tztime.h>
25
30
#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>
 
31
#include <drizzled/item/blob.h>
 
32
#include <drizzled/item/cmpfunc.h>
 
33
#include <drizzled/item/return_int.h>
 
34
#include <drizzled/item/empty_string.h>
 
35
#include <drizzled/item/return_date_time.h>
 
36
#include <drizzled/sql_base.h>
 
37
#include <drizzled/db.h>
 
38
#include <drizzled/field/epoch.h>
 
39
#include <drizzled/field/decimal.h>
 
40
#include <drizzled/lock.h>
 
41
#include <drizzled/item/return_date_time.h>
 
42
#include <drizzled/item/empty_string.h>
 
43
#include "drizzled/session/cache.h"
 
44
#include <drizzled/message/schema.pb.h>
 
45
#include <drizzled/plugin/client.h>
 
46
#include <drizzled/cached_directory.h>
 
47
#include "drizzled/sql_table.h"
 
48
#include "drizzled/global_charset_info.h"
 
49
#include "drizzled/pthread_globals.h"
 
50
#include "drizzled/internal/m_string.h"
 
51
#include "drizzled/internal/my_sys.h"
 
52
#include "drizzled/message/statement_transform.h"
32
53
 
33
 
#include <drizzled/statement/show.h>
34
 
#include <drizzled/statement/show_errors.h>
35
 
#include <drizzled/statement/show_warnings.h>
 
54
#include "drizzled/statement/show.h"
 
55
#include "drizzled/statement/show_errors.h"
 
56
#include "drizzled/statement/show_warnings.h"
36
57
 
37
58
 
38
59
#include <sys/stat.h>
54
75
  return str ? str : "<nil>";
55
76
}
56
77
 
57
 
int wild_case_compare(const charset_info_st * const cs, const char *str, const char *wildstr)
 
78
int wild_case_compare(const CHARSET_INFO * const cs, const char *str, const char *wildstr)
58
79
{
59
80
  register int flag;
60
81
 
64
85
    {
65
86
      if (*wildstr == internal::wild_prefix && wildstr[1])
66
87
        wildstr++;
67
 
 
68
88
      if (my_toupper(cs, *wildstr++) != my_toupper(cs, *str++))
69
89
        return (1);
70
90
    }
71
 
 
72
91
    if (! *wildstr )
73
92
      return (*str != 0);
74
 
 
75
93
    if (*wildstr++ == internal::wild_one)
76
94
    {
77
95
      if (! *str++)
81
99
    {                                           /* Found '*' */
82
100
      if (! *wildstr)
83
101
        return (0);             /* '*' as last char: OK */
84
 
 
85
102
      flag=(*wildstr != internal::wild_many && *wildstr != internal::wild_one);
86
103
      do
87
104
      {
90
107
          char cmp;
91
108
          if ((cmp= *wildstr) == internal::wild_prefix && wildstr[1])
92
109
            cmp= wildstr[1];
93
 
 
94
110
          cmp= my_toupper(cs, cmp);
95
 
 
96
111
          while (*str && my_toupper(cs, *str) != cmp)
97
112
            str++;
98
 
 
99
113
          if (! *str)
100
114
            return (1);
101
115
        }
102
 
 
103
116
        if (wild_case_compare(cs, str, wildstr) == 0)
104
117
          return (0);
105
 
 
106
118
      } while (*str++);
107
 
 
108
119
      return (1);
109
120
    }
110
121
  }
163
174
      return false;
164
175
  }
165
176
 
166
 
  Item_field *my_field= new Item_field(&session->getLex()->current_select->context, NULL, NULL, "SCHEMA_NAME");
 
177
  Item_field *my_field= new Item_field(&session->lex->current_select->context, NULL, NULL, "SCHEMA_NAME");
167
178
  my_field->is_autogenerated_name= false;
168
179
  my_field->set_name(column_name.c_str(), column_name.length(), system_charset_info);
169
180
 
193
204
    session->getLex()->select_lex.db= const_cast<char *>(ident);
194
205
    if (not plugin::StorageEngine::doesSchemaExist(identifier))
195
206
    {
196
 
      my_error(ER_BAD_DB_ERROR, identifier);
 
207
      my_error(ER_BAD_DB_ERROR, MYF(0), ident);
197
208
    }
198
209
    select->setShowPredicate(ident, "");
199
210
  }
219
230
  if (prepare_new_schema_table(session, session->getLex(), "SHOW_TABLES"))
220
231
    return false;
221
232
 
222
 
  Item_field *my_field= new Item_field(&session->getLex()->current_select->context, NULL, NULL, "TABLE_NAME");
 
233
  Item_field *my_field= new Item_field(&session->lex->current_select->context, NULL, NULL, "TABLE_NAME");
223
234
  my_field->is_autogenerated_name= false;
224
235
  my_field->set_name(column_name.c_str(), column_name.length(), system_charset_info);
225
236
 
242
253
  if (prepare_new_schema_table(session, session->getLex(), "SHOW_TEMPORARY_TABLES"))
243
254
    return false;
244
255
 
245
 
  if (session->add_item_to_list( new Item_field(&session->getLex()->current_select->context, NULL, NULL, "*")))
 
256
  if (session->add_item_to_list( new Item_field(&session->lex->current_select->context, NULL, NULL, "*")))
246
257
    return false;
247
258
 
248
 
  (session->getLex()->current_select->with_wild)++;
 
259
  (session->lex->current_select->with_wild)++;
249
260
 
250
261
  return true;
251
262
}
266
277
    identifier::Schema identifier(ident);
267
278
    if (not plugin::StorageEngine::doesSchemaExist(identifier))
268
279
    {
269
 
      my_error(ER_BAD_DB_ERROR, identifier);
 
280
      my_error(ER_BAD_DB_ERROR, MYF(0), ident);
270
281
    }
271
282
 
272
283
    select->setShowPredicate(ident, "");
284
295
  if (prepare_new_schema_table(session, session->getLex(), "SHOW_TABLE_STATUS"))
285
296
    return false;
286
297
 
287
 
  if (session->add_item_to_list( new Item_field(&session->getLex()->current_select->
 
298
  if (session->add_item_to_list( new Item_field(&session->lex->current_select->
288
299
                                                  context,
289
300
                                                  NULL, NULL, "*")))
290
301
    return false;
291
302
 
292
 
  (session->getLex()->current_select->with_wild)++;
 
303
  (session->lex->current_select->with_wild)++;
293
304
 
294
305
  return true;
295
306
}
296
307
 
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
 
 
307
308
bool buildColumns(Session *session, const char *schema_ident, Table_ident *table_ident)
308
309
{
309
310
  session->getLex()->sql_command= SQLCOM_SELECT;
334
335
    drizzled::identifier::Table identifier(select->getShowSchema().c_str(), table_ident->table.str);
335
336
    if (not plugin::StorageEngine::doesTableExist(*session, identifier))
336
337
    {
337
 
      my_error(ER_TABLE_UNKNOWN, identifier);
 
338
      my_error(ER_NO_SUCH_TABLE, MYF(0),
 
339
               select->getShowSchema().c_str(), 
 
340
               table_ident->table.str);
338
341
    }
339
342
  }
340
343
 
341
344
  if (prepare_new_schema_table(session, session->getLex(), "SHOW_COLUMNS"))
342
345
    return false;
343
346
 
344
 
  if (session->add_item_to_list( new Item_field(&session->getLex()->current_select->context, NULL, NULL, "*")))
 
347
  if (session->add_item_to_list( new Item_field(&session->lex->current_select->context, NULL, NULL, "*")))
345
348
    return false;
346
349
 
347
 
  (session->getLex()->current_select->with_wild)++;
 
350
  (session->lex->current_select->with_wild)++;
348
351
 
349
352
  return true;
350
353
}
351
354
 
352
 
void buildSelectWarning(Session *session)
353
 
{
354
 
  (void) create_select_for_variable(session, "warning_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)
 
355
bool buildWarnings(Session *session)
365
356
{
366
357
  session->getLex()->statement= new statement::ShowWarnings(session);
 
358
 
 
359
  return true;
367
360
}
368
361
 
369
 
void buildErrors(Session *session)
 
362
bool buildErrors(Session *session)
370
363
{
371
364
  session->getLex()->statement= new statement::ShowErrors(session);
 
365
 
 
366
  return true;
372
367
}
373
368
 
374
369
bool buildIndex(Session *session, const char *schema_ident, Table_ident *table_ident)
400
395
    drizzled::identifier::Table identifier(select->getShowSchema().c_str(), table_ident->table.str);
401
396
    if (not plugin::StorageEngine::doesTableExist(*session, identifier))
402
397
    {
403
 
      my_error(ER_TABLE_UNKNOWN, identifier);
 
398
      my_error(ER_NO_SUCH_TABLE, MYF(0),
 
399
               select->getShowSchema().c_str(), 
 
400
               table_ident->table.str);
404
401
    }
405
402
  }
406
403
 
407
404
  if (prepare_new_schema_table(session, session->getLex(), "SHOW_INDEXES"))
408
405
    return false;
409
406
 
410
 
  if (session->add_item_to_list( new Item_field(&session->getLex()->current_select->context, NULL, NULL, "*")))
 
407
  if (session->add_item_to_list( new Item_field(&session->lex->current_select->context, NULL, NULL, "*")))
411
408
    return false;
412
409
 
413
 
  (session->getLex()->current_select->with_wild)++;
 
410
  (session->lex->current_select->with_wild)++;
414
411
 
415
412
  return true;
416
413
}
434
431
  std::string key("Variable_name");
435
432
  std::string value("Value");
436
433
 
437
 
  Item_field *my_field= new Item_field(&session->getLex()->current_select->context, NULL, NULL, "VARIABLE_NAME");
 
434
  Item_field *my_field= new Item_field(&session->lex->current_select->context, NULL, NULL, "VARIABLE_NAME");
438
435
  my_field->is_autogenerated_name= false;
439
436
  my_field->set_name(key.c_str(), key.length(), system_charset_info);
440
437
 
441
438
  if (session->add_item_to_list(my_field))
442
439
    return false;
443
440
 
444
 
  my_field= new Item_field(&session->getLex()->current_select->context, NULL, NULL, "VARIABLE_VALUE");
 
441
  my_field= new Item_field(&session->lex->current_select->context, NULL, NULL, "VARIABLE_VALUE");
445
442
  my_field->is_autogenerated_name= false;
446
443
  my_field->set_name(value.c_str(), value.length(), system_charset_info);
447
444
 
481
478
  std::string key("Table");
482
479
  std::string value("Create Table");
483
480
 
484
 
  Item_field *my_field= new Item_field(&session->getLex()->current_select->context, NULL, NULL, "TABLE_NAME");
 
481
  Item_field *my_field= new Item_field(&session->lex->current_select->context, NULL, NULL, "TABLE_NAME");
485
482
  my_field->is_autogenerated_name= false;
486
483
  my_field->set_name(key.c_str(), key.length(), system_charset_info);
487
484
 
488
485
  if (session->add_item_to_list(my_field))
489
486
    return false;
490
487
 
491
 
  my_field= new Item_field(&session->getLex()->current_select->context, NULL, NULL, "TABLE_SQL_DEFINITION");
 
488
  my_field= new Item_field(&session->lex->current_select->context, NULL, NULL, "TABLE_SQL_DEFINITION");
492
489
  my_field->is_autogenerated_name= false;
493
490
  my_field->set_name(value.c_str(), value.length(), system_charset_info);
494
491
 
506
503
  if (prepare_new_schema_table(session, session->getLex(), "PROCESSLIST"))
507
504
    return false;
508
505
 
509
 
  if (session->add_item_to_list( new Item_field(&session->getLex()->current_select->context, NULL, NULL, "*")))
 
506
  if (session->add_item_to_list( new Item_field(&session->lex->current_select->context, NULL, NULL, "*")))
510
507
    return false;
511
508
 
512
 
  (session->getLex()->current_select->with_wild)++;
 
509
  (session->lex->current_select->with_wild)++;
513
510
 
514
511
  return true;
515
512
}
533
530
  std::string key("Variable_name");
534
531
  std::string value("Value");
535
532
 
536
 
  Item_field *my_field= new Item_field(&session->getLex()->current_select->context, NULL, NULL, "VARIABLE_NAME");
 
533
  Item_field *my_field= new Item_field(&session->lex->current_select->context, NULL, NULL, "VARIABLE_NAME");
537
534
  my_field->is_autogenerated_name= false;
538
535
  my_field->set_name(key.c_str(), key.length(), system_charset_info);
539
536
 
540
537
  if (session->add_item_to_list(my_field))
541
538
    return false;
542
539
 
543
 
  my_field= new Item_field(&session->getLex()->current_select->context, NULL, NULL, "VARIABLE_VALUE");
 
540
  my_field= new Item_field(&session->lex->current_select->context, NULL, NULL, "VARIABLE_VALUE");
544
541
  my_field->is_autogenerated_name= false;
545
542
  my_field->set_name(value.c_str(), value.length(), system_charset_info);
546
543
 
577
574
  std::string key("Database");
578
575
  std::string value("Create Database");
579
576
 
580
 
  Item_field *my_field= new Item_field(&session->getLex()->current_select->context, NULL, NULL, "SCHEMA_NAME");
 
577
  Item_field *my_field= new Item_field(&session->lex->current_select->context, NULL, NULL, "SCHEMA_NAME");
581
578
  my_field->is_autogenerated_name= false;
582
579
  my_field->set_name(key.c_str(), key.length(), system_charset_info);
583
580
 
584
581
  if (session->add_item_to_list(my_field))
585
582
    return false;
586
583
 
587
 
  my_field= new Item_field(&session->getLex()->current_select->context, NULL, NULL, "SCHEMA_SQL_DEFINITION");
 
584
  my_field= new Item_field(&session->lex->current_select->context, NULL, NULL, "SCHEMA_SQL_DEFINITION");
588
585
  my_field->is_autogenerated_name= false;
589
586
  my_field->set_name(value.c_str(), value.length(), system_charset_info);
590
587
 
623
620
    drizzled::identifier::Table identifier(select->getShowSchema().c_str(), ident->table.str);
624
621
    if (not plugin::StorageEngine::doesTableExist(*session, identifier))
625
622
    {
626
 
      my_error(ER_TABLE_UNKNOWN, identifier);
 
623
      my_error(ER_NO_SUCH_TABLE, MYF(0),
 
624
               select->getShowSchema().c_str(), 
 
625
               ident->table.str);
627
626
    }
628
627
  }
629
628
 
632
631
    return false;
633
632
  }
634
633
 
635
 
  if (session->add_item_to_list( new Item_field(&session->getLex()->current_select->
 
634
  if (session->add_item_to_list( new Item_field(&session->lex->current_select->
636
635
                                                  context,
637
636
                                                  NULL, NULL, "*")))
638
637
  {
639
638
    return false;
640
639
  }
641
640
 
642
 
  (session->getLex()->current_select->with_wild)++;
 
641
  (session->lex->current_select->with_wild)++;
643
642
 
644
643
  return true;
645
644
}