~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/show.cc

  • Committer: Brian Aker
  • Date: 2011-02-04 09:29:39 UTC
  • mfrom: (2139.3.6 catalogs)
  • mto: This revision was merged to the branch mainline in revision 2144.
  • Revision ID: brian@tangent.org-20110204092939-nlwrimamw0fxxhgl
Main bit of this patch is that Inno now just uses the identifier so we only
have one spot to make changes for paths.

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
}
341
352
  if (prepare_new_schema_table(session, session->getLex(), "SHOW_COLUMNS"))
342
353
    return false;
343
354
 
344
 
  if (session->add_item_to_list( new Item_field(&session->getLex()->current_select->context, NULL, NULL, "*")))
 
355
  if (session->add_item_to_list( new Item_field(&session->lex->current_select->context, NULL, NULL, "*")))
345
356
    return false;
346
357
 
347
 
  (session->getLex()->current_select->with_wild)++;
 
358
  (session->lex->current_select->with_wild)++;
348
359
 
349
360
  return true;
350
361
}
351
362
 
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)
 
363
bool buildWarnings(Session *session)
365
364
{
366
365
  session->getLex()->statement= new statement::ShowWarnings(session);
 
366
 
 
367
  return true;
367
368
}
368
369
 
369
 
void buildErrors(Session *session)
 
370
bool buildErrors(Session *session)
370
371
{
371
372
  session->getLex()->statement= new statement::ShowErrors(session);
 
373
 
 
374
  return true;
372
375
}
373
376
 
374
377
bool buildIndex(Session *session, const char *schema_ident, Table_ident *table_ident)
407
410
  if (prepare_new_schema_table(session, session->getLex(), "SHOW_INDEXES"))
408
411
    return false;
409
412
 
410
 
  if (session->add_item_to_list( new Item_field(&session->getLex()->current_select->context, NULL, NULL, "*")))
 
413
  if (session->add_item_to_list( new Item_field(&session->lex->current_select->context, NULL, NULL, "*")))
411
414
    return false;
412
415
 
413
 
  (session->getLex()->current_select->with_wild)++;
 
416
  (session->lex->current_select->with_wild)++;
414
417
 
415
418
  return true;
416
419
}
434
437
  std::string key("Variable_name");
435
438
  std::string value("Value");
436
439
 
437
 
  Item_field *my_field= new Item_field(&session->getLex()->current_select->context, NULL, NULL, "VARIABLE_NAME");
 
440
  Item_field *my_field= new Item_field(&session->lex->current_select->context, NULL, NULL, "VARIABLE_NAME");
438
441
  my_field->is_autogenerated_name= false;
439
442
  my_field->set_name(key.c_str(), key.length(), system_charset_info);
440
443
 
441
444
  if (session->add_item_to_list(my_field))
442
445
    return false;
443
446
 
444
 
  my_field= new Item_field(&session->getLex()->current_select->context, NULL, NULL, "VARIABLE_VALUE");
 
447
  my_field= new Item_field(&session->lex->current_select->context, NULL, NULL, "VARIABLE_VALUE");
445
448
  my_field->is_autogenerated_name= false;
446
449
  my_field->set_name(value.c_str(), value.length(), system_charset_info);
447
450
 
481
484
  std::string key("Table");
482
485
  std::string value("Create Table");
483
486
 
484
 
  Item_field *my_field= new Item_field(&session->getLex()->current_select->context, NULL, NULL, "TABLE_NAME");
 
487
  Item_field *my_field= new Item_field(&session->lex->current_select->context, NULL, NULL, "TABLE_NAME");
485
488
  my_field->is_autogenerated_name= false;
486
489
  my_field->set_name(key.c_str(), key.length(), system_charset_info);
487
490
 
488
491
  if (session->add_item_to_list(my_field))
489
492
    return false;
490
493
 
491
 
  my_field= new Item_field(&session->getLex()->current_select->context, NULL, NULL, "TABLE_SQL_DEFINITION");
 
494
  my_field= new Item_field(&session->lex->current_select->context, NULL, NULL, "TABLE_SQL_DEFINITION");
492
495
  my_field->is_autogenerated_name= false;
493
496
  my_field->set_name(value.c_str(), value.length(), system_charset_info);
494
497
 
506
509
  if (prepare_new_schema_table(session, session->getLex(), "PROCESSLIST"))
507
510
    return false;
508
511
 
509
 
  if (session->add_item_to_list( new Item_field(&session->getLex()->current_select->context, NULL, NULL, "*")))
 
512
  if (session->add_item_to_list( new Item_field(&session->lex->current_select->context, NULL, NULL, "*")))
510
513
    return false;
511
514
 
512
 
  (session->getLex()->current_select->with_wild)++;
 
515
  (session->lex->current_select->with_wild)++;
513
516
 
514
517
  return true;
515
518
}
533
536
  std::string key("Variable_name");
534
537
  std::string value("Value");
535
538
 
536
 
  Item_field *my_field= new Item_field(&session->getLex()->current_select->context, NULL, NULL, "VARIABLE_NAME");
 
539
  Item_field *my_field= new Item_field(&session->lex->current_select->context, NULL, NULL, "VARIABLE_NAME");
537
540
  my_field->is_autogenerated_name= false;
538
541
  my_field->set_name(key.c_str(), key.length(), system_charset_info);
539
542
 
540
543
  if (session->add_item_to_list(my_field))
541
544
    return false;
542
545
 
543
 
  my_field= new Item_field(&session->getLex()->current_select->context, NULL, NULL, "VARIABLE_VALUE");
 
546
  my_field= new Item_field(&session->lex->current_select->context, NULL, NULL, "VARIABLE_VALUE");
544
547
  my_field->is_autogenerated_name= false;
545
548
  my_field->set_name(value.c_str(), value.length(), system_charset_info);
546
549
 
577
580
  std::string key("Database");
578
581
  std::string value("Create Database");
579
582
 
580
 
  Item_field *my_field= new Item_field(&session->getLex()->current_select->context, NULL, NULL, "SCHEMA_NAME");
 
583
  Item_field *my_field= new Item_field(&session->lex->current_select->context, NULL, NULL, "SCHEMA_NAME");
581
584
  my_field->is_autogenerated_name= false;
582
585
  my_field->set_name(key.c_str(), key.length(), system_charset_info);
583
586
 
584
587
  if (session->add_item_to_list(my_field))
585
588
    return false;
586
589
 
587
 
  my_field= new Item_field(&session->getLex()->current_select->context, NULL, NULL, "SCHEMA_SQL_DEFINITION");
 
590
  my_field= new Item_field(&session->lex->current_select->context, NULL, NULL, "SCHEMA_SQL_DEFINITION");
588
591
  my_field->is_autogenerated_name= false;
589
592
  my_field->set_name(value.c_str(), value.length(), system_charset_info);
590
593
 
632
635
    return false;
633
636
  }
634
637
 
635
 
  if (session->add_item_to_list( new Item_field(&session->getLex()->current_select->
 
638
  if (session->add_item_to_list( new Item_field(&session->lex->current_select->
636
639
                                                  context,
637
640
                                                  NULL, NULL, "*")))
638
641
  {
639
642
    return false;
640
643
  }
641
644
 
642
 
  (session->getLex()->current_select->with_wild)++;
 
645
  (session->lex->current_select->with_wild)++;
643
646
 
644
647
  return true;
645
648
}