1 #======================================================================
4 # (test case numbering refer to requirement document TP v1.1)
5 #======================================================================
8 --source suite/funcs_1/include/tb3.inc
13 ###############################################
15 --disable_abort_on_error
17 #####################################################
18 ################# Section 3.5.1 #####################
19 # Syntax checks for CREATE TRIGGER and DROP TRIGGER #
20 #####################################################
23 # Testcase: Ensure that all clauses that should be supported are supported.
24 let $message= Testcase: 3.5.1.1:;
25 --source include/show_msg.inc
26 # OBN - This test case tests basic trigger definition and execution
27 # of INSERT/UPDATE/DELETE actions and BEFORE/AFTER timings.
28 # As such it covers the equirements in sections 3.5.6.1, 3.5.6.2,
29 # 3.5.6.4, 3.5.6.5, 3.5.7.1, 3.5.7.2, 3.5.7.3, 3.5.7.17 below.
30 # - Note currently as a result of limitations with locking tables in
31 # triggers, a specifc lockingof the tables is done.
32 # Once fixed, the locking and alias referances should be removed
36 Create trigger trg1_1 BEFORE INSERT
37 on tb3
for each row
set @test_before = 2,
new.f142 = @test_before;
38 Create trigger trg1_2 AFTER INSERT
39 on tb3
for each row
set @test_after = 6;
40 Create trigger trg1_4 BEFORE UPDATE
41 on tb3
for each row
set @test_before = 27,
42 new.f142 = @test_before,
43 new.f122 =
'Before Update Trigger';
44 Create trigger trg1_3 AFTER UPDATE
45 on tb3
for each row
set @test_after =
'15';
46 Create trigger trg1_5 BEFORE DELETE on tb3
for each row
47 select count(*) into @test_before from tb3 as tr_tb3
48 where f121 = '
Test 3.5.1.1';
49 Create trigger trg1_6 AFTER DELETE on tb3 for each row
50 select count(*) into @test_after from tb3 as tr_tb3
51 where f121 = 'Test 3.5.1.1';
52 # Trigger Execution Insert (before and after)
55 select @test_before, @test_after;
56 Insert into tb3 (f121, f122, f142, f144, f134)
57 values ('Test 3.5.1.1', 'First
Row', @test_before, @test_after, 1);
59 select f121, f122, f142, f144, f134 from tb3 where f121 = 'Test 3.5.1.1';
60 select @test_before, @test_after;
62 # Trigger Execution Update (before and after)
63 set @test_before = 18;
65 select @test_before, @test_after;
66 Update tb3
set tb3.f122 =
'Update',
67 tb3.f142 = @test_before,
68 tb3.f144 = @test_after
69 where tb3.f121 =
'Test 3.5.1.1';
71 select f121, f122, f142, f144, f134 from tb3 where f121 =
'Test 3.5.1.1';
72 select @test_before, @test_after;
74 # Trigger Execution Delete (before and after)
75 Insert into tb3 (f121, f122, f142, f144, f134)
76 values ('Test 3.5.1.1', 'Second Row', 5, 6, 2);
80 select f121, f122, f142, f144, f134 from tb3 where f121 = 'Test 3.5.1.1';
81 select @test_before, @test_after;
82 Delete from tb3 where f121 = 'Test 3.5.1.1' and f134 = 2;
84 select f121, f122, f142, f144, f134 from tb3 where f121 = 'Test 3.5.1.1';
85 select @test_before, @test_after;
89 --error 0, ER_TRG_DOES_NOT_EXIST
91 --error 0, ER_TRG_DOES_NOT_EXIST
93 --error 0, ER_TRG_DOES_NOT_EXIST
95 --error 0, ER_TRG_DOES_NOT_EXIST
97 --error 0, ER_TRG_DOES_NOT_EXIST
99 --error 0, ER_TRG_DOES_NOT_EXIST
102 delete from tb3 where f121=
'Test 3.5.1.1';
106 # Testcase: Ensure that all clauses that should not be supported are disallowed
107 # with an appropriate error message.
108 let $message= Testcase: 3.5.1.2:;
109 --source include/show_msg.inc
111 --error ER_PARSE_ERROR
112 Create trigger trg_1 after insert
117 --error 0, ER_TRG_DOES_NOT_EXIST
123 # Testcase: Ensure that all supported clauses are supported only in the correct order.
124 let $message= Testcase 3.5.1.3:;
125 --source include/show_msg.inc
126 --error ER_PARSE_ERROR
127 CREATE TRIGGER trg3_1 on tb3 BEFORE INSERT
for each row
set new.f120 =
't';
129 --error ER_PARSE_ERROR
130 CREATE trg3_2 TRIGGER AFTER INSERT on tb3
for each row
set new.f120 =
's';
132 --error ER_PARSE_ERROR
133 CREATE TRIGGER trg3_3 Before DELETE on tb3
set @ret1 =
'test' for each row;
135 --error ER_PARSE_ERROR
136 CREATE TRIGGER trg3_4 DELETE AFTER on tb3
set @ret1 =
'test' for each row;
138 --error ER_PARSE_ERROR
139 CREATE
for each row TRIGGER trg3_5 AFTER UPDATE on tb3
set @ret1 =
'test';
142 # OBN - Although none of the above should have been created we should do a cleanup
143 # since if they have been created, not dropping them will affect following
146 --error 0, ER_TRG_DOES_NOT_EXIST
148 --error 0, ER_TRG_DOES_NOT_EXIST
150 --error 0, ER_TRG_DOES_NOT_EXIST
152 --error 0, ER_TRG_DOES_NOT_EXIST
154 --error 0, ER_TRG_DOES_NOT_EXIST
160 # Testcase: Ensure that an appropriate error message is returned if a clause
161 # is out-of-order in an SQL statement.
162 # OBN - FIXME - Missing 3.5.1.4 need to add
165 # Testcase: Ensure that all clauses that are defined to be mandatory are indeed
166 # required to be mandatory by the MySQL server and tools
167 let $message= Testcase: 3.5.1.5:;
168 --source include/show_msg.inc
170 --error ER_PARSE_ERROR
171 CREATE TRIGGER trg4_1 AFTER on tb3
for each row
set new.f120 =
'e';
173 --error ER_PARSE_ERROR
174 CREATE TRIGGER trg4_2 INSERT on tb3
for each set row
new.f120 =
'f';
176 --error ER_PARSE_ERROR
177 CREATE TRIGGER trg4_3 BEFORE INSERT tb3
for each row
set new.f120 =
'g';
179 --error ER_PARSE_ERROR
180 CREATE TRIGGER trg4_4 AFTER UPDATE on tb3
for each set new.f120 =
'g';
182 --error ER_PARSE_ERROR
183 CREATE trg4_5 AFTER DELETE on tb3
for each set new.f120 =
'g';
185 --error ER_PARSE_ERROR
186 CREATE TRIGGER trg4_6 BEFORE DELETE
for each row
set new.f120 =
'g';
189 # OBN - Although none of the above should have been created we should do a cleanup
190 # since if they have been created, not dropping them will affect following
193 --error 0, ER_TRG_DOES_NOT_EXIST
195 --error 0, ER_TRG_DOES_NOT_EXIST
197 --error 0, ER_TRG_DOES_NOT_EXIST
199 --error 0, ER_TRG_DOES_NOT_EXIST
201 --error 0, ER_TRG_DOES_NOT_EXIST
203 --error 0, ER_TRG_DOES_NOT_EXIST
208 # Testcase: Ensure that any clauses that are defined to be optional are indeed
209 # trated as optional by MySQL server and tools
210 let $message= Testcase 3.5.1.6: - Need
to fix;
211 --source include/show_msg.inc
212 # OBN - FIXME - Missing 3.5.1.6 need to add
215 # Testcase: Ensure that all valid, fully-qualified, and non-qualified,
216 # trigger names are accepted, at creation time.
217 let $message= Testcase 3.5.1.7: - need
to fix;
218 --source include/show_msg.inc
220 drop
table if exists t1;
221 --replace_result $engine_type <engine_to_be_used>
222 eval create
table t1 (f1
int, f2
char(25),f3
int) engine = $engine_type;
223 CREATE TRIGGER trg5_1 BEFORE INSERT on
test.t1
224 for each row
set new.f3 =
'14';
225 # In 5.0 names to long (more than 64 chars) were trimed without an error
226 # In 5.1 an error is returned. So adding a call with the expected error
227 # and one with a shorter name to validate proper execution
228 --error ER_TOO_LONG_IDENT
229 CREATE TRIGGER trg_abcdefghijklmnopqrstuvwxyz1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZ
230 BEFORE UPDATE on
test.t1
for each row
set new.f3 =
'42';
231 CREATE TRIGGER trg_abcdefghijklmnopqrstuvwxyz1234567890ABCDEFGHIJKLMNOPQRSTUVWX
232 BEFORE UPDATE on
test.t1
for each row
set new.f3 =
'42';
234 insert into t1 (f2) values ('insert 3.5.1.7');
236 update t1 set f2='update 3.5.1.7';
238 select trigger_name from information_schema.triggers order by trigger_name;
242 --error 0, ER_TRG_DOES_NOT_EXIST
244 # In 5.1 the long name should generate an error that is to long
245 --error ER_TOO_LONG_IDENT
246 drop trigger trg_abcdefghijklmnopqrstuvwxyz1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZ;
247 drop trigger trg_abcdefghijklmnopqrstuvwxyz1234567890ABCDEFGHIJKLMNOPQRSTUVWX;
251 # Testcase: Ensure that any invalid trigger name is never accepted, and that an
252 # appropriate error message is returned when the name is rejected.
253 let $message= Testcase 3.5.1.8:;
254 --source include/show_msg.inc
256 --error ER_PARSE_ERROR
257 CREATE TRIGGER trg12* before insert on tb3
for each row
set new.f120 =
't';
259 --error ER_PARSE_ERROR
260 CREATE TRIGGER trigger before insert on tb3
for each row
set new.f120 =
't';
262 --error ER_PARSE_ERROR
263 CREATE TRIGGER 100 before insert on tb3
for each row
set new.f120 =
't';
265 --error ER_PARSE_ERROR
266 CREATE TRIGGER @@
view before insert on tb3
for each row
set new.f120 =
't';
268 --error ER_PARSE_ERROR
269 CREATE TRIGGER @
name before insert on tb3
for each row
set new.f120 =
't';
271 --error ER_TRG_IN_WRONG_SCHEMA
272 CREATE TRIGGER tb3.trg6_1 BEFORE INSERT on
test.tb3
273 for each row
set new.f120 =
'X';
276 drop database
if exists trig_db;
278 create database trig_db;
280 --replace_result $engine_type <engine_to_be_used>
281 eval create
table t1 (f1 integer) engine = $engine_type;
283 # Can't create a trigger in a different database
285 --error ER_NO_SUCH_TABLE
286 CREATE TRIGGER trig_db.trg6_2 AFTER INSERT on tb3
287 for each row
set @ret_trg6_2 = 5;
289 # Can't create a trigger refrencing a table in a different db
291 --error ER_TRG_IN_WRONG_SCHEMA
292 CREATE TRIGGER trg6_3 AFTER INSERT on test.tb3
293 for each row
set @ret_trg6_3 = 18;
299 drop database trig_db;
300 # OBN - Although none of the above should have been created we should do a cleanup
301 # since if they have been created, not dropping them will affect following
303 --error 0, ER_TRG_DOES_NOT_EXIST
305 --error 0, ER_TRG_DOES_NOT_EXIST
310 #Testcase: Ensure that a reference to a non-existent trigger is rejected with
311 # an appropriate error message.
312 let $message= Testcase 3.5.1.9:(cannot be inplemented at
this point);
313 --source include/show_msg.inc
317 #Testcase: Ensure that it is not possible to create two triggers with the same name on
319 let $message= Testcase 3.5.1.10:;
320 --source include/show_msg.inc
322 CREATE TRIGGER trg7_1 BEFORE UPDATE on tb3
for each row
set new.f120 =
'X';
324 --error ER_TRG_ALREADY_EXISTS
325 CREATE TRIGGER trg7_1 AFTER INSERT on tb3
for each row
set @x =
'Y';
329 --error 0, ER_TRG_DOES_NOT_EXIST
335 # Testcase: Ensure that it is not possible to create two or more triggers with
336 # the same name, provided each is associated with a different table.
337 let $message= Testcase 3.5.1.?:;
338 --source include/show_msg.inc
341 drop
table if exists t1;
342 drop
table if exists t2;
344 --replace_result $engine_type <engine_to_be_used>
345 eval create
table t1 (f1
char(50), f2 integer) engine = $engine_type;
346 --replace_result $engine_type <engine_to_be_used>
347 eval create
table t2 (f1
char(50), f2 integer) engine = $engine_type;
349 create trigger trig before insert on t1
350 for each row
set new.f1 =
'trig t1';
352 --error ER_TRG_ALREADY_EXISTS
353 create trigger trig before update on t2
354 for each row
set new.f1 =
'trig t2';
356 insert into t1 value (
'insert to t1',1);
358 update t1
set f1=
'update to t1';
360 insert into t2 value (
'insert to t2',2);
361 update t2
set f1=
'update to t1';
368 --error 0, ER_TRG_DOES_NOT_EXIST
374 # Testcase: Ensure that it is possible to create two or more triggers with
375 # the same name, provided each resides in a different database
376 let $message= Testcase 3.5.1.11:;
377 --source include/show_msg.inc
380 drop database
if exists trig_db1;
381 drop database
if exists trig_db2;
382 drop database
if exists trig_db3;
384 create database trig_db1;
385 create database trig_db2;
386 create database trig_db3;
388 --replace_result $engine_type <engine_to_be_used>
389 eval create
table t1 (f1
char(50), f2 integer) engine = $engine_type;
390 create trigger trig before insert on t1
391 for each row
set new.f1 =
'trig1', @test_var1=
'trig1';
393 --replace_result $engine_type <engine_to_be_used>
394 eval create
table t2 (f1
char(50), f2 integer) engine = $engine_type;
395 create trigger trig before insert on t2
396 for each row
set new.f1 =
'trig2', @test_var2=
'trig2';
398 --replace_result $engine_type <engine_to_be_used>
399 eval create
table t1 (f1
char(50), f2 integer) engine = $engine_type;
400 create trigger trig before insert on t1
401 for each row
set new.f1 =
'trig3', @test_var3=
'trig3';
403 set @test_var1=
'', @test_var2=
'', @test_var3=
'';
405 insert into t1 (f1,f2) values ('insert
to db1 t1',1);
406 insert into trig_db1.t1 (f1,f2) values ('insert
to db1 t1 from db1',2);
407 insert into trig_db2.t2 (f1,f2) values ('insert
to db2 t2 from db1',3);
408 insert into trig_db3.t1 (f1,f2) values ('insert
to db3 t1 from db1',4);
409 select @test_var1, @test_var2, @test_var3;
410 select * from t1 order by f2;
411 select * from trig_db2.t2;
412 select * from trig_db3.t1;
413 select * from t1 order by f2;
418 drop database trig_db1;
419 drop database trig_db2;
420 drop database trig_db3;
423 ###########################################
424 ################ Section 3.5.2 ############
425 # Check for the global nature of Triggers #
426 ###########################################
429 # Test case: Ensure that if a trigger created without a qualifying database
430 # name belongs to the database in use at creation time.
432 # Test case: Ensure that if a trigger created with a qualifying database name
433 # belongs to the database specified.
435 # Test case: Ensure that if a trigger created with a qualifying database name
436 # does not belong to the database in use at creation time unless
437 # the qualifying database name identifies the database that is
438 # also in use at creation time.
439 let $message= Testcase 3.5.2.1/2/3:;
440 --source include/show_msg.inc
444 drop database
if exists trig_db1;
445 drop database
if exists trig_db2;
447 create database trig_db1;
448 create database trig_db2;
450 --replace_result $engine_type <engine_to_be_used>
451 eval create
table t1 (f1
char(50), f2 integer) engine = $engine_type;
452 --replace_result $engine_type <engine_to_be_used>
453 eval create
table trig_db2.t1 (f1
char(50), f2 integer) engine = $engine_type;
454 create trigger trig1_b before insert on t1
455 for each row
set @test_var1=
'trig1_b';
456 create trigger trig_db1.trig1_a after insert on t1
457 for each row
set @test_var2=
'trig1_a';
458 create trigger trig_db2.trig2 before insert on trig_db2.t1
459 for each row
set @test_var3=
'trig2';
460 select trigger_schema, trigger_name, event_object_table
461 from information_schema.triggers
462 where trigger_schema like
'trig_db%'
463 order by trigger_name;
465 set @test_var1=
'', @test_var2=
'', @test_var3=
'';
466 insert into t1 (f1,f2) values ('insert
to db1 t1 from db1',352);
467 insert into trig_db2.t1 (f1,f2) values ('insert
to db2 t1 from db1',352);
468 select @test_var1, @test_var2, @test_var3;
472 drop database trig_db1;
473 drop database trig_db2;