~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/plugin/storage_engine.cc

Reworked delete table code (thank god... or... whatever... how about my dog?
Yeah... thank dog...))

Show diffs side-by-side

added added

removed removed

Lines of Context:
591
591
}
592
592
 
593
593
 
594
 
class DeleteTableStorageEngine
595
 
  : public unary_function<plugin::StorageEngine *, void>
596
 
{
597
 
  Session *session;
598
 
  const char *path;
599
 
  Cursor **file;
600
 
  int *dt_error;
601
 
public:
602
 
  DeleteTableStorageEngine(Session *session_arg, const char *path_arg,
603
 
                           Cursor **file_arg, int *error_arg)
604
 
    : session(session_arg), path(path_arg), file(file_arg), dt_error(error_arg) {}
605
 
 
606
 
  result_type operator() (argument_type engine)
607
 
  {
608
 
    char tmp_path[FN_REFLEN];
609
 
    Cursor *tmp_file;
610
 
 
611
 
    if(*dt_error!=ENOENT) /* already deleted table */
612
 
      return;
613
 
 
614
 
    if (!engine)
615
 
      return;
616
 
 
617
 
    if (!engine->is_enabled())
618
 
      return;
619
 
 
620
 
    if ((tmp_file= engine->create(NULL, session->mem_root)))
621
 
      tmp_file->init();
622
 
    else
623
 
      return;
624
 
 
625
 
    path= engine->checkLowercaseNames(path, tmp_path);
626
 
    const string table_path(path);
627
 
    int tmp_error= engine->doDeleteTable(session, table_path);
628
 
 
629
 
    if (tmp_error != ENOENT)
630
 
    {
631
 
      if (tmp_error == 0)
632
 
      {
633
 
        if (engine->check_flag(HTON_BIT_HAS_DATA_DICTIONARY))
634
 
          delete_table_proto_file(path);
635
 
        else
636
 
          tmp_error= delete_table_proto_file(path);
637
 
      }
638
 
 
639
 
      *dt_error= tmp_error;
640
 
      if(*file)
641
 
        delete *file;
642
 
      *file= tmp_file;
643
 
      return;
644
 
    }
645
 
    else
646
 
      delete tmp_file;
647
 
 
648
 
    return;
649
 
  }
650
 
};
651
 
 
652
 
 
653
594
/**
654
595
  This should return ENOENT if the file doesn't exists.
655
596
  The .frm file will be deleted only if we return 0 or ENOENT
658
599
                                       const char *db, const char *alias,
659
600
                                       bool generate_warning)
660
601
{
661
 
  TableShare dummy_share;
662
 
  Table dummy_table;
663
 
  memset(&dummy_table, 0, sizeof(dummy_table));
664
 
  memset(&dummy_share, 0, sizeof(dummy_share));
665
 
 
666
 
  dummy_table.s= &dummy_share;
667
 
 
668
 
  int error= ENOENT;
669
 
  Cursor *file= NULL;
670
 
 
671
 
  for_each(all_engines.begin(), all_engines.end(),
672
 
           DeleteTableStorageEngine(session, path, &file, &error));
673
 
 
674
 
  if (error == ENOENT) /* proto may be left behind */
675
 
    error= delete_table_proto_file(path);
 
602
  int error= 0;
 
603
  int error_proto;
 
604
  message::Table src_proto;
 
605
  plugin::StorageEngine* engine;
 
606
 
 
607
  error_proto= plugin::StorageEngine::getTableProto(path, &src_proto);
 
608
 
 
609
  engine= plugin::StorageEngine::findByName(session,
 
610
                                            src_proto.engine().name());
 
611
 
 
612
  if (engine)
 
613
    error= engine->doDeleteTable(session, path);
 
614
 
 
615
  if (error != ENOENT)
 
616
  {
 
617
    if (error == 0)
 
618
    {
 
619
      if (engine && engine->check_flag(HTON_BIT_HAS_DATA_DICTIONARY))
 
620
        delete_table_proto_file(path);
 
621
      else
 
622
        error= delete_table_proto_file(path);
 
623
    }
 
624
  }
 
625
 
 
626
  if (error_proto && error == 0)
 
627
    return 0;
676
628
 
677
629
  if (error && generate_warning)
678
630
  {
 
631
    TableShare dummy_share;
 
632
    Table dummy_table;
 
633
    Cursor *file= NULL;
 
634
 
 
635
    if (engine)
 
636
    {
 
637
      if ((file= engine->create(NULL, session->mem_root)))
 
638
        file->init();
 
639
    }
 
640
    memset(&dummy_table, 0, sizeof(dummy_table));
 
641
    memset(&dummy_share, 0, sizeof(dummy_share));
 
642
    dummy_table.s= &dummy_share;
 
643
 
679
644
    /*
680
645
      Because file->print_error() use my_error() to generate the error message
681
646
      we use an internal error Cursor to intercept it and store the text
693
658
    dummy_share.table_name.length= strlen(alias);
694
659
    dummy_table.alias= alias;
695
660
 
696
 
    if(file != NULL)
 
661
    if (file != NULL)
697
662
    {
698
663
      file->change_table_ptr(&dummy_table, &dummy_share);
699
664
 
713
678
                 ha_delete_table_error_handler.buff);
714
679
  }
715
680
 
716
 
  if(file)
717
 
    delete file;
718
 
 
719
681
  return error;
720
682
}
721
683