~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/sql_table.cc

  • Committer: Brian Aker
  • Date: 2011-09-26 15:02:54 UTC
  • mto: This revision was merged to the branch mainline in revision 2427.
  • Revision ID: brian@tangent.org-20110926150254-zpi0gifzexj2crdt
Wrap thread specfic

Show diffs side-by-side

added added

removed removed

Lines of Context:
73
73
    apply it to the table.
74
74
  */
75
75
  if (not create_info->default_table_charset)
76
 
    create_info->default_table_charset= plugin::StorageEngine::getSchemaCollation(identifier::Schema(str_ref(db)));
 
76
    create_info->default_table_charset= plugin::StorageEngine::getSchemaCollation(identifier::Schema(db));
77
77
}
78
78
 
79
79
/*
685
685
    /* Check if we have used the same field name before */
686
686
    for (dup_no=0; (dup_field=it2++) != sql_field; dup_no++)
687
687
    {
688
 
      if (system_charset_info->strcasecmp(sql_field->field_name, dup_field->field_name) == 0)
 
688
      if (my_strcasecmp(system_charset_info,
 
689
                        sql_field->field_name,
 
690
                        dup_field->field_name) == 0)
689
691
      {
690
692
        /*
691
693
          If this was a CREATE ... SELECT statement, accept a field
804
806
      Foreign_key *fk_key= (Foreign_key*) key;
805
807
 
806
808
      add_foreign_key_to_table_message(&create_proto,
807
 
                                       fk_key->name.data(),
 
809
                                       fk_key->name.str,
808
810
                                       fk_key->columns,
809
811
                                       fk_key->ref_table,
810
812
                                       fk_key->ref_columns,
816
818
          fk_key->ref_columns.size() != fk_key->columns.size())
817
819
      {
818
820
        my_error(ER_WRONG_FK_DEF, MYF(0),
819
 
                 (fk_key->name.data() ? fk_key->name.data() : "foreign key without name"),
 
821
                 (fk_key->name.str ? fk_key->name.str :
 
822
                                     "foreign key without name"),
820
823
                 ER(ER_KEY_REF_DO_NOT_MATCH_TABLE_REF));
821
824
        return true;
822
825
      }
829
832
      my_error(ER_TOO_MANY_KEY_PARTS,MYF(0),tmp);
830
833
      return true;
831
834
    }
832
 
    if (check_identifier_name(key->name, ER_TOO_LONG_IDENT))
 
835
    if (check_identifier_name(&key->name, ER_TOO_LONG_IDENT))
833
836
      return true;
834
837
    key_iterator2= alter_info->key_list.begin();
835
838
    if (key->type != Key::FOREIGN_KEY)
842
845
          Then we do not need the generated shorter key.
843
846
        */
844
847
        if ((key2->type != Key::FOREIGN_KEY &&
845
 
             key2->name.data() != ignore_key &&
 
848
             key2->name.str != ignore_key &&
846
849
             !foreign_key_prefix(key, key2)))
847
850
        {
848
851
          /* @todo issue warning message */
850
853
          if (!key2->generated ||
851
854
              (key->generated && key->columns.size() <
852
855
               key2->columns.size()))
853
 
            key->name.assign(ignore_key, 1);
 
856
            key->name.str= ignore_key;
854
857
          else
855
858
          {
856
 
            key2->name.assign(ignore_key, 1);
 
859
            key2->name.str= ignore_key;
857
860
            key_parts-= key2->columns.size();
858
861
            (*key_count)--;
859
862
          }
861
864
        }
862
865
      }
863
866
    }
864
 
    if (key->name.data() != ignore_key)
 
867
    if (key->name.str != ignore_key)
865
868
      key_parts+=key->columns.size();
866
869
    else
867
870
      (*key_count)--;
868
 
    if (key->name.data() && !tmp_table && (key->type != Key::PRIMARY) && is_primary_key(key->name.data()))
 
871
    if (key->name.str && !tmp_table && (key->type != Key::PRIMARY) && is_primary_key(key->name.str))
869
872
    {
870
 
      my_error(ER_WRONG_NAME_FOR_INDEX, MYF(0), key->name.data());
 
873
      my_error(ER_WRONG_NAME_FOR_INDEX, MYF(0), key->name.str);
871
874
      return true;
872
875
    }
873
876
  }
888
891
    uint32_t key_length=0;
889
892
    Key_part_spec *column;
890
893
 
891
 
    if (key->name.data() == ignore_key)
 
894
    if (key->name.str == ignore_key)
892
895
    {
893
896
      /* ignore redundant keys */
894
897
      do
895
898
        key=key_iterator++;
896
 
      while (key && key->name.data() == ignore_key);
 
899
      while (key && key->name.str == ignore_key);
897
900
      if (!key)
898
901
        break;
899
902
    }
918
921
    key_info->algorithm= key->key_create_info.algorithm;
919
922
 
920
923
    uint32_t tmp_len= system_charset_info->cset->charpos(system_charset_info,
921
 
                                           key->key_create_info.comment.begin(),
922
 
                                           key->key_create_info.comment.end(),
 
924
                                           key->key_create_info.comment.str,
 
925
                                           key->key_create_info.comment.str +
 
926
                                           key->key_create_info.comment.length,
923
927
                                           INDEX_COMMENT_MAXLEN);
924
928
 
925
 
    if (tmp_len < key->key_create_info.comment.size())
 
929
    if (tmp_len < key->key_create_info.comment.length)
926
930
    {
927
 
      my_error(ER_WRONG_STRING_LENGTH, MYF(0), key->key_create_info.comment.data(), "INDEX COMMENT", (uint32_t) INDEX_COMMENT_MAXLEN);
 
931
      my_error(ER_WRONG_STRING_LENGTH, MYF(0),
 
932
               key->key_create_info.comment.str,"INDEX COMMENT",
 
933
               (uint32_t) INDEX_COMMENT_MAXLEN);
928
934
      return -1;
929
935
    }
930
936
 
931
 
    key_info->comment.assign(key_info->comment.data(), key->key_create_info.comment.size());
932
 
    if (key_info->comment.size() > 0)
 
937
    key_info->comment.length= key->key_create_info.comment.length;
 
938
    if (key_info->comment.length > 0)
933
939
    {
934
940
      key_info->flags|= HA_USES_COMMENT;
935
 
      key_info->comment.assign(key->key_create_info.comment.data(), key_info->comment.size()); // weird
 
941
      key_info->comment.str= key->key_create_info.comment.str;
936
942
    }
937
943
 
938
944
    message::Table::Field *protofield= NULL;
948
954
      it= alter_info->create_list.begin();
949
955
      field=0;
950
956
      while ((sql_field=it++) && ++proto_field_nr &&
951
 
             system_charset_info->strcasecmp(column->field_name.data(), sql_field->field_name))
 
957
             my_strcasecmp(system_charset_info,
 
958
                           column->field_name.str,
 
959
                           sql_field->field_name))
952
960
      {
953
 
        field++;
 
961
        field++;
954
962
      }
955
963
 
956
964
      if (!sql_field)
957
965
      {
958
 
        my_error(ER_KEY_COLUMN_DOES_NOT_EXITS, MYF(0), column->field_name.data());
 
966
        my_error(ER_KEY_COLUMN_DOES_NOT_EXITS, MYF(0), column->field_name.str);
959
967
        return true;
960
968
      }
961
969
 
962
970
      while ((dup_column= cols2++) != column)
963
971
      {
964
 
        if (!system_charset_info->strcasecmp(column->field_name.data(), dup_column->field_name.data()))
 
972
        if (!my_strcasecmp(system_charset_info,
 
973
                           column->field_name.str, dup_column->field_name.str))
965
974
        {
966
975
          my_printf_error(ER_DUP_FIELDNAME,
967
976
                          ER(ER_DUP_FIELDNAME),MYF(0),
968
 
                          column->field_name.data());
 
977
                          column->field_name.str);
969
978
          return true;
970
979
        }
971
980
      }
981
990
        {
982
991
          if (! (engine->check_flag(HTON_BIT_CAN_INDEX_BLOBS)))
983
992
          {
984
 
            my_error(ER_BLOB_USED_AS_KEY, MYF(0), column->field_name.data());
 
993
            my_error(ER_BLOB_USED_AS_KEY, MYF(0), column->field_name.str);
985
994
            return true;
986
995
          }
987
996
          if (! column->length)
988
997
          {
989
 
            my_error(ER_BLOB_KEY_WITHOUT_LENGTH, MYF(0), column->field_name.data());
 
998
            my_error(ER_BLOB_KEY_WITHOUT_LENGTH, MYF(0), column->field_name.str);
990
999
            return true;
991
1000
          }
992
1001
        }
1012
1021
            key_info->flags|= HA_NULL_PART_KEY;
1013
1022
            if (! (engine->check_flag(HTON_BIT_NULL_IN_KEY)))
1014
1023
            {
1015
 
              my_error(ER_NULL_COLUMN_IN_INDEX, MYF(0), column->field_name.data());
 
1024
              my_error(ER_NULL_COLUMN_IN_INDEX, MYF(0), column->field_name.str);
1016
1025
              return true;
1017
1026
            }
1018
1027
          }
1069
1078
      }
1070
1079
      else if (length == 0)
1071
1080
      {
1072
 
        my_error(ER_WRONG_KEY_COLUMN, MYF(0), column->field_name.data());
 
1081
        my_error(ER_WRONG_KEY_COLUMN, MYF(0), column->field_name.str);
1073
1082
          return true;
1074
1083
      }
1075
1084
      if (length > engine->max_key_part_length())
1131
1140
          key_name=pkey_name;
1132
1141
          primary_key=1;
1133
1142
        }
1134
 
        else if (!(key_name= key->name.data()))
 
1143
        else if (!(key_name= key->name.str))
1135
1144
          key_name=make_unique_key_name(sql_field->field_name,
1136
1145
                                        *key_info_buffer, key_info);
1137
1146
        if (check_if_keyname_exists(key_name, *key_info_buffer, key_info))
1526
1535
static bool
1527
1536
check_if_keyname_exists(const char *name, KeyInfo *start, KeyInfo *end)
1528
1537
{
1529
 
  for (KeyInfo *key= start; key != end; key++)
1530
 
  {
1531
 
    if (!system_charset_info->strcasecmp(name, key->name))
 
1538
  for (KeyInfo *key=start ; key != end ; key++)
 
1539
    if (!my_strcasecmp(system_charset_info,name,key->name))
1532
1540
      return 1;
1533
 
  }
1534
1541
  return 0;
1535
1542
}
1536
1543
 
1802
1809
      {
1803
1810
        session->getClient()->store(table_name.c_str());
1804
1811
        session->getClient()->store(operator_name);
1805
 
        session->getClient()->store(warning_level_names[err->level].data(), warning_level_names[err->level].size());
 
1812
        session->getClient()->store(warning_level_names[err->level].str, warning_level_names[err->level].length);
1806
1813
        session->getClient()->store(err->msg);
1807
1814
        if (session->getClient()->flush())
1808
1815
          goto err;