##################################################################
# Author: Giuseppe                                               #
# Date: 2006-12-20                                               #
# Purpose: To test that event effects are replicated             #
# in both row based and statement based format                   #
##################################################################

--source include/not_embedded.inc
--source include/master-slave.inc

SET @old_event_scheduler = @@global.event_scheduler;
set global event_scheduler=1;

let $engine_type= MyISAM;

set binlog_format=row;

# Embedded server doesn't support binlogging
--source include/rpl_events.inc

set binlog_format=statement;

# Embedded server doesn't support binlogging
--source include/rpl_events.inc

#
# Bug #28953  	Using events in a replication let the slave crash.
#

connection master;

CREATE TABLE t28953 (a INT);

DELIMITER |;
CREATE EVENT event1 ON SCHEDULE EVERY 1 YEAR
DO BEGIN
	select * from t28953;
END;|
DELIMITER ;|

ALTER EVENT event1 RENAME TO event2;

sync_slave_with_master;

connection master;

DROP EVENT event2;

#
# BUG#44331
# This test verifies if the definer is consistent between master and slave,
# when the event is created without the DEFINER clause set explicitly or the 
# DEFINER is set to CURRENT_USER
#
CREATE TABLE test.t1(details CHAR(30));

CREATE EVENT /*!50000 event44331_1 */
  ON SCHEDULE AT CURRENT_TIMESTAMP
  ON COMPLETION PRESERVE DISABLE
  DO INSERT INTO test.t1 VALUES('event event44331_1 fired - no definer');

CREATE DEFINER=CURRENT_USER /*!50000 EVENT event44331_2 */
  ON SCHEDULE AT CURRENT_TIMESTAMP
  ON COMPLETION PRESERVE DISABLE
  DO INSERT INTO test.t1 VALUES('event event44331_2 fired - DEFINER=CURRENT_USER');
            
CREATE DEFINER=CURRENT_USER() EVENT event44331_3
  ON SCHEDULE AT CURRENT_TIMESTAMP
  ON COMPLETION PRESERVE DISABLE
  DO INSERT INTO test.t1 VALUES('event event44331_3 fired - DEFINER=CURRENT_USER() function');

CREATE /*!50000 DEFINER='user44331' */ EVENT event44331_4
  ON SCHEDULE AT CURRENT_TIMESTAMP
  ON COMPLETION PRESERVE DISABLE
  DO INSERT INTO test.t1 VALUES('event event44331_4 fired - DEFINER=user1');

--echo #on master 
select EVENT_SCHEMA, EVENT_NAME, DEFINER from information_schema.events
  where EVENT_NAME='event44331_1';
select EVENT_SCHEMA, EVENT_NAME, DEFINER from information_schema.events
  where EVENT_NAME='event44331_2';
select EVENT_SCHEMA, EVENT_NAME, DEFINER from information_schema.events
  where EVENT_NAME='event44331_3';
select EVENT_SCHEMA, EVENT_NAME, DEFINER from information_schema.events
  where EVENT_NAME='event44331_4';

sync_slave_with_master;
connection slave;
--echo #on slave
select EVENT_SCHEMA, EVENT_NAME, DEFINER from information_schema.events
  where EVENT_NAME='event44331_1';
select EVENT_SCHEMA, EVENT_NAME, DEFINER from information_schema.events
  where EVENT_NAME='event44331_2';
select EVENT_SCHEMA, EVENT_NAME, DEFINER from information_schema.events
  where EVENT_NAME='event44331_3';
select EVENT_SCHEMA, EVENT_NAME, DEFINER from information_schema.events
  where EVENT_NAME='event44331_4';

connection master;
SET @@global.event_scheduler= @old_event_scheduler;
DROP TABLE t28953;
DROP TABLE t1;
DROP EVENT event44331_1;
DROP EVENT event44331_2;
DROP EVENT event44331_3;
DROP EVENT event44331_4;
sync_slave_with_master;
