Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(5)

Side by Side Diff: third_party/sqlite/src/test/trigger1.test

Issue 949043002: Add //third_party/sqlite to dirs_to_snapshot, remove net_sql.patch (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 5 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « third_party/sqlite/src/test/transitive1.test ('k') | third_party/sqlite/src/test/trigger2.test » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 # The author disclaims copyright to this source code. In place of 1 # The author disclaims copyright to this source code. In place of
2 # a legal notice, here is a blessing: 2 # a legal notice, here is a blessing:
3 # 3 #
4 # May you do good and not evil. 4 # May you do good and not evil.
5 # May you find forgiveness for yourself and forgive others. 5 # May you find forgiveness for yourself and forgive others.
6 # May you share freely, never taking more than you give. 6 # May you share freely, never taking more than you give.
7 # 7 #
8 #*********************************************************************** 8 #***********************************************************************
9 # 9 #
10 # This file tests creating and dropping triggers, and interaction thereof 10 # This file tests creating and dropping triggers, and interaction thereof
11 # with the database COMMIT/ROLLBACK logic. 11 # with the database COMMIT/ROLLBACK logic.
12 # 12 #
13 # 1. CREATE and DROP TRIGGER tests 13 # 1. CREATE and DROP TRIGGER tests
14 # trig-1.1: Error if table does not exist 14 # trigger1-1.1: Error if table does not exist
15 # trig-1.2: Error if trigger already exists 15 # trigger1-1.2: Error if trigger already exists
16 # trig-1.3: Created triggers are deleted if the transaction is rolled back 16 # trigger1-1.3: Created triggers are deleted if the transaction is rolled back
17 # trig-1.4: DROP TRIGGER removes trigger 17 # trigger1-1.4: DROP TRIGGER removes trigger
18 # trig-1.5: Dropped triggers are restored if the transaction is rolled back 18 # trigger1-1.5: Dropped triggers are restored if the transaction is rolled back
19 # trig-1.6: Error if dropped trigger doesn't exist 19 # trigger1-1.6: Error if dropped trigger doesn't exist
20 # trig-1.7: Dropping the table automatically drops all triggers 20 # trigger1-1.7: Dropping the table automatically drops all triggers
21 # trig-1.8: A trigger created on a TEMP table is not inserted into sqlite_master 21 # trigger1-1.8: A trigger created on a TEMP table is not inserted into sqlite_ma ster
22 # trig-1.9: Ensure that we cannot create a trigger on sqlite_master 22 # trigger1-1.9: Ensure that we cannot create a trigger on sqlite_master
23 # trig-1.10: 23 # trigger1-1.10:
24 # trig-1.11: 24 # trigger1-1.11:
25 # trig-1.12: Ensure that INSTEAD OF triggers cannot be created on tables 25 # trigger1-1.12: Ensure that INSTEAD OF triggers cannot be created on tables
26 # trig-1.13: Ensure that AFTER triggers cannot be created on views 26 # trigger1-1.13: Ensure that AFTER triggers cannot be created on views
27 # trig-1.14: Ensure that BEFORE triggers cannot be created on views 27 # trigger1-1.14: Ensure that BEFORE triggers cannot be created on views
28 # 28 #
29 29
30 set testdir [file dirname $argv0] 30 set testdir [file dirname $argv0]
31 source $testdir/tester.tcl 31 source $testdir/tester.tcl
32 ifcapable {!trigger} { 32 ifcapable !trigger||!compound {
33 finish_test 33 finish_test
34 return 34 return
35 } 35 }
36 36
37 do_test trigger1-1.1.1 { 37 do_test trigger1-1.1.1 {
38 catchsql { 38 catchsql {
39 CREATE TRIGGER trig UPDATE ON no_such_table BEGIN 39 CREATE TRIGGER trig UPDATE ON no_such_table BEGIN
40 SELECT * from sqlite_master; 40 SELECT * from sqlite_master;
41 END; 41 END;
42 } 42 }
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after
203 } {1 x-a 2 b 4 d} 203 } {1 x-a 2 b 4 d}
204 204
205 # Ensure that we cannot create INSTEAD OF triggers on tables 205 # Ensure that we cannot create INSTEAD OF triggers on tables
206 do_test trigger1-1.12 { 206 do_test trigger1-1.12 {
207 catchsql { 207 catchsql {
208 create table t1(a,b); 208 create table t1(a,b);
209 create trigger t1t instead of update on t1 for each row begin 209 create trigger t1t instead of update on t1 for each row begin
210 delete from t1 WHERE a=old.a+2; 210 delete from t1 WHERE a=old.a+2;
211 end; 211 end;
212 } 212 }
213 } {1 {cannot create INSTEAD OF trigger on table: main.t1}} 213 } {1 {cannot create INSTEAD OF trigger on table: t1}}
214 214
215 ifcapable view { 215 ifcapable view {
216 # Ensure that we cannot create BEFORE triggers on views 216 # Ensure that we cannot create BEFORE triggers on views
217 do_test trigger1-1.13 { 217 do_test trigger1-1.13 {
218 catchsql { 218 catchsql {
219 create view v1 as select * from t1; 219 create view v1 as select * from t1;
220 create trigger v1t before update on v1 for each row begin 220 create trigger v1t before update on v1 for each row begin
221 delete from t1 WHERE a=old.a+2; 221 delete from t1 WHERE a=old.a+2;
222 end; 222 end;
223 } 223 }
224 } {1 {cannot create BEFORE trigger on view: main.v1}} 224 } {1 {cannot create BEFORE trigger on view: v1}}
225 # Ensure that we cannot create AFTER triggers on views 225 # Ensure that we cannot create AFTER triggers on views
226 do_test trigger1-1.14 { 226 do_test trigger1-1.14 {
227 catchsql { 227 catchsql {
228 drop view v1; 228 drop view v1;
229 create view v1 as select * from t1; 229 create view v1 as select * from t1;
230 create trigger v1t AFTER update on v1 for each row begin 230 create trigger v1t AFTER update on v1 for each row begin
231 delete from t1 WHERE a=old.a+2; 231 delete from t1 WHERE a=old.a+2;
232 end; 232 end;
233 } 233 }
234 } {1 {cannot create AFTER trigger on view: main.v1}} 234 } {1 {cannot create AFTER trigger on view: v1}}
235 } ;# ifcapable view 235 } ;# ifcapable view
236 236
237 # Check for memory leaks in the trigger parser 237 # Check for memory leaks in the trigger parser
238 # 238 #
239 do_test trigger1-2.1 { 239 do_test trigger1-2.1 {
240 catchsql { 240 catchsql {
241 CREATE TRIGGER r1 AFTER INSERT ON t1 BEGIN 241 CREATE TRIGGER r1 AFTER INSERT ON t1 BEGIN
242 SELECT * FROM; -- Syntax error 242 SELECT * FROM; -- Syntax error
243 END; 243 END;
244 } 244 }
(...skipping 13 matching lines...) Expand all
258 do_test trigger1-3.1 { 258 do_test trigger1-3.1 {
259 execsql { 259 execsql {
260 CREATE TEMP TABLE t2(x,y); 260 CREATE TEMP TABLE t2(x,y);
261 } 261 }
262 catchsql { 262 catchsql {
263 CREATE TRIGGER r1 AFTER INSERT ON t1 BEGIN 263 CREATE TRIGGER r1 AFTER INSERT ON t1 BEGIN
264 INSERT INTO t2 VALUES(NEW.a,NEW.b); 264 INSERT INTO t2 VALUES(NEW.a,NEW.b);
265 END; 265 END;
266 } 266 }
267 } {0 {}} 267 } {0 {}}
268 do_test trigger-3.2 { 268 do_test trigger1-3.2 {
269 catchsql { 269 catchsql {
270 INSERT INTO t1 VALUES(1,2); 270 INSERT INTO t1 VALUES(1,2);
271 SELECT * FROM t2; 271 SELECT * FROM t2;
272 } 272 }
273 } {1 {no such table: main.t2}} 273 } {1 {no such table: main.t2}}
274 do_test trigger-3.3 { 274 do_test trigger1-3.3 {
275 db close 275 db close
276 set rc [catch {sqlite3 db test.db} err] 276 set rc [catch {sqlite3 db test.db} err]
277 if {$rc} {lappend rc $err} 277 if {$rc} {lappend rc $err}
278 set rc 278 set rc
279 } {0} 279 } {0}
280 do_test trigger-3.4 { 280 do_test trigger1-3.4 {
281 catchsql { 281 catchsql {
282 INSERT INTO t1 VALUES(1,2); 282 INSERT INTO t1 VALUES(1,2);
283 SELECT * FROM t2; 283 SELECT * FROM t2;
284 } 284 }
285 } {1 {no such table: main.t2}} 285 } {1 {no such table: main.t2}}
286 do_test trigger-3.5 { 286 do_test trigger1-3.5 {
287 catchsql { 287 catchsql {
288 CREATE TEMP TABLE t2(x,y); 288 CREATE TEMP TABLE t2(x,y);
289 INSERT INTO t1 VALUES(1,2); 289 INSERT INTO t1 VALUES(1,2);
290 SELECT * FROM t2; 290 SELECT * FROM t2;
291 } 291 }
292 } {1 {no such table: main.t2}} 292 } {1 {no such table: main.t2}}
293 do_test trigger-3.6 { 293 do_test trigger1-3.6.1 {
294 catchsql { 294 catchsql {
295 DROP TRIGGER r1; 295 DROP TRIGGER r1;
296 CREATE TEMP TRIGGER r1 AFTER INSERT ON t1 BEGIN 296 CREATE TEMP TRIGGER r1 AFTER INSERT ON t1 BEGIN
297 INSERT INTO t2 VALUES(NEW.a,NEW.b), (NEW.b*100, NEW.a*100);
298 END;
299 INSERT INTO t1 VALUES(1,2);
300 SELECT * FROM t2;
301 }
302 } {0 {1 2 200 100}}
303 do_test trigger1-3.6.2 {
304 catchsql {
305 DROP TRIGGER r1;
306 DELETE FROM t1;
307 DELETE FROM t2;
308 CREATE TEMP TRIGGER r1 AFTER INSERT ON t1 BEGIN
297 INSERT INTO t2 VALUES(NEW.a,NEW.b); 309 INSERT INTO t2 VALUES(NEW.a,NEW.b);
298 END; 310 END;
299 INSERT INTO t1 VALUES(1,2); 311 INSERT INTO t1 VALUES(1,2);
300 SELECT * FROM t2; 312 SELECT * FROM t2;
301 } 313 }
302 } {0 {1 2}} 314 } {0 {1 2}}
303 do_test trigger-3.7 { 315 do_test trigger1-3.7 {
304 execsql { 316 execsql {
305 DROP TABLE t2; 317 DROP TABLE t2;
306 CREATE TABLE t2(x,y); 318 CREATE TABLE t2(x,y);
307 SELECT * FROM t2; 319 SELECT * FROM t2;
308 } 320 }
309 } {} 321 } {}
310 322
311 # There are two versions of trigger-3.8 and trigger-3.9. One that uses 323 # There are two versions of trigger1-3.8 and trigger1-3.9. One that uses
312 # compound SELECT statements, and another that does not. 324 # compound SELECT statements, and another that does not.
313 ifcapable compound { 325 ifcapable compound {
314 do_test trigger1-3.8 { 326 do_test trigger1-3.8 {
315 execsql { 327 execsql {
316 INSERT INTO t1 VALUES(3,4); 328 INSERT INTO t1 VALUES(3,4);
317 SELECT * FROM t1 UNION ALL SELECT * FROM t2; 329 SELECT * FROM t1 UNION ALL SELECT * FROM t2;
318 } 330 }
319 } {1 2 3 4 3 4} 331 } {1 2 3 4 3 4}
320 do_test trigger1-3.9 { 332 do_test trigger1-3.9 {
321 db close 333 db close
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
404 execsql { 416 execsql {
405 CREATE TRIGGER t2 BEFORE DELETE ON t2 BEGIN 417 CREATE TRIGGER t2 BEFORE DELETE ON t2 BEGIN
406 SELECT RAISE(ABORT,'deletes are not permitted'); 418 SELECT RAISE(ABORT,'deletes are not permitted');
407 END; 419 END;
408 SELECT type, name FROM sqlite_master; 420 SELECT type, name FROM sqlite_master;
409 } 421 }
410 } [concat $view_v1 {table t2 trigger t2}] 422 } [concat $view_v1 {table t2 trigger t2}]
411 do_test trigger1-6.3 { 423 do_test trigger1-6.3 {
412 catchsql {DELETE FROM t2} 424 catchsql {DELETE FROM t2}
413 } {1 {deletes are not permitted}} 425 } {1 {deletes are not permitted}}
426 verify_ex_errcode trigger1-6.3b SQLITE_CONSTRAINT_TRIGGER
414 do_test trigger1-6.4 { 427 do_test trigger1-6.4 {
415 execsql {SELECT * FROM t2} 428 execsql {SELECT * FROM t2}
416 } {3 4 7 8} 429 } {3 4 7 8}
417 do_test trigger1-6.5 { 430 do_test trigger1-6.5 {
418 db close 431 db close
419 sqlite3 db test.db 432 sqlite3 db test.db
420 execsql {SELECT type, name FROM sqlite_master} 433 execsql {SELECT type, name FROM sqlite_master}
421 } [concat $view_v1 {table t2 trigger t2}] 434 } [concat $view_v1 {table t2 trigger t2}]
422 do_test trigger1-6.6 { 435 do_test trigger1-6.6 {
423 execsql { 436 execsql {
424 DROP TRIGGER t2; 437 DROP TRIGGER t2;
425 SELECT type, name FROM sqlite_master; 438 SELECT type, name FROM sqlite_master;
426 } 439 }
427 } [concat $view_v1 {table t2}] 440 } [concat $view_v1 {table t2}]
428 do_test trigger1-6.7 { 441 do_test trigger1-6.7 {
429 execsql {SELECT * FROM t2} 442 execsql {SELECT * FROM t2}
430 } {3 4 7 8} 443 } {3 4 7 8}
431 do_test trigger1-6.8 { 444 do_test trigger1-6.8 {
432 db close 445 db close
433 sqlite3 db test.db 446 sqlite3 db test.db
434 execsql {SELECT * FROM t2} 447 execsql {SELECT * FROM t2}
435 } {3 4 7 8} 448 } {3 4 7 8}
436 449
437 integrity_check trigger-7.1 450 integrity_check trigger1-7.1
438 451
439 # Check to make sure the name of a trigger can be quoted so that keywords 452 # Check to make sure the name of a trigger can be quoted so that keywords
440 # can be used as trigger names. Ticket #468 453 # can be used as trigger names. Ticket #468
441 # 454 #
442 do_test trigger1-8.1 { 455 do_test trigger1-8.1 {
443 execsql { 456 execsql {
444 CREATE TRIGGER 'trigger' AFTER INSERT ON t2 BEGIN SELECT 1; END; 457 CREATE TRIGGER 'trigger' AFTER INSERT ON t2 BEGIN SELECT 1; END;
445 SELECT name FROM sqlite_master WHERE type='trigger'; 458 SELECT name FROM sqlite_master WHERE type='trigger';
446 } 459 }
447 } {trigger} 460 } {trigger}
(...skipping 24 matching lines...) Expand all
472 do_test trigger1-8.6 { 485 do_test trigger1-8.6 {
473 execsql { 486 execsql {
474 DROP TRIGGER [trigger]; 487 DROP TRIGGER [trigger];
475 SELECT name FROM sqlite_master WHERE type='trigger'; 488 SELECT name FROM sqlite_master WHERE type='trigger';
476 } 489 }
477 } {} 490 } {}
478 491
479 ifcapable conflict { 492 ifcapable conflict {
480 # Make sure REPLACE works inside of triggers. 493 # Make sure REPLACE works inside of triggers.
481 # 494 #
482 # There are two versions of trigger-9.1 and trigger-9.2. One that uses 495 # There are two versions of trigger1-9.1 and trigger1-9.2. One that uses
483 # compound SELECT statements, and another that does not. 496 # compound SELECT statements, and another that does not.
484 ifcapable compound { 497 ifcapable compound {
485 do_test trigger1-9.1 { 498 do_test trigger1-9.1 {
486 execsql { 499 execsql {
487 CREATE TABLE t3(a,b); 500 CREATE TABLE t3(a,b);
488 CREATE TABLE t4(x UNIQUE, b); 501 CREATE TABLE t4(x UNIQUE, b);
489 CREATE TRIGGER r34 AFTER INSERT ON t3 BEGIN 502 CREATE TRIGGER r34 AFTER INSERT ON t3 BEGIN
490 REPLACE INTO t4 VALUES(new.a,new.b); 503 REPLACE INTO t4 VALUES(new.a,new.b);
491 END; 504 END;
492 INSERT INTO t3 VALUES(1,2); 505 INSERT INTO t3 VALUES(1,2);
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
527 540
528 # Ticket #764. At one stage TEMP triggers would fail to re-install when the 541 # Ticket #764. At one stage TEMP triggers would fail to re-install when the
529 # schema was reloaded. The following tests ensure that TEMP triggers are 542 # schema was reloaded. The following tests ensure that TEMP triggers are
530 # correctly re-installed. 543 # correctly re-installed.
531 # 544 #
532 # Also verify that references within trigger programs are resolved at 545 # Also verify that references within trigger programs are resolved at
533 # statement compile time, not trigger installation time. This means, for 546 # statement compile time, not trigger installation time. This means, for
534 # example, that you can drop and re-create tables referenced by triggers. 547 # example, that you can drop and re-create tables referenced by triggers.
535 ifcapable tempdb&&attach { 548 ifcapable tempdb&&attach {
536 do_test trigger1-10.0 { 549 do_test trigger1-10.0 {
537 file delete -force test2.db 550 forcedelete test2.db
538 file delete -force test2.db-journal 551 forcedelete test2.db-journal
539 execsql { 552 execsql {
540 ATTACH 'test2.db' AS aux; 553 ATTACH 'test2.db' AS aux;
541 } 554 }
542 } {} 555 } {}
543 do_test trigger1-10.1 { 556 do_test trigger1-10.1 {
544 execsql { 557 execsql {
545 CREATE TABLE main.t4(a, b, c); 558 CREATE TABLE main.t4(a, b, c);
546 CREATE TABLE temp.t4(a, b, c); 559 CREATE TABLE temp.t4(a, b, c);
547 CREATE TABLE aux.t4(a, b, c); 560 CREATE TABLE aux.t4(a, b, c);
548 CREATE TABLE insert_log(db, a, b, c); 561 CREATE TABLE insert_log(db, a, b, c);
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
593 INSERT INTO main.t4 VALUES(11, 12, 13); 606 INSERT INTO main.t4 VALUES(11, 12, 13);
594 INSERT INTO temp.t4 VALUES(14, 15, 16); 607 INSERT INTO temp.t4 VALUES(14, 15, 16);
595 INSERT INTO aux.t4 VALUES(17, 18, 19); 608 INSERT INTO aux.t4 VALUES(17, 18, 19);
596 } 609 }
597 } {} 610 } {}
598 do_test trigger1-10.8 { 611 do_test trigger1-10.8 {
599 execsql { 612 execsql {
600 SELECT * FROM insert_log; 613 SELECT * FROM insert_log;
601 } 614 }
602 } {main 11 12 13 temp 14 15 16 aux 17 18 19} 615 } {main 11 12 13 temp 14 15 16 aux 17 18 19}
603 do_test trigger1-10.8 { 616 do_test trigger1-10.9 {
604 # Drop and re-create the insert_log table in a different database. Note 617 # Drop and re-create the insert_log table in a different database. Note
605 # that we can change the column names because the trigger programs don't 618 # that we can change the column names because the trigger programs don't
606 # use them explicitly. 619 # use them explicitly.
607 execsql { 620 execsql {
608 DROP TABLE insert_log; 621 DROP TABLE insert_log;
609 CREATE TABLE aux.insert_log(db, d, e, f); 622 CREATE TABLE aux.insert_log(db, d, e, f);
610 } 623 }
611 } {} 624 } {}
612 do_test trigger1-10.10 { 625 do_test trigger1-10.10 {
613 execsql { 626 execsql {
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
693 } {1 {the NOT INDEXED clause is not allowed on UPDATE or DELETE statements withi n triggers}} 706 } {1 {the NOT INDEXED clause is not allowed on UPDATE or DELETE statements withi n triggers}}
694 do_test trigger1-16.7 { 707 do_test trigger1-16.7 {
695 catchsql { 708 catchsql {
696 CREATE TRIGGER main.t16err7 AFTER INSERT ON tA BEGIN 709 CREATE TRIGGER main.t16err7 AFTER INSERT ON tA BEGIN
697 DELETE FROM t16 INDEXED BY t16a WHERE a=123; 710 DELETE FROM t16 INDEXED BY t16a WHERE a=123;
698 END; 711 END;
699 } 712 }
700 } {1 {the INDEXED BY clause is not allowed on UPDATE or DELETE statements within triggers}} 713 } {1 {the INDEXED BY clause is not allowed on UPDATE or DELETE statements within triggers}}
701 714
702 finish_test 715 finish_test
OLDNEW
« no previous file with comments | « third_party/sqlite/src/test/transitive1.test ('k') | third_party/sqlite/src/test/trigger2.test » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698