~ubuntu-branches/ubuntu/saucy/drizzle/saucy-proposed

« back to all changes in this revision

Viewing changes to drizzled/show.cc

  • Committer: Package Import Robot
  • Author(s): Clint Byrum
  • Date: 2012-06-19 10:46:49 UTC
  • mfrom: (1.1.6)
  • mto: This revision was merged to the branch mainline in revision 29.
  • Revision ID: package-import@ubuntu.com-20120619104649-e2l0ggd4oz3um0f4
Tags: upstream-7.1.36-stable
ImportĀ upstreamĀ versionĀ 7.1.36-stable

Show diffs side-by-side

added added

removed removed

Lines of Context:
33
33
#include <drizzled/statement/show_errors.h>
34
34
#include <drizzled/statement/show_warnings.h>
35
35
#include <drizzled/sql_lex.h>
 
36
#include <drizzled/table_ident.h>
36
37
 
37
38
#include <sys/stat.h>
38
39
 
44
45
 
45
46
using namespace std;
46
47
 
47
 
namespace drizzled
48
 
{
 
48
namespace drizzled {
49
49
 
50
 
inline const char *
51
 
str_or_nil(const char *str)
 
50
inline const char* str_or_nil(const char *str)
52
51
{
53
52
  return str ? str : "<nil>";
54
53
}
55
54
 
56
 
int wild_case_compare(const charset_info_st * const cs, const char *str, const char *wildstr)
57
 
{
58
 
  int flag;
59
 
 
60
 
  while (*wildstr)
61
 
  {
62
 
    while (*wildstr && *wildstr != internal::wild_many && *wildstr != internal::wild_one)
63
 
    {
64
 
      if (*wildstr == internal::wild_prefix && wildstr[1])
65
 
        wildstr++;
66
 
 
67
 
      if (my_toupper(cs, *wildstr++) != my_toupper(cs, *str++))
68
 
        return (1);
69
 
    }
70
 
 
71
 
    if (! *wildstr )
72
 
      return (*str != 0);
73
 
 
74
 
    if (*wildstr++ == internal::wild_one)
75
 
    {
76
 
      if (! *str++)
77
 
        return (1);     /* One char; skip */
78
 
    }
79
 
    else
80
 
    {                                           /* Found '*' */
81
 
      if (! *wildstr)
82
 
        return (0);             /* '*' as last char: OK */
83
 
 
84
 
      flag=(*wildstr != internal::wild_many && *wildstr != internal::wild_one);
85
 
      do
86
 
      {
87
 
        if (flag)
88
 
        {
89
 
          char cmp;
90
 
          if ((cmp= *wildstr) == internal::wild_prefix && wildstr[1])
91
 
            cmp= wildstr[1];
92
 
 
93
 
          cmp= my_toupper(cs, cmp);
94
 
 
95
 
          while (*str && my_toupper(cs, *str) != cmp)
96
 
            str++;
97
 
 
98
 
          if (! *str)
99
 
            return (1);
100
 
        }
101
 
 
102
 
        if (wild_case_compare(cs, str, wildstr) == 0)
103
 
          return (0);
104
 
 
105
 
      } while (*str++);
106
 
 
107
 
      return (1);
108
 
    }
109
 
  }
110
 
 
111
 
  return (*str != '\0');
112
 
}
113
 
 
114
55
/*
115
56
  Get the quote character for displaying an identifier.
116
57
 
138
79
 
139
80
namespace show {
140
81
 
141
 
bool buildScemas(Session *session)
 
82
bool buildSchemas(Session *session)
142
83
{
143
84
  session->lex().sql_command= SQLCOM_SELECT;
144
85
  session->lex().statement= new statement::Show(session);
151
92
    column_name.append(")");
152
93
  }
153
94
 
154
 
  if (session->lex().current_select->where)
155
 
  {
156
 
    if (prepare_new_schema_table(session, session->lex(), "SCHEMAS"))
157
 
      return false;
158
 
  }
159
 
  else
160
 
  {
161
 
    if (prepare_new_schema_table(session, session->lex(), "SHOW_SCHEMAS"))
162
 
      return false;
163
 
  }
 
95
  if (prepare_new_schema_table(session, session->lex(), session->lex().current_select->where ? "SCHEMAS" : "SHOW_SCHEMAS"))
 
96
    return false;
164
97
 
165
98
  Item_field *my_field= new Item_field(&session->lex().current_select->context, NULL, NULL, "SCHEMA_NAME");
166
99
  my_field->is_autogenerated_name= false;
167
 
  my_field->set_name(column_name.c_str(), column_name.length(), system_charset_info);
168
 
 
169
 
  if (session->add_item_to_list(my_field))
170
 
    return false;
171
 
 
172
 
  if (session->add_order_to_list(my_field, true))
173
 
    return false;
174
 
 
 
100
  my_field->set_name(column_name);
 
101
 
 
102
  session->add_item_to_list(my_field);
 
103
  session->add_order_to_list(my_field, true);
175
104
  return true;
176
105
}
177
106
 
184
113
 
185
114
  std::string column_name= "Tables_in_";
186
115
 
187
 
  util::string::const_shared_ptr schema(session->schema());
 
116
  util::string::ptr schema(session->schema());
188
117
  if (ident)
189
118
  {
190
 
    identifier::Schema identifier(ident);
 
119
    identifier::Schema identifier= str_ref(ident);
191
120
    column_name.append(ident);
192
 
    session->lex().select_lex.db= const_cast<char *>(ident);
 
121
    session->lex().select_lex.db= ident;
193
122
    if (not plugin::StorageEngine::doesSchemaExist(identifier))
194
123
    {
195
124
      my_error(ER_BAD_DB_ERROR, identifier);
220
149
 
221
150
  Item_field *my_field= new Item_field(&session->lex().current_select->context, NULL, NULL, "TABLE_NAME");
222
151
  my_field->is_autogenerated_name= false;
223
 
  my_field->set_name(column_name.c_str(), column_name.length(), system_charset_info);
224
 
 
225
 
  if (session->add_item_to_list(my_field))
226
 
    return false;
227
 
 
228
 
  if (session->add_order_to_list(my_field, true))
229
 
    return false;
230
 
 
 
152
  my_field->set_name(column_name);
 
153
 
 
154
  session->add_item_to_list(my_field);
 
155
  session->add_order_to_list(my_field, true);
231
156
  return true;
232
157
}
233
158
 
234
159
bool buildTemporaryTables(Session *session)
235
160
{
236
161
  session->lex().sql_command= SQLCOM_SELECT;
237
 
 
238
162
  session->lex().statement= new statement::Show(session);
239
163
 
240
 
 
241
164
  if (prepare_new_schema_table(session, session->lex(), "SHOW_TEMPORARY_TABLES"))
242
165
    return false;
243
166
 
244
 
  if (session->add_item_to_list( new Item_field(&session->lex().current_select->context, NULL, NULL, "*")))
245
 
    return false;
246
 
 
247
 
  (session->lex().current_select->with_wild)++;
248
 
 
 
167
  session->add_item_to_list( new Item_field(&session->lex().current_select->context, NULL, NULL, "*"));
 
168
  session->lex().current_select->with_wild++;
249
169
  return true;
250
170
}
251
171
 
257
177
 
258
178
  std::string column_name= "Tables_in_";
259
179
 
260
 
  util::string::const_shared_ptr schema(session->schema());
 
180
  util::string::ptr schema(session->schema());
261
181
  if (ident)
262
182
  {
263
 
    session->lex().select_lex.db= const_cast<char *>(ident);
 
183
    session->lex().select_lex.db= ident;
264
184
 
265
 
    identifier::Schema identifier(ident);
 
185
    identifier::Schema identifier= str_ref(ident);
266
186
    if (not plugin::StorageEngine::doesSchemaExist(identifier))
267
187
    {
268
188
      my_error(ER_BAD_DB_ERROR, identifier);
283
203
  if (prepare_new_schema_table(session, session->lex(), "SHOW_TABLE_STATUS"))
284
204
    return false;
285
205
 
286
 
  if (session->add_item_to_list( new Item_field(&session->lex().current_select->context, NULL, NULL, "*")))
287
 
    return false;
288
 
 
289
 
  (session->lex().current_select->with_wild)++;
290
 
 
 
206
  session->add_item_to_list( new Item_field(&session->lex().current_select->context, NULL, NULL, "*"));
 
207
  session->lex().current_select->with_wild++;
291
208
  return true;
292
209
}
293
210
 
294
 
bool buildEngineStatus(Session *session, LEX_STRING)
 
211
bool buildEngineStatus(Session *session, str_ref)
295
212
{
296
213
  session->lex().sql_command= SQLCOM_SELECT;
297
214
  drizzled::statement::Show *select= new statement::Show(session);
308
225
  drizzled::statement::Show *select= new statement::Show(session);
309
226
  session->lex().statement= select;
310
227
 
311
 
  util::string::const_shared_ptr schema(session->schema());
 
228
  util::string::ptr schema(session->schema());
312
229
  if (schema_ident)
313
230
  {
314
 
    select->setShowPredicate(schema_ident, table_ident->table.str);
 
231
    select->setShowPredicate(schema_ident, table_ident->table.data());
315
232
  }
316
 
  else if (table_ident->db.str)
 
233
  else if (table_ident->db.data())
317
234
  {
318
 
    select->setShowPredicate(table_ident->db.str, table_ident->table.str);
 
235
    select->setShowPredicate(table_ident->db.data(), table_ident->table.data());
319
236
  }
320
237
  else if (schema)
321
238
  {
322
 
    select->setShowPredicate(*schema, table_ident->table.str);
 
239
    select->setShowPredicate(*schema, table_ident->table.data());
323
240
  }
324
241
  else
325
242
  {
328
245
  }
329
246
 
330
247
  {
331
 
    drizzled::identifier::Table identifier(select->getShowSchema().c_str(), table_ident->table.str);
 
248
    drizzled::identifier::Table identifier(select->getShowSchema(), table_ident->table.data());
332
249
    if (not plugin::StorageEngine::doesTableExist(*session, identifier))
333
250
    {
334
251
      my_error(ER_TABLE_UNKNOWN, identifier);
338
255
  if (prepare_new_schema_table(session, session->lex(), "SHOW_COLUMNS"))
339
256
    return false;
340
257
 
341
 
  if (session->add_item_to_list( new Item_field(&session->lex().current_select->context, NULL, NULL, "*")))
342
 
    return false;
343
 
 
344
 
  (session->lex().current_select->with_wild)++;
345
 
 
 
258
  session->add_item_to_list( new Item_field(&session->lex().current_select->context, NULL, NULL, "*"));
 
259
  session->lex().current_select->with_wild++;
346
260
  return true;
347
261
}
348
262
 
374
288
  drizzled::statement::Show *select= new statement::Show(session);
375
289
  session->lex().statement= select;
376
290
 
377
 
  util::string::const_shared_ptr schema(session->schema());
 
291
  util::string::ptr schema(session->schema());
378
292
  if (schema_ident)
379
293
  {
380
 
    select->setShowPredicate(schema_ident, table_ident->table.str);
 
294
    select->setShowPredicate(schema_ident, table_ident->table.data());
381
295
  }
382
 
  else if (table_ident->db.str)
 
296
  else if (table_ident->db.data())
383
297
  {
384
 
    select->setShowPredicate(table_ident->db.str, table_ident->table.str);
 
298
    select->setShowPredicate(table_ident->db.data(), table_ident->table.data());
385
299
  }
386
300
  else if (schema)
387
301
  {
388
 
    select->setShowPredicate(*schema, table_ident->table.str);
 
302
    select->setShowPredicate(*schema, table_ident->table.data());
389
303
  }
390
304
  else
391
305
  {
394
308
  }
395
309
 
396
310
  {
397
 
    drizzled::identifier::Table identifier(select->getShowSchema().c_str(), table_ident->table.str);
 
311
    drizzled::identifier::Table identifier(select->getShowSchema(), table_ident->table.data());
398
312
    if (not plugin::StorageEngine::doesTableExist(*session, identifier))
399
313
    {
400
314
      my_error(ER_TABLE_UNKNOWN, identifier);
404
318
  if (prepare_new_schema_table(session, session->lex(), "SHOW_INDEXES"))
405
319
    return false;
406
320
 
407
 
  if (session->add_item_to_list( new Item_field(&session->lex().current_select->context, NULL, NULL, "*")))
408
 
    return false;
409
 
 
410
 
  (session->lex().current_select->with_wild)++;
411
 
 
 
321
  session->add_item_to_list(new Item_field(&session->lex().current_select->context, NULL, NULL, "*"));
 
322
  session->lex().current_select->with_wild++;
412
323
  return true;
413
324
}
414
325
 
417
328
  session->lex().sql_command= SQLCOM_SELECT;
418
329
  session->lex().statement= new statement::Show(session);
419
330
 
420
 
  if (is_global == OPT_GLOBAL)
421
 
  {
422
 
    if (prepare_new_schema_table(session, session->lex(), "GLOBAL_STATUS"))
423
 
      return false;
424
 
  }
425
 
  else
426
 
  {
427
 
    if (prepare_new_schema_table(session, session->lex(), "SESSION_STATUS"))
428
 
      return false;
429
 
  }
430
 
 
431
 
  std::string key("Variable_name");
432
 
  std::string value("Value");
 
331
  if (prepare_new_schema_table(session, session->lex(), is_global == OPT_GLOBAL ? "GLOBAL_STATUS" : "SESSION_STATUS"))
 
332
    return false;
433
333
 
434
334
  Item_field *my_field= new Item_field(&session->lex().current_select->context, NULL, NULL, "VARIABLE_NAME");
435
335
  my_field->is_autogenerated_name= false;
436
 
  my_field->set_name(key.c_str(), key.length(), system_charset_info);
437
 
 
438
 
  if (session->add_item_to_list(my_field))
439
 
    return false;
440
 
 
 
336
  my_field->set_name("Variable_name");
 
337
  session->add_item_to_list(my_field);
441
338
  my_field= new Item_field(&session->lex().current_select->context, NULL, NULL, "VARIABLE_VALUE");
442
339
  my_field->is_autogenerated_name= false;
443
 
  my_field->set_name(value.c_str(), value.length(), system_charset_info);
444
 
 
445
 
  if (session->add_item_to_list(my_field))
446
 
    return false;
447
 
 
 
340
  my_field->set_name("Value");
 
341
  session->add_item_to_list(my_field);
448
342
  return true;
449
343
}
450
344
 
460
354
  if (prepare_new_schema_table(session, session->lex(), "TABLE_SQL_DEFINITION"))
461
355
    return false;
462
356
 
463
 
  util::string::const_shared_ptr schema(session->schema());
464
 
  if (ident->db.str)
 
357
  util::string::ptr schema(session->schema());
 
358
  if (ident->db.data())
465
359
  {
466
 
    select->setShowPredicate(ident->db.str, ident->table.str);
 
360
    select->setShowPredicate(ident->db.data(), ident->table.data());
467
361
  }
468
362
  else if (schema)
469
363
  {
470
 
    select->setShowPredicate(*schema, ident->table.str);
 
364
    select->setShowPredicate(*schema, ident->table.data());
471
365
  }
472
366
  else
473
367
  {
475
369
    return false;
476
370
  }
477
371
 
478
 
  std::string key("Table");
479
 
  std::string value("Create Table");
480
 
 
481
372
  Item_field *my_field= new Item_field(&session->lex().current_select->context, NULL, NULL, "TABLE_NAME");
482
373
  my_field->is_autogenerated_name= false;
483
 
  my_field->set_name(key.c_str(), key.length(), system_charset_info);
484
 
 
485
 
  if (session->add_item_to_list(my_field))
486
 
    return false;
487
 
 
 
374
  my_field->set_name("Table");
 
375
  session->add_item_to_list(my_field);
488
376
  my_field= new Item_field(&session->lex().current_select->context, NULL, NULL, "TABLE_SQL_DEFINITION");
489
377
  my_field->is_autogenerated_name= false;
490
 
  my_field->set_name(value.c_str(), value.length(), system_charset_info);
491
 
 
492
 
  if (session->add_item_to_list(my_field))
493
 
    return false;
494
 
 
 
378
  my_field->set_name("Create Table");
 
379
  session->add_item_to_list(my_field);
495
380
  return true;
496
381
}
497
382
 
503
388
  if (prepare_new_schema_table(session, session->lex(), "PROCESSLIST"))
504
389
    return false;
505
390
 
506
 
  if (session->add_item_to_list( new Item_field(&session->lex().current_select->context, NULL, NULL, "*")))
507
 
    return false;
508
 
 
509
 
  (session->lex().current_select->with_wild)++;
510
 
 
 
391
  session->add_item_to_list( new Item_field(&session->lex().current_select->context, NULL, NULL, "*"));
 
392
  session->lex().current_select->with_wild++;
511
393
  return true;
512
394
}
513
395
 
527
409
      return false;
528
410
  }
529
411
 
530
 
  std::string key("Variable_name");
531
 
  std::string value("Value");
532
 
 
533
412
  Item_field *my_field= new Item_field(&session->lex().current_select->context, NULL, NULL, "VARIABLE_NAME");
534
413
  my_field->is_autogenerated_name= false;
535
 
  my_field->set_name(key.c_str(), key.length(), system_charset_info);
536
 
 
537
 
  if (session->add_item_to_list(my_field))
538
 
    return false;
539
 
 
 
414
  my_field->set_name("Variable_name");
 
415
  session->add_item_to_list(my_field);
540
416
  my_field= new Item_field(&session->lex().current_select->context, NULL, NULL, "VARIABLE_VALUE");
541
417
  my_field->is_autogenerated_name= false;
542
 
  my_field->set_name(value.c_str(), value.length(), system_charset_info);
543
 
 
544
 
  if (session->add_item_to_list(my_field))
545
 
    return false;
546
 
 
 
418
  my_field->set_name("Value");
 
419
 
 
420
  session->add_item_to_list(my_field);
547
421
  return true;
548
422
}
549
423
 
550
 
bool buildCreateSchema(Session *session, LEX_STRING &ident)
 
424
bool buildCreateSchema(Session *session, str_ref ident)
551
425
{
552
426
  session->lex().sql_command= SQLCOM_SELECT;
553
427
  drizzled::statement::Show *select= new statement::Show(session);
556
430
  if (prepare_new_schema_table(session, session->lex(), "SCHEMA_SQL_DEFINITION"))
557
431
    return false;
558
432
 
559
 
  util::string::const_shared_ptr schema(session->schema());
560
 
  if (ident.str)
 
433
  util::string::ptr schema(session->schema());
 
434
  if (ident.data())
561
435
  {
562
 
    select->setShowPredicate(ident.str);
 
436
    select->setShowPredicate(ident.data());
563
437
  }
564
438
  else if (schema)
565
439
  {
571
445
    return false;
572
446
  }
573
447
 
574
 
  std::string key("Database");
575
 
  std::string value("Create Database");
576
 
 
577
448
  Item_field *my_field= new Item_field(&session->lex().current_select->context, NULL, NULL, "SCHEMA_NAME");
578
449
  my_field->is_autogenerated_name= false;
579
 
  my_field->set_name(key.c_str(), key.length(), system_charset_info);
580
 
 
581
 
  if (session->add_item_to_list(my_field))
582
 
    return false;
 
450
  my_field->set_name("Database");
 
451
  session->add_item_to_list(my_field);
583
452
 
584
453
  my_field= new Item_field(&session->lex().current_select->context, NULL, NULL, "SCHEMA_SQL_DEFINITION");
585
454
  my_field->is_autogenerated_name= false;
586
 
  my_field->set_name(value.c_str(), value.length(), system_charset_info);
587
 
 
588
 
  if (session->add_item_to_list(my_field))
589
 
    return false;
590
 
 
 
455
  my_field->set_name("Create Database");
 
456
  session->add_item_to_list(my_field);
591
457
  return true;
592
458
}
593
459
 
601
467
  session->lex().statement= select;
602
468
  session->lex().select_lex.db= 0;
603
469
 
604
 
  util::string::const_shared_ptr schema(session->schema());
605
 
  if (ident->db.str)
 
470
  util::string::ptr schema(session->schema());
 
471
  if (ident->db.data())
606
472
  {
607
 
    select->setShowPredicate(ident->db.str, ident->table.str);
 
473
    select->setShowPredicate(ident->db.data(), ident->table.data());
608
474
  }
609
475
  else if (schema)
610
476
  {
611
 
    select->setShowPredicate(*schema, ident->table.str);
 
477
    select->setShowPredicate(*schema, ident->table.data());
612
478
  }
613
479
  else
614
480
  {
617
483
  }
618
484
 
619
485
  {
620
 
    drizzled::identifier::Table identifier(select->getShowSchema().c_str(), ident->table.str);
 
486
    drizzled::identifier::Table identifier(select->getShowSchema(), ident->table.data());
621
487
    if (not plugin::StorageEngine::doesTableExist(*session, identifier))
622
488
    {
623
489
      my_error(ER_TABLE_UNKNOWN, identifier);
628
494
  {
629
495
    return false;
630
496
  }
631
 
 
632
 
  if (session->add_item_to_list( new Item_field(&session->lex().current_select->context, NULL, NULL, "*")))
633
 
  {
634
 
    return false;
635
 
  }
636
 
 
637
 
  (session->lex().current_select->with_wild)++;
638
 
 
 
497
  session->add_item_to_list( new Item_field(&session->lex().current_select->context, NULL, NULL, "*"));
 
498
  session->lex().current_select->with_wild++;
639
499
  return true;
640
500
}
641
501
 
642
 
} /* namespace drizzled */
643
 
 
 
502
}
644
503
} /* namespace drizzled */