mariadb/mysql-test/t/events.test
unknown 8fd74f314b merging before test + push
mysql-test/r/events.result:
  Auto merged
mysql-test/t/events.test:
  Auto merged
sql/event.h:
  Auto merged
sql/event_timed.cc:
  manual merge
2006-02-15 21:51:57 +01:00

395 lines
13 KiB
Text
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

create database if not exists events_test;
use events_test;
#
# START: BUG #17289 Events: missing privilege check for drop database
#
CREATE USER pauline@localhost;
CREATE DATABASE db_x;
GRANT EVENT ON db_x.* TO pauline@localhost;
USE db_x;
CREATE TABLE x_table(a int);
connect (priv_conn,localhost,pauline,,db_x);
CREATE EVENT e_x1 ON SCHEDULE EVERY 1 SECOND DO DROP DATABASE db_x;
CREATE EVENT e_x2 ON SCHEDULE EVERY 1 SECOND DO DROP TABLE x_table;
connection default;
SHOW DATABASES LIKE 'db_x';
SET GLOBAL event_scheduler=1;
--sleep 2
SHOW DATABASES LIKE 'db_x';
SHOW TABLES FROM db_x;
SET GLOBAL event_scheduler=0;
--sleep 1
connection priv_conn;
DROP EVENT e_x1;
DROP EVENT e_x2;
disconnect priv_conn;
connection default;
DROP DATABASE db_x;
DROP USER pauline@localhost;
USE events_test;
--sleep 1
#
# END: BUG #17289 Events: missing privilege check for drop database
#
drop event if exists event1;
create event event1 on schedule every 15 minute starts now() ends date_add(now(), interval 5 hour) DO begin end;
alter event event1 rename to event2 enable;
alter event event2 disable;
alter event event2 enable;
alter event event2 on completion not preserve;
delimiter __;
alter event event2 on schedule every 1 year on completion preserve rename to event3 comment "new comment" do begin select 1; end__
delimiter ;__
alter event event3 rename to event2;
drop event event2;
create event event2 on schedule every 2 second starts now() ends date_add(now(), interval 5 hour) comment "some" DO begin end;
drop event event2;
create event e_43 on schedule every 1 second do set @a = 5;
set global event_scheduler = 1;
--sleep 2
alter event e_43 do alter event e_43 do set @a = 4;
--sleep 2
select db, name, body, status, interval_field, interval_value from mysql.event;
drop event e_43;
--sleep 1
set global event_scheduler = 0;
create table t_event3 (a int, b float);
drop event if exists event3;
create event event3 on schedule every 50 + 10 minute starts date_add("20100101", interval 5 minute) ends date_add("20151010", interval 5 day) comment "portokala_comment" DO insert into t_event3 values (unix_timestamp(), rand());
set max_allowed_packet=128000000;
select count(*) from t_event3;
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;
set names cp1251;
create event <20><><EFBFBD><EFBFBD>21 on schedule every '50:23:59:95' day_second COMMENT '<27><><EFBFBD><EFBFBD> <20> 1251 <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>' do select 1;
SHOW CREATE EVENT <20><><EFBFBD><EFBFBD>21;
insert into mysql.event (db, name, body, definer, interval_value, interval_field) values (database(), "root22", "select 1", user(), 100, "SECOND_MICROSECOND");
--error 1235
show create event root22;
--error 1235
SHOW EVENTS;
drop event root22;
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 <20><><EFBFBD><EFBFBD>21;
set names latin1;
#
# SHOW CREATE EVENT test end
#
#
# mysql.event intact checking start
#
# There should be at least 1 second between the ALTERs or we can't catch the change of create_time!!
#
CREATE EVENT intact_check ON SCHEDULE EVERY 10 HOUR DO SELECT "nothing";
--replace_column 8 # 9 #
SHOW EVENTS;
ALTER TABLE mysql.event ADD dummy INT FIRST;
--error 1525
SHOW EVENTS;
ALTER TABLE mysql.event DROP dummy, ADD dummy2 VARCHAR(64) FIRST;
--error 1525
SHOW EVENTS;
ALTER TABLE mysql.event DROP dummy2;
--replace_column 8 # 9 #
SHOW EVENTS;
CREATE TABLE event_like LIKE mysql.event;
INSERT INTO event_like SELECT * FROM mysql.event;
#sleep a bit or we won't catch the change of time
--sleep 1
ALTER TABLE mysql.event MODIFY db char(20) character set utf8 collate utf8_bin default '';
#wait a bit or we won't see the difference because of seconds resolution
--sleep 1
SHOW CREATE TABLE mysql.event;
--error 1526
SELECT event_name FROM INFORMATION_SCHEMA.EVENTS;
--sleep 1
ALTER TABLE mysql.event MODIFY db char(64) character set utf8 collate utf8_bin default '';
--sleep 1
--echo "This should work"
--replace_column 8 # 9 #
SHOW EVENTS;
--sleep 1
ALTER TABLE mysql.event MODIFY db char(64) character set cp1251 default '';
--error 1526
SELECT event_name FROM INFORMATION_SCHEMA.EVENTS;
--sleep 1
ALTER TABLE mysql.event MODIFY db varchar(64) character set utf8 collate utf8_bin default '';
--error 1526
SELECT event_name FROM INFORMATION_SCHEMA.EVENTS;
--sleep 1
ALTER TABLE mysql.event DROP comment, DROP starts;
--sleep 1
--error 1525
SELECT event_name FROM INFORMATION_SCHEMA.EVENTS;
DROP TABLE mysql.event;
CREATE TABLE mysql.event like event_like;
INSERT INTO mysql.event SELECT * FROM event_like;
DROP TABLE event_like;
--replace_column 8 # 9 #
SHOW EVENTS;
DROP EVENT intact_check;
#
# mysql.event intact checking end
#
#
#INFORMATION_SCHEMA.EVENTS test begin
#
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;
CREATE DATABASE events_test2;
CREATE USER ev_test@localhost;
GRANT ALL ON events_test.* to ev_test@localhost;
GRANT ALL on events_test2.* to ev_test@localhost;
REVOKE EVENT ON events_test2.* FROM ev_test@localhost;
REVOKE PROCESS on *.* from ev_test@localhost;
#now we are on con1
connect (ev_con1,localhost,ev_test,,events_test2);
select "NEW CONNECTION";
SELECT USER(), DATABASE();
SHOW GRANTS;
--echo "Here comes an error:";
#NO EVENT_ACL on events_test2
--error 1044
SHOW EVENTS;
USE events_test;
--echo "Now the list should be empty:";
--replace_column 8 # 9 #
SHOW EVENTS;
#now create an event with the same name but we are different user
select concat("Let's create some new events from the name of ",user());
create event one_event on schedule every 20 second do select 123;
create event two_event on schedule every 20 second on completion not preserve comment "two event" do select 123;
create event three_event on schedule every 20 second on completion preserve comment "three event" do select 123;
--echo "Now we should see 3 events:";
--replace_column 8 # 9 #
SHOW EVENTS;
--echo "This should show us only 3 events:";
--replace_column 8 # 9 #
SHOW FULL EVENTS;
--echo "This should show us only 2 events:";
--replace_column 8 # 9 #
SHOW FULL EVENTS LIKE 't%event';
--echo "This should show us no events:";
--replace_column 8 # 9 #
SHOW FULL EVENTS FROM test LIKE '%';
#ok, we are back
connection default;
DROP DATABASE events_test2;
--echo "should see 1 event:";
--replace_column 8 # 9 #
SHOW EVENTS;
--echo "we should see 4 events now:";
--replace_column 8 # 9 #
SHOW FULL 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;
connection ev_con1;
drop event one_event;
drop event two_event;
drop event three_event;
disconnect ev_con1;
connection default;
drop user ev_test@localhost;
drop event one_event;
#
##INFORMATION_SCHEMA.EVENTS test end
#
--echo "Sleep a bit so the server closes the second connection"
--sleep 2
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;
drop event e_26;
--error 1503
create event e_26 on schedule at NULL disabled do set @a = 5;
--error 1503
create event e_26 on schedule at 'definitely not a datetime' disabled do set @a = 5;
set names utf8;
create event задачка on schedule every 123 minute starts now() ends now() + interval 1 month do select 1;
drop event задачка;
# event_scheduler is a global var
--error 1229
set event_scheduler=0;
# event_scheduler could be only either 0 or 1
--error 1231
set global event_scheduler=2;
--echo "DISABLE the scheduler. Testing that it does not work when the variable is 0"
set global event_scheduler=0;
select definer, name, db from mysql.event;
select get_lock("test_lock1", 20);
create event закачка on schedule every 10 hour do select get_lock("test_lock1", 20);
--echo "Should return 1 row"
select definer, name, db from mysql.event;
--echo "Should be only 1 process"
--replace_column 1 # 6 #
show processlist;
select release_lock("test_lock1");
drop event закачка;
--echo "Should have 0 events"
select count(*) from mysql.event;
#
#
#
--echo "ENABLE the scheduler and get a lock"
set global event_scheduler=1;
select get_lock("test_lock2", 20);
--echo "Create an event which tries to acquire a mutex. The event locks on the mutex"
create event закачка on schedule every 10 hour do select get_lock("test_lock2", 20);
--echo "Let some time pass to the event starts"
--sleep 2
--echo "Should have only 3 processes: the scheduler, our conn and the locked event"
--replace_column 1 # 6 #
show processlist;
--echo "Release the mutex, the event worker should finish."
select release_lock("test_lock2");
drop event закачка;
##
## 1. get a lock
## 2. create an event
## 3. sleep so it has time to start
## 4. should appear in processlist
## 5. kill the scheduler, it will wait for the child to stop
## 6. both processes should be there on show processlist
## 7. release the lock and sleep, both scheduler and child should end
set global event_scheduler=1;
select get_lock("test_lock2_1", 20);
create event закачка21 on schedule every 10 hour do select get_lock("test_lock2_1", 20);
--sleep 1
--echo "Should see 2 processes, one locked on get_lock("
#--replace_column 1 # 6 #
#show processlist;
--echo "Shutting down the scheduler, it should wait for the running event"
set global event_scheduler=0;
--sleep 1
--echo "Should have only 3 processes: the scheduler, our conn and the locked event"
--replace_column 1 # 6 #
show processlist;
--echo "Release the lock so the child process should finish. Hence the scheduler also"
select release_lock("test_lock2_1");
--sleep 1
--echo "Should have only our process now:"
--replace_column 1 # 6 #
show processlist;
drop event закачка21;
####
# Bug #16410 Events: CREATE EVENT is legal in a CREATE TRIGGER statement
#
create table t_16 (s1 int);
--error 1422
create trigger t_16_bi before insert on t_16 for each row create event e_16 on schedule every 1 second do set @a=5;
drop table t_16;
#
# end of test case
####
##set global event_scheduler=1;
##select get_lock("test_lock3", 20);
##create event закачка on schedule every 10 hour do select get_lock("test_lock3", 20);
##select sleep(2);
##show processlist;
##drop event закачка;
##select release_lock("test_lock3");
#
# test with very often occuring event
# (disabled for now, locks)
##select get_lock("test_lock4", 20);
##create event закачка4 on schedule every 1 second do select get_lock("test_lock4", 20);
##select sleep(3);
##--replace_column 1 # 6 #
##show processlist;
##drop event закачка4;
##select release_lock("test_lock4");
##set global event_scheduler=0;
##select sleep(2);
##--replace_column 1 # 6 #
##show processlist;
##select count(*) from mysql.event;
drop database events_test;