~jaypipes/drizzle/bug534806

« back to all changes in this revision

Viewing changes to drizzled/statement/alter_table.cc

  • Committer: Brian Aker
  • Date: 2010-03-03 05:02:36 UTC
  • mfrom: (1309.2.19 build)
  • Revision ID: brian@gaz-20100303050236-y7dotibgwks12gyp
Merge.

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
 
711
707
  /*
724
720
    return mysql_discard_or_import_tablespace(session, table_list, alter_info->tablespace_op);
725
721
  }
726
722
 
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
723
  /*
733
724
    If this is just a rename of a view, short cut to the
734
725
    following scenario: 1) lock LOCK_open 2) do a RENAME
743
734
    This code is wrong and will be removed, please do not copy.
744
735
  */
745
736
 
746
 
  if (!(table= session->openTableLock(table_list, TL_WRITE_ALLOW_READ)))
 
737
  if (not (table= session->openTableLock(table_list, TL_WRITE_ALLOW_READ)))
747
738
    return true;
748
739
  
749
740
  table->use_all_columns();
751
742
  /* Check that we are not trying to rename to an existing table */
752
743
  if (new_name)
753
744
  {
754
 
    strcpy(new_name_buff, new_name);
 
745
    char new_alias_buff[FN_REFLEN];
 
746
    char lower_case_table_name[FN_REFLEN];
 
747
 
 
748
    strcpy(lower_case_table_name, new_name);
755
749
    strcpy(new_alias_buff, new_name);
756
750
    new_alias= new_alias_buff;
757
751
 
758
 
    my_casedn_str(files_charset_info, new_name_buff);
 
752
    my_casedn_str(files_charset_info, lower_case_table_name);
759
753
    new_alias= new_name; // Create lower case table name
760
754
    my_casedn_str(files_charset_info, new_name);
761
755
 
762
756
    if (new_db == db &&
763
 
        ! my_strcasecmp(table_alias_charset, new_name_buff, table_name))
 
757
        not my_strcasecmp(table_alias_charset, lower_case_table_name, table_name))
764
758
    {
765
759
      /*
766
760
        Source and destination table names are equal: make later check
770
764
    }
771
765
    else
772
766
    {
773
 
      if (table->s->tmp_table != NO_TMP_TABLE)
 
767
      if (table->s->tmp_table != STANDARD_TABLE)
774
768
      {
775
 
        if (session->find_temporary_table(new_db, new_name_buff))
 
769
        if (session->find_temporary_table(new_db, lower_case_table_name))
776
770
        {
777
 
          my_error(ER_TABLE_EXISTS_ERROR, MYF(0), new_name_buff);
 
771
          my_error(ER_TABLE_EXISTS_ERROR, MYF(0), lower_case_table_name);
778
772
          return true;
779
773
        }
780
774
      }
789
783
          return true;
790
784
        }
791
785
 
792
 
        TableIdentifier identifier(new_db, new_name_buff);
 
786
        TableIdentifier identifier(new_db, lower_case_table_name);
793
787
 
794
788
        if (plugin::StorageEngine::doesTableExist(*session, identifier))
795
789
        {
807
801
  }
808
802
 
809
803
  old_db_type= table->s->db_type();
810
 
  if (! create_info->db_type)
 
804
  if (not create_info->db_type)
811
805
  {
812
806
    create_info->db_type= old_db_type;
813
807
  }
814
808
 
815
 
  if (table->s->tmp_table != NO_TMP_TABLE)
 
809
  if (table->s->tmp_table != STANDARD_TABLE)
816
810
  {
817
811
    create_proto->set_type(message::Table::TEMPORARY);
818
812
  }
823
817
 
824
818
  new_db_type= create_info->db_type;
825
819
 
 
820
  /**
 
821
    @todo Have a check on the table definition for FK in the future 
 
822
    to remove the need for the cursor. (aka can_switch_engines())
 
823
  */
826
824
  if (new_db_type != old_db_type &&
827
 
      !table->cursor->can_switch_engines())
 
825
      not table->cursor->can_switch_engines())
828
826
  {
829
827
    assert(0);
830
828
    my_error(ER_ROW_IS_REFERENCED, MYF(0));
1032
1030
  /* We must not ignore bad input! */
1033
1031
  session->count_cuted_fields= CHECK_FIELD_ERROR_FOR_NULL;
1034
1032
 
1035
 
  if (table->s->tmp_table != NO_TMP_TABLE)
 
1033
  if (table->s->tmp_table != STANDARD_TABLE)
1036
1034
  {
1037
1035
    /* We changed a temporary table */
1038
1036
    if (error)
1125
1123
      /* Try to get everything back. */
1126
1124
      error= 1;
1127
1125
 
1128
 
      TableIdentifier alias_identifier(new_db, new_alias, NO_TMP_TABLE);
 
1126
      TableIdentifier alias_identifier(new_db, new_alias, STANDARD_TABLE);
1129
1127
      quick_rm_table(*session, alias_identifier);
1130
1128
 
1131
1129
      TableIdentifier tmp_identifier(new_db, tmp_name, INTERNAL_TMP_TABLE);