List:Commits« Previous MessageNext Message »
From:ahristov Date:June 7 2006 2:51pm
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/07 16:50:14 andrey@lmy004. +11 -0
  fix for bug#16424 : DROP USER does not drop user's events
  post-first-review commit

  sql/sql_acl.cc
    1.194 06/06/07 16:49:52 andrey@lmy004. +42 -7
    add dropping of user's events when the user has been dropped
    in open_grant_tables() open also mysql.event, if needed to ensure
    no deadlocks.

  sql/event_timed.cc
    1.56 06/06/07 16:49:52 andrey@lmy004. +2 -1
    reorganize inlusion of headers

  sql/event_scheduler.h
    1.5 06/06/07 16:49:52 andrey@lmy004. +1 -2
    drop_user_events is now implemented, as fix for bug#16424

  sql/event_scheduler.cc
    1.6 06/06/07 16:49:52 andrey@lmy004. +41 -8
    Event_scheduler::drop_user_events() implemented

  sql/event_priv.h
    1.23 06/06/07 16:49:52 andrey@lmy004. +3 -4
    change declaration of refactored function

  sql/event.h
    1.30 06/06/07 16:49:52 andrey@lmy004. +3 -0
    extend the interface for DROP USER drops user's events

  sql/event.cc
    1.42 06/06/07 16:49:52 andrey@lmy004. +89 -57
    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_scheduling.test
    1.5 06/06/07 16:49:51 andrey@lmy004. +1 -1
    order by the result

  mysql-test/t/events_grant.test
    1.2 06/06/07 16:49:51 andrey@lmy004. +38 -9
    use order by on selects
    add test case for DROP USER should drop user's events (bug#16424)

  mysql-test/r/events_scheduling.result
    1.4 06/06/07 16:49:51 andrey@lmy004. +1 -1
    order by the result

  mysql-test/r/events_grant.result
    1.2 06/06/07 16:49:51 andrey@lmy004. +64 -11
    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-07 16:49:52 +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;
 
@@ -148,6 +149,12 @@ TABLE_FIELD_W_TYPE mysql_db_table_fields
 };
 
 
+enum enum_open_grant_tables_flag
+{
+  NO_FLAG= 0,
+  OPEN_EVENT_TABLE
+};
+
 #ifndef NO_EMBEDDED_ACCESS_CHECKS
 
 #define FIRST_NON_YN_FIELD 26
@@ -4725,7 +4732,9 @@ void get_mqh(const char *user, const cha
 */
 
 #define GRANT_TABLES 5
-int open_grant_tables(THD *thd, TABLE_LIST *tables)
+static
+int open_grant_tables(THD *thd, TABLE_LIST *tables,
+                      enum_open_grant_tables_flag flag)
 {
   DBUG_ENTER("open_grant_tables");
 
@@ -4751,6 +4760,15 @@ int open_grant_tables(THD *thd, TABLE_LI
   tables->db= (tables+1)->db= (tables+2)->db= 
     (tables+3)->db= (tables+4)->db= (char*) "mysql";
 
+  if (flag == OPEN_EVENT_TABLE)
+  {
+    /* Clean a bit more */
+    bzero((char *)tables + GRANT_TABLES*sizeof(*tables), sizeof(*tables));
+    (tables+5)->alias= (tables+5)->table_name= (char*) "event";
+    (tables+4)->next_local= (tables+4)->next_global= tables+5;
+    (tables+5)->lock_type= TL_WRITE;
+    (tables+5)->db= (tables+4)->db;
+  }
 #ifdef HAVE_REPLICATION
   /*
     GRANT and REVOKE are applied the slave in/exclusion rules as they are
@@ -5313,7 +5331,7 @@ bool mysql_create_user(THD *thd, List <L
   DBUG_ENTER("mysql_create_user");
 
   /* CREATE USER may be skipped on replication client. */
-  if ((result= open_grant_tables(thd, tables)))
+  if ((result= open_grant_tables(thd, tables, NO_FLAG)))
     DBUG_RETURN(result != 1);
 
   rw_wrlock(&LOCK_grant);
@@ -5368,11 +5386,11 @@ bool mysql_drop_user(THD *thd, List <LEX
   String wrong_users;
   LEX_USER *user_name;
   List_iterator <LEX_USER> user_list(list);
-  TABLE_LIST tables[GRANT_TABLES];
+  TABLE_LIST tables[GRANT_TABLES + 1];          // + space for mysql.event
   DBUG_ENTER("mysql_drop_user");
 
   /* DROP USER may be skipped on replication client. */
-  if ((result= open_grant_tables(thd, tables)))
+  if ((result= open_grant_tables(thd, tables, OPEN_EVENT_TABLE)))
     DBUG_RETURN(result != 1);
 
   rw_wrlock(&LOCK_grant);
@@ -5385,6 +5403,23 @@ 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, (tables + GRANT_TABLES)->table, &definer); 
+    }
   }
 
   /* Rebuild 'acl_check_hosts' since 'acl_users' has been modified */
@@ -5423,7 +5458,7 @@ bool mysql_rename_user(THD *thd, List <L
   DBUG_ENTER("mysql_rename_user");
 
   /* RENAME USER may be skipped on replication client. */
-  if ((result= open_grant_tables(thd, tables)))
+  if ((result= open_grant_tables(thd, tables, NO_FLAG)))
     DBUG_RETURN(result != 1);
 
   rw_wrlock(&LOCK_grant);
@@ -5480,7 +5515,7 @@ bool mysql_revoke_all(THD *thd,  List <L
   TABLE_LIST tables[GRANT_TABLES];
   DBUG_ENTER("mysql_revoke_all");
 
-  if ((result= open_grant_tables(thd, tables)))
+  if ((result= open_grant_tables(thd, tables, NO_FLAG)))
     DBUG_RETURN(result != 1);
 
   rw_wrlock(&LOCK_grant);
@@ -5653,7 +5688,7 @@ bool sp_revoke_privileges(THD *thd, cons
   HASH *hash= is_proc ? &proc_priv_hash : &func_priv_hash;
   DBUG_ENTER("sp_revoke_privileges");
 
-  if ((result= open_grant_tables(thd, tables)))
+  if ((result= open_grant_tables(thd, tables, NO_FLAG)))
     DBUG_RETURN(result != 1);
 
   rw_wrlock(&LOCK_grant);

--- 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-07 16:49:51 +02:00
@@ -4,13 +4,17 @@ 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;
 CREATE USER ev_test@localhost;
+CREATE USER ev_test2@localhost;
+CREATE USER ev_test3@localhost;
 GRANT ALL ON events_test.* to ev_test@localhost;
 GRANT ALL ON events_test2.* to ev_test@localhost;
+GRANT ALL ON events_test2.* to ev_test2@localhost;
+GRANT ALL ON events_test2.* to ev_test3@localhost;
 REVOKE EVENT ON events_test2.* FROM ev_test@localhost;
 select "NEW CONNECTION";
 NEW CONNECTION
@@ -57,37 +61,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 +115,60 @@ 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	
+CREATE EVENT ev_test2_event1 ON SCHEDULE EVERY 1 HOUR DISABLE DO SELECT 196;
+CREATE EVENT ev_test2_event2 ON SCHEDULE EVERY 1 HOUR DISABLE DO SELECT 225;
+CREATE EVENT ev_test2_event3 ON SCHEDULE EVERY 1 HOUR DISABLE DO SELECT 256;
+CREATE EVENT ev_test3_event1 ON SCHEDULE EVERY 1 HOUR DISABLE DO SELECT 289;
+CREATE EVENT ev_test3_event2 ON SCHEDULE EVERY 1 HOUR DISABLE DO SELECT 324;
+CREATE EVENT ev_test3_event3 ON SCHEDULE EVERY 1 HOUR DISABLE DO SELECT 361;
+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	ev_test2_event1	ev_test2@localhost	SELECT 196	RECURRING	NULL	1	HOUR	DISABLED	NOT PRESERVE	
+NULL	events_test2	ev_test2_event2	ev_test2@localhost	SELECT 225	RECURRING	NULL	1	HOUR	DISABLED	NOT PRESERVE	
+NULL	events_test2	ev_test2_event3	ev_test2@localhost	SELECT 256	RECURRING	NULL	1	HOUR	DISABLED	NOT PRESERVE	
+NULL	events_test2	ev_test3_event1	ev_test3@localhost	SELECT 289	RECURRING	NULL	1	HOUR	DISABLED	NOT PRESERVE	
+NULL	events_test2	ev_test3_event2	ev_test3@localhost	SELECT 324	RECURRING	NULL	1	HOUR	DISABLED	NOT PRESERVE	
+NULL	events_test2	ev_test3_event3	ev_test3@localhost	SELECT 361	RECURRING	NULL	1	HOUR	DISABLED	NOT PRESERVE	
+NULL	events_test2	five_event	root@localhost	SELECT 42	RECURRING	NULL	20	SECOND	ENABLED	NOT PRESERVE	
+"Drop one existing and one non-existing user. Events of the former will be dropped."
+DROP USER ev_test_non_exists@localhost, ev_test@localhost;
+ERROR HY000: Operation DROP USER failed for 'ev_test_non_exists'@'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	ev_test2_event1	ev_test2@localhost	SELECT 196	RECURRING	NULL	1	HOUR	DISABLED	NOT PRESERVE	
+NULL	events_test2	ev_test2_event2	ev_test2@localhost	SELECT 225	RECURRING	NULL	1	HOUR	DISABLED	NOT PRESERVE	
+NULL	events_test2	ev_test2_event3	ev_test2@localhost	SELECT 256	RECURRING	NULL	1	HOUR	DISABLED	NOT PRESERVE	
+NULL	events_test2	ev_test3_event1	ev_test3@localhost	SELECT 289	RECURRING	NULL	1	HOUR	DISABLED	NOT PRESERVE	
+NULL	events_test2	ev_test3_event2	ev_test3@localhost	SELECT 324	RECURRING	NULL	1	HOUR	DISABLED	NOT PRESERVE	
+NULL	events_test2	ev_test3_event3	ev_test3@localhost	SELECT 361	RECURRING	NULL	1	HOUR	DISABLED	NOT PRESERVE	
+NULL	events_test2	five_event	root@localhost	SELECT 42	RECURRING	NULL	20	SECOND	ENABLED	NOT PRESERVE	
+"Drop two existing users. All their events will be dropped."
+DROP USER ev_test2@localhost, ev_test3@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 USER ev_test@localhost;
 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.3/mysql-test/r/events_scheduling.result	2006-05-22 20:45:57 +02:00
+++ 1.4/mysql-test/r/events_scheduling.result	2006-06-07 16:49:51 +02:00
@@ -39,7 +39,7 @@ DROP EVENT start_n_end;
 DROP EVENT only_one_time;
 ERROR HY000: Unknown event 'only_one_time'
 "Should be preserved"
-SELECT EVENT_NAME, STATUS FROM INFORMATION_SCHEMA.EVENTS;
+SELECT EVENT_NAME, STATUS FROM INFORMATION_SCHEMA.EVENTS ORDER BY EVENT_NAME;
 EVENT_NAME	STATUS
 E19170	ENABLED
 two_time	DISABLED

--- 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-07 16:49:51 +02:00
@@ -6,12 +6,18 @@ 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;
+CREATE USER ev_test2@localhost;
+CREATE USER ev_test3@localhost;
 GRANT ALL ON events_test.* to ev_test@localhost;
 GRANT ALL ON events_test2.* to ev_test@localhost;
+GRANT ALL ON events_test2.* to ev_test2@localhost;
+GRANT ALL ON events_test2.* to ev_test3@localhost;
 REVOKE EVENT ON events_test2.* FROM ev_test@localhost;
+connect (ev_con3,localhost,ev_test3,,events_test2);
+connect (ev_con2,localhost,ev_test2,,events_test2);
 #now we are on con1
 connect (ev_con1,localhost,ev_test,,events_test2);
 select "NEW CONNECTION";
@@ -19,7 +25,7 @@ SELECT USER(), DATABASE();
 SHOW GRANTS;
 --echo "Here comes an error:";
 #NO EVENT_ACL on events_test2
---error 1044
+--error ER_DBACCESS_DENIED_ERROR
 SHOW EVENTS;
 USE events_test;
 --echo "We should see one event";
@@ -52,10 +58,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 +70,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 +97,38 @@ 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;
+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;
+connection ev_con2;
+CREATE EVENT ev_test2_event1 ON SCHEDULE EVERY 1 HOUR DISABLE DO SELECT 196;
+CREATE EVENT ev_test2_event2 ON SCHEDULE EVERY 1 HOUR DISABLE DO SELECT 225;
+CREATE EVENT ev_test2_event3 ON SCHEDULE EVERY 1 HOUR DISABLE DO SELECT 256;
+connection ev_con3;
+CREATE EVENT ev_test3_event1 ON SCHEDULE EVERY 1 HOUR DISABLE DO SELECT 289;
+CREATE EVENT ev_test3_event2 ON SCHEDULE EVERY 1 HOUR DISABLE DO SELECT 324;
+CREATE EVENT ev_test3_event3 ON SCHEDULE EVERY 1 HOUR DISABLE DO SELECT 361;
 disconnect ev_con1;
+disconnect ev_con2;
+disconnect ev_con3;
 connection default;
-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;
+--echo "Drop one existing and one non-existing user. Events of the former will be dropped."
+--error ER_CANNOT_USER
+DROP USER ev_test_non_exists@localhost, 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;
+--echo "Drop two existing users. All their events will be dropped."
+DROP USER ev_test2@localhost, ev_test3@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.4/mysql-test/t/events_scheduling.test	2006-05-22 20:45:57 +02:00
+++ 1.5/mysql-test/t/events_scheduling.test	2006-06-07 16:49:51 +02:00
@@ -29,7 +29,7 @@ DROP EVENT start_n_end;
 --error ER_EVENT_DOES_NOT_EXIST
 DROP EVENT only_one_time;
 --echo "Should be preserved"
-SELECT EVENT_NAME, STATUS FROM INFORMATION_SCHEMA.EVENTS;
+SELECT EVENT_NAME, STATUS FROM INFORMATION_SCHEMA.EVENTS ORDER BY EVENT_NAME;
 DROP EVENT two_time;
 DROP TABLE table_1;
 DROP TABLE table_2;

--- 1.41/sql/event.cc	2006-05-29 10:39:35 +02:00
+++ 1.42/sql/event.cc	2006-06-07 16:49:52 +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"
@@ -1225,44 +1226,14 @@ err:
 
 
 /*
-  Drops all events from a schema
-
-  SYNOPSIS
-    Events::drop_schema_events()
-      thd  Thread
-      db   ASCIIZ schema name
-
-  RETURN VALUE
-    0   OK
-    !0  Error
-*/
-
-int
-Events::drop_schema_events(THD *thd, char *db)
-{
-  int ret= 0;
-  LEX_STRING db_lex= {db, strlen(db)};
-  
-  DBUG_ENTER("evex_drop_db_events");  
-  DBUG_PRINT("enter", ("dropping events from %s", db));
-
-  Event_scheduler *scheduler= Event_scheduler::get_instance();
-  if (scheduler->initialized())
-    ret= scheduler->drop_schema_events(thd, &db_lex);
-  else
-    ret= db_drop_events_from_table(thd, &db_lex);
-
-  DBUG_RETURN(ret);
-}
-
-
-/*
   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
+      table       mysql.event TABLE
+      field       Which field of the row to use for matching
+      field_value The value that should match
 
   RETURN VALUE
      0  OK
@@ -1270,32 +1241,28 @@ 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, TABLE *table, 
+                                Events::enum_table_field field,
+                                LEX_STRING *field_value)
 {
-  int ret;
-  TABLE *table;
+  int ret= 0;
+  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("drop_events_from_table_by_field");  
+  DBUG_PRINT("enter", ("field=%d field_value=%s", field, field_value->str));
 
-  if ((ret= Events::open_event_table(thd, TL_WRITE, &table)))
-  {
-    sql_print_error("Table mysql.event is damaged.");
-    DBUG_RETURN(ret);
-  }
   /* only enabled events are in memory, so we go now and delete the rest */
   init_read_record(&read_record_info, thd, table, NULL, 1, 0);
-  while (!(read_record_info.read_record(&read_record_info)) && !ret)
+  while (!ret && !(read_record_info.read_record(&read_record_info)) )
   {
-    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])))
@@ -1307,13 +1274,10 @@ db_drop_events_from_table(THD *thd, LEX_
   end_read_record(&read_record_info);
   thd->version--;   /* Force close to free memory */
 
-  close_thread_tables(thd);
-
   DBUG_RETURN(ret);
 }
 
 
-
 /*
   Inits the scheduler's structures.
 
@@ -1331,10 +1295,8 @@ db_drop_events_from_table(THD *thd, LEX_
 int
 Events::init()
 {
-  int ret= 0;
   DBUG_ENTER("Events::init");
 
-  /* it should be an assignment! */
   if (opt_event_scheduler)
   {
     Event_scheduler *scheduler= Event_scheduler::get_instance();
@@ -1417,4 +1379,74 @@ void
 Events::destroy_mutexes()
 {
   Event_scheduler::destroy_mutexes();
+}
+
+
+/*
+  Drops all events from a schema
+
+  SYNOPSIS
+    Events::drop_schema_events()
+      thd  Thread
+      db   ASCIIZ schema name
+
+  RETURN VALUE
+    0   OK
+    !0  Error
+*/
+
+int
+Events::drop_schema_events(THD *thd, char *db)
+{
+  int ret;
+  LEX_STRING db_lex= {db, strlen(db)};
+  
+  DBUG_ENTER("Events::drop_schema_events");  
+  DBUG_PRINT("enter", ("dropping events from %s", db));
+
+  Event_scheduler *scheduler= Event_scheduler::get_instance();
+  if (scheduler->initialized())
+    ret= scheduler->drop_schema_events(thd, &db_lex);
+  else
+  {
+    TABLE *table;
+    if (!(ret= Events::open_event_table(thd, TL_WRITE, &table)))
+      ret= drop_events_from_table_by_field(thd, table, Events::FIELD_DB,
+                                           &db_lex);
+  }
+
+  DBUG_RETURN(ret);
+}
+
+
+/*
+  Drops all events of a specific user
+
+  SYNOPSIS
+    Events::drop_schema_events()
+      thd      Thread
+      table    mysql.event opened beforehand
+      definer  The user
+
+  RETURN VALUE
+    0   OK
+    !0  Error
+*/
+
+int
+Events::drop_user_events(THD *thd, TABLE *table, LEX_STRING *definer)
+{
+  int ret;
+  
+  DBUG_ENTER(" Events::drop_schema_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, table, definer);
+  else
+    ret= drop_events_from_table_by_field(thd, table, Events::FIELD_DEFINER,
+                                         definer);
+
+  DBUG_RETURN(ret);
 }

--- 1.29/sql/event.h	2006-05-29 10:39:35 +02:00
+++ 1.30/sql/event.h	2006-06-07 16:49:52 +02:00
@@ -93,6 +93,9 @@ public:
 
   static int
   drop_schema_events(THD *thd, char *db);
+
+  static int
+  drop_user_events(THD *thd, TABLE *table, 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-07 16:49:52 +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,9 @@ 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, TABLE *table,
+                                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-07 16:49:52 +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"
 
@@ -1090,24 +1091,58 @@ Event_scheduler::drop_matching_events(TH
 
   SYNOPSIS
     Event_scheduler::drop_schema_events()
-      thd        THD
-      db         The schema name
+      thd   THD
+      db    The schema name
 
   RETURN VALUE
-     -1  Scheduler not working
-    >=0  Number of dropped events
+     0  OK
+    !0  Error
 */
 
 int
 Event_scheduler::drop_schema_events(THD *thd, LEX_STRING *schema)
 {
   int ret;
+  TABLE *table;
   DBUG_ENTER("Event_scheduler::drop_schema_events");
   LOCK_SCHEDULER_DATA();
   if (is_running_or_suspended())
     drop_matching_events(thd, schema, event_timed_db_equal);
 
-  ret= db_drop_events_from_table(thd, schema);
+  if (!(ret= Events::open_event_table(thd, TL_WRITE, &table)))
+    ret= drop_events_from_table_by_field(thd, table, 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
+      table   mysql.event TABLE 
+      definer The definer
+
+  RETURN VALUE
+     0  OK
+    !0  Error
+*/
+
+int
+Event_scheduler::drop_user_events(THD *thd, TABLE *table, LEX_STRING *definer)
+{
+  int ret;
+  DBUG_ENTER("Event_scheduler::drop_user_events");
+  LOCK_SCHEDULER_DATA();
+  if (is_running_or_suspended())
+    drop_matching_events(thd, definer, event_timed_definer_equal);
+
+  ret= drop_events_from_table_by_field(thd, table, Events::FIELD_DEFINER,
+                                       definer);
   UNLOCK_SCHEDULER_DATA();
 
   DBUG_RETURN(ret);
@@ -1271,8 +1306,6 @@ Event_scheduler::run(THD *thd)
   if (!check_n_suspend_if_needed(thd))
     UNLOCK_SCHEDULER_DATA();
 
-  sql_print_information("SCHEDULER: Manager thread started with id %lu",
-                        thd->thread_id);
   abstime.tv_nsec= 0;
   while (is_running_or_suspended())
   {

--- 1.4/sql/event_scheduler.h	2006-05-23 17:46:28 +02:00
+++ 1.5/sql/event_scheduler.h	2006-06-07 16:49:52 +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, TABLE *table, 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-07 16:49:52 +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#16424ahristov7 Jun