OLD | NEW |
1 # 2009 September 15 | 1 # 2009 September 15 |
2 # | 2 # |
3 # The author disclaims copyright to this source code. In place of | 3 # The author disclaims copyright to this source code. In place of |
4 # a legal notice, here is a blessing: | 4 # a legal notice, here is a blessing: |
5 # | 5 # |
6 # May you do good and not evil. | 6 # May you do good and not evil. |
7 # May you find forgiveness for yourself and forgive others. | 7 # May you find forgiveness for yourself and forgive others. |
8 # May you share freely, never taking more than you give. | 8 # May you share freely, never taking more than you give. |
9 # | 9 # |
10 #*********************************************************************** | 10 #*********************************************************************** |
(...skipping 658 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
669 UPDATE pp SET b = 1 WHERE a = 7; | 669 UPDATE pp SET b = 1 WHERE a = 7; |
670 SELECT * FROM cc; | 670 SELECT * FROM cc; |
671 } | 671 } |
672 } {6 A 5 6 B 5 3 A 2 3 B 2} | 672 } {6 A 5 6 B 5 3 A 2 3 B 2} |
673 do_test fkey2-9.2.3 { | 673 do_test fkey2-9.2.3 { |
674 execsql { | 674 execsql { |
675 DELETE FROM pp WHERE a = 4; | 675 DELETE FROM pp WHERE a = 4; |
676 SELECT * FROM cc; | 676 SELECT * FROM cc; |
677 } | 677 } |
678 } {{} A {} {} B {} 3 A 2 3 B 2} | 678 } {{} A {} {} B {} 3 A 2 3 B 2} |
| 679 do_execsql_test fkey2-9.3.0 { |
| 680 CREATE TABLE t3(x PRIMARY KEY REFERENCES t3 ON DELETE SET NULL); |
| 681 INSERT INTO t3(x) VALUES(12345); |
| 682 DROP TABLE t3; |
| 683 } {} |
679 | 684 |
680 #------------------------------------------------------------------------- | 685 #------------------------------------------------------------------------- |
681 # The following tests, fkey2-10.*, test "foreign key mismatch" and | 686 # The following tests, fkey2-10.*, test "foreign key mismatch" and |
682 # other errors. | 687 # other errors. |
683 # | 688 # |
684 set tn 0 | 689 set tn 0 |
685 foreach zSql [list { | 690 foreach zSql [list { |
686 CREATE TABLE p(a PRIMARY KEY, b); | 691 CREATE TABLE p(a PRIMARY KEY, b); |
687 CREATE TABLE c(x REFERENCES p(c)); | 692 CREATE TABLE c(x REFERENCES p(c)); |
688 } { | 693 } { |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
739 } | 744 } |
740 } {0 {}} | 745 } {0 {}} |
741 | 746 |
742 | 747 |
743 #------------------------------------------------------------------------- | 748 #------------------------------------------------------------------------- |
744 # The following tests, fkey2-11.*, test CASCADE actions. | 749 # The following tests, fkey2-11.*, test CASCADE actions. |
745 # | 750 # |
746 drop_all_tables | 751 drop_all_tables |
747 do_test fkey2-11.1.1 { | 752 do_test fkey2-11.1.1 { |
748 execsql { | 753 execsql { |
749 CREATE TABLE t1(a INTEGER PRIMARY KEY, b); | 754 CREATE TABLE t1(a INTEGER PRIMARY KEY, b, rowid, _rowid_, oid); |
750 CREATE TABLE t2(c, d, FOREIGN KEY(c) REFERENCES t1(a) ON UPDATE CASCADE); | 755 CREATE TABLE t2(c, d, FOREIGN KEY(c) REFERENCES t1(a) ON UPDATE CASCADE); |
751 | 756 |
752 INSERT INTO t1 VALUES(10, 100); | 757 INSERT INTO t1 VALUES(10, 100, 'abc', 'def', 'ghi'); |
753 INSERT INTO t2 VALUES(10, 100); | 758 INSERT INTO t2 VALUES(10, 100); |
754 UPDATE t1 SET a = 15; | 759 UPDATE t1 SET a = 15; |
755 SELECT * FROM t2; | 760 SELECT * FROM t2; |
756 } | 761 } |
757 } {15 100} | 762 } {15 100} |
758 | 763 |
759 #------------------------------------------------------------------------- | 764 #------------------------------------------------------------------------- |
760 # The following tests, fkey2-12.*, test RESTRICT actions. | 765 # The following tests, fkey2-12.*, test RESTRICT actions. |
761 # | 766 # |
762 drop_all_tables | 767 drop_all_tables |
(...skipping 1244 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2007 catchsql { | 2012 catchsql { |
2008 UPDATE tce73 set b = 201 where a = 100; | 2013 UPDATE tce73 set b = 201 where a = 100; |
2009 } | 2014 } |
2010 } {1 {FOREIGN KEY constraint failed}} | 2015 } {1 {FOREIGN KEY constraint failed}} |
2011 do_test fkey2-ce7c13.1.6 { | 2016 do_test fkey2-ce7c13.1.6 { |
2012 catchsql { | 2017 catchsql { |
2013 UPDATE tce73 set a = 101 where a = 100; | 2018 UPDATE tce73 set a = 101 where a = 100; |
2014 } | 2019 } |
2015 } {1 {FOREIGN KEY constraint failed}} | 2020 } {1 {FOREIGN KEY constraint failed}} |
2016 | 2021 |
| 2022 # 2015-04-16: Foreign key errors propagate back up to the parser. |
| 2023 # |
| 2024 do_test fkey2-20150416-100 { |
| 2025 db close |
| 2026 sqlite3 db :memory: |
| 2027 catchsql { |
| 2028 PRAGMA foreign_keys=1; |
| 2029 CREATE TABLE t1(x PRIMARY KEY); |
| 2030 CREATE TABLE t(y REFERENCES t0(x)ON DELETE SET DEFAULT); |
| 2031 CREATE TABLE t0(y REFERENCES t1 ON DELETE SET NULL); |
| 2032 REPLACE INTO t1 SELECT(0);CREATE TABLE t2(x);CREATE TABLE t3; |
| 2033 } |
| 2034 } {1 {foreign key mismatch - "t" referencing "t0"}} |
| 2035 |
2017 finish_test | 2036 finish_test |
OLD | NEW |