mirror of
https://github.com/MariaDB/server.git
synced 2025-07-29 05:21:33 +03:00
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'
This commit is contained in:
@ -468,3 +468,44 @@ NULL
|
|||||||
select database();
|
select database();
|
||||||
database()
|
database()
|
||||||
NULL
|
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 without a database
|
||||||
connect (user4,localhost,mysqltest_1,,*NO-ONE*);
|
connect (user4,localhost,mysqltest_1,,*NO-ONE*);
|
||||||
select database();
|
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);
|
DBUG_RETURN(-1);
|
||||||
}
|
}
|
||||||
key_parts+=key->columns.elements;
|
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);
|
tmp=min(file->max_keys(), MAX_KEY);
|
||||||
if (key_count > tmp)
|
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;
|
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
|
return (char*) field_name; // Use fieldname
|
||||||
buff_end=strmake(buff,field_name,MAX_FIELD_NAME-4);
|
buff_end=strmake(buff,field_name,MAX_FIELD_NAME-4);
|
||||||
for (uint i=2 ; ; i++)
|
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)
|
if (key->type != Key::FOREIGN_KEY)
|
||||||
key_list.push_back(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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user