List:Commits« Previous MessageNext Message »
From:ahristov Date:June 2 2006 3:43pm
Subject:bk commit into 5.1 tree (andrey:1.2173) BUG#16424
View as plain text  
Below is the list of changes that have just been committed into a local
5.1 repository of andrey. When andrey 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
  1.2173 06/06/02 17:42:49 andrey@lmy004. +9 -0
  fix for bug#16424 : DROP USER does not drop user's events

  sql/sql_acl.cc
    1.194 06/06/02 17:42:38 andrey@lmy004. +17 -0
    add dropping of user's events when the user has been dropped

  sql/event_timed.cc
    1.56 06/06/02 17:42:38 andrey@lmy004. +2 -1
    reorganize inlusion of headers

  sql/event_scheduler.h
    1.5 06/06/02 17:42:38 andrey@lmy004. +1 -2
    drop_user_events is now implemented, as fix for bug#16424

  sql/event_scheduler.cc
    1.6 06/06/02 17:42:38 andrey@lmy004. +33 -2
    Event_scheduler::drop_user_events() implemented

  sql/event_priv.h
    1.23 06/06/02 17:42:38 andrey@lmy004. +2 -4
    change declaration of refactored function

  sql/event.h
    1.30 06/06/02 17:42:38 andrey@lmy004. +3 -0
    extend the interface for DROP USER drops user's events

  sql/event.cc
    1.42 06/06/02 17:42:38 andrey@lmy004. +49 -14
    move inclusion of mysql_priv.h out of event_priv.h
    refactor db_frop_events_from_table to drop_event_from_table_by_field
    to support both droping events based on FIELD_DB and FIELD_DEFINER
    add Events::drop_user_events() to be called from sql_acl.cc

  mysql-test/t/events_grant.test
    1.2 06/06/02 17:42:38 andrey@lmy004. +15 -8
    use order by on selects
    add test case for DROP USER should drop user's events (bug#16424)

  mysql-test/r/events_grant.result
    1.2 06/06/02 17:42:38 andrey@lmy004. +34 -10
    update result

# This is a BitKeeper patch.  What follows are the unified diffs for the
# set of deltas contained in the patch.  The rest of the patch, the part
# that BitKeeper cares about, is below these diffs.
# User:	andrey
# Host:	lmy004.
# Root:	/work/mysql-5.1-runtime-16424

--- 1.193/sql/sql_acl.cc	2006-05-20 04:00:55 +02:00
+++ 1.194/sql/sql_acl.cc	2006-06-02 17:42:38 +02:00
@@ -31,6 +31,7 @@
 #include <stdarg.h>
 #include "sp_head.h"
 #include "sp.h"
+#include "event.h"
 
 time_t mysql_db_table_last_check= 0L;
 
@@ -5384,6 +5385,22 @@ bool mysql_drop_user(THD *thd, List <LEX
     {
       append_user(&wrong_users, user_name);
       result= TRUE;
+    }
+    else
+    {
+      LEX_STRING definer;
+      definer.length= user_name->user.length + user_name->host.length + 1;
+      definer.str= alloc_root(thd->mem_root, definer.length + 1);
+
+      DBUG_PRINT("info", ("copy the user"));
+      memcpy(definer.str, user_name->user.str, user_name->user.length);
+      definer.str[user_name->user.length]= '@';
+
+      DBUG_PRINT("info",("copy the host"));
+      memcpy(definer.str + user_name->user.length + 1, user_name->host.str,
+             user_name->host.length);
+      definer.str[definer.length]= '\0';
+      Events::drop_user_events(thd, &definer); 
     }
   }
 

--- 1.1/mysql-test/r/events_grant.result	2006-05-29 13:16:19 +02:00
+++ 1.2/mysql-test/r/events_grant.result	2006-06-02 17:42:38 +02:00
@@ -4,7 +4,7 @@ CREATE EVENT one_event ON SCHEDULE EVERY
 SHOW EVENTS;
 Db	Name	Definer	Type	Execute at	Interval value	Interval field	Starts	Ends	Status
 events_test	one_event	root@localhost	RECURRING	NULL	10	SECOND	#	#	ENABLED
-SELECT EVENT_CATALOG, EVENT_SCHEMA, EVENT_NAME, DEFINER, EVENT_BODY, EVENT_TYPE, EXECUTE_AT, INTERVAL_VALUE, INTERVAL_FIELD, STATUS,ON_COMPLETION, EVENT_COMMENT from information_schema.events;
+SELECT EVENT_CATALOG, EVENT_SCHEMA, EVENT_NAME, DEFINER, EVENT_BODY, EVENT_TYPE, EXECUTE_AT, INTERVAL_VALUE, INTERVAL_FIELD, STATUS,ON_COMPLETION, EVENT_COMMENT FROM INFORMATION_SCHEMA.EVENTS ORDER BY EVENT_SCHEMA, EVENT_NAME, DEFINER;
 EVENT_CATALOG	EVENT_SCHEMA	EVENT_NAME	DEFINER	EVENT_BODY	EVENT_TYPE	EXECUTE_AT	INTERVAL_VALUE	INTERVAL_FIELD	STATUS	ON_COMPLETION	EVENT_COMMENT
 NULL	events_test	one_event	root@localhost	SELECT 123	RECURRING	NULL	10	SECOND	ENABLED	NOT PRESERVE	
 CREATE DATABASE events_test2;
@@ -57,37 +57,37 @@ USE events_test2;
 CREATE EVENT four_event ON SCHEDULE EVERY 20 SECOND DO SELECT 42;
 USE events_test;
 "We should see 4 events : one_event, two_event, three_event & four_event"
-SELECT EVENT_CATALOG, EVENT_SCHEMA, EVENT_NAME, DEFINER, EVENT_BODY, EVENT_TYPE, EXECUTE_AT, INTERVAL_VALUE, INTERVAL_FIELD, STATUS,ON_COMPLETION, EVENT_COMMENT FROM INFORMATION_SCHEMA.EVENTS;
+SELECT EVENT_CATALOG, EVENT_SCHEMA, EVENT_NAME, DEFINER, EVENT_BODY, EVENT_TYPE, EXECUTE_AT, INTERVAL_VALUE, INTERVAL_FIELD, STATUS,ON_COMPLETION, EVENT_COMMENT FROM INFORMATION_SCHEMA.EVENTS ORDER BY EVENT_SCHEMA, EVENT_NAME, DEFINER;
 EVENT_CATALOG	EVENT_SCHEMA	EVENT_NAME	DEFINER	EVENT_BODY	EVENT_TYPE	EXECUTE_AT	INTERVAL_VALUE	INTERVAL_FIELD	STATUS	ON_COMPLETION	EVENT_COMMENT
 NULL	events_test	one_event	root@localhost	SELECT 123	RECURRING	NULL	10	SECOND	ENABLED	NOT PRESERVE	
-NULL	events_test	two_event	ev_test@localhost	SELECT 123	RECURRING	NULL	20	SECOND	ENABLED	NOT PRESERVE	two event
 NULL	events_test	three_event	ev_test@localhost	SELECT 123	RECURRING	NULL	20	SECOND	ENABLED	PRESERVE	three event
+NULL	events_test	two_event	ev_test@localhost	SELECT 123	RECURRING	NULL	20	SECOND	ENABLED	NOT PRESERVE	two event
 NULL	events_test2	four_event	ev_test@localhost	SELECT 42	RECURRING	NULL	20	SECOND	ENABLED	NOT PRESERVE	
 DROP DATABASE events_test2;
 "We should see 3 events : one_event, two_event, three_event"
-SELECT EVENT_CATALOG, EVENT_SCHEMA, EVENT_NAME, DEFINER, EVENT_BODY, EVENT_TYPE, EXECUTE_AT, INTERVAL_VALUE, INTERVAL_FIELD, STATUS,ON_COMPLETION, EVENT_COMMENT FROM INFORMATION_SCHEMA.EVENTS;
+SELECT EVENT_CATALOG, EVENT_SCHEMA, EVENT_NAME, DEFINER, EVENT_BODY, EVENT_TYPE, EXECUTE_AT, INTERVAL_VALUE, INTERVAL_FIELD, STATUS,ON_COMPLETION, EVENT_COMMENT FROM INFORMATION_SCHEMA.EVENTS ORDER BY EVENT_SCHEMA, EVENT_NAME, DEFINER;
 EVENT_CATALOG	EVENT_SCHEMA	EVENT_NAME	DEFINER	EVENT_BODY	EVENT_TYPE	EXECUTE_AT	INTERVAL_VALUE	INTERVAL_FIELD	STATUS	ON_COMPLETION	EVENT_COMMENT
 NULL	events_test	one_event	root@localhost	SELECT 123	RECURRING	NULL	10	SECOND	ENABLED	NOT PRESERVE	
-NULL	events_test	two_event	ev_test@localhost	SELECT 123	RECURRING	NULL	20	SECOND	ENABLED	NOT PRESERVE	two event
 NULL	events_test	three_event	ev_test@localhost	SELECT 123	RECURRING	NULL	20	SECOND	ENABLED	PRESERVE	three event
+NULL	events_test	two_event	ev_test@localhost	SELECT 123	RECURRING	NULL	20	SECOND	ENABLED	NOT PRESERVE	two event
 CREATE DATABASE events_test2;
 USE events_test2;
 CREATE EVENT five_event ON SCHEDULE EVERY 20 SECOND DO SELECT 42;
 "Should see 4 events - one, two, three & five"
-SELECT EVENT_CATALOG, EVENT_SCHEMA, EVENT_NAME, DEFINER, EVENT_BODY, EVENT_TYPE, EXECUTE_AT, INTERVAL_VALUE, INTERVAL_FIELD, STATUS,ON_COMPLETION, EVENT_COMMENT FROM INFORMATION_SCHEMA.EVENTS;
+SELECT EVENT_CATALOG, EVENT_SCHEMA, EVENT_NAME, DEFINER, EVENT_BODY, EVENT_TYPE, EXECUTE_AT, INTERVAL_VALUE, INTERVAL_FIELD, STATUS,ON_COMPLETION, EVENT_COMMENT FROM INFORMATION_SCHEMA.EVENTS ORDER BY EVENT_SCHEMA, EVENT_NAME, DEFINER;
 EVENT_CATALOG	EVENT_SCHEMA	EVENT_NAME	DEFINER	EVENT_BODY	EVENT_TYPE	EXECUTE_AT	INTERVAL_VALUE	INTERVAL_FIELD	STATUS	ON_COMPLETION	EVENT_COMMENT
 NULL	events_test	one_event	root@localhost	SELECT 123	RECURRING	NULL	10	SECOND	ENABLED	NOT PRESERVE	
-NULL	events_test	two_event	ev_test@localhost	SELECT 123	RECURRING	NULL	20	SECOND	ENABLED	NOT PRESERVE	two event
 NULL	events_test	three_event	ev_test@localhost	SELECT 123	RECURRING	NULL	20	SECOND	ENABLED	PRESERVE	three event
+NULL	events_test	two_event	ev_test@localhost	SELECT 123	RECURRING	NULL	20	SECOND	ENABLED	NOT PRESERVE	two event
 NULL	events_test2	five_event	root@localhost	SELECT 42	RECURRING	NULL	20	SECOND	ENABLED	NOT PRESERVE	
 REVOKE EVENT ON events_test2.* FROM ev_test@localhost;
 USE test;
 "Should see 3 events - one, two & three"
-SELECT EVENT_CATALOG, EVENT_SCHEMA, EVENT_NAME, DEFINER, EVENT_BODY, EVENT_TYPE, EXECUTE_AT, INTERVAL_VALUE, INTERVAL_FIELD, STATUS,ON_COMPLETION, EVENT_COMMENT FROM INFORMATION_SCHEMA.EVENTS;
+SELECT EVENT_CATALOG, EVENT_SCHEMA, EVENT_NAME, DEFINER, EVENT_BODY, EVENT_TYPE, EXECUTE_AT, INTERVAL_VALUE, INTERVAL_FIELD, STATUS,ON_COMPLETION, EVENT_COMMENT FROM INFORMATION_SCHEMA.EVENTS ORDER BY EVENT_SCHEMA, EVENT_NAME, DEFINER;
 EVENT_CATALOG	EVENT_SCHEMA	EVENT_NAME	DEFINER	EVENT_BODY	EVENT_TYPE	EXECUTE_AT	INTERVAL_VALUE	INTERVAL_FIELD	STATUS	ON_COMPLETION	EVENT_COMMENT
 NULL	events_test	one_event	root@localhost	SELECT 123	RECURRING	NULL	10	SECOND	ENABLED	NOT PRESERVE	
-NULL	events_test	two_event	ev_test@localhost	SELECT 123	RECURRING	NULL	20	SECOND	ENABLED	NOT PRESERVE	two event
 NULL	events_test	three_event	ev_test@localhost	SELECT 123	RECURRING	NULL	20	SECOND	ENABLED	PRESERVE	three event
+NULL	events_test	two_event	ev_test@localhost	SELECT 123	RECURRING	NULL	20	SECOND	ENABLED	NOT PRESERVE	two event
 "Let's test ALTER EVENT which changes the definer"
 USE events_test;
 ALTER EVENT one_event ON SCHEDULE EVERY 10 SECOND;
@@ -111,11 +111,35 @@ ALTER EVENT one_event COMMENT "new comme
 "test DROP by another user"
 DROP EVENT one_event;
 "One event should not be there"
-SELECT EVENT_CATALOG, EVENT_SCHEMA, EVENT_NAME, DEFINER, EVENT_BODY, EVENT_TYPE, EXECUTE_AT, INTERVAL_VALUE, INTERVAL_FIELD, STATUS,ON_COMPLETION, EVENT_COMMENT FROM INFORMATION_SCHEMA.EVENTS;
+SELECT EVENT_CATALOG, EVENT_SCHEMA, EVENT_NAME, DEFINER, EVENT_BODY, EVENT_TYPE, EXECUTE_AT, INTERVAL_VALUE, INTERVAL_FIELD, STATUS,ON_COMPLETION, EVENT_COMMENT FROM INFORMATION_SCHEMA.EVENTS ORDER BY EVENT_SCHEMA, EVENT_NAME, DEFINER;
 EVENT_CATALOG	EVENT_SCHEMA	EVENT_NAME	DEFINER	EVENT_BODY	EVENT_TYPE	EXECUTE_AT	INTERVAL_VALUE	INTERVAL_FIELD	STATUS	ON_COMPLETION	EVENT_COMMENT
+NULL	events_test	three_event	ev_test@localhost	SELECT 123	RECURRING	NULL	20	SECOND	ENABLED	PRESERVE	three event
 NULL	events_test	two_event	ev_test@localhost	SELECT 123	RECURRING	NULL	20	SECOND	ENABLED	NOT PRESERVE	two event
+"Now let's test whether we drop user's events on DROP USER"
+CREATE EVENT ev_test_event1 ON SCHEDULE EVERY 1 HOUR DISABLE DO SELECT 121;
+CREATE EVENT ev_test_event2 ON SCHEDULE EVERY 1 HOUR DISABLE DO SELECT 144;
+CREATE EVENT ev_test_event3 ON SCHEDULE EVERY 1 HOUR DISABLE DO SELECT 169;
+SELECT EVENT_CATALOG, EVENT_SCHEMA, EVENT_NAME, DEFINER, EVENT_BODY, EVENT_TYPE, EXECUTE_AT, INTERVAL_VALUE, INTERVAL_FIELD, STATUS,ON_COMPLETION, EVENT_COMMENT FROM INFORMATION_SCHEMA.EVENTS ORDER BY EVENT_SCHEMA, EVENT_NAME, DEFINER;
+EVENT_CATALOG	EVENT_SCHEMA	EVENT_NAME	DEFINER	EVENT_BODY	EVENT_TYPE	EXECUTE_AT	INTERVAL_VALUE	INTERVAL_FIELD	STATUS	ON_COMPLETION	EVENT_COMMENT
+NULL	events_test	ev_test_event1	ev_test@localhost	SELECT 121	RECURRING	NULL	1	HOUR	DISABLED	NOT PRESERVE	
+NULL	events_test	ev_test_event2	ev_test@localhost	SELECT 144	RECURRING	NULL	1	HOUR	DISABLED	NOT PRESERVE	
+NULL	events_test	ev_test_event3	ev_test@localhost	SELECT 169	RECURRING	NULL	1	HOUR	DISABLED	NOT PRESERVE	
 NULL	events_test	three_event	ev_test@localhost	SELECT 123	RECURRING	NULL	20	SECOND	ENABLED	PRESERVE	three event
+NULL	events_test	two_event	ev_test@localhost	SELECT 123	RECURRING	NULL	20	SECOND	ENABLED	NOT PRESERVE	two event
+NULL	events_test2	five_event	root@localhost	SELECT 42	RECURRING	NULL	20	SECOND	ENABLED	NOT PRESERVE	
+SELECT EVENT_CATALOG, EVENT_SCHEMA, EVENT_NAME, DEFINER, EVENT_BODY, EVENT_TYPE, EXECUTE_AT, INTERVAL_VALUE, INTERVAL_FIELD, STATUS,ON_COMPLETION, EVENT_COMMENT FROM INFORMATION_SCHEMA.EVENTS ORDER BY EVENT_SCHEMA, EVENT_NAME, DEFINER;
+EVENT_CATALOG	EVENT_SCHEMA	EVENT_NAME	DEFINER	EVENT_BODY	EVENT_TYPE	EXECUTE_AT	INTERVAL_VALUE	INTERVAL_FIELD	STATUS	ON_COMPLETION	EVENT_COMMENT
+NULL	events_test	ev_test_event1	ev_test@localhost	SELECT 121	RECURRING	NULL	1	HOUR	DISABLED	NOT PRESERVE	
+NULL	events_test	ev_test_event2	ev_test@localhost	SELECT 144	RECURRING	NULL	1	HOUR	DISABLED	NOT PRESERVE	
+NULL	events_test	ev_test_event3	ev_test@localhost	SELECT 169	RECURRING	NULL	1	HOUR	DISABLED	NOT PRESERVE	
+NULL	events_test	three_event	ev_test@localhost	SELECT 123	RECURRING	NULL	20	SECOND	ENABLED	PRESERVE	three event
+NULL	events_test	two_event	ev_test@localhost	SELECT 123	RECURRING	NULL	20	SECOND	ENABLED	NOT PRESERVE	two event
 NULL	events_test2	five_event	root@localhost	SELECT 42	RECURRING	NULL	20	SECOND	ENABLED	NOT PRESERVE	
 DROP USER ev_test@localhost;
+SELECT EVENT_CATALOG, EVENT_SCHEMA, EVENT_NAME, DEFINER, EVENT_BODY, EVENT_TYPE, EXECUTE_AT, INTERVAL_VALUE, INTERVAL_FIELD, STATUS,ON_COMPLETION, EVENT_COMMENT FROM INFORMATION_SCHEMA.EVENTS ORDER BY EVENT_SCHEMA, EVENT_NAME, DEFINER;
+EVENT_CATALOG	EVENT_SCHEMA	EVENT_NAME	DEFINER	EVENT_BODY	EVENT_TYPE	EXECUTE_AT	INTERVAL_VALUE	INTERVAL_FIELD	STATUS	ON_COMPLETION	EVENT_COMMENT
+NULL	events_test2	five_event	root@localhost	SELECT 42	RECURRING	NULL	20	SECOND	ENABLED	NOT PRESERVE	
 DROP DATABASE events_test2;
+SELECT EVENT_CATALOG, EVENT_SCHEMA, EVENT_NAME, DEFINER, EVENT_BODY, EVENT_TYPE, EXECUTE_AT, INTERVAL_VALUE, INTERVAL_FIELD, STATUS,ON_COMPLETION, EVENT_COMMENT FROM INFORMATION_SCHEMA.EVENTS ORDER BY EVENT_SCHEMA, EVENT_NAME, DEFINER;
+EVENT_CATALOG	EVENT_SCHEMA	EVENT_NAME	DEFINER	EVENT_BODY	EVENT_TYPE	EXECUTE_AT	INTERVAL_VALUE	INTERVAL_FIELD	STATUS	ON_COMPLETION	EVENT_COMMENT
 DROP DATABASE events_test;

--- 1.1/mysql-test/t/events_grant.test	2006-05-29 13:16:19 +02:00
+++ 1.2/mysql-test/t/events_grant.test	2006-06-02 17:42:38 +02:00
@@ -6,7 +6,7 @@ use events_test;
 CREATE EVENT one_event ON SCHEDULE EVERY 10 SECOND DO SELECT 123;
 --replace_column 8 # 9 #
 SHOW EVENTS;
-SELECT EVENT_CATALOG, EVENT_SCHEMA, EVENT_NAME, DEFINER, EVENT_BODY, EVENT_TYPE, EXECUTE_AT, INTERVAL_VALUE, INTERVAL_FIELD, STATUS,ON_COMPLETION, EVENT_COMMENT from information_schema.events;
+SELECT EVENT_CATALOG, EVENT_SCHEMA, EVENT_NAME, DEFINER, EVENT_BODY, EVENT_TYPE, EXECUTE_AT, INTERVAL_VALUE, INTERVAL_FIELD, STATUS,ON_COMPLETION, EVENT_COMMENT FROM INFORMATION_SCHEMA.EVENTS ORDER BY EVENT_SCHEMA, EVENT_NAME, DEFINER;
 CREATE DATABASE events_test2;
 CREATE USER ev_test@localhost;
 GRANT ALL ON events_test.* to ev_test@localhost;
@@ -52,10 +52,10 @@ CREATE EVENT four_event ON SCHEDULE EVER
 connection default;
 USE events_test;
 --echo "We should see 4 events : one_event, two_event, three_event & four_event"
-SELECT EVENT_CATALOG, EVENT_SCHEMA, EVENT_NAME, DEFINER, EVENT_BODY, EVENT_TYPE, EXECUTE_AT, INTERVAL_VALUE, INTERVAL_FIELD, STATUS,ON_COMPLETION, EVENT_COMMENT FROM INFORMATION_SCHEMA.EVENTS;
+SELECT EVENT_CATALOG, EVENT_SCHEMA, EVENT_NAME, DEFINER, EVENT_BODY, EVENT_TYPE, EXECUTE_AT, INTERVAL_VALUE, INTERVAL_FIELD, STATUS,ON_COMPLETION, EVENT_COMMENT FROM INFORMATION_SCHEMA.EVENTS ORDER BY EVENT_SCHEMA, EVENT_NAME, DEFINER;
 DROP DATABASE events_test2;
 --echo "We should see 3 events : one_event, two_event, three_event"
-SELECT EVENT_CATALOG, EVENT_SCHEMA, EVENT_NAME, DEFINER, EVENT_BODY, EVENT_TYPE, EXECUTE_AT, INTERVAL_VALUE, INTERVAL_FIELD, STATUS,ON_COMPLETION, EVENT_COMMENT FROM INFORMATION_SCHEMA.EVENTS;
+SELECT EVENT_CATALOG, EVENT_SCHEMA, EVENT_NAME, DEFINER, EVENT_BODY, EVENT_TYPE, EXECUTE_AT, INTERVAL_VALUE, INTERVAL_FIELD, STATUS,ON_COMPLETION, EVENT_COMMENT FROM INFORMATION_SCHEMA.EVENTS ORDER BY EVENT_SCHEMA, EVENT_NAME, DEFINER;
 
 connection default;
 CREATE DATABASE events_test2;
@@ -64,13 +64,13 @@ CREATE EVENT five_event ON SCHEDULE EVER
 
 connection ev_con1;
 --echo "Should see 4 events - one, two, three & five"
-SELECT EVENT_CATALOG, EVENT_SCHEMA, EVENT_NAME, DEFINER, EVENT_BODY, EVENT_TYPE, EXECUTE_AT, INTERVAL_VALUE, INTERVAL_FIELD, STATUS,ON_COMPLETION, EVENT_COMMENT FROM INFORMATION_SCHEMA.EVENTS;
+SELECT EVENT_CATALOG, EVENT_SCHEMA, EVENT_NAME, DEFINER, EVENT_BODY, EVENT_TYPE, EXECUTE_AT, INTERVAL_VALUE, INTERVAL_FIELD, STATUS,ON_COMPLETION, EVENT_COMMENT FROM INFORMATION_SCHEMA.EVENTS ORDER BY EVENT_SCHEMA, EVENT_NAME, DEFINER;
 connection default;
 REVOKE EVENT ON events_test2.* FROM ev_test@localhost;
 connection ev_con1;
 USE test;
 --echo "Should see 3 events - one, two & three"
-SELECT EVENT_CATALOG, EVENT_SCHEMA, EVENT_NAME, DEFINER, EVENT_BODY, EVENT_TYPE, EXECUTE_AT, INTERVAL_VALUE, INTERVAL_FIELD, STATUS,ON_COMPLETION, EVENT_COMMENT FROM INFORMATION_SCHEMA.EVENTS;
+SELECT EVENT_CATALOG, EVENT_SCHEMA, EVENT_NAME, DEFINER, EVENT_BODY, EVENT_TYPE, EXECUTE_AT, INTERVAL_VALUE, INTERVAL_FIELD, STATUS,ON_COMPLETION, EVENT_COMMENT FROM INFORMATION_SCHEMA.EVENTS ORDER BY EVENT_SCHEMA, EVENT_NAME, DEFINER;
 --echo "Let's test ALTER EVENT which changes the definer"
 USE events_test;
 ALTER EVENT one_event ON SCHEDULE EVERY 10 SECOND;
@@ -91,15 +91,22 @@ ALTER EVENT one_event COMMENT "new comme
 connection ev_con1;
 --echo "test DROP by another user"
 DROP EVENT one_event;
-connection default;
 --echo "One event should not be there"
-SELECT EVENT_CATALOG, EVENT_SCHEMA, EVENT_NAME, DEFINER, EVENT_BODY, EVENT_TYPE, EXECUTE_AT, INTERVAL_VALUE, INTERVAL_FIELD, STATUS,ON_COMPLETION, EVENT_COMMENT FROM INFORMATION_SCHEMA.EVENTS;
-disconnect ev_con1;
+SELECT EVENT_CATALOG, EVENT_SCHEMA, EVENT_NAME, DEFINER, EVENT_BODY, EVENT_TYPE, EXECUTE_AT, INTERVAL_VALUE, INTERVAL_FIELD, STATUS,ON_COMPLETION, EVENT_COMMENT FROM INFORMATION_SCHEMA.EVENTS ORDER BY EVENT_SCHEMA, EVENT_NAME, DEFINER;
+--echo "Now let's test whether we drop user's events on DROP USER"
+CREATE EVENT ev_test_event1 ON SCHEDULE EVERY 1 HOUR DISABLE DO SELECT 121;
+CREATE EVENT ev_test_event2 ON SCHEDULE EVERY 1 HOUR DISABLE DO SELECT 144;
+CREATE EVENT ev_test_event3 ON SCHEDULE EVERY 1 HOUR DISABLE DO SELECT 169;
 connection default;
+SELECT EVENT_CATALOG, EVENT_SCHEMA, EVENT_NAME, DEFINER, EVENT_BODY, EVENT_TYPE, EXECUTE_AT, INTERVAL_VALUE, INTERVAL_FIELD, STATUS,ON_COMPLETION, EVENT_COMMENT FROM INFORMATION_SCHEMA.EVENTS ORDER BY EVENT_SCHEMA, EVENT_NAME, DEFINER;
+disconnect ev_con1;
+SELECT EVENT_CATALOG, EVENT_SCHEMA, EVENT_NAME, DEFINER, EVENT_BODY, EVENT_TYPE, EXECUTE_AT, INTERVAL_VALUE, INTERVAL_FIELD, STATUS,ON_COMPLETION, EVENT_COMMENT FROM INFORMATION_SCHEMA.EVENTS ORDER BY EVENT_SCHEMA, EVENT_NAME, DEFINER;
 DROP USER ev_test@localhost;
+SELECT EVENT_CATALOG, EVENT_SCHEMA, EVENT_NAME, DEFINER, EVENT_BODY, EVENT_TYPE, EXECUTE_AT, INTERVAL_VALUE, INTERVAL_FIELD, STATUS,ON_COMPLETION, EVENT_COMMENT FROM INFORMATION_SCHEMA.EVENTS ORDER BY EVENT_SCHEMA, EVENT_NAME, DEFINER;
 DROP DATABASE events_test2;
 #
 ## EVENTS grants test end
 #
+SELECT EVENT_CATALOG, EVENT_SCHEMA, EVENT_NAME, DEFINER, EVENT_BODY, EVENT_TYPE, EXECUTE_AT, INTERVAL_VALUE, INTERVAL_FIELD, STATUS,ON_COMPLETION, EVENT_COMMENT FROM INFORMATION_SCHEMA.EVENTS ORDER BY EVENT_SCHEMA, EVENT_NAME, DEFINER;
 
 DROP DATABASE events_test;

--- 1.41/sql/event.cc	2006-05-29 10:39:35 +02:00
+++ 1.42/sql/event.cc	2006-06-02 17:42:38 +02:00
@@ -14,8 +14,9 @@
    along with this program; if not, write to the Free Software
    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */
 
-#include "event_priv.h"
+#include "mysql_priv.h"
 #include "event.h"
+#include "event_priv.h"
 #include "event_scheduler.h"
 #include "sp.h"
 #include "sp_head.h"
@@ -1250,7 +1251,38 @@ Events::drop_schema_events(THD *thd, cha
   if (scheduler->initialized())
     ret= scheduler->drop_schema_events(thd, &db_lex);
   else
-    ret= db_drop_events_from_table(thd, &db_lex);
+    ret= drop_events_from_table_by_field(thd, Events::FIELD_DB, &db_lex);
+
+  DBUG_RETURN(ret);
+}
+
+
+/*
+  Drops all events of a specific user
+
+  SYNOPSIS
+    Events::drop_schema_events()
+      thd      Thread
+      definer  The user
+
+  RETURN VALUE
+    0   OK
+    !0  Error
+*/
+
+int
+Events::drop_user_events(THD *thd, LEX_STRING *definer)
+{
+  int ret= 0;
+  
+  DBUG_ENTER("drop_user_events");  
+  DBUG_PRINT("enter", ("dropping events of %s", definer->str));
+
+  Event_scheduler *scheduler= Event_scheduler::get_instance();
+  if (scheduler->initialized())
+    ret= scheduler->drop_user_events(thd, definer);
+  else
+    ret= drop_events_from_table_by_field(thd, Events::FIELD_DEFINER, definer);
 
   DBUG_RETURN(ret);
 }
@@ -1260,9 +1292,10 @@ Events::drop_schema_events(THD *thd, cha
   Drops all events in the selected database, from mysql.event.
 
   SYNOPSIS
-    evex_drop_db_events_from_table()
-      thd  Thread
-      db   Schema name
+    drop_events_from_table_by_field()
+      thd         Thread
+      field       Which field of the row to use for matching
+      field_value The value that should match
 
   RETURN VALUE
      0  OK
@@ -1270,14 +1303,17 @@ Events::drop_schema_events(THD *thd, cha
 */
 
 int
-db_drop_events_from_table(THD *thd, LEX_STRING *db)
+drop_events_from_table_by_field(THD *thd, Events::enum_table_field field,
+                                LEX_STRING *field_value)
 {
   int ret;
   TABLE *table;
+  Open_tables_state backup;
   READ_RECORD read_record_info;
-  DBUG_ENTER("db_drop_events_from_table");  
-  DBUG_PRINT("info", ("dropping events from %s", db->str));
+  DBUG_ENTER("db_drop_events_from_table_by_field");  
+  DBUG_PRINT("enter", ("field=%d field_value=%s", field, field_value->str));
 
+  thd->reset_n_backup_open_tables_state(&backup);
   if ((ret= Events::open_event_table(thd, TL_WRITE, &table)))
   {
     sql_print_error("Table mysql.event is damaged.");
@@ -1287,15 +1323,14 @@ db_drop_events_from_table(THD *thd, LEX_
   init_read_record(&read_record_info, thd, table, NULL, 1, 0);
   while (!(read_record_info.read_record(&read_record_info)) && !ret)
   {
-    char *et_db= get_field(thd->mem_root,
-                           table->field[Events::FIELD_DB]);
+    char *et_field= get_field(thd->mem_root, table->field[field]);
 
-    LEX_STRING et_db_lex= {et_db, strlen(et_db)};
-    DBUG_PRINT("info", ("Current event %s.%s", et_db,
+    LEX_STRING et_field_lex= {et_field, strlen(et_field)};
+    DBUG_PRINT("info", ("Current event %s name=%s", et_field,
                get_field(thd->mem_root,
                table->field[Events::FIELD_NAME])));
 
-    if (!sortcmp_lex_string(et_db_lex, *db, system_charset_info))
+    if (!sortcmp_lex_string(et_field_lex, *field_value, system_charset_info))
     {
       DBUG_PRINT("info", ("Dropping"));
       if ((ret= table->file->ha_delete_row(table->record[0])))
@@ -1308,10 +1343,10 @@ db_drop_events_from_table(THD *thd, LEX_
   thd->version--;   /* Force close to free memory */
 
   close_thread_tables(thd);
+  thd->restore_backup_open_tables_state(&backup);
 
   DBUG_RETURN(ret);
 }
-
 
 
 /*

--- 1.29/sql/event.h	2006-05-29 10:39:35 +02:00
+++ 1.30/sql/event.h	2006-06-02 17:42:38 +02:00
@@ -93,6 +93,9 @@ public:
 
   static int
   drop_schema_events(THD *thd, char *db);
+
+  static int
+  drop_user_events(THD *thd, LEX_STRING *definer);
   
   static int
   dump_internal_status(THD *thd);

--- 1.22/sql/event_priv.h	2006-05-29 10:39:35 +02:00
+++ 1.23/sql/event_priv.h	2006-06-02 17:42:38 +02:00
@@ -16,9 +16,6 @@
    along with this program; if not, write to the Free Software
    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */
 
-#include "mysql_priv.h"
-
-
 #define EVENT_EXEC_STARTED      0
 #define EVENT_EXEC_ALREADY_EXEC 1
 #define EVENT_EXEC_CANT_FORK    2
@@ -50,7 +47,8 @@ db_create_event(THD *thd, Event_timed *e
                 uint *rows_affected);
 
 int
-db_drop_events_from_table(THD *thd, LEX_STRING *db);
+drop_events_from_table_by_field(THD *thd, enum Events::enum_table_field field,
+                                LEX_STRING *field_value);
 
 int
 sortcmp_lex_string(LEX_STRING s, LEX_STRING t, CHARSET_INFO *cs);

--- 1.5/sql/event_scheduler.cc	2006-05-29 15:16:01 +02:00
+++ 1.6/sql/event_scheduler.cc	2006-06-02 17:42:38 +02:00
@@ -14,8 +14,9 @@
    along with this program; if not, write to the Free Software
    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */
 
-#include "event_priv.h"
+#include "mysql_priv.h"
 #include "event.h"
+#include "event_priv.h"
 #include "event_scheduler.h"
 #include "sp_head.h"
 
@@ -1107,7 +1108,37 @@ Event_scheduler::drop_schema_events(THD 
   if (is_running_or_suspended())
     drop_matching_events(thd, schema, event_timed_db_equal);
 
-  ret= db_drop_events_from_table(thd, schema);
+  ret= drop_events_from_table_by_field(thd, Events::FIELD_DB, schema);
+  UNLOCK_SCHEDULER_DATA();
+
+  DBUG_RETURN(ret);
+}
+
+
+/*
+  Drops all events from the in-memory queue and disk that have
+  certain definer.
+
+  SYNOPSIS
+    Event_scheduler::drop_user_events()
+      thd        THD
+      db         The schema name
+
+  RETURN VALUE
+     -1  Scheduler not working
+    >=0  Number of dropped events
+*/
+
+int
+Event_scheduler::drop_user_events(THD *thd, LEX_STRING *schema)
+{
+  int ret;
+  DBUG_ENTER("Event_scheduler::drop_user_events");
+  LOCK_SCHEDULER_DATA();
+  if (is_running_or_suspended())
+    drop_matching_events(thd, schema, event_timed_definer_equal);
+
+  ret= drop_events_from_table_by_field(thd, Events::FIELD_DEFINER, schema);
   UNLOCK_SCHEDULER_DATA();
 
   DBUG_RETURN(ret);

--- 1.4/sql/event_scheduler.h	2006-05-23 17:46:28 +02:00
+++ 1.5/sql/event_scheduler.h	2006-06-02 17:42:38 +02:00
@@ -79,8 +79,7 @@ public:
   drop_schema_events(THD *thd, LEX_STRING *schema);
 
   int
-  drop_user_events(THD *thd, LEX_STRING *definer, uint *dropped_num)
-  { DBUG_ASSERT(0); return 0;}
+  drop_user_events(THD *thd, LEX_STRING *definer);
 
   uint
   events_count();

--- 1.55/sql/event_timed.cc	2006-05-29 13:12:26 +02:00
+++ 1.56/sql/event_timed.cc	2006-06-02 17:42:38 +02:00
@@ -15,8 +15,9 @@
    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */
 
 #define MYSQL_LEX 1
-#include "event_priv.h"
+#include "mysql_priv.h"
 #include "event.h"
+#include "event_priv.h"
 #include "sp_head.h"
 
 
Thread
bk commit into 5.1 tree (andrey:1.2173) BUG#16424ahristov2 Jun