List:Commits« Previous MessageNext Message »
From:ahristov Date:February 1 2006 10:51pm
Subject:bk commit into 5.1 tree (andrey:1.2102) BUG#16423
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.2102 06/02/01 22:51:10 andrey@lmy004. +10 -0
  - final fixes for bug#16431 (Events: An event which alters itself disappears)
  - fix for bug#16423 (Events: SHOW CREATE EVENT doesn't work)
  - this Changeset commits makes CREATE/UPDATE/DELETE EVENT real DDL statements
    by committing the currently open transaction before they are executed.
  - this Changeset also fixes a trailing space problem since the very early days
    of the internal cron
  WL#1034 (Internal CRON)

  sql/sql_yacc.yy
    1.448 06/02/01 22:50:58 andrey@lmy004. +4 -0
    init the definer of event_timed also when doing SHOW CREATE EVENT
    because it's needed for checking into mysql.event

  sql/sql_show.cc
    1.295 06/02/01 22:50:58 andrey@lmy004. +1 -1
    export it to other files

  sql/sql_parse.cc
    1.516 06/02/01 22:50:58 andrey@lmy004. +15 -2
    - handle SQLCOM_SHOW_CREATE_EVENT
    - end the current transaction becase CREATE/UPDATE/DELETE EVENT is a DDL
      statement

  sql/share/errmsg.txt
    1.78 06/02/01 22:50:57 andrey@lmy004. +4 -2
    - fix an error message and add a new one

  sql/event_timed.cc
    1.25 06/02/01 22:50:57 andrey@lmy004. +199 -34
    - implement SHOW CREATE EVENT

  sql/event_executor.cc
    1.23 06/02/01 22:50:57 andrey@lmy004. +72 -0
    - add evex_check_system_tables() that checks on boot and event
      main thread startup that the tables are correct.

  sql/event.h
    1.17 06/02/01 22:50:57 andrey@lmy004. +5 -2
    - add evex_show_create_event(THD *thd, sp_name *spn, LEX_STRING definer)
    - change get_show_create_event() to get_create_event()

  sql/event.cc
    1.24 06/02/01 22:50:57 andrey@lmy004. +94 -9
    - do more checking on mysql.event whether it's valid
    - add evex_show_create_event(THD *thd, sp_name *spn, LEX_STRING definer)

  mysql-test/t/events.test
    1.13 06/02/01 22:50:57 andrey@lmy004. +66 -0
    add test cases for SHOW CREATE EVENT

  mysql-test/r/events.result
    1.12 06/02/01 22:50:57 andrey@lmy004. +103 -7
    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-bug16548

--- 1.515/sql/sql_parse.cc	2006-01-30 13:31:20 +01:00
+++ 1.516/sql/sql_parse.cc	2006-02-01 22:50:58 +01:00
@@ -3711,6 +3711,12 @@
                        is_schema_db(lex->et->dbname.str)))
         break;
 
+      if (end_active_trans(thd)) 
+      {
+        res= -1;
+        break;
+      }
+
       switch (lex->sql_command) {
       case SQLCOM_CREATE_EVENT:
         res= evex_create_event(thd, lex->et, (uint) lex->create_info.options,
@@ -3735,6 +3741,14 @@
   }
   case SQLCOM_SHOW_CREATE_EVENT:
   {
+    DBUG_ASSERT(lex->spname);
+    DBUG_ASSERT(lex->et);
+    if (! lex->spname->m_db.str)
+    {
+      my_message(ER_NO_DB_ERROR, ER(ER_NO_DB_ERROR), MYF(0));
+      res= true;
+      break;
+    }
     if (check_access(thd, EVENT_ACL, lex->spname->m_db.str, 0, 0, 0,
                      is_schema_db(lex->spname->m_db.str)))
       break;
@@ -3744,8 +3758,7 @@
       my_error(ER_TOO_LONG_IDENT, MYF(0), lex->spname->m_name.str);
       goto error;
     }
-    /* TODO : Implement it */
-    send_ok(thd, 1);
+    res= evex_show_create_event(thd, lex->spname, lex->et->definer);
     break;
   }
   case SQLCOM_CREATE_FUNCTION:                  // UDF function

--- 1.294/sql/sql_show.cc	2006-01-30 13:15:05 +01:00
+++ 1.295/sql/sql_show.cc	2006-02-01 22:50:58 +01:00
@@ -3772,7 +3772,7 @@
 }
 
 
-static LEX_STRING interval_type_to_name[] = {
+LEX_STRING interval_type_to_name[] = {
   {(char *) STRING_WITH_LEN("INTERVAL_YEAR")}, 
   {(char *) STRING_WITH_LEN("INTERVAL_QUARTER")}, 
   {(char *) STRING_WITH_LEN("INTERVAL_MONTH")}, 

--- 1.447/sql/sql_yacc.yy	2006-01-30 13:31:21 +01:00
+++ 1.448/sql/sql_yacc.yy	2006-02-01 22:50:58 +01:00
@@ -8402,6 +8402,10 @@
           {
             Lex->sql_command = SQLCOM_SHOW_CREATE_EVENT;
             Lex->spname= $3;
+            Lex->et= new event_timed();
+            if (!Lex->et)
+              YYABORT;
+            Lex->et->init_definer(YYTHD);
           }
       ;
 

--- 1.11/mysql-test/r/events.result	2006-01-30 17:11:41 +01:00
+++ 1.12/mysql-test/r/events.result	2006-02-01 22:50:57 +01:00
@@ -24,7 +24,7 @@
 0
 select db, name, body, status, interval_field, interval_value from mysql.event;
 db	name	body	status	interval_field	interval_value
-events_test	e_43	 set @a = 4	ENABLED	SECOND	1
+events_test	e_43	set @a = 4	ENABLED	SECOND	1
 drop event e_43;
 select sleep(1);
 sleep(1)
@@ -41,13 +41,109 @@
 0
 drop event event3;
 drop table t_event3;
+set names utf8;
+CREATE EVENT root6 ON SCHEDULE EVERY '10:20' MINUTE_SECOND ON COMPLETION PRESERVE ENABLE
COMMENT 'some comment' DO select 1;
+SHOW CREATE EVENT root6;
+Event	Create Procedure
+root6	CREATE EVENT `events_test`.`root6` ON SCHEDULE EVERY '10:20' MINUTE_SECOND ON
COMPLETION PRESERVE ENABLE COMMENT 'some comment' DO select 1
+create event root7 on schedule every 2 year do select 1;
+SHOW CREATE EVENT root7;
+Event	Create Procedure
+root7	CREATE EVENT `events_test`.`root7` ON SCHEDULE EVERY 2 YEAR ON COMPLETION NOT
PRESERVE ENABLE DO select 1
+create event root8 on schedule every '2:5' year_month do select 1;
+SHOW CREATE EVENT root8;
+Event	Create Procedure
+root8	CREATE EVENT `events_test`.`root8` ON SCHEDULE EVERY '2:5' YEAR_MONTH ON COMPLETION
NOT PRESERVE ENABLE DO select 1
+create event root8_1 on schedule every '2:15' year_month do select 1;
+SHOW CREATE EVENT root8_1;
+Event	Create Procedure
+root8_1	CREATE EVENT `events_test`.`root8_1` ON SCHEDULE EVERY '3:3' YEAR_MONTH ON
COMPLETION NOT PRESERVE ENABLE DO select 1
+create event root9 on schedule every 2 week ON COMPLETION PRESERVE DISABLE COMMENT
'коментар на кирилица' do select 1;
+SHOW CREATE EVENT root9;
+Event	Create Procedure
+root9	CREATE EVENT `events_test`.`root9` ON SCHEDULE EVERY 2 WEEK ON COMPLETION PRESERVE
DISABLE COMMENT 'коментар на кирилица' DO select 1
+create event root10 on schedule every '20:5' day_hour do select 1;
+SHOW CREATE EVENT root10;
+Event	Create Procedure
+root10	CREATE EVENT `events_test`.`root10` ON SCHEDULE EVERY '20:5' DAY_HOUR ON
COMPLETION NOT PRESERVE ENABLE DO select 1
+create event root11 on schedule every '20:25' day_hour do select 1;
+SHOW CREATE EVENT root11;
+Event	Create Procedure
+root11	CREATE EVENT `events_test`.`root11` ON SCHEDULE EVERY '21:1' DAY_HOUR ON
COMPLETION NOT PRESERVE ENABLE DO select 1
+create event root12 on schedule every '20:25' hour_minute do select 1;
+SHOW CREATE EVENT root12;
+Event	Create Procedure
+root12	CREATE EVENT `events_test`.`root12` ON SCHEDULE EVERY '20:25' HOUR_MINUTE ON
COMPLETION NOT PRESERVE ENABLE DO select 1
+create event root13 on schedule every '25:25' hour_minute do select 1;
+SHOW CREATE EVENT root13;
+Event	Create Procedure
+root13	CREATE EVENT `events_test`.`root13` ON SCHEDULE EVERY '25:25' HOUR_MINUTE ON
COMPLETION NOT PRESERVE ENABLE DO select 1
+create event root13_1 on schedule every '11:65' hour_minute do select 1;
+SHOW CREATE EVENT root13_1;
+Event	Create Procedure
+root13_1	CREATE EVENT `events_test`.`root13_1` ON SCHEDULE EVERY '12:5' HOUR_MINUTE ON
COMPLETION NOT PRESERVE ENABLE DO select 1
+create event root14 on schedule every '35:35' minute_second do select 1;
+SHOW CREATE EVENT root14;
+Event	Create Procedure
+root14	CREATE EVENT `events_test`.`root14` ON SCHEDULE EVERY '35:35' MINUTE_SECOND ON
COMPLETION NOT PRESERVE ENABLE DO select 1
+create event root15 on schedule every '35:66' minute_second do select 1;
+SHOW CREATE EVENT root15;
+Event	Create Procedure
+root15	CREATE EVENT `events_test`.`root15` ON SCHEDULE EVERY '36:6' MINUTE_SECOND ON
COMPLETION NOT PRESERVE ENABLE DO select 1
+create event root16 on schedule every '35:56' day_minute do select 1;
+SHOW CREATE EVENT root16;
+Event	Create Procedure
+root16	CREATE EVENT `events_test`.`root16` ON SCHEDULE EVERY '1:11:56' DAY_MINUTE ON
COMPLETION NOT PRESERVE ENABLE DO select 1
+create event root17 on schedule every '35:12:45' day_minute do select 1;
+SHOW CREATE EVENT root17;
+Event	Create Procedure
+root17	CREATE EVENT `events_test`.`root17` ON SCHEDULE EVERY '35:12:45' DAY_MINUTE ON
COMPLETION NOT PRESERVE ENABLE DO select 1
+create event root17_1 on schedule every '35:25:65' day_minute do select 1;
+SHOW CREATE EVENT root17_1;
+Event	Create Procedure
+root17_1	CREATE EVENT `events_test`.`root17_1` ON SCHEDULE EVERY '36:2:5' DAY_MINUTE ON
COMPLETION NOT PRESERVE ENABLE DO select 1
+create event root18 on schedule every '35:12:45' hour_second do select 1;
+SHOW CREATE EVENT root18;
+Event	Create Procedure
+root18	CREATE EVENT `events_test`.`root18` ON SCHEDULE EVERY '35:12:45' HOUR_SECOND ON
COMPLETION NOT PRESERVE ENABLE DO select 1
+create event root19 on schedule every '15:59:85' hour_second do select 1;
+SHOW CREATE EVENT root19;
+Event	Create Procedure
+root19	CREATE EVENT `events_test`.`root19` ON SCHEDULE EVERY '16:0:25' HOUR_SECOND ON
COMPLETION NOT PRESERVE ENABLE DO select 1
+create event root20 on schedule every '50:20:12:45' day_second do select 1;
+SHOW CREATE EVENT root20;
+Event	Create Procedure
+root20	CREATE EVENT `events_test`.`root20` ON SCHEDULE EVERY '50:20:12:45' DAY_SECOND ON
COMPLETION NOT PRESERVE ENABLE DO select 1
+create event root21 on schedule every '50:23:59:95' day_second do select 1;
+SHOW CREATE EVENT root21;
+Event	Create Procedure
+root21	CREATE EVENT `events_test`.`root21` ON SCHEDULE EVERY '51:0:0:35' DAY_SECOND ON
COMPLETION NOT PRESERVE ENABLE DO select 1
+drop event root6;
+drop event root7;
+drop event root8;
+drop event root8_1;
+drop event root9;
+drop event root10;
+drop event root11;
+drop event root12;
+drop event root13;
+drop event root13_1;
+drop event root14;
+drop event root15;
+drop event root16;
+drop event root17;
+drop event root17_1;
+drop event root18;
+drop event root19;
+drop event root20;
+drop event root21;
 create event one_event on schedule every 10 second do select 123;
 SHOW EVENTS;
 Db	Name	Definer	Type	Execute at	Interval value	Interval field	Starts	Ends	Status
 events_test	one_event	root@localhost	RECURRING	NULL	10	INTERVAL_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;
 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	INTERVAL_SECOND	ENABLED	NOT PRESERVE	
+NULL	events_test	one_event	root@localhost	select
123	RECURRING	NULL	10	INTERVAL_SECOND	ENABLED	NOT PRESERVE	
 CREATE DATABASE events_test2;
 CREATE USER ev_test@localhost;
 GRANT ALL ON events_test.* to ev_test@localhost;
@@ -112,10 +208,10 @@
 events_test	one_event	root@localhost	RECURRING	NULL	10	INTERVAL_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;
 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	ev_test@localhost	 select
123	RECURRING	NULL	20	INTERVAL_SECOND	ENABLED	NOT PRESERVE	
-NULL	events_test	three_event	ev_test@localhost	 select
123	RECURRING	NULL	20	INTERVAL_SECOND	ENABLED	PRESERVE	three event
-NULL	events_test	two_event	ev_test@localhost	 select
123	RECURRING	NULL	20	INTERVAL_SECOND	ENABLED	NOT PRESERVE	two event
-NULL	events_test	one_event	root@localhost	 select
123	RECURRING	NULL	10	INTERVAL_SECOND	ENABLED	NOT PRESERVE	
+NULL	events_test	one_event	ev_test@localhost	select
123	RECURRING	NULL	20	INTERVAL_SECOND	ENABLED	NOT PRESERVE	
+NULL	events_test	three_event	ev_test@localhost	select
123	RECURRING	NULL	20	INTERVAL_SECOND	ENABLED	PRESERVE	three event
+NULL	events_test	two_event	ev_test@localhost	select
123	RECURRING	NULL	20	INTERVAL_SECOND	ENABLED	NOT PRESERVE	two event
+NULL	events_test	one_event	root@localhost	select
123	RECURRING	NULL	10	INTERVAL_SECOND	ENABLED	NOT PRESERVE	
 drop event one_event;
 drop event two_event;
 drop event three_event;
@@ -124,7 +220,7 @@
 create event e_26 on schedule at '2017-01-01 00:00:00' disable do set @a = 5;
 select db, name, body, definer, convert_tz(execute_at, 'UTC', 'SYSTEM'), on_completion
from mysql.event;
 db	name	body	definer	convert_tz(execute_at, 'UTC', 'SYSTEM')	on_completion
-events_test	e_26	 set @a = 5	root@localhost	2017-01-01 00:00:00	DROP
+events_test	e_26	set @a = 5	root@localhost	2017-01-01 00:00:00	DROP
 drop event e_26;
 create event e_26 on schedule at NULL disabled do set @a = 5;
 ERROR HY000: Incorrect AT value: 'NULL'

--- 1.12/mysql-test/t/events.test	2006-01-30 17:11:42 +01:00
+++ 1.13/mysql-test/t/events.test	2006-02-01 22:50:57 +01:00
@@ -33,6 +33,72 @@
 drop event event3;
 drop table t_event3;
 
+
+set names utf8;
+#
+# SHOW CREATE EVENT test begin
+#
+CREATE EVENT root6 ON SCHEDULE EVERY '10:20' MINUTE_SECOND ON COMPLETION PRESERVE ENABLE
COMMENT 'some comment' DO select 1;
+SHOW CREATE EVENT root6;
+create event root7 on schedule every 2 year do select 1;
+SHOW CREATE EVENT root7;
+create event root8 on schedule every '2:5' year_month do select 1;
+SHOW CREATE EVENT root8;
+create event root8_1 on schedule every '2:15' year_month do select 1;
+SHOW CREATE EVENT root8_1;
+create event root9 on schedule every 2 week ON COMPLETION PRESERVE DISABLE COMMENT
'коментар на кирилица' do select 1;
+SHOW CREATE EVENT root9;
+create event root10 on schedule every '20:5' day_hour do select 1;
+SHOW CREATE EVENT root10;
+create event root11 on schedule every '20:25' day_hour do select 1;
+SHOW CREATE EVENT root11;
+create event root12 on schedule every '20:25' hour_minute do select 1;
+SHOW CREATE EVENT root12;
+create event root13 on schedule every '25:25' hour_minute do select 1;
+SHOW CREATE EVENT root13;
+create event root13_1 on schedule every '11:65' hour_minute do select 1;
+SHOW CREATE EVENT root13_1;
+create event root14 on schedule every '35:35' minute_second do select 1;
+SHOW CREATE EVENT root14;
+create event root15 on schedule every '35:66' minute_second do select 1;
+SHOW CREATE EVENT root15;
+create event root16 on schedule every '35:56' day_minute do select 1;
+SHOW CREATE EVENT root16;
+create event root17 on schedule every '35:12:45' day_minute do select 1;
+SHOW CREATE EVENT root17;
+create event root17_1 on schedule every '35:25:65' day_minute do select 1;
+SHOW CREATE EVENT root17_1;
+create event root18 on schedule every '35:12:45' hour_second do select 1;
+SHOW CREATE EVENT root18;
+create event root19 on schedule every '15:59:85' hour_second do select 1;
+SHOW CREATE EVENT root19;
+create event root20 on schedule every '50:20:12:45' day_second do select 1;
+SHOW CREATE EVENT root20;
+create event root21 on schedule every '50:23:59:95' day_second do select 1;
+SHOW CREATE EVENT root21;
+drop event root6;
+drop event root7;
+drop event root8;
+drop event root8_1;
+drop event root9;
+drop event root10;
+drop event root11;
+drop event root12;
+drop event root13;
+drop event root13_1;
+drop event root14;
+drop event root15;
+drop event root16;
+drop event root17;
+drop event root17_1;
+drop event root18;
+drop event root19;
+drop event root20;
+drop event root21;
+#
+# SHOW CREATE EVENT test end
+#
+
 #
 #INFORMATION_SCHEMA.EVENTS test begin
 #

--- 1.23/sql/event.cc	2006-01-30 13:31:16 +01:00
+++ 1.24/sql/event.cc	2006-02-01 22:50:57 +01:00
@@ -68,6 +68,15 @@
 MEM_ROOT evex_mem_root;
 
 
+#define EVEX_CHECK_FIELD_COUNT_ERR(version) \
+{ \
+ if (version == MYSQL_VERSION_ID) \
+   my_error(ER_EVENT_COL_COUNT_DOESNT_MATCH_CORRUPTED,MYF(0),"mysql","event");\
+ else \
+   my_error(ER_EVENT_COL_COUNT_DOESNT_MATCH_PLEASE_UPDATE, MYF(0), "mysql", \
+            "event", version, MYSQL_VERSION_ID);\
+}
+
 void
 evex_queue_init(EVEX_QUEUE_TYPE *queue)
 {
@@ -155,7 +164,7 @@
   
   if (tables.table->s->fields != EVEX_FIELD_COUNT)
   {
-    my_error(ER_EVENT_COL_COUNT_DOESNT_MATCH, MYF(0), "mysql", "event");
+    EVEX_CHECK_FIELD_COUNT_ERR(tables.table->s->version);
     close_thread_tables(thd);
     DBUG_RETURN(2);
   }
@@ -247,7 +256,7 @@
 
   if (table->s->fields != EVEX_FIELD_COUNT)
   {
-    my_error(ER_EVENT_COL_COUNT_DOESNT_MATCH, MYF(0), "mysql", "event");
+    EVEX_CHECK_FIELD_COUNT_ERR(table->s->version);
     DBUG_RETURN(EVEX_GET_FIELD_FAILED);
   }
   
@@ -584,16 +593,19 @@
 */
 
 static int
-db_find_event(THD *thd, sp_name *name, LEX_STRING definer, event_timed **ett,
-              TABLE *tbl)
+db_find_event(THD *thd, sp_name *name, LEX_STRING *definer, event_timed **ett,
+              TABLE *tbl, MEM_ROOT *root)
 {
   TABLE *table;
   int ret;
   char *ptr;
-  event_timed *et;  
+  event_timed *et=NULL;
   DBUG_ENTER("db_find_event");
   DBUG_PRINT("enter", ("name: %*s", name->m_name.length, name->m_name.str));
 
+  if (!root)
+    root= &evex_mem_root;
+
   if (tbl)
     table= tbl;
   else if (evex_open_event_table(thd, TL_READ, &table))
@@ -603,7 +615,7 @@
     goto done;
   }
 
-  if ((ret= evex_db_find_event_aux(thd, name->m_db, name->m_name, definer,
+  if ((ret= evex_db_find_event_aux(thd, name->m_db, name->m_name, *definer,
                                    table)))
   {
     my_error(ER_EVENT_DOES_NOT_EXIST, MYF(0), name->m_name.str);
@@ -617,7 +629,7 @@
 
     2)::load_from_row() is silent on error therefore we emit error msg here
   */
-  if ((ret= et->load_from_row(&evex_mem_root, table)))
+  if ((ret= et->load_from_row(root, table)))
   {
     my_error(ER_EVENT_CANNOT_LOAD_FROM_TABLE, MYF(0));
     goto done;
@@ -671,10 +683,11 @@
 
   thd->reset_n_backup_open_tables_state(&backup);
   // no need to use my_error() here because db_find_event() has done it
-  if ((ret= db_find_event(thd, spn, definer, &ett, NULL)))
+  ret= db_find_event(thd, spn, &definer, &ett, NULL, NULL);
+  thd->restore_backup_open_tables_state(&backup);
+  if (ret)
     goto done;
 
-  thd->restore_backup_open_tables_state(&backup);
   /*
     allocate on evex_mem_root. if you call without evex_mem_root
     then sphead will not be cleared!
@@ -923,3 +936,75 @@
   DBUG_RETURN(ret);
 }
 
+/*
+   SHOW CREATE EVENT
+
+   SYNOPSIS
+     evex_update_event()
+       thd        THD
+       et         event's data
+       new_name   set in case of RENAME TO.    
+          
+   NOTES
+     et contains data about dbname and event name. 
+     name is the new name of the event, if not null this means
+     that RENAME TO was specified in the query.
+*/
+
+int
+evex_show_create_event(THD *thd, sp_name *spn, LEX_STRING definer)
+{
+  int ret;
+  event_timed *et= NULL;
+  Open_tables_state backup;
+
+  DBUG_ENTER("evex_update_event");
+  DBUG_PRINT("enter", ("name: %*s", spn->m_name.length, spn->m_name.str));
+
+  thd->reset_n_backup_open_tables_state(&backup);
+  ret= db_find_event(thd, spn, &definer, &et, NULL, thd->mem_root);
+  thd->restore_backup_open_tables_state(&backup);
+
+  if (!ret && et)
+  {    
+    Protocol *protocol= thd->protocol;
+    String show_str;
+    int res;
+    List<Item> field_list;
+#ifdef TO_BE_ENABLED_WHEN_SQLMODE_IS_FIXED
+    byte *sql_mode_str;
+    ulong sql_mode_len;
+#endif
+
+    field_list.push_back(new Item_empty_string("Event", NAME_LEN));
+#ifdef TO_BE_ENABLED_WHEN_SQLMODE_IS_FIXED
+    sql_mode_str=
+      sys_var_thd_sql_mode::symbolic_mode_representation(thd,
+                                                       this.sql_mode,
+                                                       &sql_mode_len);
+    field_list.push_back(new Item_empty_string("sql_mode", sql_mode_len));
+#endif
+
+    // 1024 is for not to confuse old clients
+    field_list.push_back(new Item_empty_string("Create Procedure",
+					     max(show_str.length(), 1024)));
+    if (protocol->send_fields(&field_list, Protocol::SEND_NUM_ROWS |
+                                           Protocol::SEND_EOF))
+      DBUG_RETURN(1);
+
+    protocol->prepare_for_resend();
+    protocol->store(et->name.str, et->name.length, system_charset_info);
+
+#ifdef TO_BE_ENABLED_WHEN_SQLMODE_IS_FIXED
+    protocol->store((char*) sql_mode_str, sql_mode_len, system_charset_info);
+#endif
+    
+    show_str.set_charset(system_charset_info);
+    et->get_create_event(thd, &show_str);
+    protocol->store(show_str.c_ptr(), show_str.length(), system_charset_info);
+    ret= protocol->write();
+    send_eof(thd);
+  }
+  
+  DBUG_RETURN(ret);
+}

--- 1.16/sql/event.h	2006-01-30 17:54:11 +01:00
+++ 1.17/sql/event.h	2006-02-01 22:50:57 +01:00
@@ -176,8 +176,8 @@
   bool
   update_fields(THD *thd);
 
-  char *
-  get_show_create_event(THD *thd, uint32 *length);
+  int
+  get_create_event(THD *thd, String *buf);
   
   int
   execute(THD *thd, MEM_ROOT *mem_root= NULL);
@@ -219,6 +219,9 @@
 
 int
 evex_open_event_table(THD *thd, enum thr_lock_type lock_type, TABLE **table);
+
+int
+evex_show_create_event(THD *thd, sp_name *spn, LEX_STRING definer);
 
 int sortcmp_lex_string(LEX_STRING s, LEX_STRING t, CHARSET_INFO *cs);
 

--- 1.22/sql/event_executor.cc	2006-01-30 17:54:11 +01:00
+++ 1.23/sql/event_executor.cc	2006-02-01 22:50:57 +01:00
@@ -83,6 +83,76 @@
 }
 
 
+/*
+  Opens mysql.event , mysql.db and mysql.user and checks whether
+  1. the number of columns in mysql.event is correct
+  2. mysql.db has column Event_priv at column 20 (0 based);
+  3. mysql.user has column Event_priv at column 29 (0 based);
+*/
+
+void
+evex_check_system_tables()
+{
+  THD *thd= current_thd;
+  TABLE_LIST tables;
+  TABLE *table;
+  bool not_used;
+  Open_tables_state backup;
+
+  // thd is 0x0 during boot of the server. Later it's !=0x0
+  if (!thd)
+    return;
+
+  thd->reset_n_backup_open_tables_state(&backup);
+  
+  {
+    if (evex_open_event_table(thd, TL_READ, &table))
+      sql_print_error("Cannot open mysql.event");
+    if (table)
+      close_thread_tables(thd);
+  }
+  {
+    bzero((char*) &tables, sizeof(tables));
+    tables.db= (char*) "mysql";
+    tables.table_name= tables.alias= (char*) "db";
+    tables.lock_type= TL_READ;
+
+    if (simple_open_n_lock_tables(thd, &tables))
+      sql_print_information("Cannot open mysql.db");
+    else
+    {
+      if (tables.table->s->fields < 20)
+        sql_print_error("mysql.db has no Event_priv");
+      else if (strncmp(tables.table->field[20]->field_name,
+                       STRING_WITH_LEN("Event_priv")))
+        sql_print_error("mysql.db has no `Event_priv` column at position 20");
+
+      close_thread_tables(thd);
+    }
+  }
+  {
+    bzero((char*) &tables, sizeof(tables));
+    tables.db= (char*) "mysql";
+    tables.table_name= tables.alias= (char*) "user";
+    tables.lock_type= TL_READ;
+
+    if (simple_open_n_lock_tables(thd, &tables))
+      sql_print_information("Cannot open mysql.db");
+    else
+    {
+      if (tables.table->s->fields < 29 ||
+          strncmp(tables.table->field[29]->field_name,
+                  STRING_WITH_LEN("Event_priv")))
+        sql_print_error("mysql.user has no `Event_priv` column at position 29");
+
+      close_thread_tables(thd);
+    }
+  }
+
+  thd->restore_backup_open_tables_state(&backup);
+}
+
+
 int
 init_events()
 {
@@ -91,6 +161,8 @@
   DBUG_ENTER("init_events");
 
   DBUG_PRINT("info",("Starting events main thread"));
+  
+  evex_check_system_tables();
 
   evex_init_mutexes();
 

--- 1.24/sql/event_timed.cc	2006-01-30 17:54:11 +01:00
+++ 1.25/sql/event_timed.cc	2006-02-01 22:50:57 +01:00
@@ -116,7 +116,9 @@
   while (body.length && body_begin[body.length-1] == '\0')
     body.length--;
 
-  body.str= strmake_root(root, (char *)body_begin, body.length);
+  //the first is always space which I cannot skip in the parser
+  body.length--;
+  body.str= strmake_root(root, (char *)body_begin + 1, body.length);
 
   DBUG_VOID_RETURN;
 }
@@ -950,41 +952,198 @@
   DBUG_RETURN(ret);
 }
 
+static LEX_STRING interval_type_to_name[] = {
+  {(char *) STRING_WITH_LEN("YEAR")}, 
+  {(char *) STRING_WITH_LEN("QUARTER")}, 
+  {(char *) STRING_WITH_LEN("MONTH")}, 
+  {(char *) STRING_WITH_LEN("DAY")}, 
+  {(char *) STRING_WITH_LEN("HOUR")}, 
+  {(char *) STRING_WITH_LEN("MINUTE")}, 
+  {(char *) STRING_WITH_LEN("WEEK")}, 
+  {(char *) STRING_WITH_LEN("SECOND")}, 
+  {(char *) STRING_WITH_LEN("MICROSECOND")}, 
+  {(char *) STRING_WITH_LEN("YEAR_MONTH")}, 
+  {(char *) STRING_WITH_LEN("DAY_HOUR")}, 
+  {(char *) STRING_WITH_LEN("DAY_MINUTE")}, 
+  {(char *) STRING_WITH_LEN("DAY_SECOND")}, 
+  {(char *) STRING_WITH_LEN("HOUR_MINUTE")}, 
+  {(char *) STRING_WITH_LEN("HOUR_SECOND")}, 
+  {(char *) STRING_WITH_LEN("MINUTE_SECOND")}, 
+  {(char *) STRING_WITH_LEN("DAY_MICROSECOND")}, 
+  {(char *) STRING_WITH_LEN("HOUR_MICROSECOND")}, 
+  {(char *) STRING_WITH_LEN("MINUTE_MICROSECOND")}, 
+  {(char *) STRING_WITH_LEN("SECOND_MICROSECOND")}
+}; 
 
-char *
-event_timed::get_show_create_event(THD *thd, uint32 *length)
-{
-  char *dst, *ret;
-  uint len, tmp_len;
-  DBUG_ENTER("get_show_create_event");
-  DBUG_PRINT("ret_info",("body_len=[%d]body=[%s]", body.length, body.str));
 
-  len = strlen("CREATE EVENT `") + dbname.length + strlen("`.`") + name.length +
-        strlen("` ON SCHEDULE EVERY 5 MINUTE DO ") + body.length;// + strlen(";");
+/*
+  Get SHOW CREATE EVENT as string
   
-  ret= dst= (char*) alloc_root(thd->mem_root, len + 1);
-  memcpy(dst, "CREATE EVENT `", tmp_len= strlen("CREATE EVENT `"));
-  dst+= tmp_len;
-  memcpy(dst, dbname.str, tmp_len=dbname.length);
-  dst+= tmp_len;
-  memcpy(dst, "`.`", tmp_len= strlen("`.`"));
-  dst+= tmp_len;
-  memcpy(dst, name.str, tmp_len= name.length);
-  dst+= tmp_len;
-  memcpy(dst, "` ON SCHEDULE EVERY 5 MINUTE DO ",
-         tmp_len= strlen("` ON SCHEDULE EVERY 5 MINUTE DO "));
-  dst+= tmp_len;
-
-  memcpy(dst, body.str, tmp_len= body.length);
-  dst+= tmp_len;
-//  memcpy(dst, ";", 1);
-//  ++dst;
-  *dst= '\0';
- 
-  *length= len;
+  thd  - Thread
+  buf  - String*, should be already allocated. CREATE EVENT goes inside.
   
-  DBUG_PRINT("ret_info",("len=%d",*length));
-  DBUG_RETURN(ret);
+  Returns:
+  0 - OK
+
+*/
+
+int
+event_timed::get_create_event(THD *thd, String *buf)
+{
+  char tmp_buff[128];
+  ulonglong expr= expression;
+  int multipl= 0;
+
+  DBUG_ENTER("get_create_event");
+  DBUG_PRINT("ret_info",("body_len=[%d]body=[%s]", body.length, body.str));
+
+  buf->append(STRING_WITH_LEN("CREATE EVENT "));
+  append_identifier(thd, buf, dbname.str, dbname.length);
+  buf->append(STRING_WITH_LEN("."));
+  append_identifier(thd, buf, name.str, name.length);
+
+  buf->append(STRING_WITH_LEN(" ON SCHEDULE "));
+  if (expr)
+  {
+    char *end;
+    bool close_quote= TRUE;
+    
+    buf->append(STRING_WITH_LEN("EVERY "));
+
+    switch (interval) {
+    case INTERVAL_YEAR_MONTH:
+      multipl= 12;
+      goto common_1_lev_code;
+    case INTERVAL_DAY_HOUR:
+      multipl= 24;
+      goto common_1_lev_code;
+    case INTERVAL_HOUR_MINUTE:
+    case INTERVAL_MINUTE_SECOND:
+      multipl= 60;      
+common_1_lev_code:
+      buf->append('\'');
+      end= longlong10_to_str(expression/multipl, tmp_buff, 10);
+      buf->append(tmp_buff, (uint) (end- tmp_buff));
+      expr= expr - (expr/multipl)*multipl;
+      break;
+    case INTERVAL_DAY_MINUTE:
+    {
+      int tmp_expr= expr;
+
+      tmp_expr/=(24*60);
+      buf->append('\'');
+      end= longlong10_to_str(tmp_expr, tmp_buff, 10);
+      buf->append(tmp_buff, (uint) (end- tmp_buff));// days
+      buf->append(':');
+
+      tmp_expr= expr - tmp_expr*(24*60);//minutes left
+      end= longlong10_to_str(tmp_expr/60, tmp_buff, 10);
+      buf->append(tmp_buff, (uint) (end- tmp_buff));// hours
+
+      expr= tmp_expr - (tmp_expr/60)*60;
+      /* the code after the switch will finish */
+    }
+      break;
+    case INTERVAL_HOUR_SECOND:
+    {
+      int tmp_expr= expr;
+
+      buf->append('\'');
+      end= longlong10_to_str(tmp_expr/3600, tmp_buff, 10);
+      buf->append(tmp_buff, (uint) (end- tmp_buff));// hours
+      buf->append(':');
+
+      tmp_expr= tmp_expr - (tmp_expr/3600)*3600;
+      end= longlong10_to_str(tmp_expr/60, tmp_buff, 10);
+      buf->append(tmp_buff, (uint) (end- tmp_buff));// minutes
+
+      expr= tmp_expr - (tmp_expr/60)*60;
+      /* the code after the switch will finish */
+    }
+      break;      
+    case INTERVAL_DAY_SECOND:
+    {
+      int tmp_expr= expr;
+
+      tmp_expr/=(24*3600);
+      buf->append('\'');
+      end= longlong10_to_str(tmp_expr, tmp_buff, 10);
+      buf->append(tmp_buff, (uint) (end- tmp_buff));// days
+      buf->append(':');
+
+      tmp_expr= expr - tmp_expr*(24*3600);//seconds left
+      end= longlong10_to_str(tmp_expr/3600, tmp_buff, 10);
+      buf->append(tmp_buff, (uint) (end- tmp_buff));// hours
+      buf->append(':');
+
+      tmp_expr= tmp_expr - (tmp_expr/3600)*3600;
+      end= longlong10_to_str(tmp_expr/60, tmp_buff, 10);
+      buf->append(tmp_buff, (uint) (end- tmp_buff));// minutes
+
+      expr= tmp_expr - (tmp_expr/60)*60;
+      /* the code after the switch will finish */
+    }
+      break;  
+    case INTERVAL_DAY_MICROSECOND:
+      break;
+    case INTERVAL_HOUR_MICROSECOND:
+      break;
+    case INTERVAL_MINUTE_MICROSECOND:
+      break;
+    case INTERVAL_SECOND_MICROSECOND:
+      break;
+    case INTERVAL_QUARTER:
+      expr/= 3;
+      close_quote= FALSE;
+      break;
+    case INTERVAL_WEEK:
+      expr/= 7;
+    default:
+      close_quote= FALSE;
+      break;
+    }
+    if (close_quote)
+      buf->append(':');
+    end= longlong10_to_str(expr, tmp_buff, 10);
+    buf->append(tmp_buff, (uint) (end- tmp_buff));
+    if (close_quote)
+      buf->append('\'');
+    
+    buf->append(' ');
+    LEX_STRING *ival= &interval_type_to_name[interval];
+    buf->append(ival->str, ival->length);
+  }
+  else
+  {
+    char dtime_buff[20*2+32];// +32 to make my_snprintf_{8bit|ucs2} happy
+    buf->append(STRING_WITH_LEN("AT '"));
+    /* 
+      pass the buffer and the second param tells fills the buffer and returns
+      the number of chars to copy
+    */
+    buf->append(dtime_buff, my_datetime_to_str(&execute_at, dtime_buff));
+    buf->append(STRING_WITH_LEN("'"));
+  }
+
+  if (on_completion == MYSQL_EVENT_ON_COMPLETION_DROP)
+    buf->append(STRING_WITH_LEN(" ON COMPLETION NOT PRESERVE "));
+  else
+    buf->append(STRING_WITH_LEN(" ON COMPLETION PRESERVE "));
+
+  if (status == MYSQL_EVENT_ENABLED)
+    buf->append(STRING_WITH_LEN("ENABLE"));
+  else
+    buf->append(STRING_WITH_LEN("DISABLE"));
+
+  if (comment.length)
+  {
+    buf->append(STRING_WITH_LEN(" COMMENT "));
+    append_unescaped(buf, comment.str, comment.length);
+  }
+  buf->append(STRING_WITH_LEN(" DO "));
+  buf->append(body.str, body.length);  
+
+  DBUG_RETURN(0);
 }
 
 
@@ -1064,7 +1223,9 @@
   char *old_query;
   uint old_query_len;
   st_sp_chistics *p;
-  CHARSET_INFO *old_character_set_client, *old_collation_connection,
+  String show_create;
+  CHARSET_INFO *old_character_set_client,
+               *old_collation_connection,
                *old_character_set_results;
 
   old_character_set_client= thd->variables.character_set_client;
@@ -1089,7 +1250,11 @@
   old_query= thd->query;
   old_db= thd->db;
   thd->db= dbname.str;
-  thd->query= get_show_create_event(thd, &thd->query_length);
+
+  get_create_event(thd, &show_create);
+
+  thd->query= show_create.c_ptr();
+  thd->query_length= show_create.length();
   DBUG_PRINT("event_timed::compile", ("query:%s",thd->query));
 
   thd->lex= &lex;

--- 1.77/sql/share/errmsg.txt	2006-01-27 01:07:29 +01:00
+++ 1.78/sql/share/errmsg.txt	2006-02-01 22:50:57 +01:00
@@ -5779,8 +5779,8 @@
         eng "Failed to open mysql.event"
 ER_EVENT_NEITHER_M_EXPR_NOR_M_AT
         eng "No datetime expression provided"
-ER_EVENT_COL_COUNT_DOESNT_MATCH
-        eng "Column count of %s.%s is wrong. Table probably corrupted"
+ER_EVENT_COL_COUNT_DOESNT_MATCH_CORRUPTED
+        eng "Column count of %s.%s is wrong. Table probably corrupted."
 ER_EVENT_CANNOT_LOAD_FROM_TABLE
         eng "Cannot load from mysql.event. Table probably corrupted"
 ER_EVENT_CANNOT_DELETE
@@ -5798,3 +5798,5 @@
         eng "You can't write-lock a log table. Only read access is possible."
 ER_CANT_READ_LOCK_LOG_TABLE
         eng "You can't use usual read lock with log tables. Try READ LOCAL instead."
+ER_EVENT_COL_COUNT_DOESNT_MATCH_PLEASE_UPDATE
+        eng "Column count of %s.%s is wrong. Created with MySQL %d, now running %d.
Please use scripts/mysql_fix_privilege_tables"
Thread
bk commit into 5.1 tree (andrey:1.2102) BUG#16423ahristov1 Feb