Commit 4af93110 authored by jyang's avatar jyang

branches/5.1: Block creating table with column name conflicting

with Innodb reserved key words. (Bug #44369) rb://151 approved
by Sunny Bains.
parent 6d890859
...@@ -1268,7 +1268,7 @@ dict_col_name_is_reserved( ...@@ -1268,7 +1268,7 @@ dict_col_name_is_reserved(
ulint i; ulint i;
for (i = 0; i < UT_ARR_SIZE(reserved_names); i++) { for (i = 0; i < UT_ARR_SIZE(reserved_names); i++) {
if (strcmp(name, reserved_names[i]) == 0) { if (innobase_strcasecmp(name, reserved_names[i]) == 0) {
return(TRUE); return(TRUE);
} }
......
...@@ -5063,6 +5063,27 @@ create_table_def( ...@@ -5063,6 +5063,27 @@ create_table_def(
} }
} }
/* First check whether the column to be added has a
system reserved name. */
if (dict_col_name_is_reserved(field->field_name)){
push_warning_printf(
(THD *)trx->mysql_thd,
MYSQL_ERROR::WARN_LEVEL_ERROR,
ER_CANT_CREATE_TABLE,
"Error creating table '%s' with "
"column name '%s'. '%s' is a "
"reserved name. Please try to "
"re-create the table with a "
"different column name.",
table->name, (char*) field->field_name,
(char*) field->field_name);
dict_mem_table_free(table);
trx_commit_for_mysql(trx);
DBUG_RETURN(DB_ERROR);
}
dict_mem_table_add_col(table, table->heap, dict_mem_table_add_col(table, table->heap,
(char*) field->field_name, (char*) field->field_name,
col_type, col_type,
......
SET storage_engine=InnoDB;
create table bug44369 (DB_ROW_ID int) engine innodb;
ERROR HY000: Can't create table 'test.bug44369' (errno: 11)
create table bug44369 (db_row_id int) engine innodb;
ERROR HY000: Can't create table 'test.bug44369' (errno: 11)
show errors;
Level Code Message
Error 1005 Error creating table 'test/bug44369' with column name 'db_row_id'. 'db_row_id' is a reserved name. Please try to re-create the table with a different column name.
Error 1005 Can't create table 'test.bug44369' (errno: 11)
create table bug44369 (db_TRX_Id int) engine innodb;
ERROR HY000: Can't create table 'test.bug44369' (errno: 11)
show errors;
Level Code Message
Error 1005 Error creating table 'test/bug44369' with column name 'db_TRX_Id'. 'db_TRX_Id' is a reserved name. Please try to re-create the table with a different column name.
Error 1005 Can't create table 'test.bug44369' (errno: 11)
# This is the test for bug 44369. We should
# block table creation with columns match
# some innodb internal reserved key words,
# both case sensitively and insensitely.
--source include/have_innodb.inc
SET storage_engine=InnoDB;
# This create table operation should fail.
--error ER_CANT_CREATE_TABLE
create table bug44369 (DB_ROW_ID int) engine innodb;
# This create should fail as well
--error ER_CANT_CREATE_TABLE
create table bug44369 (db_row_id int) engine innodb;
show errors;
--error ER_CANT_CREATE_TABLE
create table bug44369 (db_TRX_Id int) engine innodb;
show errors;
...@@ -1827,18 +1827,6 @@ row_create_table_for_mysql( ...@@ -1827,18 +1827,6 @@ row_create_table_for_mysql(
return(DB_ERROR); return(DB_ERROR);
} }
/* Check that no reserved column names are used. */
for (i = 0; i < dict_table_get_n_user_cols(table); i++) {
if (dict_col_name_is_reserved(
dict_table_get_col_name(table, i))) {
dict_mem_table_free(table);
trx_commit_for_mysql(trx);
return(DB_ERROR);
}
}
trx_start_if_not_started(trx); trx_start_if_not_started(trx);
/* The table name is prefixed with the database name and a '/'. /* The table name is prefixed with the database name and a '/'.
......
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