1
0
mirror of https://github.com/MariaDB/server.git synced 2025-08-01 03:47:19 +03:00

Generate warning in ha_delete_table() if files is missing in handler

mysql-test/r/myisam.result:
  Test of DROP TABLE when .MYI or .MYD is missing
mysql-test/r/ndb_autodiscover.result:
  Update test results
mysql-test/r/rpl_EE_error.result:
  Change test to conform with new handling of drop table when handler file is missing
mysql-test/t/myisam.test:
  Test of DROP TABLE when .MYI or .MYD is missing
mysql-test/t/rpl_EE_error.test:
  Change test to conform with new handling of drop table when handler file is missing
sql/handler.cc:
  Generate a warning in ha_delete_table() if we get an error from 'delete_table()'
sql/handler.h:
  More parameters to ha_delete_table() so that we can generate better error messages
sql/sql_table.cc:
  Generate warning in ha_delete_table()
This commit is contained in:
unknown
2005-02-21 20:41:48 +02:00
parent ac1852b403
commit 8cb6031dd7
8 changed files with 108 additions and 26 deletions

View File

@ -1027,15 +1027,24 @@ bool ha_flush_logs()
The .frm file will be deleted only if we return 0 or ENOENT
*/
int ha_delete_table(enum db_type table_type, const char *path)
int ha_delete_table(THD *thd, enum db_type table_type, const char *path,
const char *alias, bool generate_warning)
{
handler *file;
char tmp_path[FN_REFLEN];
int error;
TABLE dummy_table;
TABLE_SHARE dummy_share;
DBUG_ENTER("ha_delete_table");
bzero((char*) &dummy_table, sizeof(dummy_table));
bzero((char*) &dummy_share, sizeof(dummy_share));
dummy_table.s= &dummy_share;
/* DB_TYPE_UNKNOWN is used in ALTER TABLE when renaming only .frm files */
if (table_type == DB_TYPE_UNKNOWN ||
! (file=get_new_handler((TABLE*) 0, table_type)))
return ENOENT;
! (file=get_new_handler(&dummy_table, table_type)))
DBUG_RETURN(ENOENT);
if (lower_case_table_names == 2 && !(file->table_flags() & HA_FILE_BASED))
{
@ -1044,9 +1053,45 @@ int ha_delete_table(enum db_type table_type, const char *path)
my_casedn_str(files_charset_info, tmp_path);
path= tmp_path;
}
int error=file->delete_table(path);
if ((error= file->delete_table(path)) && generate_warning)
{
/*
Because file->print_error() use my_error() to generate the error message
we must store the error state in thd, reset it and restore it to
be able to get hold of the error message.
(We should in the future either rewrite handler::print_error() or make
a nice method of this.
*/
bool query_error= thd->query_error;
sp_rcontext *spcont= thd->spcont;
SELECT_LEX *current_select= thd->lex->current_select;
char buff[sizeof(thd->net.last_error)];
char new_error[sizeof(thd->net.last_error)];
int last_errno= thd->net.last_errno;
strmake(buff, thd->net.last_error, sizeof(buff)-1);
thd->query_error= 0;
thd->spcont= 0;
thd->lex->current_select= 0;
thd->net.last_error[0]= 0;
/* Fill up strucutures that print_error may need */
dummy_table.s->path= path;
dummy_table.alias= alias;
file->print_error(error, 0);
strmake(new_error, thd->net.last_error, sizeof(buff)-1);
/* restore thd */
thd->query_error= query_error;
thd->spcont= spcont;
thd->lex->current_select= current_select;
thd->net.last_errno= last_errno;
strmake(thd->net.last_error, buff, sizeof(buff)-1);
push_warning(thd, MYSQL_ERROR::WARN_LEVEL_ERROR, error, new_error);
}
delete file;
return error;
DBUG_RETURN(error);
}
/****************************************************************************
@ -1320,7 +1365,16 @@ ulonglong handler::get_auto_increment()
return nr;
}
/* Print error that we got from handler function */
/*
Print error that we got from handler function
NOTE:
In case of delete table it's only safe to use the following parts of
the 'table' structure:
table->s->path
table->alias
*/
void handler::print_error(int error, myf errflag)
{
@ -1529,7 +1583,7 @@ int handler::delete_table(const char *name)
break;
}
else
enoent_or_zero= 0;
enoent_or_zero= 0; // No error for ENOENT
error= enoent_or_zero;
}
return error;