mySQL 5.0.11 sources for tomato
[tomato.git] / release / src / router / mysql / mysql-test / t / events_1.test
blob7f31e3fc8818f950ec2349977eb02feafd08f3a2
1 # changes 2008-02-20 hhunger splitted events.test into events_1 and events_2
2 # changes 2008-02-22 hhunger replaced all sleep by wait_condition
4 # Can't test with embedded server that doesn't support grants
5 -- source include/not_embedded.inc
7 call mtr.add_suppression("Column count of mysql.event is wrong. Expected .*, found .*\. The table is probably corrupted");
9 --disable_warnings
10 drop database if exists events_test;
11 drop database if exists db_x;
12 drop database if exists mysqltest_db2;
13 drop database if exists mysqltest_no_such_database;
14 --enable_warnings
15 create database events_test;
16 use events_test;
19 # START:  BUG #17289 Events: missing privilege check for drop database
21 CREATE USER pauline@localhost;
22 CREATE DATABASE db_x;
23 GRANT EVENT ON db_x.* TO pauline@localhost;
24 USE db_x;
25 CREATE TABLE x_table(a int);
26 connect (priv_conn,localhost,pauline,,db_x);
27 CREATE EVENT e_x1 ON SCHEDULE EVERY 1 SECOND DO DROP DATABASE db_x;
28 CREATE EVENT e_x2 ON SCHEDULE EVERY 1 SECOND DO DROP TABLE x_table;
29 connection default;
30 SHOW DATABASES LIKE 'db_x';
31 SET GLOBAL event_scheduler=1;
32 let $wait_condition= SELECT count(*)= 1 FROM INFORMATION_SCHEMA.SCHEMATA WHERE SCHEMA_NAME LIKE 'db_x';
33 --source include/wait_condition.inc
34 SHOW DATABASES LIKE 'db_x';
35 SHOW TABLES FROM db_x;
36 SET GLOBAL event_scheduler=off;
37 connection priv_conn;
38 DROP EVENT e_x1;
39 DROP EVENT e_x2;
40 disconnect priv_conn;
41 connection default;
42 DROP DATABASE db_x;
43 DROP USER pauline@localhost;
44 USE events_test;
46 # END:    BUG #17289 Events: missing privilege check for drop database
48 SET GLOBAL event_scheduler=off;
49 drop event if exists event1;
50 create event event1 on schedule every 15 minute starts now() ends date_add(now(), interval 5 hour) DO begin end;
51 alter event event1 rename to event2 enable;
52 alter event event2 disable;
53 alter event event2 enable;
54 alter event event2 on completion not preserve;
55 delimiter __;
56 alter event event2 on schedule every 1 year on completion preserve rename to event3 comment "new comment" do begin select 1; end__
57 delimiter ;__
58 alter event event3 rename to event2;
60 drop event event2;
61 create event event2 on schedule every 2 second starts now() ends date_add(now(), interval 5 hour) comment "some" DO begin end;
62 drop event event2;
65 # BUG #16537 (Events: mysql.event.starts is null)
67 CREATE EVENT event_starts_test ON SCHEDULE EVERY 10 SECOND COMMENT "" DO SELECT 1;
68 SELECT interval_field, interval_value, body FROM mysql.event WHERE db='events_test' AND name='event_starts_test';
69 SELECT execute_at IS NULL, starts IS NULL, ends IS NULL, comment FROM mysql.event WHERE db='events_test' AND name='event_starts_test';
70 ALTER EVENT event_starts_test ON SCHEDULE AT '2020-02-02 20:00:02';
71 SELECT execute_at IS NULL, starts IS NULL, ends IS NULL, comment FROM mysql.event WHERE db='events_test' AND name='event_starts_test';
72 ALTER EVENT event_starts_test COMMENT "non-empty comment";
73 SELECT execute_at IS NULL, starts IS NULL, ends IS NULL, comment FROM mysql.event WHERE db='events_test' AND name='event_starts_test';
74 ALTER EVENT event_starts_test COMMENT "";
75 SELECT execute_at IS NULL, starts IS NULL, ends IS NULL, comment FROM mysql.event WHERE db='events_test' AND name='event_starts_test';
76 DROP EVENT event_starts_test;
78 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;
79 SELECT execute_at IS NULL, starts IS NULL, ends IS NULL, comment FROM mysql.event WHERE db='events_test' AND name='event_starts_test';
80 ALTER EVENT event_starts_test COMMENT "non-empty comment";
81 SELECT execute_at IS NULL, starts IS NULL, ends IS NULL, comment FROM mysql.event WHERE db='events_test' AND name='event_starts_test';
82 ALTER EVENT event_starts_test COMMENT "";
83 SELECT execute_at IS NULL, starts IS NULL, ends IS NULL, comment FROM mysql.event WHERE db='events_test' AND name='event_starts_test';
84 DROP EVENT event_starts_test;
87 create table test_nested(a int);
88 create event e_43 on schedule every 1 second do set @a = 5;
89 --error ER_EVENT_RECURSION_FORBIDDEN
90 alter event e_43 do alter event e_43 do set @a = 4;
91 delimiter |;
92 alter event e_43 do
93 begin
94   alter event e_43 on schedule every 5 minute;
95   insert into test_nested values(1);
96 end|
97 delimiter ;|
98 set global event_scheduler = on;
99 let $wait_condition= SELECT count(*)>0 from mysql.event where name='e_43' and interval_value= 5;
100 --source include/wait_condition.inc
101 select db, name, body, status, interval_field, interval_value from mysql.event;
102 drop event e_43;
103 drop table test_nested;
105 --echo "Let's check whether we can use non-qualified names"
106 create table non_qualif(a int);
107 create event non_qualif_ev on schedule every 10 minute do insert into non_qualif values (800219);
108 let $wait_condition=SELECT count(*)= 1 from non_qualif where a=800219;
109 --source include/wait_condition.inc
110 select * from non_qualif;
111 drop event non_qualif_ev;
112 drop table non_qualif;
114 --error ER_EVENT_DOES_NOT_EXIST
115 alter event non_existant rename to non_existant_too;
117 set global event_scheduler = off;
118 create event existant on schedule at now() + interval 1 year do select 12;
119 --error ER_EVENT_ALREADY_EXISTS
120 alter event non_existant rename to existant;
121 --error ER_EVENT_SAME_NAME
122 alter event existant rename to events_test.existant;
123 drop event existant;
126 create table t_event3 (a int, b float);
127 drop event if exists event3;
128 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());
129 let $wait_condition=SELECT count(*)=0 from t_event3;
130 --source include/wait_condition.inc
131 select count(*) from t_event3;
132 drop event event3;
133 drop table t_event3;
136 set names utf8;
138 # SHOW CREATE EVENT test begin
140 CREATE EVENT root6 ON SCHEDULE EVERY '10:20' MINUTE_SECOND ON COMPLETION PRESERVE ENABLE COMMENT 'some comment' DO select 1;
141 --replace_regex /STARTS '[^']+'/STARTS '#'/
142 SHOW CREATE EVENT root6;
143 create event root7 on schedule every 2 year do select 1;
144 --replace_regex /STARTS '[^']+'/STARTS '#'/
145 SHOW CREATE EVENT root7;
146 create event root8 on schedule every '2:5' year_month do select 1;
147 --replace_regex /STARTS '[^']+'/STARTS '#'/
148 SHOW CREATE EVENT root8;
149 create event root8_1 on schedule every '2:15' year_month do select 1;
150 --replace_regex /STARTS '[^']+'/STARTS '#'/
151 SHOW CREATE EVENT root8_1;
152 create event root9 on schedule every 2 week ON COMPLETION PRESERVE DISABLE COMMENT 'коментар на кирилица' do select 1;
153 --replace_regex /STARTS '[^']+'/STARTS '#'/
154 SHOW CREATE EVENT root9;
155 create event root10 on schedule every '20:5' day_hour do select 1;
156 --replace_regex /STARTS '[^']+'/STARTS '#'/
157 SHOW CREATE EVENT root10;
158 create event root11 on schedule every '20:25' day_hour do select 1;
159 --replace_regex /STARTS '[^']+'/STARTS '#'/
160 SHOW CREATE EVENT root11;
161 create event root12 on schedule every '20:25' hour_minute do select 1;
162 --replace_regex /STARTS '[^']+'/STARTS '#'/
163 SHOW CREATE EVENT root12;
164 create event root13 on schedule every '25:25' hour_minute do select 1;
165 --replace_regex /STARTS '[^']+'/STARTS '#'/
166 SHOW CREATE EVENT root13;
167 create event root13_1 on schedule every '11:65' hour_minute do select 1;
168 --replace_regex /STARTS '[^']+'/STARTS '#'/
169 SHOW CREATE EVENT root13_1;
170 create event root14 on schedule every '35:35' minute_second do select 1;
171 --replace_regex /STARTS '[^']+'/STARTS '#'/
172 SHOW CREATE EVENT root14;
173 create event root15 on schedule every '35:66' minute_second do select 1;
174 --replace_regex /STARTS '[^']+'/STARTS '#'/
175 SHOW CREATE EVENT root15;
176 create event root16 on schedule every '35:56' day_minute do select 1;
177 --replace_regex /STARTS '[^']+'/STARTS '#'/
178 SHOW CREATE EVENT root16;
179 create event root17 on schedule every '35:12:45' day_minute do select 1;
180 --replace_regex /STARTS '[^']+'/STARTS '#'/
181 SHOW CREATE EVENT root17;
182 create event root17_1 on schedule every '35:25:65' day_minute do select 1;
183 --replace_regex /STARTS '[^']+'/STARTS '#'/
184 SHOW CREATE EVENT root17_1;
185 create event root18 on schedule every '35:12:45' hour_second do select 1;
186 --replace_regex /STARTS '[^']+'/STARTS '#'/
187 SHOW CREATE EVENT root18;
188 create event root19 on schedule every '15:59:85' hour_second do select 1;
189 --replace_regex /STARTS '[^']+'/STARTS '#'/
190 SHOW CREATE EVENT root19;
191 create event root20 on schedule every '50:20:12:45' day_second do select 1;
192 --replace_regex /STARTS '[^']+'/STARTS '#'/
193 SHOW CREATE EVENT root20;
194 set names cp1251;
195 create event ðóóò21 on schedule every '50:23:59:95' day_second COMMENT 'òîâà å 1251 êîìåíòàð' do select 1;
196 --replace_regex /STARTS '[^']+'/STARTS '#'/
197 SHOW CREATE EVENT ðóóò21;
198 insert into mysql.event (
199   db,
200   name,
201   body,
202   definer,
203   interval_value,
204   interval_field,
205   originator,
206   character_set_client,
207   collation_connection,
208   db_collation,
209   body_utf8)
210 values (
211   database(),
212   "root22",
213   "select 1",
214   user(),
215   100,
216   "SECOND_MICROSECOND",
217   1,
218   'utf8',
219   'utf8_general_ci',
220   'utf8_general_ci',
221   'select 1');
222 --error ER_NOT_SUPPORTED_YET
223 show create event root22;
224 --error ER_NOT_SUPPORTED_YET
225 SHOW EVENTS;
226 drop event root22;
227 --error ER_EVENT_INTERVAL_NOT_POSITIVE_OR_TOO_BIG
228 create event root23 on schedule every -100 year do select 1;
229 --error ER_EVENT_INTERVAL_NOT_POSITIVE_OR_TOO_BIG
230 create event root23 on schedule every 222222222222222222222 year do select 1;
231 drop event root6;
232 drop event root7;
233 drop event root8;
234 drop event root8_1;
235 drop event root9;
236 drop event root10;
237 drop event root11;
238 drop event root12;
239 drop event root13;
240 drop event root13_1;
241 drop event root14;
242 drop event root15;
243 drop event root16;
244 drop event root17;
245 drop event root17_1;
246 drop event root18;
247 drop event root19;
248 drop event root20;
249 drop event ðóóò21;
251 set names latin1;
253 # SHOW CREATE EVENT test end
257 # mysql.event intact checking
258 # Check that the server does not crash if
259 # one has destroyed or tampered with the event table. 
260 # Please see see for events_restart_phase* tests to 
261 # see the server behavior at start up with bad mysql.event
262 # table.
265 --echo Create a test event. Only event metadata is relevant, 
266 --echo the actual schedule and body are not.
268 CREATE EVENT intact_check ON SCHEDULE EVERY 10 HOUR DO SELECT "nothing";
269 --replace_column 8 # 9 #
270 SHOW EVENTS;
272 --echo Try to alter mysql.event: the server should fail to load
273 --echo event information after mysql.event was tampered with.
274 --echo 
275 --echo First, let's add a column to the end and check the error is emitted.
276 --echo 
277 ALTER TABLE mysql.event ADD dummy INT;
278 --error ER_EVENT_OPEN_TABLE_FAILED
279 SHOW EVENTS;
280 --error ER_EVENT_OPEN_TABLE_FAILED
281 SELECT event_name FROM INFORMATION_SCHEMA.events;
282 --error ER_EVENT_OPEN_TABLE_FAILED
283 SHOW CREATE EVENT intact_check;
284 --error ER_EVENT_OPEN_TABLE_FAILED
285 DROP EVENT no_such_event;
286 --error ER_EVENT_OPEN_TABLE_FAILED
287 CREATE EVENT intact_check_1 ON SCHEDULE EVERY 5 HOUR DO SELECT 5;
288 --error ER_EVENT_OPEN_TABLE_FAILED
289 ALTER EVENT intact_check_1 ON SCHEDULE EVERY 8 HOUR DO SELECT 8;
290 --error ER_EVENT_OPEN_TABLE_FAILED
291 ALTER EVENT intact_check_1 RENAME TO intact_check_2;
292 --error ER_EVENT_OPEN_TABLE_FAILED
293 DROP EVENT intact_check_1;
294 --error ER_EVENT_OPEN_TABLE_FAILED
295 DROP EVENT intact_check_2;
296 --error ER_EVENT_OPEN_TABLE_FAILED
297 DROP EVENT intact_check;
298 DROP DATABASE IF EXISTS mysqltest_no_such_database;
299 CREATE DATABASE mysqltest_db2;
300 DROP DATABASE mysqltest_db2;
301 SELECT @@event_scheduler;
302 SHOW VARIABLES LIKE 'event_scheduler';
303 SET GLOBAL event_scheduler=OFF;
304 # Clean up
305 ALTER TABLE mysql.event DROP dummy;
306 DROP EVENT intact_check;
307 CREATE EVENT intact_check ON SCHEDULE EVERY 10 HOUR DO SELECT "nothing";
308 --echo 
309 --echo Now let's add a column to the first position: the server
310 --echo expects to see event schema name there
311 --echo 
312 ALTER TABLE mysql.event ADD dummy INT FIRST;
313 --error ER_CANNOT_LOAD_FROM_TABLE
314 --error ER_EVENT_OPEN_TABLE_FAILED
315 SHOW EVENTS;
316 --error ER_CANNOT_LOAD_FROM_TABLE
317 --error ER_EVENT_OPEN_TABLE_FAILED
318 SELECT event_name FROM INFORMATION_SCHEMA.events;
319 --error ER_EVENT_OPEN_TABLE_FAILED
320 SHOW CREATE EVENT intact_check;
321 --error ER_EVENT_OPEN_TABLE_FAILED
322 DROP EVENT no_such_event;
323 --error ER_EVENT_OPEN_TABLE_FAILED
324 CREATE EVENT intact_check_1 ON SCHEDULE EVERY 5 HOUR DO SELECT 5;
325 --error ER_EVENT_OPEN_TABLE_FAILED
326 ALTER EVENT intact_check_1 ON SCHEDULE EVERY 8 HOUR DO SELECT 8;
327 --error ER_EVENT_OPEN_TABLE_FAILED
328 ALTER EVENT intact_check_1 RENAME TO intact_check_2;
329 --error ER_EVENT_OPEN_TABLE_FAILED
330 DROP EVENT intact_check_1;
331 --error ER_EVENT_OPEN_TABLE_FAILED
332 DROP EVENT intact_check_2;
333 --error ER_EVENT_OPEN_TABLE_FAILED
334 DROP EVENT intact_check;
335 # Should work OK
336 DROP DATABASE IF EXISTS mysqltest_no_such_database;
337 CREATE DATABASE mysqltest_db2;
338 DROP DATABASE mysqltest_db2;
339 SELECT @@event_scheduler;
340 SHOW VARIABLES LIKE 'event_scheduler';
341 SET GLOBAL event_scheduler=OFF;
342 --echo Clean up
343 ALTER TABLE mysql.event DROP dummy;
344 DELETE FROM mysql.event;
345 CREATE EVENT intact_check ON SCHEDULE EVERY 10 HOUR DO SELECT "nothing";
346 --echo Back up the table, further changes are not reversible
347 CREATE TABLE event_like LIKE mysql.event;
348 INSERT INTO event_like SELECT * FROM mysql.event;
349 --echo 
350 --echo Drop some columns and try more checks. 
351 --echo
352 --echo 
353 ALTER TABLE mysql.event DROP comment, DROP starts;
354 --error ER_EVENT_OPEN_TABLE_FAILED
355 SHOW EVENTS;
356 --error ER_EVENT_OPEN_TABLE_FAILED
357 SELECT event_name FROM INFORMATION_SCHEMA.EVENTS;
358 --error ER_EVENT_OPEN_TABLE_FAILED
359 SHOW CREATE EVENT intact_check;
360 --error ER_EVENT_OPEN_TABLE_FAILED
361 DROP EVENT no_such_event;
362 --error ER_EVENT_OPEN_TABLE_FAILED
363 CREATE EVENT intact_check_1 ON SCHEDULE EVERY 5 HOUR DO SELECT 5;
364 --error ER_EVENT_OPEN_TABLE_FAILED
365 ALTER EVENT intact_check_1 ON SCHEDULE EVERY 8 HOUR DO SELECT 8;
366 --error ER_EVENT_OPEN_TABLE_FAILED
367 ALTER EVENT intact_check_1 RENAME TO intact_check_2;
368 --error ER_EVENT_OPEN_TABLE_FAILED
369 DROP EVENT intact_check_1;
370 --error ER_EVENT_OPEN_TABLE_FAILED
371 DROP EVENT intact_check_2;
372 --error ER_EVENT_OPEN_TABLE_FAILED
373 DROP EVENT intact_check;
374 DROP DATABASE IF EXISTS mysqltest_no_such_database;
375 CREATE DATABASE mysqltest_db2;
376 DROP DATABASE mysqltest_db2;
377 SELECT @@event_scheduler;
378 SHOW VARIABLES LIKE 'event_scheduler';
379 SET GLOBAL event_scheduler=OFF;
380 --echo 
381 --echo Now drop the table, and test again
382 --echo
383 --echo 
384 DROP TABLE mysql.event;
385 --error ER_NO_SUCH_TABLE
386 SHOW EVENTS;
387 --error ER_NO_SUCH_TABLE
388 SELECT event_name FROM INFORMATION_SCHEMA.events;
389 --error ER_NO_SUCH_TABLE
390 SHOW CREATE EVENT intact_check;
391 --error ER_NO_SUCH_TABLE
392 DROP EVENT no_such_event;
393 --error ER_NO_SUCH_TABLE
394 CREATE EVENT intact_check_1 ON SCHEDULE EVERY 5 HOUR DO SELECT 5;
395 --error ER_NO_SUCH_TABLE
396 ALTER EVENT intact_check_1 ON SCHEDULE EVERY 8 HOUR DO SELECT 8;
397 --error ER_NO_SUCH_TABLE
398 ALTER EVENT intact_check_1 RENAME  TO intact_check_2;
399 --error ER_NO_SUCH_TABLE
400 DROP EVENT intact_check_1;
401 --error ER_NO_SUCH_TABLE
402 DROP EVENT intact_check_2;
403 --error ER_NO_SUCH_TABLE
404 DROP EVENT intact_check;
405 DROP DATABASE IF EXISTS mysqltest_no_such_database;
406 CREATE DATABASE mysqltest_db2;
407 DROP DATABASE mysqltest_db2;
408 --echo OK, there is an unnecessary warning about the non-existent table 
409 --echo but it's not easy to fix and no one complained about it.
410 --echo A similar warning is printed if mysql.proc is missing.
411 SHOW WARNINGS;
412 SELECT @@event_scheduler;
413 SHOW VARIABLES LIKE 'event_scheduler';
414 SET GLOBAL event_scheduler=OFF;
415 --echo Restore the original table.
416 CREATE TABLE mysql.event like event_like;
417 DROP TABLE event_like;
418 --replace_column 8 # 9 #
419 SHOW EVENTS;
421 --echo
422 --echo #
423 --echo # Bug#12394306: the sever may crash if mysql.event is corrupted
424 --echo #
426 --echo
427 CREATE EVENT ev1 ON SCHEDULE EVERY 5 HOUR DO SELECT 5;
428 ALTER EVENT ev1 ON SCHEDULE EVERY 8 HOUR DO SELECT 8;
430 --echo
431 CREATE TABLE event_original LIKE mysql.event;
432 INSERT INTO event_original SELECT * FROM mysql.event;
434 --echo
435 ALTER TABLE mysql.event MODIFY modified CHAR(1);
437 --echo
438 --error ER_EVENT_OPEN_TABLE_FAILED
439 SHOW EVENTS;
441 --echo
442 --error ER_EVENT_OPEN_TABLE_FAILED
443 SELECT event_name, created, last_altered FROM information_schema.events;
445 --echo
446 --error ER_EVENT_OPEN_TABLE_FAILED
447 CREATE EVENT ev2 ON SCHEDULE EVERY 5 HOUR DO SELECT 5;
449 --echo
450 --error ER_EVENT_OPEN_TABLE_FAILED
451 ALTER EVENT ev1 ON SCHEDULE EVERY 9 HOUR DO SELECT 9;
453 --echo
454 DROP TABLE mysql.event;
455 RENAME TABLE event_original TO mysql.event;
457 --echo
458 DROP EVENT ev1;
460 --echo
461 SHOW EVENTS;
464 --echo
465 --echo # 
466 --echo # End of tests
467 --echo #
469 let $wait_condition=
470   select count(*) = 0 from information_schema.processlist
471   where db='events_test' and command = 'Connect' and user=current_user();
472 --source include/wait_condition.inc
474 drop database events_test;