mirror of
https://github.com/MariaDB/server.git
synced 2025-01-18 04:53:01 +01:00
Merge vvagin@bk-internal.mysql.com:/home/bk/mysql-4.1
into eagle.mysql.r18.ru:/home/vva/work/BUG_856/mysql-4.1
This commit is contained in:
commit
283d455711
3 changed files with 85 additions and 1 deletions
|
@ -482,3 +482,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;
|
||||
|
|
|
@ -368,3 +368,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;
|
||||
|
|
|
@ -687,6 +687,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)
|
||||
|
@ -1127,7 +1133,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++)
|
||||
|
@ -2451,6 +2458,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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue