Commit 2c5d427c authored by unknown's avatar unknown

Fix for bugs #5859 "DROP TABLE does not drop triggers" and

#6559 "DROP DATABASE forgets to drop triggers".

If we drop table we should also drop all triggers associated with it.
To do this we have to check for existence of .TRG file when we are 
dropping table and delete it too.


mysql-test/r/trigger.result:
  Added tests for bugs #5859 "DROP TABLE does not drop triggers"
  and #6559 "DROP DATABASE forgets to drop triggers".
mysql-test/t/trigger.test:
  Added tests for bugs #5859 "DROP TABLE does not drop triggers"
  and #6559 "DROP DATABASE forgets to drop triggers".
sql/handler.cc:
  Added .TRG to the list of known extensions of files associated with 
  tables.
sql/mysql_priv.h:
  Added declaration of constant holding extension for trigger files.
sql/sql_table.cc:
  mysql_rm_table_part2():
    If we drop table we should also drop all triggers associated with it.
    To do this we have to check for existence of .TRG file and delete it
    (until the moment when we will store trigger definitions in the same
     .FRM file as table description).
sql/sql_trigger.cc:
  Made constant holding extension for trigger files externally visible.
parent 7ff83a3f
drop table if exists t1, t2; drop table if exists t1, t2;
drop view if exists v1; drop view if exists v1;
drop database if exists mysqltest;
create table t1 (i int); create table t1 (i int);
create trigger trg before insert on t1 for each row set @a:=1; create trigger trg before insert on t1 for each row set @a:=1;
set @a:=0; set @a:=0;
...@@ -190,3 +191,18 @@ select @del_before, @del_after; ...@@ -190,3 +191,18 @@ select @del_before, @del_after;
drop trigger t1.trg1; drop trigger t1.trg1;
drop trigger t1.trg2; drop trigger t1.trg2;
drop table t1; drop table t1;
create table t1 (a int);
create trigger trg1 before insert on t1 for each row set new.a= 10;
drop table t1;
create table t1 (a int);
insert into t1 values ();
select * from t1;
a
NULL
drop table t1;
create database mysqltest;
use mysqltest;
create table t1 (i int);
create trigger trg1 before insert on t1 for each row set @a:= 1;
drop database mysqltest;
use test;
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
--disable_warnings --disable_warnings
drop table if exists t1, t2; drop table if exists t1, t2;
drop view if exists v1; drop view if exists v1;
drop database if exists mysqltest;
--enable_warnings --enable_warnings
create table t1 (i int); create table t1 (i int);
...@@ -229,3 +230,22 @@ select @del_before, @del_after; ...@@ -229,3 +230,22 @@ select @del_before, @del_after;
drop trigger t1.trg1; drop trigger t1.trg1;
drop trigger t1.trg2; drop trigger t1.trg2;
drop table t1; drop table t1;
# Test for bug #5859 "DROP TABLE does not drop triggers". Trigger should not
# magically reappear when we recreate dropped table.
create table t1 (a int);
create trigger trg1 before insert on t1 for each row set new.a= 10;
drop table t1;
create table t1 (a int);
insert into t1 values ();
select * from t1;
drop table t1;
# Test for bug #6559 "DROP DATABASE forgets to drop triggers".
create database mysqltest;
use mysqltest;
create table t1 (i int);
create trigger trg1 before insert on t1 for each row set @a:= 1;
# This should succeed
drop database mysqltest;
use test;
...@@ -2366,6 +2366,7 @@ TYPELIB *ha_known_exts(void) ...@@ -2366,6 +2366,7 @@ TYPELIB *ha_known_exts(void)
known_extensions_id= mysys_usage_id; known_extensions_id= mysys_usage_id;
found_exts.push_back((char*) ".db"); found_exts.push_back((char*) ".db");
found_exts.push_back((char*) triggers_file_ext);
for (types= sys_table_types; types->type; types++) for (types= sys_table_types; types->type; types++)
{ {
if (*types->value == SHOW_OPTION_YES) if (*types->value == SHOW_OPTION_YES)
......
...@@ -1044,6 +1044,7 @@ extern const char *first_keyword, *my_localhost, *delayed_user, *binary_keyword; ...@@ -1044,6 +1044,7 @@ extern const char *first_keyword, *my_localhost, *delayed_user, *binary_keyword;
extern const char **errmesg; /* Error messages */ extern const char **errmesg; /* Error messages */
extern const char *myisam_recover_options_str; extern const char *myisam_recover_options_str;
extern const char *in_left_expr_name, *in_additional_cond; extern const char *in_left_expr_name, *in_additional_cond;
extern const char * const triggers_file_ext;
extern Eq_creator eq_creator; extern Eq_creator eq_creator;
extern Ne_creator ne_creator; extern Ne_creator ne_creator;
extern Gt_creator gt_creator; extern Gt_creator gt_creator;
......
...@@ -257,7 +257,19 @@ int mysql_rm_table_part2(THD *thd, TABLE_LIST *tables, bool if_exists, ...@@ -257,7 +257,19 @@ int mysql_rm_table_part2(THD *thd, TABLE_LIST *tables, bool if_exists,
/* Delete the table definition file */ /* Delete the table definition file */
strmov(end,reg_ext); strmov(end,reg_ext);
if (!(new_error=my_delete(path,MYF(MY_WME)))) if (!(new_error=my_delete(path,MYF(MY_WME))))
{
some_tables_deleted=1; some_tables_deleted=1;
/*
Destroy triggers for this table if there are any.
We won't need this as soon as we will have new .FRM format,
in which we will store trigger definitions in the same .FRM
files as table descriptions.
*/
strmov(end, triggers_file_ext);
if (!access(path, F_OK))
new_error= my_delete(path, MYF(MY_WME));
}
error|= new_error; error|= new_error;
} }
} }
......
...@@ -4,7 +4,8 @@ ...@@ -4,7 +4,8 @@
#include "parse_file.h" #include "parse_file.h"
static const LEX_STRING triggers_file_type= {(char *)"TRIGGERS", 8}; static const LEX_STRING triggers_file_type= {(char *)"TRIGGERS", 8};
static const char * const triggers_file_ext= ".TRG";
const char * const triggers_file_ext= ".TRG";
/* /*
Table of .TRG file field descriptors. Table of .TRG file field descriptors.
......
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