~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to plugin/info_schema/helper_methods.cc

MergedĀ fromĀ me.

Show diffs side-by-side

added added

removed removed

Lines of Context:
20
20
 
21
21
/**
22
22
 * @file 
23
 
 *   Implementation of the methods for I_S tables.
 
23
 *   Implementation of helper methods for I_S tables.
24
24
 */
25
25
 
26
 
#include <drizzled/server_includes.h>
27
 
#include <drizzled/session.h>
28
 
#include <drizzled/show.h>
29
 
#include <drizzled/tztime.h>
30
 
#include <drizzled/sql_base.h>
31
 
#include <drizzled/plugin/client.h>
 
26
#include "drizzled/server_includes.h"
 
27
#include "drizzled/session.h"
 
28
#include "drizzled/show.h"
 
29
#include "drizzled/sql_base.h"
 
30
#include "drizzled/plugin/client.h"
32
31
#include "drizzled/join_table.h"
33
32
 
34
 
#include "info_schema_methods.h"
 
33
#include "helper_methods.h"
35
34
 
36
35
#include <vector>
37
36
#include <string>
44
43
    *buf= my_toupper(system_charset_info, *buf);
45
44
}
46
45
 
47
 
static bool show_status_array(Session *session, const char *wild,
48
 
                              SHOW_VAR *variables,
49
 
                              enum enum_var_type value_type,
50
 
                              struct system_status_var *status_var,
51
 
                              const char *prefix, Table *table,
52
 
                              bool ucase_names)
 
46
bool show_status_array(Session *session, 
 
47
                       const char *wild,
 
48
                       SHOW_VAR *variables,
 
49
                       enum enum_var_type value_type,
 
50
                       struct system_status_var *status_var,
 
51
                       const char *prefix, Table *table,
 
52
                       bool ucase_names)
53
53
{
54
54
  MY_ALIGNED_BYTE_ARRAY(buff_data, SHOW_VAR_FUNC_BUFF_SIZE, int64_t);
55
55
  char * const buff= (char *) &buff_data;
203
203
  return false;
204
204
}
205
205
 
206
 
int CharSetISMethods::fillTable(Session *session, TableList *tables)
207
 
{
208
 
  CHARSET_INFO **cs;
209
 
  const char *wild= session->lex->wild ? session->lex->wild->ptr() : NULL;
210
 
  Table *table= tables->table;
211
 
  const CHARSET_INFO * const scs= system_charset_info;
212
 
 
213
 
  for (cs= all_charsets ; cs < all_charsets+255 ; cs++)
214
 
  {
215
 
    const CHARSET_INFO * const tmp_cs= cs[0];
216
 
    if (tmp_cs && (tmp_cs->state & MY_CS_PRIMARY) &&
217
 
        (tmp_cs->state & MY_CS_AVAILABLE) &&
218
 
        !(tmp_cs->state & MY_CS_HIDDEN) &&
219
 
        !(wild && wild[0] &&
220
 
          wild_case_compare(scs, tmp_cs->csname,wild)))
221
 
    {
222
 
      const char *comment;
223
 
      table->restoreRecordAsDefault();
224
 
      table->field[0]->store(tmp_cs->csname, strlen(tmp_cs->csname), scs);
225
 
      table->field[1]->store(tmp_cs->name, strlen(tmp_cs->name), scs);
226
 
      comment= tmp_cs->comment ? tmp_cs->comment : "";
227
 
      table->field[2]->store(comment, strlen(comment), scs);
228
 
      table->field[3]->store((int64_t) tmp_cs->mbmaxlen, true);
229
 
      if (schema_table_store_record(session, table))
230
 
        return 1;
231
 
    }
232
 
  }
233
 
  return 0;
234
 
}
235
 
 
236
 
int CharSetISMethods::oldFormat(Session *session, drizzled::plugin::InfoSchemaTable *schema_table)
237
 
  const
238
 
{
239
 
  int fields_arr[]= {0, 2, 1, 3, -1};
240
 
  int *field_num= fields_arr;
241
 
  const drizzled::plugin::InfoSchemaTable::Columns columns= schema_table->getColumns();
242
 
  const drizzled::plugin::ColumnInfo *column;
243
 
  Name_resolution_context *context= &session->lex->select_lex.context;
244
 
 
245
 
  for (; *field_num >= 0; field_num++)
246
 
  {
247
 
    column= columns[*field_num];
248
 
    Item_field *field= new Item_field(context,
249
 
                                      NULL, NULL, column->getName().c_str());
250
 
    if (field)
251
 
    {
252
 
      field->set_name(column->getOldName().c_str(),
253
 
                      column->getOldName().length(),
254
 
                      system_charset_info);
255
 
      if (session->add_item_to_list(field))
256
 
        return 1;
257
 
    }
258
 
  }
259
 
  return 0;
260
 
}
261
 
 
262
 
int CollationISMethods::fillTable(Session *session, TableList *tables)
263
 
{
264
 
  CHARSET_INFO **cs;
265
 
  const char *wild= session->lex->wild ? session->lex->wild->ptr() : NULL;
266
 
  Table *table= tables->table;
267
 
  const CHARSET_INFO * const scs= system_charset_info;
268
 
  for (cs= all_charsets ; cs < all_charsets+255 ; cs++ )
269
 
  {
270
 
    CHARSET_INFO **cl;
271
 
    const CHARSET_INFO *tmp_cs= cs[0];
272
 
    if (! tmp_cs || ! (tmp_cs->state & MY_CS_AVAILABLE) ||
273
 
         (tmp_cs->state & MY_CS_HIDDEN) ||
274
 
        !(tmp_cs->state & MY_CS_PRIMARY))
275
 
      continue;
276
 
    for (cl= all_charsets; cl < all_charsets+255 ;cl ++)
277
 
    {
278
 
      const CHARSET_INFO *tmp_cl= cl[0];
279
 
      if (! tmp_cl || ! (tmp_cl->state & MY_CS_AVAILABLE) ||
280
 
          !my_charset_same(tmp_cs, tmp_cl))
281
 
        continue;
282
 
      if (! (wild && wild[0] &&
283
 
          wild_case_compare(scs, tmp_cl->name,wild)))
284
 
      {
285
 
        const char *tmp_buff;
286
 
        table->restoreRecordAsDefault();
287
 
        table->field[0]->store(tmp_cl->name, strlen(tmp_cl->name), scs);
288
 
        table->field[1]->store(tmp_cl->csname , strlen(tmp_cl->csname), scs);
289
 
        table->field[2]->store((int64_t) tmp_cl->number, true);
290
 
        tmp_buff= (tmp_cl->state & MY_CS_PRIMARY) ? "Yes" : "";
291
 
        table->field[3]->store(tmp_buff, strlen(tmp_buff), scs);
292
 
        tmp_buff= (tmp_cl->state & MY_CS_COMPILED)? "Yes" : "";
293
 
        table->field[4]->store(tmp_buff, strlen(tmp_buff), scs);
294
 
        table->field[5]->store((int64_t) tmp_cl->strxfrm_multiply, true);
295
 
        if (schema_table_store_record(session, table))
296
 
          return 1;
297
 
      }
298
 
    }
299
 
  }
300
 
  return 0;
301
 
}
302
 
 
303
 
int CollCharISMethods::fillTable(Session *session, TableList *tables)
304
 
{
305
 
  CHARSET_INFO **cs;
306
 
  Table *table= tables->table;
307
 
  const CHARSET_INFO * const scs= system_charset_info;
308
 
  for (cs= all_charsets ; cs < all_charsets+255 ; cs++ )
309
 
  {
310
 
    CHARSET_INFO **cl;
311
 
    const CHARSET_INFO *tmp_cs= cs[0];
312
 
    if (! tmp_cs || ! (tmp_cs->state & MY_CS_AVAILABLE) ||
313
 
        ! (tmp_cs->state & MY_CS_PRIMARY))
314
 
      continue;
315
 
    for (cl= all_charsets; cl < all_charsets+255 ;cl ++)
316
 
    {
317
 
      const CHARSET_INFO *tmp_cl= cl[0];
318
 
      if (! tmp_cl || ! (tmp_cl->state & MY_CS_AVAILABLE) ||
319
 
          ! my_charset_same(tmp_cs,tmp_cl))
320
 
        continue;
321
 
      table->restoreRecordAsDefault();
322
 
      table->field[0]->store(tmp_cl->name, strlen(tmp_cl->name), scs);
323
 
      table->field[1]->store(tmp_cl->csname , strlen(tmp_cl->csname), scs);
324
 
      if (schema_table_store_record(session, table))
325
 
        return 1;
326
 
    }
327
 
  }
328
 
  return 0;
329
 
}
330
 
 
331
 
int ColumnsISMethods::oldFormat(Session *session, drizzled::plugin::InfoSchemaTable *schema_table)
332
 
  const
333
 
{
334
 
  int fields_arr[]= {3, 14, 13, 6, 15, 5, 16, 17, 18, -1};
335
 
  int *field_num= fields_arr;
336
 
  const drizzled::plugin::InfoSchemaTable::Columns columns= schema_table->getColumns();
337
 
  const drizzled::plugin::ColumnInfo *column;
338
 
  Name_resolution_context *context= &session->lex->select_lex.context;
339
 
 
340
 
  for (; *field_num >= 0; field_num++)
341
 
  {
342
 
    column= columns[*field_num];
343
 
    if (! session->lex->verbose && (*field_num == 13 ||
344
 
                                    *field_num == 17 ||
345
 
                                    *field_num == 18))
346
 
    {
347
 
      continue;
348
 
    }
349
 
    Item_field *field= new Item_field(context,
350
 
                                      NULL, NULL, column->getName().c_str());
351
 
    if (field)
352
 
    {
353
 
      field->set_name(column->getOldName().c_str(),
354
 
                      column->getOldName().length(),
355
 
                      system_charset_info);
356
 
      if (session->add_item_to_list(field))
357
 
      {
358
 
        return 1;
359
 
      }
360
 
    }
361
 
  }
362
 
  return 0;
363
 
}
364
 
 
365
 
static void store_key_column_usage(Table *table, LEX_STRING *db_name,
366
 
                                   LEX_STRING *table_name, const char *key_name,
367
 
                                   uint32_t key_len, const char *con_type, uint32_t con_len,
368
 
                                   int64_t idx)
 
206
 
 
207
void store_key_column_usage(Table *table, 
 
208
                            LEX_STRING *db_name,
 
209
                            LEX_STRING *table_name, 
 
210
                            const char *key_name,
 
211
                            uint32_t key_len, 
 
212
                            const char *con_type, 
 
213
                            uint32_t con_len,
 
214
                            int64_t idx)
369
215
{
370
216
  const CHARSET_INFO * const cs= system_charset_info;
371
217
  table->field[1]->store(db_name->str, db_name->length, cs);
376
222
  table->field[7]->store((int64_t) idx, true);
377
223
}
378
224
 
379
 
int KeyColUsageISMethods::processTable(Session *session,
380
 
                                              TableList *tables,
381
 
                                              Table *table, bool res,
382
 
                                              LEX_STRING *db_name,
383
 
                                              LEX_STRING *table_name) const
384
 
{
385
 
  if (res)
386
 
  {
387
 
    if (session->is_error())
388
 
      push_warning(session, DRIZZLE_ERROR::WARN_LEVEL_WARN,
389
 
                   session->main_da.sql_errno(), session->main_da.message());
390
 
    session->clear_error();
391
 
    return(0);
392
 
  }
393
 
  else
394
 
  {
395
 
    List<FOREIGN_KEY_INFO> f_key_list;
396
 
    Table *show_table= tables->table;
397
 
    KEY *key_info=show_table->key_info;
398
 
    uint32_t primary_key= show_table->s->primary_key;
399
 
    show_table->cursor->info(HA_STATUS_VARIABLE |
400
 
                             HA_STATUS_NO_LOCK |
401
 
                             HA_STATUS_TIME);
402
 
    for (uint32_t i=0 ; i < show_table->s->keys ; i++, key_info++)
403
 
    {
404
 
      if (i != primary_key && !(key_info->flags & HA_NOSAME))
405
 
      {
406
 
        continue;
407
 
      }
408
 
      uint32_t f_idx= 0;
409
 
      KEY_PART_INFO *key_part= key_info->key_part;
410
 
      for (uint32_t j=0 ; j < key_info->key_parts ; j++,key_part++)
411
 
      {
412
 
        if (key_part->field)
413
 
        {
414
 
          f_idx++;
415
 
          table->restoreRecordAsDefault();
416
 
          store_key_column_usage(table, db_name, table_name,
417
 
                                 key_info->name,
418
 
                                 strlen(key_info->name),
419
 
                                 key_part->field->field_name,
420
 
                                 strlen(key_part->field->field_name),
421
 
                                 (int64_t) f_idx);
422
 
          if (schema_table_store_record(session, table))
423
 
          {
424
 
            return (1);
425
 
          }
426
 
        }
427
 
      }
428
 
    }
429
 
 
430
 
    show_table->cursor->get_foreign_key_list(session, &f_key_list);
431
 
    FOREIGN_KEY_INFO *f_key_info;
432
 
    List_iterator_fast<FOREIGN_KEY_INFO> fkey_it(f_key_list);
433
 
    while ((f_key_info= fkey_it++))
434
 
    {
435
 
      LEX_STRING *f_info;
436
 
      LEX_STRING *r_info;
437
 
      List_iterator_fast<LEX_STRING> it(f_key_info->foreign_fields),
438
 
        it1(f_key_info->referenced_fields);
439
 
      uint32_t f_idx= 0;
440
 
      while ((f_info= it++))
441
 
      {
442
 
        r_info= it1++;
443
 
        f_idx++;
444
 
        table->restoreRecordAsDefault();
445
 
        store_key_column_usage(table, db_name, table_name,
446
 
                               f_key_info->forein_id->str,
447
 
                               f_key_info->forein_id->length,
448
 
                               f_info->str, f_info->length,
449
 
                               (int64_t) f_idx);
450
 
        table->field[8]->store((int64_t) f_idx, true);
451
 
        table->field[8]->set_notnull();
452
 
        table->field[9]->store(f_key_info->referenced_db->str,
453
 
                               f_key_info->referenced_db->length,
454
 
                               system_charset_info);
455
 
        table->field[9]->set_notnull();
456
 
        table->field[10]->store(f_key_info->referenced_table->str,
457
 
                                f_key_info->referenced_table->length,
458
 
                                system_charset_info);
459
 
        table->field[10]->set_notnull();
460
 
        table->field[11]->store(r_info->str, r_info->length,
461
 
                                system_charset_info);
462
 
        table->field[11]->set_notnull();
463
 
        if (schema_table_store_record(session, table))
464
 
        {
465
 
          return (1);
466
 
        }
467
 
      }
468
 
    }
469
 
  }
470
 
  return (res);
471
 
}
472
 
 
473
 
inline bool open_list_store(Table *table, open_table_list_st& open_list);
474
 
inline bool open_list_store(Table *table, open_table_list_st& open_list)
475
 
{
476
 
  table->restoreRecordAsDefault();
477
 
  table->field[0]->store(open_list.db.c_str(), open_list.db.length(), system_charset_info);
478
 
  table->field[1]->store(open_list.table.c_str(), open_list.table.length(), system_charset_info);
479
 
  table->field[2]->store((int64_t) open_list.in_use, true);
480
 
  table->field[3]->store((int64_t) open_list.locked, true);
481
 
  if (schema_table_store_record(table->in_use, table))
482
 
    return true;
483
 
 
484
 
  return false;
485
 
}
486
 
 
487
 
int OpenTablesISMethods::fillTable(Session *session, TableList *tables)
488
 
{
489
 
  const char *wild= session->lex->wild ? session->lex->wild->ptr() : NULL;
490
 
 
491
 
  if ((list_open_tables(session->lex->select_lex.db, wild, open_list_store, tables->table) == true) && session->is_fatal_error)
492
 
    return 1;
493
 
 
494
 
  return 0;
495
 
}
496
 
 
497
 
class ShowModules : public unary_function<drizzled::plugin::Module *, bool>
498
 
{
499
 
  Session *session;
500
 
  Table *table;
501
 
public:
502
 
  ShowModules(Session *session_arg, Table *table_arg)
503
 
    : session(session_arg), table(table_arg) {}
504
 
 
505
 
  result_type operator() (argument_type module)
506
 
  {
507
 
    const drizzled::plugin::Manifest &manifest= module->getManifest();
508
 
    const CHARSET_INFO * const cs= system_charset_info;
509
 
 
510
 
    table->restoreRecordAsDefault();
511
 
 
512
 
    table->field[0]->store(module->getName().c_str(),
513
 
                           module->getName().size(), cs);
514
 
 
515
 
    if (manifest.version)
516
 
    {
517
 
      table->field[1]->store(manifest.version, strlen(manifest.version), cs);
518
 
      table->field[1]->set_notnull();
519
 
    }
520
 
    else
521
 
      table->field[1]->set_null();
522
 
 
523
 
    if (manifest.author)
524
 
    {
525
 
      table->field[2]->store(manifest.author, strlen(manifest.author), cs);
526
 
      table->field[2]->set_notnull();
527
 
    }
528
 
    else
529
 
    {
530
 
      table->field[2]->set_null();
531
 
    }
532
 
 
533
 
    if (module->plugin_dl == NULL)
534
 
    {
535
 
      table->field[3]->store(STRING_WITH_LEN("YES"),cs);
536
 
      table->field[4]->set_null();
537
 
    }
538
 
    else
539
 
    {
540
 
      table->field[3]->store(STRING_WITH_LEN("NO"),cs);
541
 
      table->field[4]->store(module->plugin_dl->dl.str,
542
 
                             module->plugin_dl->dl.length, cs);
543
 
    }
544
 
 
545
 
    if (manifest.descr)
546
 
    {
547
 
      table->field[5]->store(manifest.descr, strlen(manifest.descr), cs);
548
 
      table->field[5]->set_notnull();
549
 
    }
550
 
    else
551
 
    {
552
 
      table->field[5]->set_null();
553
 
    }
554
 
 
555
 
    switch (manifest.license) {
556
 
    case PLUGIN_LICENSE_GPL:
557
 
      table->field[6]->store(drizzled::plugin::LICENSE_GPL_STRING.c_str(),
558
 
                             drizzled::plugin::LICENSE_GPL_STRING.size(), cs);
559
 
      break;
560
 
    case PLUGIN_LICENSE_BSD:
561
 
      table->field[6]->store(drizzled::plugin::LICENSE_BSD_STRING.c_str(),
562
 
                             drizzled::plugin::LICENSE_BSD_STRING.size(), cs);
563
 
      break;
564
 
    case PLUGIN_LICENSE_LGPL:
565
 
      table->field[6]->store(drizzled::plugin::LICENSE_LGPL_STRING.c_str(),
566
 
                             drizzled::plugin::LICENSE_LGPL_STRING.size(), cs);
567
 
      break;
568
 
    default:
569
 
      table->field[6]->store(drizzled::plugin::LICENSE_PROPRIETARY_STRING.c_str(),
570
 
                             drizzled::plugin::LICENSE_PROPRIETARY_STRING.size(),
571
 
                             cs);
572
 
      break;
573
 
    }
574
 
    table->field[6]->set_notnull();
575
 
 
576
 
    return schema_table_store_record(session, table);
577
 
  }
578
 
};
579
 
 
580
 
int ModulesISMethods::fillTable(Session *session, TableList *tables)
581
 
{
582
 
  Table *table= tables->table;
583
 
 
584
 
  drizzled::plugin::Registry &registry= drizzled::plugin::Registry::singleton();
585
 
  vector<drizzled::plugin::Module *> modules= registry.getList(true);
586
 
  vector<drizzled::plugin::Module *>::iterator iter=
587
 
    find_if(modules.begin(), modules.end(), ShowModules(session, table));
588
 
  if (iter != modules.end())
589
 
  {
590
 
    return 1;
591
 
  }
592
 
  return 0;
593
 
}
594
 
 
595
 
class ShowPlugins
596
 
 : public unary_function<pair<const string, const drizzled::plugin::Plugin *>, bool>
597
 
{
598
 
  Session *session;
599
 
  Table *table;
600
 
public:
601
 
  ShowPlugins(Session *session_arg, Table *table_arg)
602
 
    : session(session_arg), table(table_arg) {}
603
 
 
604
 
  result_type operator() (argument_type plugin)
605
 
  {
606
 
    const CHARSET_INFO * const cs= system_charset_info;
607
 
 
608
 
    table->restoreRecordAsDefault();
609
 
 
610
 
    table->field[0]->store(plugin.first.c_str(),
611
 
                           plugin.first.size(), cs);
612
 
 
613
 
    table->field[1]->store(plugin.second->getTypeName().c_str(),
614
 
                           plugin.second->getTypeName().size(), cs);
615
 
 
616
 
    if (plugin.second->isActive())
617
 
    {
618
 
      table->field[2]->store(STRING_WITH_LEN("YES"),cs);
619
 
    }
620
 
    else
621
 
    {
622
 
      table->field[2]->store(STRING_WITH_LEN("NO"), cs);
623
 
    }
624
 
 
625
 
    table->field[3]->store(plugin.second->getModuleName().c_str(),
626
 
                           plugin.second->getModuleName().size(), cs);
627
 
 
628
 
    return schema_table_store_record(session, table);
629
 
  }
630
 
};
631
 
 
632
 
int PluginsISMethods::fillTable(Session *session, TableList *tables)
633
 
{
634
 
  Table *table= tables->table;
635
 
 
636
 
  drizzled::plugin::Registry &registry= drizzled::plugin::Registry::singleton();
637
 
  const map<string, const drizzled::plugin::Plugin *> &plugin_map=
638
 
    registry.getPluginsMap();
639
 
  map<string, const drizzled::plugin::Plugin *>::const_iterator iter=
640
 
    find_if(plugin_map.begin(), plugin_map.end(), ShowPlugins(session, table));
641
 
  if (iter != plugin_map.end())
642
 
  {
643
 
    return 1;
644
 
  }
645
 
  return (0);
646
 
}
647
 
 
648
 
int ProcessListISMethods::fillTable(Session* session, TableList* tables)
649
 
{
650
 
  Table *table= tables->table;
651
 
  const CHARSET_INFO * const cs= system_charset_info;
652
 
  time_t now= time(NULL);
653
 
  size_t length;
654
 
 
655
 
  if (now == (time_t)-1)
656
 
    return 1;
657
 
 
658
 
  pthread_mutex_lock(&LOCK_thread_count);
659
 
 
660
 
  if (! session->killed)
661
 
  {
662
 
    Session* tmp;
663
 
 
664
 
    for (vector<Session*>::iterator it= session_list.begin(); it != session_list.end(); ++it)
665
 
    {
666
 
      tmp= *it;
667
 
      Security_context *tmp_sctx= &tmp->security_ctx;
668
 
      struct st_my_thread_var *mysys_var;
669
 
      const char *val;
670
 
 
671
 
      if (! tmp->client->isConnected())
672
 
        continue;
673
 
 
674
 
      table->restoreRecordAsDefault();
675
 
      /* ID */
676
 
      table->field[0]->store((int64_t) tmp->thread_id, true);
677
 
      /* USER */
678
 
      val= tmp_sctx->user.c_str() ? tmp_sctx->user.c_str() : "unauthenticated user";
679
 
      table->field[1]->store(val, strlen(val), cs);
680
 
      /* HOST */
681
 
      table->field[2]->store(tmp_sctx->ip.c_str(), strlen(tmp_sctx->ip.c_str()), cs);
682
 
      /* DB */
683
 
      if (tmp->db)
684
 
      {
685
 
        table->field[3]->store(tmp->db, strlen(tmp->db), cs);
686
 
        table->field[3]->set_notnull();
687
 
      }
688
 
 
689
 
      if ((mysys_var= tmp->mysys_var))
690
 
        pthread_mutex_lock(&mysys_var->mutex);
691
 
      /* COMMAND */
692
 
      if ((val= (char *) (tmp->killed == Session::KILL_CONNECTION? "Killed" : 0)))
693
 
        table->field[4]->store(val, strlen(val), cs);
694
 
      else
695
 
        table->field[4]->store(command_name[tmp->command].str,
696
 
                               command_name[tmp->command].length, cs);
697
 
      /* DRIZZLE_TIME */
698
 
      table->field[5]->store((uint32_t)(tmp->start_time ?
699
 
                                      now - tmp->start_time : 0), true);
700
 
      /* STATE */
701
 
      val= (char*) (tmp->client->isWriting() ?
702
 
                    "Writing to net" :
703
 
                    tmp->client->isReading() ?
704
 
                    (tmp->command == COM_SLEEP ?
705
 
                     NULL : "Reading from net") :
706
 
                    tmp->get_proc_info() ? tmp->get_proc_info() :
707
 
                    tmp->mysys_var &&
708
 
                    tmp->mysys_var->current_cond ?
709
 
                    "Waiting on cond" : NULL);
710
 
      if (val)
711
 
      {
712
 
        table->field[6]->store(val, strlen(val), cs);
713
 
        table->field[6]->set_notnull();
714
 
      }
715
 
 
716
 
      if (mysys_var)
717
 
        pthread_mutex_unlock(&mysys_var->mutex);
718
 
 
719
 
      length= strlen(tmp->process_list_info);
720
 
 
721
 
      if (length)
722
 
      {
723
 
        table->field[7]->store(tmp->process_list_info, length, cs);
724
 
        table->field[7]->set_notnull();
725
 
      }
726
 
 
727
 
      if (schema_table_store_record(session, table))
728
 
      {
729
 
        pthread_mutex_unlock(&LOCK_thread_count);
730
 
        return(1);
731
 
      }
732
 
    }
733
 
  }
734
 
 
735
 
  pthread_mutex_unlock(&LOCK_thread_count);
736
 
  return(0);
737
 
}
738
 
 
739
 
int
740
 
RefConstraintsISMethods::processTable(Session *session, TableList *tables,
741
 
                                      Table *table, bool res,
742
 
                                      LEX_STRING *db_name, LEX_STRING *table_name)
743
 
  const
744
 
{
745
 
  const CHARSET_INFO * const cs= system_charset_info;
746
 
 
747
 
  if (res)
748
 
  {
749
 
    if (session->is_error())
750
 
      push_warning(session, DRIZZLE_ERROR::WARN_LEVEL_WARN,
751
 
                   session->main_da.sql_errno(), session->main_da.message());
752
 
    session->clear_error();
753
 
    return(0);
754
 
  }
755
 
 
756
 
  {
757
 
    List<FOREIGN_KEY_INFO> f_key_list;
758
 
    Table *show_table= tables->table;
759
 
    show_table->cursor->info(HA_STATUS_VARIABLE |
760
 
                           HA_STATUS_NO_LOCK |
761
 
                           HA_STATUS_TIME);
762
 
 
763
 
    show_table->cursor->get_foreign_key_list(session, &f_key_list);
764
 
    FOREIGN_KEY_INFO *f_key_info;
765
 
    List_iterator_fast<FOREIGN_KEY_INFO> it(f_key_list);
766
 
    while ((f_key_info= it++))
767
 
    {
768
 
      table->restoreRecordAsDefault();
769
 
      table->field[1]->store(db_name->str, db_name->length, cs);
770
 
      table->field[9]->store(table_name->str, table_name->length, cs);
771
 
      table->field[2]->store(f_key_info->forein_id->str,
772
 
                             f_key_info->forein_id->length, cs);
773
 
      table->field[4]->store(f_key_info->referenced_db->str,
774
 
                             f_key_info->referenced_db->length, cs);
775
 
      table->field[10]->store(f_key_info->referenced_table->str,
776
 
                             f_key_info->referenced_table->length, cs);
777
 
      if (f_key_info->referenced_key_name)
778
 
      {
779
 
        table->field[5]->store(f_key_info->referenced_key_name->str,
780
 
                               f_key_info->referenced_key_name->length, cs);
781
 
        table->field[5]->set_notnull();
782
 
      }
783
 
      else
784
 
      {
785
 
        table->field[5]->set_null();
786
 
      }
787
 
      table->field[6]->store(STRING_WITH_LEN("NONE"), cs);
788
 
      table->field[7]->store(f_key_info->update_method->str,
789
 
                             f_key_info->update_method->length, cs);
790
 
      table->field[8]->store(f_key_info->delete_method->str,
791
 
                             f_key_info->delete_method->length, cs);
792
 
      if (schema_table_store_record(session, table))
793
 
      {
794
 
        return (1);
795
 
      }
796
 
    }
797
 
  }
798
 
  return (0);
799
 
}
800
 
 
801
 
static bool store_schema_schemata(Session* session, Table *table, LEX_STRING *db_name,
802
 
                                  const CHARSET_INFO * const cs)
803
 
{
804
 
  table->restoreRecordAsDefault();
805
 
  table->field[1]->store(db_name->str, db_name->length, system_charset_info);
806
 
  table->field[2]->store(cs->csname, strlen(cs->csname), system_charset_info);
807
 
  table->field[3]->store(cs->name, strlen(cs->name), system_charset_info);
808
 
  return schema_table_store_record(session, table);
809
 
}
810
 
 
811
 
int SchemataISMethods::fillTable(Session *session, TableList *tables)
812
 
{
813
 
  /*
814
 
    TODO: fill_schema_shemata() is called when new client is connected.
815
 
    Returning error status in this case leads to client hangup.
816
 
  */
817
 
 
818
 
  LOOKUP_FIELD_VALUES lookup_field_vals;
819
 
  vector<LEX_STRING*> db_names;
820
 
  bool with_i_schema;
821
 
  Table *table= tables->table;
822
 
  /* the WHERE condition */
823
 
  COND *cond= table->reginfo.join_tab->select_cond;
824
 
 
825
 
  if (get_lookup_field_values(session, cond, tables, &lookup_field_vals))
826
 
    return(0);
827
 
  if (make_db_list(session, db_names, &lookup_field_vals,
828
 
                   &with_i_schema))
829
 
    return(1);
830
 
 
831
 
  /*
832
 
    If we have lookup db value we should check that the database exists
833
 
  */
834
 
  if(lookup_field_vals.db_value.str && !lookup_field_vals.wild_db_value &&
835
 
     !with_i_schema)
836
 
  {
837
 
    char path[FN_REFLEN+16];
838
 
    uint32_t path_len;
839
 
    struct stat stat_info;
840
 
    if (!lookup_field_vals.db_value.str[0])
841
 
      return(0);
842
 
    path_len= build_table_filename(path, sizeof(path),
843
 
                                   lookup_field_vals.db_value.str, "", false);
844
 
    path[path_len-1]= 0;
845
 
    if (stat(path,&stat_info))
846
 
      return(0);
847
 
  }
848
 
 
849
 
  vector<LEX_STRING*>::iterator db_name= db_names.begin();
850
 
  while (db_name != db_names.end())
851
 
  {
852
 
    if (with_i_schema)       // information schema name is always first in list
853
 
    {
854
 
      if (store_schema_schemata(session, table, *db_name, system_charset_info))
855
 
        return(1);
856
 
 
857
 
      with_i_schema= 0;
858
 
    }
859
 
    else
860
 
    {
861
 
      const CHARSET_INFO *cs= get_default_db_collation((*db_name)->str);
862
 
 
863
 
      if (store_schema_schemata(session, table, *db_name, cs))
864
 
        return(1);
865
 
    }
866
 
 
867
 
    ++db_name;
868
 
  }
869
 
  return(0);
870
 
}
871
 
 
872
 
int SchemataISMethods::oldFormat(Session *session, drizzled::plugin::InfoSchemaTable *schema_table)
873
 
  const
874
 
{
875
 
  char tmp[128];
876
 
  LEX *lex= session->lex;
877
 
  Select_Lex *sel= lex->current_select;
878
 
  Name_resolution_context *context= &sel->context;
879
 
  const drizzled::plugin::InfoSchemaTable::Columns columns= schema_table->getColumns();
880
 
 
881
 
  if (!sel->item_list.elements)
882
 
  {
883
 
    const drizzled::plugin::ColumnInfo *column= columns[1];
884
 
    String buffer(tmp,sizeof(tmp), system_charset_info);
885
 
    Item_field *field= new Item_field(context,
886
 
                                      NULL, NULL, column->getName().c_str());
887
 
    if (!field || session->add_item_to_list(field))
888
 
      return 1;
889
 
    buffer.length(0);
890
 
    buffer.append(column->getOldName().c_str());
891
 
    if (lex->wild && lex->wild->ptr())
892
 
    {
893
 
      buffer.append(STRING_WITH_LEN(" ("));
894
 
      buffer.append(lex->wild->ptr());
895
 
      buffer.append(')');
896
 
    }
897
 
    field->set_name(buffer.ptr(), buffer.length(), system_charset_info);
898
 
  }
899
 
  return 0;
900
 
}
901
 
 
902
 
int StatsISMethods::processTable(Session *session, TableList *tables,
903
 
                                  Table *table, bool res,
904
 
                                  LEX_STRING *db_name,
905
 
                                  LEX_STRING *table_name) const
906
 
{
907
 
  const CHARSET_INFO * const cs= system_charset_info;
908
 
  if (res)
909
 
  {
910
 
    if (session->lex->sql_command != SQLCOM_SHOW_KEYS)
911
 
    {
912
 
      /*
913
 
        I.e. we are in SELECT FROM INFORMATION_SCHEMA.STATISTICS
914
 
        rather than in SHOW KEYS
915
 
      */
916
 
      if (session->is_error())
917
 
      {
918
 
        push_warning(session, DRIZZLE_ERROR::WARN_LEVEL_WARN,
919
 
                     session->main_da.sql_errno(), session->main_da.message());
920
 
      }
921
 
      session->clear_error();
922
 
      res= 0;
923
 
    }
924
 
    return (res);
925
 
  }
926
 
  else
927
 
  {
928
 
    Table *show_table= tables->table;
929
 
    KEY *key_info=show_table->s->key_info;
930
 
    if (show_table->cursor)
931
 
    {
932
 
      show_table->cursor->info(HA_STATUS_VARIABLE |
933
 
                               HA_STATUS_NO_LOCK |
934
 
                               HA_STATUS_TIME);
935
 
    }
936
 
    for (uint32_t i=0 ; i < show_table->s->keys ; i++,key_info++)
937
 
    {
938
 
      KEY_PART_INFO *key_part= key_info->key_part;
939
 
      const char *str;
940
 
      for (uint32_t j=0 ; j < key_info->key_parts ; j++,key_part++)
941
 
      {
942
 
        table->restoreRecordAsDefault();
943
 
        table->field[1]->store(db_name->str, db_name->length, cs);
944
 
        table->field[2]->store(table_name->str, table_name->length, cs);
945
 
        table->field[3]->store((int64_t) ((key_info->flags &
946
 
                                            HA_NOSAME) ? 0 : 1), true);
947
 
        table->field[4]->store(db_name->str, db_name->length, cs);
948
 
        table->field[5]->store(key_info->name, strlen(key_info->name), cs);
949
 
        table->field[6]->store((int64_t) (j+1), true);
950
 
        str=(key_part->field ? key_part->field->field_name :
951
 
             "?unknown field?");
952
 
        table->field[7]->store(str, strlen(str), cs);
953
 
        if (show_table->cursor)
954
 
        {
955
 
          if (show_table->cursor->index_flags(i, j, 0) & HA_READ_ORDER)
956
 
          {
957
 
            table->field[8]->store(((key_part->key_part_flag &
958
 
                                     HA_REVERSE_SORT) ?
959
 
                                    "D" : "A"), 1, cs);
960
 
            table->field[8]->set_notnull();
961
 
          }
962
 
          KEY *key=show_table->key_info+i;
963
 
          if (key->rec_per_key[j])
964
 
          {
965
 
            ha_rows records=(show_table->cursor->stats.records /
966
 
                             key->rec_per_key[j]);
967
 
            table->field[9]->store((int64_t) records, true);
968
 
            table->field[9]->set_notnull();
969
 
          }
970
 
          str= show_table->cursor->index_type(i);
971
 
          table->field[13]->store(str, strlen(str), cs);
972
 
        }
973
 
        if ((key_part->field &&
974
 
             key_part->length !=
975
 
             show_table->s->field[key_part->fieldnr-1]->key_length()))
976
 
        {
977
 
          table->field[10]->store((int64_t) key_part->length /
978
 
                                  key_part->field->charset()->mbmaxlen, true);
979
 
          table->field[10]->set_notnull();
980
 
        }
981
 
        uint32_t flags= key_part->field ? key_part->field->flags : 0;
982
 
        const char *pos=(char*) ((flags & NOT_NULL_FLAG) ? "" : "YES");
983
 
        table->field[12]->store(pos, strlen(pos), cs);
984
 
        if (!show_table->s->keys_in_use.test(i))
985
 
        {
986
 
          table->field[14]->store(STRING_WITH_LEN("disabled"), cs);
987
 
        }
988
 
        else
989
 
        {
990
 
          table->field[14]->store("", 0, cs);
991
 
        }
992
 
        table->field[14]->set_notnull();
993
 
        assert(test(key_info->flags & HA_USES_COMMENT) ==
994
 
                   (key_info->comment.length > 0));
995
 
        if (key_info->flags & HA_USES_COMMENT)
996
 
        {
997
 
          table->field[15]->store(key_info->comment.str,
998
 
                                  key_info->comment.length, cs);
999
 
        }
1000
 
        if (schema_table_store_record(session, table))
1001
 
        {
1002
 
          return (1);
1003
 
        }
1004
 
      }
1005
 
    }
1006
 
  }
1007
 
  return(res);
1008
 
}
1009
 
 
1010
 
int StatusISMethods::fillTable(Session *session, TableList *tables)
1011
 
{
1012
 
  LEX *lex= session->lex;
1013
 
  const char *wild= lex->wild ? lex->wild->ptr() : NULL;
1014
 
  int res= 0;
1015
 
  STATUS_VAR *tmp1, tmp;
1016
 
  const string schema_table_name= tables->schema_table->getTableName();
1017
 
  enum enum_var_type option_type;
1018
 
  bool upper_case_names= (schema_table_name.compare("STATUS") != 0);
1019
 
 
1020
 
  if (schema_table_name.compare("STATUS") == 0)
1021
 
  {
1022
 
    option_type= lex->option_type;
1023
 
    if (option_type == OPT_GLOBAL)
1024
 
      tmp1= &tmp;
1025
 
    else
1026
 
      tmp1= session->initial_status_var;
1027
 
  }
1028
 
  else if (schema_table_name.compare("GLOBAL_STATUS") == 0)
1029
 
  {
1030
 
    option_type= OPT_GLOBAL;
1031
 
    tmp1= &tmp;
1032
 
  }
1033
 
  else
1034
 
  {
1035
 
    option_type= OPT_SESSION;
1036
 
    tmp1= &session->status_var;
1037
 
  }
1038
 
 
1039
 
  pthread_mutex_lock(&LOCK_status);
1040
 
  if (option_type == OPT_GLOBAL)
1041
 
    calc_sum_of_all_status(&tmp);
1042
 
  res= show_status_array(session, wild,
1043
 
                         getFrontOfStatusVars(),
1044
 
                         option_type, tmp1, "", tables->table,
1045
 
                         upper_case_names);
1046
 
  pthread_mutex_unlock(&LOCK_status);
1047
 
  return(res);
1048
 
}
1049
 
 
1050
 
static bool store_constraints(Session *session, Table *table, LEX_STRING *db_name,
1051
 
                              LEX_STRING *table_name, const char *key_name,
1052
 
                              uint32_t key_len, const char *con_type, uint32_t con_len)
1053
 
{
1054
 
  const CHARSET_INFO * const cs= system_charset_info;
1055
 
  table->restoreRecordAsDefault();
1056
 
  table->field[1]->store(db_name->str, db_name->length, cs);
1057
 
  table->field[2]->store(key_name, key_len, cs);
1058
 
  table->field[3]->store(db_name->str, db_name->length, cs);
1059
 
  table->field[4]->store(table_name->str, table_name->length, cs);
1060
 
  table->field[5]->store(con_type, con_len, cs);
1061
 
  return schema_table_store_record(session, table);
1062
 
}
1063
 
 
1064
 
int TabConstraintsISMethods::processTable(Session *session, TableList *tables,
1065
 
                                          Table *table, bool res,
1066
 
                                          LEX_STRING *db_name,
1067
 
                                          LEX_STRING *table_name) const
1068
 
{
1069
 
  if (res)
1070
 
  {
1071
 
    if (session->is_error())
1072
 
    {
1073
 
      push_warning(session, DRIZZLE_ERROR::WARN_LEVEL_WARN,
1074
 
                   session->main_da.sql_errno(), session->main_da.message());
1075
 
    }
1076
 
    session->clear_error();
1077
 
    return (0);
1078
 
  }
1079
 
  else
1080
 
  {
1081
 
    List<FOREIGN_KEY_INFO> f_key_list;
1082
 
    Table *show_table= tables->table;
1083
 
    KEY *key_info=show_table->key_info;
1084
 
    uint32_t primary_key= show_table->s->primary_key;
1085
 
    show_table->cursor->info(HA_STATUS_VARIABLE |
1086
 
                             HA_STATUS_NO_LOCK |
1087
 
                             HA_STATUS_TIME);
1088
 
    for (uint32_t i=0 ; i < show_table->s->keys ; i++, key_info++)
1089
 
    {
1090
 
      if (i != primary_key && !(key_info->flags & HA_NOSAME))
1091
 
      {
1092
 
        continue;
1093
 
      }
1094
 
 
1095
 
      if (i == primary_key && is_primary_key(key_info))
1096
 
      {
1097
 
        if (store_constraints(session, table, db_name, table_name, key_info->name,
1098
 
                              strlen(key_info->name),
1099
 
                              STRING_WITH_LEN("PRIMARY KEY")))
1100
 
        {
1101
 
          return (1);
1102
 
        }
1103
 
      }
1104
 
      else if (key_info->flags & HA_NOSAME)
1105
 
      {
1106
 
        if (store_constraints(session, table, db_name, table_name, key_info->name,
1107
 
                              strlen(key_info->name),
1108
 
                              STRING_WITH_LEN("UNIQUE")))
1109
 
        {
1110
 
          return (1);
1111
 
        }
1112
 
      }
1113
 
    }
1114
 
 
1115
 
    show_table->cursor->get_foreign_key_list(session, &f_key_list);
1116
 
    FOREIGN_KEY_INFO *f_key_info;
1117
 
    List_iterator_fast<FOREIGN_KEY_INFO> it(f_key_list);
1118
 
    while ((f_key_info=it++))
1119
 
    {
1120
 
      if (store_constraints(session, table, db_name, table_name,
1121
 
                            f_key_info->forein_id->str,
1122
 
                            strlen(f_key_info->forein_id->str),
1123
 
                            "FOREIGN KEY", 11))
1124
 
      {
1125
 
        return (1);
1126
 
      }
1127
 
    }
1128
 
  }
1129
 
  return (res);
1130
 
}
1131
 
 
1132
 
int TablesISMethods::processTable(Session *session, TableList *tables,
1133
 
                                    Table *table, bool res,
1134
 
                                    LEX_STRING *db_name,
1135
 
                                    LEX_STRING *table_name) const
1136
 
{
1137
 
  const char *tmp_buff;
1138
 
  DRIZZLE_TIME time;
1139
 
  const CHARSET_INFO * const cs= system_charset_info;
1140
 
 
1141
 
  table->restoreRecordAsDefault();
1142
 
  table->field[1]->store(db_name->str, db_name->length, cs);
1143
 
  table->field[2]->store(table_name->str, table_name->length, cs);
1144
 
  if (res)
1145
 
  {
1146
 
    /*
1147
 
      there was errors during opening tables
1148
 
    */
1149
 
    const char *error= session->is_error() ? session->main_da.message() : "";
1150
 
    if (tables->schema_table)
1151
 
    {
1152
 
      table->field[3]->store(STRING_WITH_LEN("SYSTEM VIEW"), cs);
1153
 
    }
1154
 
    else
1155
 
    {
1156
 
      table->field[3]->store(STRING_WITH_LEN("BASE Table"), cs);
1157
 
    }
1158
 
    table->field[20]->store(error, strlen(error), cs);
1159
 
    session->clear_error();
1160
 
  }
1161
 
  else
1162
 
  {
1163
 
    char option_buff[400],*ptr;
1164
 
    Table *show_table= tables->table;
1165
 
    TableShare *share= show_table->s;
1166
 
    Cursor *cursor= show_table->cursor;
1167
 
    drizzled::plugin::StorageEngine *tmp_db_type= share->db_type();
1168
 
 
1169
 
    if (share->tmp_table == SYSTEM_TMP_TABLE)
1170
 
    {
1171
 
      table->field[3]->store(STRING_WITH_LEN("SYSTEM VIEW"), cs);
1172
 
    }
1173
 
    else if (share->tmp_table)
1174
 
    {
1175
 
      table->field[3]->store(STRING_WITH_LEN("LOCAL TEMPORARY"), cs);
1176
 
    }
1177
 
    else
1178
 
    {
1179
 
      table->field[3]->store(STRING_WITH_LEN("BASE Table"), cs);
1180
 
    }
1181
 
 
1182
 
    for (int i= 4; i < 20; i++)
1183
 
    {
1184
 
      if (i == 7 || (i > 12 && i < 17) || i == 18)
1185
 
      {
1186
 
        continue;
1187
 
      }
1188
 
      table->field[i]->set_notnull();
1189
 
    }
1190
 
    const string &engine_name= drizzled::plugin::StorageEngine::resolveName(tmp_db_type);
1191
 
    table->field[4]->store(engine_name.c_str(), engine_name.size(), cs);
1192
 
    table->field[5]->store((int64_t) 0, true);
1193
 
 
1194
 
    ptr=option_buff;
1195
 
 
1196
 
    if (share->db_create_options & HA_OPTION_PACK_KEYS)
1197
 
    {
1198
 
      ptr= strcpy(ptr," pack_keys=1")+12;
1199
 
    }
1200
 
    if (share->db_create_options & HA_OPTION_NO_PACK_KEYS)
1201
 
    {
1202
 
      ptr= strcpy(ptr," pack_keys=0")+12;
1203
 
    }
1204
 
    if (share->row_type != ROW_TYPE_DEFAULT)
1205
 
    {
1206
 
      ptr+= sprintf(ptr, " row_format=%s", ha_row_type[(uint32_t)share->row_type]);
1207
 
    }
1208
 
    if (share->block_size)
1209
 
    {
1210
 
      ptr= strcpy(ptr, " block_size=")+12;
1211
 
      ptr= int64_t10_to_str(share->block_size, ptr, 10);
1212
 
    }
1213
 
 
1214
 
    table->field[19]->store(option_buff+1,
1215
 
                            (ptr == option_buff ? 0 :
1216
 
                             (uint32_t) (ptr-option_buff)-1), cs);
1217
 
 
1218
 
    tmp_buff= (share->table_charset ?
1219
 
               share->table_charset->name : "default");
1220
 
    table->field[17]->store(tmp_buff, strlen(tmp_buff), cs);
1221
 
 
1222
 
    if (share->hasComment())
1223
 
      table->field[20]->store(share->getComment(),
1224
 
                              share->getCommentLength(), cs);
1225
 
 
1226
 
    if (cursor)
1227
 
    {
1228
 
      cursor->info(HA_STATUS_VARIABLE | HA_STATUS_TIME | HA_STATUS_AUTO |
1229
 
                   HA_STATUS_NO_LOCK);
1230
 
      enum row_type row_type = cursor->get_row_type();
1231
 
      switch (row_type) {
1232
 
      case ROW_TYPE_NOT_USED:
1233
 
      case ROW_TYPE_DEFAULT:
1234
 
        tmp_buff= ((share->db_options_in_use &
1235
 
                    HA_OPTION_COMPRESS_RECORD) ? "Compressed" :
1236
 
                   (share->db_options_in_use & HA_OPTION_PACK_RECORD) ?
1237
 
                   "Dynamic" : "Fixed");
1238
 
        break;
1239
 
      case ROW_TYPE_FIXED:
1240
 
        tmp_buff= "Fixed";
1241
 
        break;
1242
 
      case ROW_TYPE_DYNAMIC:
1243
 
        tmp_buff= "Dynamic";
1244
 
        break;
1245
 
      case ROW_TYPE_COMPRESSED:
1246
 
        tmp_buff= "Compressed";
1247
 
        break;
1248
 
      case ROW_TYPE_REDUNDANT:
1249
 
        tmp_buff= "Redundant";
1250
 
        break;
1251
 
      case ROW_TYPE_COMPACT:
1252
 
        tmp_buff= "Compact";
1253
 
        break;
1254
 
      case ROW_TYPE_PAGE:
1255
 
        tmp_buff= "Paged";
1256
 
        break;
1257
 
      }
1258
 
      table->field[6]->store(tmp_buff, strlen(tmp_buff), cs);
1259
 
      if (! tables->schema_table)
1260
 
      {
1261
 
        table->field[7]->store((int64_t) cursor->stats.records, true);
1262
 
        table->field[7]->set_notnull();
1263
 
      }
1264
 
      table->field[8]->store((int64_t) cursor->stats.mean_rec_length, true);
1265
 
      table->field[9]->store((int64_t) cursor->stats.data_file_length, true);
1266
 
      if (cursor->stats.max_data_file_length)
1267
 
      {
1268
 
        table->field[10]->store((int64_t) cursor->stats.max_data_file_length,
1269
 
                                true);
1270
 
      }
1271
 
      table->field[11]->store((int64_t) cursor->stats.index_file_length, true);
1272
 
      table->field[12]->store((int64_t) cursor->stats.delete_length, true);
1273
 
      if (show_table->found_next_number_field)
1274
 
      {
1275
 
        table->field[13]->store((int64_t) cursor->stats.auto_increment_value, true);
1276
 
        table->field[13]->set_notnull();
1277
 
      }
1278
 
      if (cursor->stats.create_time)
1279
 
      {
1280
 
        session->variables.time_zone->gmt_sec_to_TIME(&time,
1281
 
                                                  (time_t) cursor->stats.create_time);
1282
 
        table->field[14]->store_time(&time, DRIZZLE_TIMESTAMP_DATETIME);
1283
 
        table->field[14]->set_notnull();
1284
 
      }
1285
 
      if (cursor->stats.update_time)
1286
 
      {
1287
 
        session->variables.time_zone->gmt_sec_to_TIME(&time,
1288
 
                                                  (time_t) cursor->stats.update_time);
1289
 
        table->field[15]->store_time(&time, DRIZZLE_TIMESTAMP_DATETIME);
1290
 
        table->field[15]->set_notnull();
1291
 
      }
1292
 
      if (cursor->stats.check_time)
1293
 
      {
1294
 
        session->variables.time_zone->gmt_sec_to_TIME(&time,
1295
 
                                                  (time_t) cursor->stats.check_time);
1296
 
        table->field[16]->store_time(&time, DRIZZLE_TIMESTAMP_DATETIME);
1297
 
        table->field[16]->set_notnull();
1298
 
      }
1299
 
      if (cursor->ha_table_flags() & (ulong) HA_HAS_CHECKSUM)
1300
 
      {
1301
 
        table->field[18]->store((int64_t) cursor->checksum(), true);
1302
 
        table->field[18]->set_notnull();
1303
 
      }
1304
 
    }
1305
 
  }
1306
 
  return (schema_table_store_record(session, table));
1307
 
}
1308
 
 
1309
 
 
1310
 
int TabNamesISMethods::oldFormat(Session *session, drizzled::plugin::InfoSchemaTable *schema_table)
1311
 
  const
1312
 
{
1313
 
  char tmp[128];
1314
 
  String buffer(tmp,sizeof(tmp), session->charset());
1315
 
  LEX *lex= session->lex;
1316
 
  Name_resolution_context *context= &lex->select_lex.context;
1317
 
  const drizzled::plugin::InfoSchemaTable::Columns columns= schema_table->getColumns();
1318
 
 
1319
 
  const drizzled::plugin::ColumnInfo *column= columns[2];
1320
 
  buffer.length(0);
1321
 
  buffer.append(column->getOldName().c_str());
1322
 
  buffer.append(lex->select_lex.db);
1323
 
  if (lex->wild && lex->wild->ptr())
1324
 
  {
1325
 
    buffer.append(STRING_WITH_LEN(" ("));
1326
 
    buffer.append(lex->wild->ptr());
1327
 
    buffer.append(')');
1328
 
  }
1329
 
  Item_field *field= new Item_field(context,
1330
 
                                    NULL, NULL, column->getName().c_str());
1331
 
  if (session->add_item_to_list(field))
1332
 
  {
1333
 
    return 1;
1334
 
  }
1335
 
  field->set_name(buffer.ptr(), buffer.length(), system_charset_info);
1336
 
  if (session->lex->verbose)
1337
 
  {
1338
 
    field->set_name(buffer.ptr(), buffer.length(), system_charset_info);
1339
 
    column= columns[3];
1340
 
    field= new Item_field(context, NULL, NULL, column->getName().c_str());
1341
 
    if (session->add_item_to_list(field))
1342
 
    {
1343
 
      return 1;
1344
 
    }
1345
 
    field->set_name(column->getOldName().c_str(),
1346
 
                    column->getOldName().length(),
1347
 
                    system_charset_info);
1348
 
  }
1349
 
  return 0;
1350
 
}
1351
 
 
1352
 
int VariablesISMethods::fillTable(Session *session, TableList *tables)
1353
 
{
1354
 
  int res= 0;
1355
 
  LEX *lex= session->lex;
1356
 
  const char *wild= lex->wild ? lex->wild->ptr() : NULL;
1357
 
  const string schema_table_name= tables->schema_table->getTableName();
1358
 
  enum enum_var_type option_type= OPT_SESSION;
1359
 
  bool upper_case_names= (schema_table_name.compare("VARIABLES") != 0);
1360
 
  bool sorted_vars= (schema_table_name.compare("VARIABLES") == 0);
1361
 
 
1362
 
  if (lex->option_type == OPT_GLOBAL ||
1363
 
      schema_table_name.compare("GLOBAL_VARIABLES") == 0)
1364
 
  {
1365
 
    option_type= OPT_GLOBAL;
1366
 
  }
1367
 
 
1368
 
  pthread_rwlock_rdlock(&LOCK_system_variables_hash);
1369
 
  res= show_status_array(session, wild, enumerate_sys_vars(session, sorted_vars),
1370
 
                         option_type, NULL, "", tables->table, upper_case_names);
1371
 
  pthread_rwlock_unlock(&LOCK_system_variables_hash);
1372
 
  return(res);
1373
 
}
1374
 
 
 
225
/*
 
226
 * Function object used for deleting the memory allocated
 
227
 * for the columns contained with the vector of columns.
 
228
 */
 
229
class DeleteColumns
 
230
{
 
231
public:
 
232
  template<typename T>
 
233
  inline void operator()(const T *ptr) const
 
234
  {
 
235
    delete ptr;
 
236
  }
 
237
};
 
238
 
 
239
void clearColumns(vector<const drizzled::plugin::ColumnInfo *> &cols)
 
240
{
 
241
  for_each(cols.begin(), cols.end(), DeleteColumns());
 
242
  cols.clear();
 
243
}