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
11 --replace_result $MYSQLTEST_VARDIR <MYSQLTEST_VARDIR>
13 load data infile
'$MYSQLTEST_VARDIR/std_data/funcs_1/memory_tb3.txt'
17 --disable_abort_on_error
19 ##############################################
20 ################ Section 3.5.10 #################
21 # Check on Trigger Activation
22 ##############################################
24 # Test case: Ensure that every trigger that should be activated by
25 # every possible type of implicit insertion into its subject
26 # table (INSERT into a view based on the subject table) is
27 # indeed activated correctly
29 # Test case: Ensure that every trigger that should be activated by every
30 # possible type of implicit insertion into its subject table
31 # (UPDATE into a view based on the subject table) is indeed
34 # Test case: Ensure that every trigger that should be activated by every
35 # possible type of implicit insertion into its subject table
36 # (DELETE from a view based on the subject table) is indeed
38 let $message= Testcase 3.5.10.1/2/3:;
39 --source include/show_msg.inc
41 Create
view vw11 as select * from tb3
42 where f122 like
'Test 3.5.10.1/2/3%';
43 Create trigger trg1a before insert on tb3
44 for each row
set new.f163=111.11;
45 Create trigger trg1b after insert on tb3
46 for each row
set @test_var=
'After Insert';
47 Create trigger trg1c before update on tb3
48 for each row
set new.f121=
'Y',
new.f122=
'Test 3.5.10.1/2/3-Update';
49 Create trigger trg1d after update on tb3
50 for each row
set @test_var=
'After Update';
51 Create trigger trg1e before
delete on tb3
52 for each row
set @test_var=5;
53 Create trigger trg1f after
delete on tb3
54 for each row
set @test_var= 2* @test_var+7;
57 Insert into vw11 (f122, f151) values ('
Test 3.5.10.1/2/3', 1);
58 Insert into vw11 (f122, f151) values ('Test 3.5.10.1/2/3', 2);
59 Insert into vw11 (f122, f151) values ('Not in View', 3);
60 select f121, f122, f151, f163
61 from tb3 where f122 like 'Test 3.5.10.1/2/3%' order by f151;
63 select f121, f122, f151, f163 from vw11;
64 select f121, f122, f151, f163
65 from tb3 where f122 like 'Not in View';
68 Update vw11
set f163=1;
69 select f121, f122, f151, f163 from tb3
70 where f122 like
'Test 3.5.10.1/2/3%' order by f151;
72 select f121, f122, f151, f163 from vw11;
76 Select @test_var as
'before delete';
77 delete from vw11 where f151=1;
78 select f121, f122, f151, f163 from tb3
79 where f122 like
'Test 3.5.10.1/2/3%' order by f151;
81 select f121, f122, f151, f163 from vw11;
82 Select @test_var as
'after delete';
93 delete from tb3 where f122 like
'Test 3.5.10.1/2/3%';
98 # Test case: Ensure that every trigger that should be activated by every
99 # possible type of implicit insertion into its subject table
100 # (LOAD into the subject table) is indeed activated correctly
101 let $message= Testcase 3.5.10.4:;
102 --source include/show_msg.inc
104 --replace_result $engine_type <engine_to_be_used>
105 eval create
table tb_load (f1
int, f2
char(25),f3
int) engine = $engine_type;
106 Create trigger trg4 before insert on tb_load
107 for each row
set new.f3=-(
new.f1 div 5), @counter= @counter+1;
110 select @counter as
'Rows Loaded Before';
111 --replace_result $MYSQLTEST_VARDIR <MYSQLTEST_VARDIR>
112 eval load data infile
'$MYSQLTEST_VARDIR/std_data/funcs_1/t9.txt' into
table tb_load;
114 select @counter as
'Rows Loaded After';
115 Select * from tb_load order by f1
limit 10;
125 # Testcase: Ensure that every trigger that should be activated by every possible
126 # type of implicit update of its subject table (e.g.a FOREIGN KEY SET
127 # DEFAULT action or an UPDATE of a view based on the subject table) is
128 # indeed activated correctly
129 let $message= Testcase 3.5.10.5: (implemented in trig_frkey.test);
130 --source include/show_msg.inc
134 # Testcase: Ensure that every trigger that should be activated by every possible
135 # type of implicit deletion from its subject table (e.g.a FOREIGN KEY
136 # CASCADE action or a DELETE from a view based on the subject table) is
137 # indeed activated correctly
138 let $message= Testcase 3.5.10.6: (implemented in trig_frkey.test);
139 --source include/show_msg.inc
141 #Section 3.5.10.extra
142 # Testcase: Ensure that every trigger that should be activated by every possible
143 # type of implicit deletion from its subject table (e.g. an action performed
144 # on the subject table from a stored procedure is indeed activated correctly
145 let $message= Testcase 3.5.10.extra:;
146 --source include/show_msg.inc
148 --replace_result $engine_type <engine_to_be_used>
149 eval create
table t1_sp (var136 tinyint, var151 decimal) engine = $engine_type;
151 create trigger trg before insert on t1_sp
152 for each row
set @counter=@counter+1;
153 # declare continue handler for sqlstate '01000' set done = 1;
156 create procedure trig_sp()
158 declare done
int default 0;
159 declare var151 decimal;
160 declare var136 tinyint;
161 declare cur1
cursor for select f136, f151 from tb3;
162 declare continue
handler for sqlstate '01000' set done = 1;
164 fetch cur1 into var136, var151;
165 wl_loop: WHILE NOT done DO
166 insert into t1_sp values (var136, var151);
167 fetch cur1 into var136, var151;
175 --error ER_SP_FETCH_NO_DATA
178 select count(*) from tb3;
179 select count(*) from t1_sp;
183 drop procedure trig_sp;
188 ##################################
189 ########## Section 3.5.11 ########
190 # Check on Trigger Performance #
191 ##################################
193 # Testcase: Ensure that a set of complicated, interlocking triggers that are activated
194 # by multiple trigger events on no fewer than 50 different tables with at least
195 # 500,000 rows each, all work correctly, return the correct results, and have
196 # the correct effects on the database. It is expected that the Services Provider
197 # will use its own skills and experience in database testing to devise tables and
198 # triggers that fulfill this requirement.
199 let $message= Testcase 3.5.11.1 (implemented in trig_perf.test);
200 --source include/show_msg.inc
203 ##########################################
204 # Other Scenasrios (not in requirements) #
205 ##########################################
207 # Checking for triggers starting triggers (no direct requirement)
208 let $message= Testcase y.y.y.2:
Check for triggers starting triggers;
209 --source include/show_msg.inc
213 drop
table if exists t1;
214 drop
table if exists t2_1;
215 drop
table if exists t2_2;
216 drop
table if exists t2_3;
217 drop
table if exists t2_4;
218 drop
table if exists t3;
221 --replace_result $engine_type <engine_to_be_used>
222 eval create
table t1 (f1 integer) engine = $engine_type;
223 --replace_result $engine_type <engine_to_be_used>
224 eval create
table t2_1 (f1 integer) engine = $engine_type;
225 --replace_result $engine_type <engine_to_be_used>
226 eval create
table t2_2 (f1 integer) engine = $engine_type;
227 --replace_result $engine_type <engine_to_be_used>
228 eval create
table t2_3 (f1 integer) engine = $engine_type;
229 --replace_result $engine_type <engine_to_be_used>
230 eval create
table t2_4 (f1 integer) engine = $engine_type;
231 --replace_result $engine_type <engine_to_be_used>
232 eval create
table t3 (f1 integer) engine = $engine_type;
234 insert into t1 values (1);
236 create trigger tr1 after insert on t1
for each row
238 insert into t2_1 (f1) values (new.f1+1);
239 insert into t2_2 (f1) values (new.f1+1);
240 insert into t2_3 (f1) values (new.f1+1);
241 insert into t2_4 (f1) values (new.f1+1);
245 create trigger tr2_1 after insert on t2_1 for each row
246 insert into t3 (f1) values (new.f1+10);
247 create trigger tr2_2 after insert on t2_2 for each row
248 insert into t3 (f1) values (new.f1+100);
249 create trigger tr2_3 after insert on t2_3 for each row
250 insert into t3 (f1) values (new.f1+1000);
251 create trigger tr2_4 after insert on t2_4 for each row
252 insert into t3 (f1) values (new.f1+10000);
254 #lock tables t1 write, t2_1 write, t2_2 write, t2_3 write, t2_4 write, t3 write;
255 insert into t1 values (1);
257 select * from t3 order by f1;
266 drop
table t1, t2_1, t2_2, t2_3, t2_4, t3;
270 # Checking for circular trigger definitions
271 let $message= Testcase y.y.y.3: Circular trigger reference;
272 --source include/show_msg.inc
275 drop
table if exists t1;
276 drop
table if exists t2;
277 drop
table if exists t3;
278 drop
table if exists t4;
280 --replace_result $engine_type <engine_to_be_used>
281 eval create
table t1 (f1 integer) engine = $engine_type;
282 --replace_result $engine_type <engine_to_be_used>
283 eval create
table t2 (f2 integer) engine = $engine_type;
284 --replace_result $engine_type <engine_to_be_used>
285 eval create
table t3 (f3 integer) engine = $engine_type;
286 --replace_result $engine_type <engine_to_be_used>
287 eval create
table t4 (f4 integer) engine = $engine_type;
289 insert into t1 values (0);
290 create trigger tr1 after insert on t1
291 for each row insert into t2 (f2) values (new.f1+1);
292 create trigger tr2 after insert on t2
293 for each row insert into t3 (f3) values (new.f2+1);
294 create trigger tr3 after insert on t3
295 for each row insert into t4 (f4) values (new.f3+1);
296 create trigger tr4 after insert on t4
297 for each row insert into t1 (f1) values (new.f4+1);
299 # Bug#11896 Partial locking in case of recursive trigger definittions
300 --error ER_CANT_UPDATE_USED_TABLE_IN_SF_OR_TRG
301 insert into t1 values (1);
302 select * from t1 order by f1;
303 select * from t2 order by f2;
304 select * from t3 order by f3;
305 select * from t4 order by f4;
321 # Testcase: create recursive trigger/storedprocedures conditions
322 let $message= Testcase y.y.y.4: Recursive trigger/SP references;
323 --source include/show_msg.inc
325 set @sql_mode=
'traditional';
326 --replace_result $engine_type <engine_to_be_used>
327 eval create
table t1_sp (
330 var151 decimal) engine = $engine_type;
333 create procedure trig_sp()
335 declare done
int default 0;
336 declare var151 decimal;
337 declare var136 tinyint;
338 declare cur1
cursor for select f136, f151 from tb3;
339 declare continue
handler for sqlstate '01000' set done = 1;
340 set @counter= @counter+1;
342 fetch cur1 into var136, var151;
343 wl_loop: WHILE NOT done DO
344 insert into t1_sp values (@counter, var136, var151);
345 fetch cur1 into var136, var151;
351 create trigger trg before insert on t1_sp
352 for each row call trig_sp();
356 --error ER_SP_RECURSION_LIMIT
359 select count(*) from tb3;
360 select count(*) from t1_sp;
362 # check recursion will not work here:
363 set @@max_sp_recursion_depth= 10;
366 --error ER_CANT_UPDATE_USED_TABLE_IN_SF_OR_TRG
369 select count(*) from tb3;
370 select count(*) from t1_sp;
374 drop procedure trig_sp;
381 # Checking rollback of nested trigger definitions
382 let $message= Testcase y.y.y.5: Rollback of nested trigger references;
383 --source include/show_msg.inc
385 set @@sql_mode=
'traditional';
388 drop
table if exists t1;
389 drop
table if exists t2;
390 drop
table if exists t3;
391 drop
table if exists t4;
393 --replace_result $engine_type <engine_to_be_used>
394 eval create
table t1 (f1 integer) engine = $engine_type;
395 --replace_result $engine_type <engine_to_be_used>
396 eval create
table t2 (f2 integer) engine = $engine_type;
397 --replace_result $engine_type <engine_to_be_used>
398 eval create
table t3 (f3 integer) engine = $engine_type;
399 --replace_result $engine_type <engine_to_be_used>
400 eval create
table t4 (f4 tinyint) engine = $engine_type;
401 --replace_result $engine_type <engine_to_be_used>
402 show create
table t1;
403 insert into t1 values (1);
404 create trigger tr1 after insert on t1
405 for each row insert into t2 (f2) values (new.f1+1);
406 create trigger tr2 after insert on t2
407 for each row insert into t3 (f3) values (new.f2+1);
408 create trigger tr3 after insert on t3
409 for each row insert into t4 (f4) values (new.f3+1000);
413 # Bug#32656 NDB: Duplicate key error aborts transaction in handler.
414 # Doesn't talk back to SQL
415 --error ER_WARN_DATA_OUT_OF_RANGE
416 insert into t1 values (1);
418 select * from t1 order by f1;
419 select * from t2 order by f2;
420 select * from t3 order by f3;