Below is the list of changes that have just been committed into a local
6.1 repository of dlenev. When dlenev does a push these changes
will be propagated to the main repository and, within 24 hours after the
push, to the public repository.
For information on how to access the public repository
see http://dev.mysql.com/doc/mysql/en/installing-source-tree.html
ChangeSet@stripped, 2008-04-18 23:00:57+04:00, dlenev@stripped +7 -0
Fix for for bug #35524 "Foreign keys: constraint name can be incorrect".
In --foreign-key-all-engines mode one was able to create foreign key
constraints with empty name or name ending with space.
This happened because we used check_identified_name() function instead
of check_table_name() for checking of constraint names. The latter does
all checks done by the former but also covers case with empty name and
name ending with space. This fix simply uses correct function for
checking of constraint names.
mysql-test/r/foreign_key_all_engines.result@stripped, 2008-04-18 23:00:49+04:00, dlenev@stripped +14 -2
Added test case for bug #35524 "Foreign keys: constraint name can be
incorrect". Adjusted test case to the fact that now we return
ER_FK_CONSTRAINT_NAME_ILLEGAL error in all cases when constraint name
is invalid. This is consistent with behavior for table names.
mysql-test/t/foreign_key_all_engines.test@stripped, 2008-04-18 23:00:49+04:00, dlenev@stripped +19 -2
Added test case for bug #35524 "Foreign keys: constraint name can be
incorrect". Adjusted test case to the fact that now we return
ER_FK_CONSTRAINT_NAME_ILLEGAL error in all cases when constraint name
is invalid. This is consistent with behavior for table names.
sql/fk_dd.cc@stripped, 2008-04-18 23:00:49+04:00, dlenev@stripped +4 -1
By using check_table_name() instead of check_identified_name() for checking
of constraint name validity we ensure that constraint name is not empty
and does not end with space. Also now we return ER_FK_CONSTRAINT_NAME_ILLEGAL
in all cases when constraint name is invalid. This is consistent with
behavior for table names.
sql/mysql_priv.h@stripped, 2008-04-18 23:00:49+04:00, dlenev@stripped +8 -1
Changed check_table_name() to accept pointer to LEX_STRING instead of
(char *, length) pair. This allows to avoid creation of temporary
LEX_STRING object in most of cases when this function is used. Also
added wrapper function to support old signature.
sql/sql_parse.cc@stripped, 2008-04-18 23:00:50+04:00, dlenev@stripped +1 -1
check_table_name() now takes pointer to LEX_STRING.
sql/sql_yacc.yy@stripped, 2008-04-18 23:00:50+04:00, dlenev@stripped +1 -1
check_table_name() now takes pointer to LEX_STRING.
sql/table.cc@stripped, 2008-04-18 23:00:50+04:00, dlenev@stripped +4 -6
Changed check_table_name() to accept pointer to LEX_STRING instead of
(char *, length) pair. This allows to avoid creation of temporary
LEX_STRING object in most of cases when this function is used. Also
added wrapper function to support old signature.
diff -Nrup a/mysql-test/r/foreign_key_all_engines.result b/mysql-test/r/foreign_key_all_engines.result
--- a/mysql-test/r/foreign_key_all_engines.result 2008-03-21 12:42:51 +03:00
+++ b/mysql-test/r/foreign_key_all_engines.result 2008-04-18 23:00:49 +04:00
@@ -234,13 +234,25 @@ ERROR 42000: Foreign key error: Constrai
drop table t2;
create table t1 (a int primary key);
create table t2 (fk int
+constraint ``
+references t1 (a));
+ERROR 42000: Foreign key error: Constraint '': Illegal constraint name
+create table t2 (fk int
+constraint ` `
+ references t1 (a));
+ERROR 42000: Foreign key error: Constraint ' ': Illegal constraint name
+create table t2 (fk int
+constraint `c `
+ references t1 (a));
+ERROR 42000: Foreign key error: Constraint 'c ': Illegal constraint name
+create table t2 (fk int
constraint CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC
references t1 (a));
-ERROR 42000: Identifier name 'CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC' is too long
+ERROR 42000: Foreign key error: Constraint 'CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC': Illegal constraint name
create table t2 (fk int,
constraint CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC
foreign key (fk) references t1 (a));
-ERROR 42000: Identifier name 'CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC' is too long
+ERROR 42000: Foreign key error: Constraint 'CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC': Illegal constraint name
create table t2 (fk int constraint `PRIMARY` references t1 (a));
ERROR 42000: Foreign key error: Constraint 'PRIMARY': Illegal constraint name
create table t2 (fk int,
diff -Nrup a/mysql-test/t/foreign_key_all_engines.test b/mysql-test/t/foreign_key_all_engines.test
--- a/mysql-test/t/foreign_key_all_engines.test 2008-03-21 12:42:51 +03:00
+++ b/mysql-test/t/foreign_key_all_engines.test 2008-04-18 23:00:49 +04:00
@@ -135,11 +135,28 @@ drop table t2;
create table t1 (a int primary key);
# First let us check that some basic limitations for constraint
# names are checked.
---error ER_TOO_LONG_IDENT
+#
+# Also contains test case for bug #35524 "Foreign keys: constraint
+# name can be incorrect" (the problem was that we allowed empty
+# names or names ending with space).
+#
+--error ER_FK_CONSTRAINT_NAME_ILLEGAL
+create table t2 (fk int
+ constraint ``
+ references t1 (a));
+--error ER_FK_CONSTRAINT_NAME_ILLEGAL
+create table t2 (fk int
+ constraint ` `
+ references t1 (a));
+--error ER_FK_CONSTRAINT_NAME_ILLEGAL
+create table t2 (fk int
+ constraint `c `
+ references t1 (a));
+--error ER_FK_CONSTRAINT_NAME_ILLEGAL
create table t2 (fk int
constraint CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC
references t1 (a));
---error ER_TOO_LONG_IDENT
+--error ER_FK_CONSTRAINT_NAME_ILLEGAL
create table t2 (fk int,
constraint CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC
foreign key (fk) references t1 (a));
diff -Nrup a/sql/fk_dd.cc b/sql/fk_dd.cc
--- a/sql/fk_dd.cc 2008-03-20 19:46:47 +03:00
+++ b/sql/fk_dd.cc 2008-04-18 23:00:49 +04:00
@@ -837,8 +837,11 @@ bool fk_check_constraint_added(Foreign_k
DBUG_RETURN(TRUE);
}
- if (check_identifier_name(&fkey->name, ER_TOO_LONG_IDENT))
+ if (check_table_name(&fkey->name))
+ {
+ my_error(ER_FK_CONSTRAINT_NAME_ILLEGAL, MYF(0), fkey->name.str);
DBUG_RETURN(TRUE);
+ }
/*
All the primary-key constraints are named 'PRIMARY' so we
diff -Nrup a/sql/mysql_priv.h b/sql/mysql_priv.h
--- a/sql/mysql_priv.h 2008-03-21 13:55:40 +03:00
+++ b/sql/mysql_priv.h 2008-04-18 23:00:49 +04:00
@@ -2256,7 +2256,14 @@ void update_create_info_from_table(HA_CR
int rename_file_ext(const char * from,const char * to,const char * ext);
bool check_db_name(LEX_STRING *db);
bool check_column_name(const char *name);
-bool check_table_name(const char *name, uint length);
+bool check_table_name(LEX_STRING *name);
+inline bool check_table_name(char *name, uint length)
+{
+ LEX_STRING table_name;
+ table_name.str= name;
+ table_name.length= length;
+ return check_table_name(&table_name);
+}
char *get_field(MEM_ROOT *mem, Field *field);
bool get_field(MEM_ROOT *mem, Field *field, class String *res);
int wild_case_compare(CHARSET_INFO *cs, const char *str,const char *wildstr);
diff -Nrup a/sql/sql_parse.cc b/sql/sql_parse.cc
--- a/sql/sql_parse.cc 2008-03-18 13:54:34 +03:00
+++ b/sql/sql_parse.cc 2008-04-18 23:00:50 +04:00
@@ -6008,7 +6008,7 @@ TABLE_LIST *st_select_lex::add_table_to_
DBUG_RETURN(0); // End of memory
alias_str= alias ? alias->str : table->table.str;
if (!test(table_options & TL_OPTION_ALIAS) &&
- check_table_name(table->table.str, table->table.length))
+ check_table_name(&table->table))
{
my_error(ER_WRONG_TABLE_NAME, MYF(0), table->table.str);
DBUG_RETURN(0);
diff -Nrup a/sql/sql_yacc.yy b/sql/sql_yacc.yy
--- a/sql/sql_yacc.yy 2008-03-21 13:55:42 +03:00
+++ b/sql/sql_yacc.yy 2008-04-18 23:00:50 +04:00
@@ -6140,7 +6140,7 @@ alter_list_item:
{
MYSQL_YYABORT;
}
- if (check_table_name($3->table.str,$3->table.length) ||
+ if (check_table_name(&($3->table)) ||
$3->db.str && check_db_name(&$3->db))
{
my_error(ER_WRONG_TABLE_NAME, MYF(0), $3->table.str);
diff -Nrup a/sql/table.cc b/sql/table.cc
--- a/sql/table.cc 2008-03-21 13:55:43 +03:00
+++ b/sql/table.cc 2008-04-18 23:00:50 +04:00
@@ -2729,14 +2729,12 @@ bool check_db_name(LEX_STRING *org_name)
*/
-bool check_table_name(const char *name, uint length)
+bool check_table_name(LEX_STRING *ident)
{
- if (!length || length > NAME_LEN || name[length - 1] == ' ')
+ if (!ident->length || ident->length > NAME_LEN ||
+ ident->str[ident->length - 1] == ' ')
return 1;
- LEX_STRING ident;
- ident.str= (char*) name;
- ident.length= length;
- return check_identifier_name(&ident);
+ return check_identifier_name(ident);
}