Commit b9793c54 authored by unknown's avatar unknown

fixed bug #856 'Naming a key "Primary" causes trouble'


mysql-test/r/create.result:
  added test for bug #856 'Naming a key "Primary" causes trouble'
mysql-test/t/create.test:
  added test for bug #856 'Naming a key "Primary" causes trouble'
parent 8b11f1c1
......@@ -468,3 +468,44 @@ NULL
select database();
database()
NULL
use test;
create table t1 (a int, index `primary` (a));
ERROR 42000: Incorrect index name 'primary'
create table t1 (a int, index `PRIMARY` (a));
ERROR 42000: Incorrect index name 'PRIMARY'
create table t1 (`primary` int, index(`primary`));
show create table t1;
Table Create Table
t1 CREATE TABLE `t1` (
`primary` int(11) default NULL,
KEY `primary_2` (`primary`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1
create table t2 (`PRIMARY` int, index(`PRIMARY`));
show create table t2;
Table Create Table
t2 CREATE TABLE `t2` (
`PRIMARY` int(11) default NULL,
KEY `PRIMARY_2` (`PRIMARY`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1
create table t3 (a int);
alter table t3 add index `primary` (a);
ERROR 42000: Incorrect index name 'primary'
alter table t3 add index `PRIMARY` (a);
ERROR 42000: Incorrect index name 'PRIMARY'
create table t4 (`primary` int);
alter table t4 add index(`primary`);
show create table t4;
Table Create Table
t4 CREATE TABLE `t4` (
`primary` int(11) default NULL,
KEY `primary_2` (`primary`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1
create table t5 (`PRIMARY` int);
alter table t5 add index(`PRIMARY`);
show create table t5;
Table Create Table
t5 CREATE TABLE `t5` (
`PRIMARY` int(11) default NULL,
KEY `PRIMARY_2` (`PRIMARY`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1
drop table t1, t2, t3, t4, t5;
......@@ -359,3 +359,33 @@ select database();
# Connect without a database
connect (user4,localhost,mysqltest_1,,*NO-ONE*);
select database();
#
# Test for Bug 856 'Naming a key "Primary" causes trouble'
#
use test;
--error 1280
create table t1 (a int, index `primary` (a));
--error 1280
create table t1 (a int, index `PRIMARY` (a));
create table t1 (`primary` int, index(`primary`));
show create table t1;
create table t2 (`PRIMARY` int, index(`PRIMARY`));
show create table t2;
create table t3 (a int);
--error 1280
alter table t3 add index `primary` (a);
--error 1280
alter table t3 add index `PRIMARY` (a);
create table t4 (`primary` int);
alter table t4 add index(`primary`);
show create table t4;
create table t5 (`PRIMARY` int);
alter table t5 add index(`PRIMARY`);
show create table t5;
drop table t1, t2, t3, t4, t5;
......@@ -639,6 +639,12 @@ int mysql_create_table(THD *thd,const char *db, const char *table_name,
DBUG_RETURN(-1);
}
key_parts+=key->columns.elements;
if (key->name && !tmp_table &&
!my_strcasecmp(system_charset_info,key->name,primary_key_name))
{
my_error(ER_WRONG_NAME_FOR_INDEX, MYF(0), key->name);
DBUG_RETURN(-1);
}
}
tmp=min(file->max_keys(), MAX_KEY);
if (key_count > tmp)
......@@ -1079,7 +1085,8 @@ make_unique_key_name(const char *field_name,KEY *start,KEY *end)
{
char buff[MAX_FIELD_NAME],*buff_end;
if (!check_if_keyname_exists(field_name,start,end))
if (!check_if_keyname_exists(field_name,start,end) &&
my_strcasecmp(system_charset_info,field_name,primary_key_name))
return (char*) field_name; // Use fieldname
buff_end=strmake(buff,field_name,MAX_FIELD_NAME-4);
for (uint i=2 ; ; i++)
......@@ -2403,6 +2410,12 @@ int mysql_alter_table(THD *thd,char *new_db, char *new_name,
{
if (key->type != Key::FOREIGN_KEY)
key_list.push_back(key);
if (key->name &&
!my_strcasecmp(system_charset_info,key->name,primary_key_name))
{
my_error(ER_WRONG_NAME_FOR_INDEX, MYF(0), key->name);
DBUG_RETURN(-1);
}
}
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment