~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/sql_table.cc

  • Committer: Olaf van der Spek
  • Date: 2011-06-22 20:05:58 UTC
  • mto: This revision was merged to the branch mainline in revision 2347.
  • Revision ID: olafvdspek@gmail.com-20110622200558-oq3jb987di9yj70r
Refactor

Show diffs side-by-side

added added

removed removed

Lines of Context:
572
572
      tmp_pos+= strlen(tmp);
573
573
      strncpy(tmp_pos, STRING_WITH_LEN("_bin"));
574
574
      my_error(ER_UNKNOWN_COLLATION, MYF(0), tmp);
575
 
      return(true);
 
575
      return true;
576
576
    }
577
577
 
578
578
    /*
599
599
      {
600
600
        /* Could not convert */
601
601
        my_error(ER_INVALID_DEFAULT, MYF(0), sql_field->field_name);
602
 
        return(true);
 
602
        return true;
603
603
      }
604
604
    }
605
605
 
621
621
          occupied memory at the same time when we free this
622
622
          sql_field -- at the end of execution.
623
623
        */
624
 
        interval= sql_field->interval= typelib(session->mem_root,
625
 
                                               sql_field->interval_list);
 
624
        interval= sql_field->interval= typelib(*session->mem_root, sql_field->interval_list);
626
625
 
627
626
        List<String>::iterator int_it(sql_field->interval_list.begin());
628
627
        String conv, *tmp;
629
628
        char comma_buf[4];
630
 
        int comma_length= cs->cset->wc_mb(cs, ',', (unsigned char*) comma_buf,
631
 
                                          (unsigned char*) comma_buf +
632
 
                                          sizeof(comma_buf));
 
629
        int comma_length= cs->cset->wc_mb(cs, ',', (unsigned char*) comma_buf, (unsigned char*) comma_buf + sizeof(comma_buf));
633
630
        assert(comma_length > 0);
634
631
 
635
632
        for (uint32_t i= 0; (tmp= int_it++); i++)
643
640
          }
644
641
 
645
642
          // Strip trailing spaces.
646
 
          lengthsp= cs->cset->lengthsp(cs, interval->type_names[i],
647
 
                                       interval->type_lengths[i]);
 
643
          lengthsp= cs->cset->lengthsp(cs, interval->type_names[i], interval->type_lengths[i]);
648
644
          interval->type_lengths[i]= lengthsp;
649
645
          ((unsigned char *)interval->type_names[i])[lengthsp]= '\0';
650
646
        }
660
656
          String str, *def= sql_field->def->val_str(&str);
661
657
          if (def == NULL) /* SQL "NULL" maps to NULL */
662
658
          {
663
 
            if ((sql_field->flags & NOT_NULL_FLAG) != 0)
 
659
            if (sql_field->flags & NOT_NULL_FLAG)
664
660
            {
665
661
              my_error(ER_INVALID_DEFAULT, MYF(0), sql_field->field_name);
666
 
              return(true);
 
662
              return true;
667
663
            }
668
664
 
669
665
            /* else, the defaults yield the correct length for NULLs. */
674
670
            if (interval->find_type2(def->ptr(), def->length(), cs) == 0) /* not found */
675
671
            {
676
672
              my_error(ER_INVALID_DEFAULT, MYF(0), sql_field->field_name);
677
 
              return(true);
 
673
              return true;
678
674
            }
679
675
          }
680
676
        }
687
683
 
688
684
    sql_field->create_length_to_internal_length();
689
685
    if (prepare_blob_field(session, sql_field))
690
 
      return(true);
 
686
      return true;
691
687
 
692
688
    if (!(sql_field->flags & NOT_NULL_FLAG))
693
689
      null_fields++;
695
691
    if (check_column_name(sql_field->field_name))
696
692
    {
697
693
      my_error(ER_WRONG_COLUMN_NAME, MYF(0), sql_field->field_name);
698
 
      return(true);
 
694
      return true;
699
695
    }
700
696
 
701
697
    /* Check if we have used the same field name before */
712
708
        if (field_no < select_field_pos || dup_no >= select_field_pos)
713
709
        {
714
710
          my_error(ER_DUP_FIELDNAME, MYF(0), sql_field->field_name);
715
 
          return(true);
 
711
          return true;
716
712
        }
717
713
        else
718
714
        {
766
762
 
767
763
    if (prepare_create_field(sql_field, &blob_columns,
768
764
                             &timestamps, &timestamps_with_niladic))
769
 
      return(true);
 
765
      return true;
770
766
    sql_field->offset= record_offset;
771
767
    if (MTYP_TYPENR(sql_field->unireg_check) == Field::NEXT_NUMBER)
772
768
      auto_increment++;
775
771
  {
776
772
    my_message(ER_TOO_MUCH_AUTO_TIMESTAMP_COLS,
777
773
               ER(ER_TOO_MUCH_AUTO_TIMESTAMP_COLS), MYF(0));
778
 
    return(true);
 
774
    return true;
779
775
  }
780
776
  if (auto_increment > 1)
781
777
  {
782
778
    my_message(ER_WRONG_AUTO_KEY, ER(ER_WRONG_AUTO_KEY), MYF(0));
783
 
    return(true);
 
779
    return true;
784
780
  }
785
781
  if (auto_increment &&
786
782
      (engine->check_flag(HTON_BIT_NO_AUTO_INCREMENT)))
787
783
  {
788
784
    my_message(ER_TABLE_CANT_HANDLE_AUTO_INCREMENT,
789
785
               ER(ER_TABLE_CANT_HANDLE_AUTO_INCREMENT), MYF(0));
790
 
    return(true);
 
786
    return true;
791
787
  }
792
788
 
793
789
  if (blob_columns && (engine->check_flag(HTON_BIT_NO_BLOBS)))
794
790
  {
795
791
    my_message(ER_TABLE_CANT_HANDLE_BLOB, ER(ER_TABLE_CANT_HANDLE_BLOB),
796
792
               MYF(0));
797
 
    return(true);
 
793
    return true;
798
794
  }
799
795
 
800
796
  /* Create keys */
837
833
                 (fk_key->name.str ? fk_key->name.str :
838
834
                                     "foreign key without name"),
839
835
                 ER(ER_KEY_REF_DO_NOT_MATCH_TABLE_REF));
840
 
        return(true);
 
836
        return true;
841
837
      }
842
838
      continue;
843
839
    }
846
842
    if (key->columns.size() > tmp)
847
843
    {
848
844
      my_error(ER_TOO_MANY_KEY_PARTS,MYF(0),tmp);
849
 
      return(true);
 
845
      return true;
850
846
    }
851
847
    if (check_identifier_name(&key->name, ER_TOO_LONG_IDENT))
852
 
      return(true);
 
848
      return true;
853
849
    key_iterator2= alter_info->key_list.begin();
854
850
    if (key->type != Key::FOREIGN_KEY)
855
851
    {
888
884
        is_primary_key_name(key->name.str))
889
885
    {
890
886
      my_error(ER_WRONG_NAME_FOR_INDEX, MYF(0), key->name.str);
891
 
      return(true);
 
887
      return true;
892
888
    }
893
889
  }
894
890
  tmp= engine->max_keys();
895
891
  if (*key_count > tmp)
896
892
  {
897
893
    my_error(ER_TOO_MANY_KEYS,MYF(0),tmp);
898
 
    return(true);
 
894
    return true;
899
895
  }
900
896
 
901
897
  (*key_info_buffer)= key_info= (KeyInfo*) memory::sql_calloc(sizeof(KeyInfo) * (*key_count));
902
898
  key_part_info=(KeyPartInfo*) memory::sql_calloc(sizeof(KeyPartInfo)*key_parts);
903
899
  if (!*key_info_buffer || ! key_part_info)
904
 
    return(true);                               // Out of memory
 
900
    return true;                                // Out of memory
905
901
 
906
902
  key_iterator= alter_info->key_list.begin();
907
903
  key_number=0;
983
979
      if (!sql_field)
984
980
      {
985
981
        my_error(ER_KEY_COLUMN_DOES_NOT_EXITS, MYF(0), column->field_name.str);
986
 
        return(true);
 
982
        return true;
987
983
      }
988
984
 
989
985
      while ((dup_column= cols2++) != column)
994
990
          my_printf_error(ER_DUP_FIELDNAME,
995
991
                          ER(ER_DUP_FIELDNAME),MYF(0),
996
992
                          column->field_name.str);
997
 
          return(true);
 
993
          return true;
998
994
        }
999
995
      }
1000
996
      cols2= key->columns.begin();
1080
1076
            else
1081
1077
            {
1082
1078
              my_error(ER_TOO_LONG_KEY,MYF(0),length);
1083
 
              return(true);
 
1079
              return true;
1084
1080
            }
1085
1081
          }
1086
1082
        }
1088
1084
            ! Field::type_can_have_key_part(sql_field->sql_type)))
1089
1085
        {
1090
1086
          my_message(ER_WRONG_SUB_KEY, ER(ER_WRONG_SUB_KEY), MYF(0));
1091
 
          return(true);
 
1087
          return true;
1092
1088
        }
1093
1089
        else if (! (engine->check_flag(HTON_BIT_NO_PREFIX_CHAR_KEYS)))
1094
1090
        {
1098
1094
      else if (length == 0)
1099
1095
      {
1100
1096
        my_error(ER_WRONG_KEY_COLUMN, MYF(0), column->field_name.str);
1101
 
          return(true);
 
1097
          return true;
1102
1098
      }
1103
1099
      if (length > engine->max_key_part_length())
1104
1100
      {
1117
1113
        else
1118
1114
        {
1119
1115
          my_error(ER_TOO_LONG_KEY,MYF(0),length);
1120
 
          return(true);
 
1116
          return true;
1121
1117
        }
1122
1118
      }
1123
1119
      key_part_info->length=(uint16_t) length;
1153
1149
          {
1154
1150
            my_message(ER_MULTIPLE_PRI_KEY, ER(ER_MULTIPLE_PRI_KEY),
1155
1151
                       MYF(0));
1156
 
            return(true);
 
1152
            return true;
1157
1153
          }
1158
1154
          static const char pkey_name[]= "PRIMARY";
1159
1155
          key_name=pkey_name;
1165
1161
        if (check_if_keyname_exists(key_name, *key_info_buffer, key_info))
1166
1162
        {
1167
1163
          my_error(ER_DUP_KEYNAME, MYF(0), key_name);
1168
 
          return(true);
 
1164
          return true;
1169
1165
        }
1170
1166
        key_info->name=(char*) key_name;
1171
1167
      }
1174
1170
    if (!key_info->name || check_column_name(key_info->name))
1175
1171
    {
1176
1172
      my_error(ER_WRONG_NAME_FOR_INDEX, MYF(0), key_info->name);
1177
 
      return(true);
 
1173
      return true;
1178
1174
    }
1179
1175
 
1180
1176
    if (!(key_info->flags & HA_NULL_PART_KEY))
1187
1183
    if (key_length > max_key_length)
1188
1184
    {
1189
1185
      my_error(ER_TOO_LONG_KEY,MYF(0),max_key_length);
1190
 
      return(true);
 
1186
      return true;
1191
1187
    }
1192
1188
 
1193
1189
    key_info++;
1197
1193
      (engine->check_flag(HTON_BIT_REQUIRE_PRIMARY_KEY)))
1198
1194
  {
1199
1195
    my_message(ER_REQUIRES_PRIMARY_KEY, ER(ER_REQUIRES_PRIMARY_KEY), MYF(0));
1200
 
    return(true);
 
1196
    return true;
1201
1197
  }
1202
1198
 
1203
1199
  if (auto_increment > 0)
1204
1200
  {
1205
1201
    my_message(ER_WRONG_AUTO_KEY, ER(ER_WRONG_AUTO_KEY), MYF(0));
1206
 
    return(true);
 
1202
    return true;
1207
1203
  }
1208
1204
  /* Sort keys in optimized order */
1209
1205
  internal::my_qsort((unsigned char*) *key_info_buffer, *key_count, sizeof(KeyInfo),
1236
1232
      */
1237
1233
 
1238
1234
      my_error(ER_INVALID_DEFAULT, MYF(0), sql_field->field_name);
1239
 
      return(true);
 
1235
      return true;
1240
1236
    }
1241
1237
  }
1242
1238
 
1243
 
  return(false);
 
1239
  return false;
1244
1240
}
1245
1241
 
1246
1242
/*
1930
1926
  }
1931
1927
 
1932
1928
  session->my_eof();
1933
 
  return(false);
 
1929
  return false;
1934
1930
 
1935
1931
err:
1936
1932
  transaction_services.autocommitOrRollback(*session, true);
1938
1934
  session->close_thread_tables();                       // Shouldn't be needed
1939
1935
  if (table)
1940
1936
    table->table=0;
1941
 
  return(true);
 
1937
  return true;
1942
1938
}
1943
1939
 
1944
1940
  /*