summaryrefslogtreecommitdiff
path: root/sql/sql_table.cc
diff options
context:
space:
mode:
authorMichael Widenius <monty@askmonty.org>2011-05-16 14:05:45 +0300
committerMichael Widenius <monty@askmonty.org>2011-05-16 14:05:45 +0300
commitf458e198c0bea67c6a3787738108bbfb139639bd (patch)
treee01d8c096a63bacfb5895de6e55d011d666e9d38 /sql/sql_table.cc
parent8c5e18c9cfde61197a9f653efa08450ae9a6ce0a (diff)
parent19f0d6b2d9930f83688943b8f98a8b7397584df9 (diff)
downloadmariadb-git-f458e198c0bea67c6a3787738108bbfb139639bd.tar.gz
Merge with 5.2
Diffstat (limited to 'sql/sql_table.cc')
-rw-r--r--sql/sql_table.cc84
1 files changed, 75 insertions, 9 deletions
diff --git a/sql/sql_table.cc b/sql/sql_table.cc
index 222991b1ed2..42f2abeca1e 100644
--- a/sql/sql_table.cc
+++ b/sql/sql_table.cc
@@ -3659,6 +3659,68 @@ static inline int write_create_table_bin_log(THD *thd,
}
+/**
+ Check that there is no frm file for given table
+
+ @param old_path path to the old frm file
+ @param path path to the frm file in new encoding
+ @param db database name
+ @param table_name table name
+ @param alias table name for error message (for new encoding)
+ @param issue_error should we issue error messages
+
+ @retval FALSE there is no frm file
+ @retval TRUE there is frm file
+*/
+
+bool check_table_file_presence(char *old_path,
+ char *path,
+ const char *db,
+ const char *table_name,
+ const char *alias,
+ bool issue_error)
+{
+ if (!access(path,F_OK))
+ {
+ if (issue_error)
+ my_error(ER_TABLE_EXISTS_ERROR,MYF(0),alias);
+ return TRUE;
+ }
+ {
+ /*
+ Check if file of the table in 5.0 file name encoding exists.
+
+ Except case when it is the same table.
+ */
+ char tbl50[FN_REFLEN];
+#ifdef _WIN32
+ if (check_if_legal_tablename(table_name) != 0)
+ {
+ /*
+ Check for reserved device names for which access() returns 0
+ (CON, AUX etc).
+ */
+ return FALSE;
+ }
+#endif
+ strxmov(tbl50, mysql_data_home, "/", db, "/", table_name, NullS);
+ fn_format(tbl50, tbl50, "", reg_ext, MY_UNPACK_FILENAME);
+ if (!access(tbl50, F_OK) &&
+ (old_path == NULL ||
+ strcmp(old_path, tbl50) != 0))
+ {
+ if (issue_error)
+ {
+ strxmov(tbl50, MYSQL50_TABLE_NAME_PREFIX, table_name, NullS);
+ my_error(ER_TABLE_EXISTS_ERROR, MYF(0), tbl50);
+ }
+ return TRUE;
+ }
+ }
+ return FALSE;
+}
+
+
/*
Create a table
@@ -3944,11 +4006,12 @@ bool mysql_create_table_no_lock(THD *thd,
VOID(pthread_mutex_lock(&LOCK_open));
if (!internal_tmp_table && !(create_info->options & HA_LEX_CREATE_TMP_TABLE))
{
- if (!access(path,F_OK))
+ if (check_table_file_presence(NULL, path, db, table_name, table_name,
+ !(create_info->options &
+ HA_LEX_CREATE_IF_NOT_EXISTS)))
{
if (create_info->options & HA_LEX_CREATE_IF_NOT_EXISTS)
goto warn;
- my_error(ER_TABLE_EXISTS_ERROR,MYF(0),table_name);
goto unlock_and_end;
}
/*
@@ -5856,10 +5919,10 @@ compare_tables(TABLE *table,
DBUG_RETURN(0);
}
- if ((create_info->fileds_option_struct=
- (void**)thd->calloc(sizeof(void*) * table->s->fields)) == NULL ||
- (create_info->indexes_option_struct=
- (void**)thd->calloc(sizeof(void*) * table->s->keys)) == NULL)
+ if ((create_info->fields_option_struct= (ha_field_option_struct**)
+ thd->calloc(sizeof(void*) * table->s->fields)) == NULL ||
+ (create_info->indexes_option_struct= (ha_index_option_struct**)
+ thd->calloc(sizeof(void*) * table->s->keys)) == NULL)
DBUG_RETURN(1);
/*
@@ -5880,7 +5943,7 @@ compare_tables(TABLE *table,
tmp_new_field= tmp_new_field_it++)
{
DBUG_ASSERT(i < table->s->fields);
- create_info->fileds_option_struct[i]= tmp_new_field->option_struct;
+ create_info->fields_option_struct[i]= tmp_new_field->option_struct;
/* reset common markers of how field changed */
field->flags&= ~(FIELD_IS_RENAMED | FIELD_IN_ADD_INDEX);
@@ -6607,6 +6670,7 @@ bool mysql_alter_table(THD *thd,char *new_db, char *new_name,
TABLE *table, *new_table= 0, *name_lock= 0;
int error= 0;
char tmp_name[80],old_name[32],new_name_buff[FN_REFLEN + 1];
+ char old_name_buff[FN_REFLEN + 1];
char new_alias_buff[FN_REFLEN], *table_name, *db, *new_alias, *alias;
char index_file[FN_REFLEN], data_file[FN_REFLEN];
char path[FN_REFLEN + 1];
@@ -6836,10 +6900,12 @@ view_err:
build_table_filename(new_name_buff, sizeof(new_name_buff) - 1,
new_db, new_name_buff, reg_ext, 0);
- if (!access(new_name_buff, F_OK))
+ build_table_filename(old_name_buff, sizeof(old_name_buff) - 1,
+ db, table_name, reg_ext, 0);
+ if (check_table_file_presence(old_name_buff, new_name_buff, new_db,
+ new_name, new_alias, TRUE))
{
/* Table will be closed in do_command() */
- my_error(ER_TABLE_EXISTS_ERROR, MYF(0), new_alias);
goto err;
}
}