1 #======================================================================
4 # (test case numbering refer to requirement document TP v1.1)
5 #======================================================================
6 # WL#4084: enable disabled parts, 2007-11-15 hhunger
9 --source suite/funcs_1/include/tb3.inc
13 # General setup for Trigger tests
14 let $message= Testcase: 3.5:;
15 --source include/show_msg.inc
17 --disable_abort_on_error
19 create User test_general@localhost;
20 set password
for test_general@localhost = password(
'PWD');
21 revoke ALL PRIVILEGES, GRANT OPTION FROM test_general@localhost;
23 create User test_super@localhost;
24 set password
for test_super@localhost = password(
'PWD');
25 grant ALL on *.*
to test_super@localhost with grant OPTION;
26 connect (con2_general,localhost,test_general,PWD,
test,$MASTER_MYPORT,$MASTER_MYSOCK);
27 connect (con2_super,localhost,test_super,PWD,
test,$MASTER_MYPORT,$MASTER_MYSOCK);
30 #################################
31 ####### Section 3.5.8 ###########
32 # Checks on Triggered Actions #
33 #################################
36 # Testcase: Ensure that the triggered action of every trigger always executes
37 # correctly and the results in all expected changes made to the database
38 let $message= Testcase 3.5.8.1: (implied in previous tests);
39 --source include/show_msg.inc
42 # Testcase: Ensure that the triggered actions of every trigger never results
43 # in an unexpected change made to the database.
44 let $message= Testcase 3.5.8.2: (implied in previous tests);
45 --source include/show_msg.inc
48 #Section 3.5.8.3 / 3.5.8.4
49 #Test case: Ensure that the triggered action can any valid SQL statement / set
50 # of valid SQL statements, provided the statements are written within
51 # a BEGIN/END compound statement construct
52 # OBN - At this point the tests focuses on the the INSERT/UPDATE/DELETE SQL statements
53 # as there are the most likely to be used in triggers
54 let $message= Testcase 3.5.8.3/4:;
55 --source include/show_msg.inc
57 # creating test tables to perform the trigger SQL on
58 connection con2_super;
59 create database db_test;
60 grant SELECT, INSERT, UPDATE, DELETE on db_test.*
to test_general;
61 grant LOCK TABLES on db_test.*
to test_general;
63 --replace_result $engine_type <engine_to_be_used>
64 eval create
table t1_i (
65 i120
char ascii not null DEFAULT b
'101',
66 i136 smallint zerofill not null DEFAULT 999,
67 i144
int zerofill not null DEFAULT 99999,
68 i163 decimal (63,30)) engine=$engine_type;
69 --replace_result $engine_type <engine_to_be_used>
70 eval create
table t1_u (
71 u120
char ascii not null DEFAULT b'101',
72 u136 smallint zerofill not null DEFAULT 999,
73 u144
int zerofill not null DEFAULT 99999,
74 u163 decimal (63,30)) engine=$engine_type;
75 --replace_result $engine_type <engine_to_be_used>
76 eval create
table t1_d (
77 d120
char ascii not null DEFAULT b'101',
78 d136 smallint zerofill not null DEFAULT 999,
79 d144
int zerofill not null DEFAULT 99999,
80 d163 decimal (63,30)) engine=$engine_type;
81 Insert into t1_u values ('a',111,99999,999.99);
82 Insert into t1_u values ('b',222,99999,999.99);
83 Insert into t1_u values ('c',333,99999,999.99);
84 Insert into t1_u values ('d',222,99999,999.99);
85 Insert into t1_u values ('e',222,99999,999.99);
86 Insert into t1_u values ('f',333,99999,999.99);
87 Insert into t1_d values ('a',111,99999,999.99);
88 Insert into t1_d values ('b',222,99999,999.99);
89 Insert into t1_d values ('c',333,99999,999.99);
90 Insert into t1_d values ('d',444,99999,999.99);
91 Insert into t1_d values ('e',222,99999,999.99);
92 Insert into t1_d values ('f',222,99999,999.99);
94 let $message= 3.5.8.4 - multiple SQL;
95 --source include/show_msg.inc
96 # Trigger definition - multiple SQL
99 Create trigger trg1 AFTER INSERT on tb3
for each row
101 insert into db_test.t1_i
102 values (
new.f120,
new.f136,
new.f144,
new.f163);
104 set u144=
new.f144, u163=
new.f163
106 delete from db_test.t1_d where d136=
new.f136;
107 select sum(db_test.t1_u.u163) into @test_var from db_test.t1_u
108 where u136= new.f136;
112 # Test trigger execution - multiple SQL
113 connection con2_general;
116 Insert into tb3 (f120, f122, f136, f144, f163)
117 values ('1', '
Test 3.5.8.4', 222, 23456, 1.05);
118 Select f120, f122, f136, f144, f163 from tb3 where f122= 'Test 3.5.8.4';
120 select * from db_test.t1_i;
122 select * from db_test.t1_u;
124 select * from db_test.t1_d;
128 let $message= 3.5.8.4 - single SQL - insert;
129 --source include/show_msg.inc
130 # Trigger definition - single SQL Insert
131 connection con2_super;
133 Create trigger trg2 BEFORE UPDATE on tb3
for each row
135 insert into db_test.t1_i
136 values (
new.f120,
new.f136,
new.f144,
new.f163);
140 # Trigger exeution - single SQL Insert
141 connection con2_general;
142 Select f120, f122, f136, f144, f163 from tb3 where f122 like
'Test 3.5.8.4%';
143 select * from db_test.t1_i order by i120;
144 update tb3
set f120=
'I', f122=
'Test 3.5.8.4-Single Insert'
145 where f122=
'Test 3.5.8.4';
146 Select f120, f122, f136, f144, f163 from tb3 where f122 like
'Test 3.5.8.4%';
147 select * from db_test.t1_i order by i120;
150 let $message= 3.5.8.4 - single SQL - update;
151 --source include/show_msg.inc
152 # Trigger definition - single SQL update
153 connection con2_super;
155 Create trigger trg3 BEFORE UPDATE on tb3
for each row
160 # Trigger exeution - single SQL - update;
161 connection con2_general;
162 update tb3
set f120=
'U', f122=
'Test 3.5.8.4-Single Update'
163 where f122=
'Test 3.5.8.4-Single Insert';
164 Select f120, f122, f136, f144, f163 from tb3 where f122 like
'Test 3.5.8.4%';
165 select * from db_test.t1_u order by u120;
168 let $message= 3.5.8.3/4 - single SQL -
delete;
169 --source include/show_msg.inc
170 # Trigger definition - single SQL delete
171 connection con2_super;
173 Create trigger trg4 AFTER UPDATE on tb3
for each row
174 delete from db_test.t1_d where d136=
new.f136;
176 # Trigger exeution - single SQL delete
177 connection con2_general;
178 #lock tables tb3 write, db_test.t1_i write, db_test.t1_u write, db_test.t1_d write;
179 update tb3
set f120=
'D', f136=444,
180 f122=
'Test 3.5.8.4-Single Delete'
181 where f122=
'Test 3.5.8.4-Single Update';
183 Select f120, f122, f136, f144, f163 from tb3 where f122 like
'Test 3.5.8.4%';
184 select * from db_test.t1_d order by d120;
187 let $message= 3.5.8.3/4 - single SQL - select;
188 --source include/show_msg.inc
189 # Trigger definition - single SQL select
190 connection con2_super;
192 Create trigger trg5 AFTER UPDATE on tb3
for each row
193 select sum(db_test.t1_u.u163) into @test_var from db_test.t1_u
194 where u136= new.f136;
196 # Trigger exeution - single SQL select
197 connection con2_general;
199 update tb3
set f120=
'S', f136=111,
200 f122=
'Test 3.5.8.4-Single Select'
201 where f122=
'Test 3.5.8.4-Single Delete';
202 Select f120, f122, f136, f144, f163 from tb3 where f122 like
'Test 3.5.8.4%';
210 drop database
if exists db_test;
211 delete from tb3 where f122 like
'Test 3.5.8.4%';
212 revoke ALL PRIVILEGES, GRANT OPTION FROM
'test_general'@
'localhost';
216 #Section 3.5.8.5 (IF)
217 # Test case: Ensure that the stored procedure-specific flow control statement like IF
218 # works correctly when it is a part of the triggered action portion of a
219 # trigger definition.
220 let $message= Testcase 3.5.8.5 (IF):;
221 --source include/show_msg.inc
224 create trigger trg2 before insert on tb3
for each row
227 set @test_var=
'one',
new.f120=
'2';
228 ELSEIF
new.f120=
'2' then
229 set @test_var=
'two',
new.f120=
'3';
230 ELSEIF
new.f120=
'3' then
231 set @test_var=
'three',
new.f120=
'4';
234 IF (
new.f120=
'4') and (new.f136=10) then
235 set @test_var2='2nd if', new.f120='d';
237 set @test_var2='2nd else', new.f120='D';
242 set @test_var='Empty', @test_var2=0;
243 Insert into tb3 (f120, f122, f136) values ('1', 'Test 3.5.8.5-if', 101);
244 select f120, f122, f136, @test_var, @test_var2
245 from tb3 where f122 = 'Test 3.5.8.5-if' order by f136;
246 Insert into tb3 (f120, f122, f136) values ('2', 'Test 3.5.8.5-if', 102);
247 select f120, f122, f136, @test_var, @test_var2
248 from tb3 where f122 = 'Test 3.5.8.5-if' order by f136;
249 Insert into tb3 (f120, f122, f136) values ('3', 'Test 3.5.8.5-if', 10);
250 select f120, f122, f136, @test_var, @test_var2
251 from tb3 where f122 = 'Test 3.5.8.5-if' order by f136;
252 Insert into tb3 (f120, f122, f136) values ('3', 'Test 3.5.8.5-if', 103);
253 select f120, f122, f136, @test_var, @test_var2
254 from tb3 where f122 = 'Test 3.5.8.5-if' order by f136;
257 --error ER_PARSE_ERROR
258 create trigger trg3 before update on tb3 for each row
260 ELSEIF new.f120='2' then
263 --error 0, ER_TRG_DOES_NOT_EXIST
266 --error ER_PARSE_ERROR
267 create trigger trg4 before update on tb3 for each row
269 IF (new.f120='4') and (new.f136=10) then
270 set @test_var2='2nd if', new.f120='d';
272 set @test_var2='2nd else', new.f120='D';
275 --error 0, ER_TRG_DOES_NOT_EXIST
281 delete from tb3 where f121=
'Test 3.5.8.5-if';
285 #Section 3.5.8.5 (CASE)
286 # Test case: Ensure that the stored procedure-specific flow control statement
287 # like CASE works correctly when it is a part of the triggered action
288 # portion of a trigger definition.
289 let $message= Testcase 3.5.8.5-
case:;
290 --source include/show_msg.inc
293 create trigger trg3 before insert on tb3
for each row
295 SET
new.f120=char(ascii(
new.f120)-32);
297 when
new.f136<100 then
set new.f136=
new.f136+120;
298 when
new.f136<10 then
set new.f144=777;
299 when
new.f136>100 then
set new.f120=
new.f136-1;
302 when
new.f136=200 then
set @test_var=CONCAT(
new.f120,
'=');
303 ELSE
set @test_var=concat(
new.f120,
'*');
306 when 1 then
set @test_var=concat(@test_var,
'one');
307 when 2 then
set @test_var=concat(@test_var,
'two');
308 when 3 then
set @test_var=concat(@test_var,
'three');
309 when 4 then
set @test_var=concat(@test_var,
'four');
310 when 5 then
set @test_var=concat(@test_var,
'five');
311 when 6 then
set @test_var=concat(@test_var,
'six');
312 when 7 then
set @test_var=concat(@test_var,
'seven');
313 when 8 then
set @test_var=concat(@test_var,
'eight');
314 when 9 then
set @test_var=concat(@test_var,
'nine');
315 when 10 then
set @test_var=concat(@test_var,
'ten');
316 when 11 then
set @test_var=concat(@test_var,
'eleven');
317 when 12 then
set @test_var=concat(@test_var,
'twelve');
318 when 13 then
set @test_var=concat(@test_var,
'thirteen');
319 when 14 then
set @test_var=concat(@test_var,
'fourteen');
320 when 15 then
set @test_var=concat(@test_var,
'fifteen');
321 ELSE
set @test_var=CONCAT(
new.f120,
'*',
new.f144);
326 set @test_var=
'Empty';
327 Insert into tb3 (f120, f122, f136, f144)
328 values ('a', 'Test 3.5.8.5-case', 5, 7);
329 select f120, f122, f136, f144, @test_var
330 from tb3 where f122 = 'Test 3.5.8.5-case' order by f120,f136;
331 Insert into tb3 (f120, f122, f136, f144)
332 values ('b', 'Test 3.5.8.5-case', 71,16);
333 select f120, f122, f136, f144, @test_var
334 from tb3 where f122 = 'Test 3.5.8.5-case' order by f120,f136;
335 Insert into tb3 (f120, f122, f136, f144)
336 values ('c', 'Test 3.5.8.5-case', 80,1);
337 select f120, f122, f136, f144, @test_var
338 from tb3 where f122 = 'Test 3.5.8.5-case' order by f120,f136;
339 Insert into tb3 (f120, f122, f136)
340 values ('d', 'Test 3.5.8.5-case', 152);
341 select f120, f122, f136, f144, @test_var
342 from tb3 where f122 = 'Test 3.5.8.5-case' order by f120,f136;
343 Insert into tb3 (f120, f122, f136, f144)
344 values ('e', 'Test 3.5.8.5-case', 200, 8);
345 select f120, f122, f136, f144, @test_var
346 from tb3 where f122 = 'Test 3.5.8.5-case' order by f120,f136;
347 --error 0, ER_SP_CASE_NOT_FOUND
348 Insert into tb3 (f120, f122, f136, f144)
349 values ('f', 'Test 3.5.8.5-case', 100, 8);
350 select f120, f122, f136, f144, @test_var
351 from tb3 where f122 = 'Test 3.5.8.5-case' order by f120,f136;
354 --error ER_PARSE_ERROR
355 create trigger trg3a before update on tb3 for each row
358 when new.f136<100 then set new.f120='p';
362 --error 0, ER_TRG_DOES_NOT_EXIST
368 delete from tb3 where f121=
'Test 3.5.8.5-case';
371 #Section 3.5.8.5 (LOOP)
372 # Test case: Ensure that the stored procedure-specific flow control
373 # statement like LOOP / LEAVE work correctly when they are
374 # part of the triggered action portion of a trigger definition.
375 let $message= Testcase 3.5.8.5-loop/leave:;
376 --source include/show_msg.inc
379 Create trigger trg4 after insert on tb3
for each row
381 set @counter=0, @flag=
'Initial';
383 if new.f136<
new.f144 then
384 set @counter=
'Nothing to loop';
387 set @counter=@counter+1;
388 if new.f136=
new.f144+@counter then
389 set @counter=concat(@counter,
' loops');
398 Insert into tb3 (f122, f136, f144)
399 values ('Test 3.5.8.5-loop', 2, 8);
400 select @counter, @flag;
401 Insert into tb3 (f122, f136, f144)
402 values ('Test 3.5.8.5-loop', 11, 8);
403 select @counter, @flag;
408 --error ER_PARSE_ERROR
409 Create trigger trg4_2 after update on tb3 for each row
412 set @counter=@counter+1;
416 --error 0, ER_TRG_DOES_NOT_EXIST
422 delete from tb3 where f122=
'Test 3.5.8.5-loop';
425 #Section 3.5.8.5 (REPEAT ITERATE)
426 #Testcase: Ensure that the stored procedure-specific flow control statements
427 # like REPEAT work correctly when they are part of the triggered action
428 # portion of a trigger definition.
429 let $message= Testcase 3.5.8.5-repeat:;
430 --source include/show_msg.inc
433 Create trigger trg6 after insert on tb3
for each row
436 SET @counter1 = @counter1 + 1;
437 IF (@counter1 MOD 2 = 0) THEN ITERATE rp_label;
439 SET @counter2 = @counter2 + 1;
440 UNTIL @counter1> new.f136 END REPEAT rp_label;
444 set @counter1= 0, @counter2= 0;
445 Insert into tb3 (f122, f136)
446 values ('Test 3.5.8.5-repeat', 13);
447 select @counter1, @counter2;
451 --error ER_PARSE_ERROR
452 Create trigger trg6_2 after update on tb3 for each row
455 SET @counter2 = @counter2 + 1;
462 delete from tb3 where f122=
'Test 3.5.8.5-repeat';
466 #Section 3.5.8.5 (WHILE)
467 # Test case: Ensure that the stored procedure-specific flow control
468 # statements WHILE, work correctly when they are part of
469 # the triggered action portion of a trigger definition.
470 let $message= Testcase 3.5.8.5-
while:;
471 --source include/show_msg.inc
474 Create trigger trg7 after insert on tb3
for each row
475 wl_label: WHILE @counter1 <
new.f136 DO
476 SET @counter1 = @counter1 + 1;
477 IF (@counter1 MOD 2 = 0) THEN ITERATE wl_label;
479 SET @counter2 = @counter2 + 1;
483 set @counter1= 0, @counter2= 0;
484 Insert into tb3 (f122, f136)
485 values ('Test 3.5.8.5-while', 7);
486 select @counter1, @counter2;
488 --error ER_PARSE_ERROR
489 Create trigger trg7_2 after update on tb3 for each row
491 WHILE @counter1 < new.f136
492 SET @counter1 = @counter1 + 1;
498 delete from tb3 where f122=
'Test 3.5.8.5-while';
503 # Test case: Ensure that a trigger definition that includes a CALL to a stored
504 # procedure fails, at CREATE TRIGGER time, with an appropriate error
505 # message. Not more valid requirement.
506 let $message= Testcase 3.5.8.6: (requirement void);
507 --source include/show_msg.inc
509 CREATE PROCEDURE sp_01 () BEGIN set @v1=1; END
511 CREATE TRIGGER trg8_1 BEFORE UPDATE ON tb3 FOR EACH ROW
516 Insert into tb3 (f120, f122, f136) values ('6', 'Test 3.5.8.6-insert', 101);
517 update tb3 set f120='S', f136=111,
518 f122='Test 3.5.8.6-tr8_1'
519 where f122='Test 3.5.8.6-insert';
521 from tb3 where f122 like 'Test 3.5.8.6%' order by f120;
523 DROP PROCEDURE sp_01;
527 # Test case: Ensure that a trigger definition that includes a
528 # transaction-delimiting statement (e.g. COMMIT,
529 # ROLLBACK, START TRANSACTION) fails, at CREATE TRIGGER
530 # time, with an appropriate error message.
531 let $message= Testcase 3.5.8.7;
532 --source include/show_msg.inc
535 --error ER_COMMIT_NOT_ALLOWED_IN_SF_OR_TRG
536 Create trigger trg9_1 before update on tb3
for each row
543 --error ER_COMMIT_NOT_ALLOWED_IN_SF_OR_TRG
544 Create trigger trg9_2 before
delete on tb3
for each row
553 # Cleanup section 3.5
555 drop user test_general@localhost;
556 drop user test_general;
557 drop user test_super@localhost;