2006-06-23 09:40:06 +02:00
# Can't test with embedded server that doesn't support grants
-- source include/not_embedded.inc
2006-01-11 18:09:05 +01:00
create database if not exists events_test;
use events_test;
2006-02-10 15:02:57 +01:00
#
# 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;
2006-07-17 16:52:45 +02:00
--sleep 1.2
2006-02-10 15:02:57 +01:00
SHOW DATABASES LIKE 'db_x';
SHOW TABLES FROM db_x;
2006-09-01 13:08:44 +02:00
SET GLOBAL event_scheduler=off;
2006-02-10 15:02:57 +01:00
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;
#
# END: BUG #17289 Events: missing privilege check for drop database
#
2006-09-01 13:08:44 +02:00
SET GLOBAL event_scheduler=off;
2005-12-02 13:28:14 +01:00
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;
2006-01-24 16:04:35 +01:00
alter event event1 rename to event2 enable;
alter event event2 disable;
alter event event2 enable;
2006-01-20 16:12:44 +01:00
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;
2005-12-02 13:28:14 +01:00
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;
2006-09-25 15:50:49 +02:00
#
2006-02-28 11:43:10 +01:00
# BUG #16537 (Events: mysql.event.starts is null)
2006-09-25 15:50:49 +02:00
#
2006-02-28 11:43:10 +01:00
CREATE EVENT event_starts_test ON SCHEDULE EVERY 10 SECOND COMMENT "" DO SELECT 1;
2006-09-25 15:50:49 +02:00
SELECT interval_field, interval_value, body FROM mysql.event WHERE db='events_test' AND name='event_starts_test';
SELECT execute_at IS NULL, starts IS NULL, ends IS NULL, comment FROM mysql.event WHERE db='events_test' AND name='event_starts_test';
2006-02-28 11:43:10 +01:00
ALTER EVENT event_starts_test ON SCHEDULE AT '2020-02-02 20:00:02';
2006-09-25 15:50:49 +02:00
SELECT execute_at IS NULL, starts IS NULL, ends IS NULL, comment FROM mysql.event WHERE db='events_test' AND name='event_starts_test';
2006-02-28 11:43:10 +01:00
ALTER EVENT event_starts_test COMMENT "non-empty comment";
2006-09-25 15:50:49 +02:00
SELECT execute_at IS NULL, starts IS NULL, ends IS NULL, comment FROM mysql.event WHERE db='events_test' AND name='event_starts_test';
2006-02-28 11:43:10 +01:00
ALTER EVENT event_starts_test COMMENT "";
2006-09-25 15:50:49 +02:00
SELECT execute_at IS NULL, starts IS NULL, ends IS NULL, comment FROM mysql.event WHERE db='events_test' AND name='event_starts_test';
2006-02-28 11:43:10 +01:00
DROP EVENT event_starts_test;
2006-09-25 15:50:49 +02:00
2006-02-28 11:43:10 +01:00
CREATE EVENT event_starts_test ON SCHEDULE EVERY 20 SECOND STARTS '2020-02-02 20:00:02' ENDS '2022-02-02 20:00:02' DO SELECT 2;
2006-09-25 15:50:49 +02:00
SELECT execute_at IS NULL, starts IS NULL, ends IS NULL, comment FROM mysql.event WHERE db='events_test' AND name='event_starts_test';
2006-02-28 11:43:10 +01:00
ALTER EVENT event_starts_test COMMENT "non-empty comment";
2006-09-25 15:50:49 +02:00
SELECT execute_at IS NULL, starts IS NULL, ends IS NULL, comment FROM mysql.event WHERE db='events_test' AND name='event_starts_test';
2006-02-28 11:43:10 +01:00
ALTER EVENT event_starts_test COMMENT "";
2006-09-25 15:50:49 +02:00
SELECT execute_at IS NULL, starts IS NULL, ends IS NULL, comment FROM mysql.event WHERE db='events_test' AND name='event_starts_test';
2006-02-28 11:43:10 +01:00
DROP EVENT event_starts_test;
#
#
2006-06-27 13:15:40 +02:00
create table test_nested(a int);
2006-01-20 22:24:58 +01:00
create event e_43 on schedule every 1 second do set @a = 5;
2006-08-15 00:50:26 +02:00
--error ER_EVENT_RECURSIVITY_FORBIDDEN
2006-01-20 22:24:58 +01:00
alter event e_43 do alter event e_43 do set @a = 4;
2006-06-27 13:15:40 +02:00
delimiter |;
alter event e_43 do
begin
alter event e_43 on schedule every 5 minute;
insert into test_nested values(1);
end|
delimiter ;|
2006-09-01 13:08:44 +02:00
set global event_scheduler = on;
2006-07-10 13:44:43 +02:00
--sleep 3
2006-01-20 22:24:58 +01:00
select db, name, body, status, interval_field, interval_value from mysql.event;
drop event e_43;
2006-06-27 13:15:40 +02:00
drop table test_nested;
2006-02-16 05:21:02 +01:00
--echo "Let's check whether we can use non-qualified names"
create table non_qualif(a int);
create event non_qualif_ev on schedule every 10 minute do insert into non_qualif values (800219);
2006-07-17 16:52:45 +02:00
--sleep 1.1
2006-02-16 05:21:02 +01:00
select * from non_qualif;
drop event non_qualif_ev;
drop table non_qualif;
2006-07-11 18:28:15 +02:00
--error ER_EVENT_DOES_NOT_EXIST
alter event non_existant rename to non_existant_too;
2006-09-01 13:08:44 +02:00
set global event_scheduler = off;
2006-07-11 18:28:15 +02:00
create event existant on schedule at now() + interval 1 year do select 12;
--error ER_EVENT_ALREADY_EXISTS
alter event non_existant rename to existant;
--error ER_EVENT_SAME_NAME
alter event existant rename to events_test.existant;
drop event existant;
2006-01-20 22:24:58 +01:00
2005-12-02 13:28:14 +01:00
create table t_event3 (a int, b float);
drop event if exists event3;
2006-01-30 17:12:30 +01:00
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());
2005-12-02 13:28:14 +01:00
select count(*) from t_event3;
drop event event3;
2005-12-15 14:12:28 +01:00
drop table t_event3;
2006-01-11 18:09:05 +01:00
2006-02-14 16:20:48 +01:00
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;
2006-04-07 11:29:15 +02:00
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;
2006-02-14 16:20:48 +01:00
insert into mysql.event (db, name, body, definer, interval_value, interval_field) values (database(), "root22", "select 1", user(), 100, "SECOND_MICROSECOND");
2006-05-29 10:39:45 +02:00
--error ER_NOT_SUPPORTED_YET
2006-02-14 16:20:48 +01:00
show create event root22;
2006-05-29 10:39:45 +02:00
--error ER_NOT_SUPPORTED_YET
2006-02-14 16:20:48 +01:00
SHOW EVENTS;
drop event root22;
2006-07-10 13:44:43 +02:00
--error ER_EVENT_INTERVAL_NOT_POSITIVE_OR_TOO_BIG
create event root23 on schedule every -100 year do select 1;
--error ER_EVENT_INTERVAL_NOT_POSITIVE_OR_TOO_BIG
create event root23 on schedule every 222222222222222222222 year do select 1;
2006-02-14 16:20:48 +01:00
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;
2006-04-07 11:29:15 +02:00
drop event <20> <> <EFBFBD> <EFBFBD> 21;
2006-02-14 16:20:48 +01:00
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;
2006-03-16 16:41:00 +01:00
--error ER_COL_COUNT_DOESNT_MATCH_CORRUPTED
2006-02-14 16:20:48 +01:00
SHOW EVENTS;
ALTER TABLE mysql.event DROP dummy, ADD dummy2 VARCHAR(64) FIRST;
2006-03-16 16:41:00 +01:00
--error ER_COL_COUNT_DOESNT_MATCH_CORRUPTED
2006-02-14 16:20:48 +01:00
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
2006-07-17 16:52:45 +02:00
--sleep 1.1
2006-04-07 09:08:58 +02:00
ALTER TABLE mysql.event MODIFY db char(64) character set cp1251 default '';
2006-04-07 11:29:15 +02:00
--error ER_CANNOT_LOAD_FROM_TABLE
2006-04-07 09:08:58 +02:00
SELECT event_name FROM INFORMATION_SCHEMA.EVENTS;
2006-02-14 16:20:48 +01:00
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
2006-07-17 16:52:45 +02:00
--sleep 1.1
2006-02-14 16:20:48 +01:00
SHOW CREATE TABLE mysql.event;
2006-03-16 16:41:00 +01:00
--error ER_CANNOT_LOAD_FROM_TABLE
2006-02-14 16:20:48 +01:00
SELECT event_name FROM INFORMATION_SCHEMA.EVENTS;
2006-07-17 16:52:45 +02:00
--sleep 1.1
2006-02-14 16:20:48 +01:00
ALTER TABLE mysql.event MODIFY db char(64) character set utf8 collate utf8_bin default '';
2006-07-17 16:52:45 +02:00
--sleep 1.1
2006-02-14 16:20:48 +01:00
--echo "This should work"
--replace_column 8 # 9 #
SHOW EVENTS;
2006-07-17 16:52:45 +02:00
--sleep 1.1
2006-02-14 16:20:48 +01:00
ALTER TABLE mysql.event MODIFY db char(64) character set cp1251 default '';
2006-03-16 16:41:00 +01:00
--error ER_CANNOT_LOAD_FROM_TABLE
2006-02-14 16:20:48 +01:00
SELECT event_name FROM INFORMATION_SCHEMA.EVENTS;
2006-07-17 16:52:45 +02:00
--sleep 1.1
2006-02-14 16:20:48 +01:00
ALTER TABLE mysql.event MODIFY db varchar(64) character set utf8 collate utf8_bin default '';
2006-07-17 16:52:45 +02:00
--sleep 1.1
2006-03-16 16:41:00 +01:00
--error ER_CANNOT_LOAD_FROM_TABLE
2006-02-14 16:20:48 +01:00
SELECT event_name FROM INFORMATION_SCHEMA.EVENTS;
2006-07-17 16:52:45 +02:00
--sleep 1.1
2006-02-14 16:20:48 +01:00
ALTER TABLE mysql.event DROP comment, DROP starts;
2006-07-17 16:52:45 +02:00
--sleep 1.1
2006-03-16 16:41:00 +01:00
--error ER_COL_COUNT_DOESNT_MATCH_CORRUPTED
2006-02-14 16:20:48 +01:00
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
#
2006-01-26 22:18:40 +01:00
create event e_26 on schedule at '2017-01-01 00:00:00' disable do set @a = 5;
2006-01-26 21:21:21 +01:00
select db, name, body, definer, convert_tz(execute_at, 'UTC', 'SYSTEM'), on_completion from mysql.event;
drop event e_26;
2006-04-22 04:29:22 +02:00
--error ER_WRONG_VALUE
2006-06-29 00:42:25 +02:00
create event e_26 on schedule at NULL disable do set @a = 5;
2006-04-22 04:29:22 +02:00
--error ER_WRONG_VALUE
2006-06-29 00:42:25 +02:00
create event e_26 on schedule at 'definitely not a datetime' disable do set @a = 5;
2006-01-26 21:21:21 +01:00
2006-01-11 18:09:05 +01:00
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
2006-05-22 20:46:13 +02:00
--error ER_GLOBAL_VARIABLE
2006-09-01 13:08:44 +02:00
set event_scheduler=off;
2006-05-22 20:46:13 +02:00
# event_scheduler could be only either 1 or 2
--error ER_WRONG_VALUE_FOR_VAR
set global event_scheduler=3;
2006-09-01 13:08:44 +02:00
--error ER_WRONG_VALUE_FOR_VAR
set global event_scheduler=disabled;
2006-01-11 18:09:05 +01:00
2006-02-07 19:28:33 +01:00
--echo "DISABLE the scheduler. Testing that it does not work when the variable is 0"
2006-09-01 13:08:44 +02:00
set global event_scheduler=off;
2006-02-07 19:28:33 +01:00
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;
2006-05-22 20:46:13 +02:00
--echo "Should be only 1 process"
2006-09-08 00:49:37 +02:00
select /*1*/ user, host, db, command, state, info from information_schema.processlist where (command!='Daemon' || user='event_scheduler') and (info is null or info not like '%processlist%') order by info;
2006-02-07 19:28:33 +01:00
select release_lock("test_lock1");
drop event закачка;
--echo "Should have 0 events"
select count(*) from mysql.event;
2006-01-11 18:09:05 +01:00
#
2006-02-07 19:28:33 +01:00
#
#
--echo "ENABLE the scheduler and get a lock"
2006-09-01 13:08:44 +02:00
set global event_scheduler=on;
2006-02-07 19:28:33 +01:00
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"
2006-05-29 10:39:45 +02:00
--sleep 1
2006-03-16 16:41:00 +01:00
--echo "Should have only 2 processes: the scheduler and the locked event"
2006-09-08 00:49:37 +02:00
select /*2*/ user, host, db, command, state, info from information_schema.processlist where (command!='Daemon' || user='event_scheduler') and (info is null or info not like '%processlist%') order by info;--echo "Release the mutex, the event worker should finish."
2006-02-07 19:28:33 +01:00
--echo "Release the mutex, the event worker should finish."
select release_lock("test_lock2");
drop event закачка;
2006-01-20 16:12:44 +01:00
##
## 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
2006-02-07 19:28:33 +01:00
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
2006-05-22 20:46:13 +02:00
--echo "Should have only 3 processes: the scheduler, our conn and the locked event"
2006-09-08 00:49:37 +02:00
select /*3*/ user, host, db, command, state, info from information_schema.processlist where (command!='Daemon' || user='event_scheduler') and (info is null or info not like '%processlist%') order by info;
2006-09-01 13:08:44 +02:00
set global event_scheduler=off;
2006-07-17 16:52:45 +02:00
--sleep 0.8
2006-05-22 20:46:13 +02:00
--echo "Should have only our process now:"
2006-09-08 00:49:37 +02:00
select /*4*/ user, host, db, command, state, info from information_schema.processlist where (command!='Daemon' || user='event_scheduler') and (info is null or info not like '%processlist%') order by info;
2006-02-07 19:28:33 +01:00
drop event за ка чка 21;
2006-02-15 17:12:27 +01:00
####
# Bug #16410 Events: CREATE EVENT is legal in a CREATE TRIGGER statement
#
create table t_16 (s1 int);
2006-08-15 00:50:26 +02:00
--error ER_EVENT_RECURSIVITY_FORBIDDEN
2006-02-15 17:12:27 +01:00
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
####
2006-02-16 16:11:02 +01:00
#
# START: BUG #17453: Creating Event crash the server
#
create event white_space
on schedule every 10 hour
disable
do
select 1;
2006-06-22 13:01:08 +02:00
select event_schema, event_name, definer, event_definition from information_schema.events where event_name='white_space';
2006-02-16 16:11:02 +01:00
drop event white_space;
create event white_space on schedule every 10 hour disable do
2006-04-07 09:18:29 +02:00
select 2;
2006-06-22 13:01:08 +02:00
select event_schema, event_name, definer, event_definition from information_schema.events where event_name='white_space';
2006-02-16 16:11:02 +01:00
drop event white_space;
create event white_space on schedule every 10 hour disable do select 3;
2006-06-22 13:01:08 +02:00
select event_schema, event_name, definer, event_definition from information_schema.events where event_name='white_space';
2006-02-16 16:11:02 +01:00
drop event white_space;
#
# END: BUG #17453: Creating Event crash the server
#
2006-05-22 20:46:13 +02:00
#
2006-03-15 18:21:59 +01:00
# Bug#17403 "Events: packets out of order with show create event"
#
create event e1 on schedule every 1 year do set @a = 5;
create table t1 (s1 int);
--error ER_SP_NO_RETSET
create trigger t1_ai after insert on t1 for each row show create event e1;
drop table t1;
drop event e1;
2006-02-07 19:28:33 +01:00
##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);
2006-05-22 20:46:13 +02:00
##select /*5*/ user, host, db, command, state, info from information_schema.processlist where info is null or info not like '%processlist%' order by info;
2006-02-07 19:28:33 +01:00
##drop event закачка;
##select release_lock("test_lock3");
2006-01-11 18:09:05 +01:00
#
# test with very often occuring event
# (disabled for now, locks)
2006-01-20 16:12:44 +01:00
##select get_lock("test_lock4", 20);
##create event за ка чка 4 on schedule every 1 second do select get_lock("test_lock4", 20);
##select sleep(3);
2006-05-22 20:46:13 +02:00
##select /*6*/ user, host, db, command, state, info from information_schema.processlist where info is null or info not like '%processlist%' order by info;
2006-01-20 16:12:44 +01:00
##drop event за ка чка 4;
##select release_lock("test_lock4");
2006-01-11 18:09:05 +01:00
2006-09-01 13:08:44 +02:00
##set global event_scheduler=off;
2006-02-07 19:28:33 +01:00
##select sleep(2);
##--replace_column 1 # 6 #
2006-05-22 20:46:13 +02:00
##show processlist;
2006-01-20 16:12:44 +01:00
##select count(*) from mysql.event;
2006-01-11 18:09:05 +01:00
drop database events_test;