~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/statement/alter_table.cc

  • Committer: Brian Aker
  • Date: 2010-03-02 22:24:51 UTC
  • mto: This revision was merged to the branch mainline in revision 1319.
  • Revision ID: brian@gaz-20100302222451-bys6hxhwmzsjlcr0
Small cleanup around alter table.

Show diffs side-by-side

added added

removed removed

Lines of Context:
692
692
  int error= 0;
693
693
  char tmp_name[80];
694
694
  char old_name[32];
695
 
  char new_name_buff[FN_REFLEN];
696
 
  char new_alias_buff[FN_REFLEN];
697
695
  char *table_name;
698
696
  char *db;
699
697
  const char *new_alias;
704
702
  plugin::StorageEngine *save_old_db_type;
705
703
  bitset<32> tmp;
706
704
 
707
 
  new_name_buff[0]= '\0';
708
 
 
709
705
  session->set_proc_info("init");
710
706
 
 
707
  cerr << "Charset for table " << table_alias_charset->name << "\n";
711
708
  /*
712
709
    Assign variables table_name, new_name, db, new_db, path
713
710
    to simplify further comparisons: we want to see if it's a RENAME
724
721
    return mysql_discard_or_import_tablespace(session, table_list, alter_info->tablespace_op);
725
722
  }
726
723
 
727
 
  ostringstream oss;
728
 
  oss << drizzle_data_home << "/" << db << "/" << table_name;
729
 
 
730
 
  (void) internal::unpack_filename(new_name_buff, oss.str().c_str());
731
 
 
732
724
  /*
733
725
    If this is just a rename of a view, short cut to the
734
726
    following scenario: 1) lock LOCK_open 2) do a RENAME
743
735
    This code is wrong and will be removed, please do not copy.
744
736
  */
745
737
 
746
 
  if (!(table= session->openTableLock(table_list, TL_WRITE_ALLOW_READ)))
 
738
  if (not (table= session->openTableLock(table_list, TL_WRITE_ALLOW_READ)))
747
739
    return true;
748
740
  
749
741
  table->use_all_columns();
751
743
  /* Check that we are not trying to rename to an existing table */
752
744
  if (new_name)
753
745
  {
754
 
    strcpy(new_name_buff, new_name);
 
746
    char new_alias_buff[FN_REFLEN];
 
747
    char lower_case_table_name[FN_REFLEN];
 
748
 
 
749
    strcpy(lower_case_table_name, new_name);
755
750
    strcpy(new_alias_buff, new_name);
756
751
    new_alias= new_alias_buff;
757
752
 
758
 
    my_casedn_str(files_charset_info, new_name_buff);
 
753
    my_casedn_str(files_charset_info, lower_case_table_name);
759
754
    new_alias= new_name; // Create lower case table name
760
755
    my_casedn_str(files_charset_info, new_name);
761
756
 
762
757
    if (new_db == db &&
763
 
        ! my_strcasecmp(table_alias_charset, new_name_buff, table_name))
 
758
        not my_strcasecmp(table_alias_charset, lower_case_table_name, table_name))
764
759
    {
765
760
      /*
766
761
        Source and destination table names are equal: make later check
772
767
    {
773
768
      if (table->s->tmp_table != NO_TMP_TABLE)
774
769
      {
775
 
        if (session->find_temporary_table(new_db, new_name_buff))
 
770
        if (session->find_temporary_table(new_db, lower_case_table_name))
776
771
        {
777
 
          my_error(ER_TABLE_EXISTS_ERROR, MYF(0), new_name_buff);
 
772
          my_error(ER_TABLE_EXISTS_ERROR, MYF(0), lower_case_table_name);
778
773
          return true;
779
774
        }
780
775
      }
789
784
          return true;
790
785
        }
791
786
 
792
 
        TableIdentifier identifier(new_db, new_name_buff);
 
787
        TableIdentifier identifier(new_db, lower_case_table_name);
793
788
 
794
789
        if (plugin::StorageEngine::doesTableExist(*session, identifier))
795
790
        {
807
802
  }
808
803
 
809
804
  old_db_type= table->s->db_type();
810
 
  if (! create_info->db_type)
 
805
  if (not create_info->db_type)
811
806
  {
812
807
    create_info->db_type= old_db_type;
813
808
  }
823
818
 
824
819
  new_db_type= create_info->db_type;
825
820
 
 
821
  /**
 
822
    @todo Have a check on the table definition for FK in the future 
 
823
    to remove the need for the cursor. (aka can_switch_engines())
 
824
  */
826
825
  if (new_db_type != old_db_type &&
827
 
      !table->cursor->can_switch_engines())
 
826
      not table->cursor->can_switch_engines())
828
827
  {
829
828
    assert(0);
830
829
    my_error(ER_ROW_IS_REFERENCED, MYF(0));