drh | a0e0d8e | 2009-08-01 15:54:25 +0000 | [diff] [blame] | 1 | # 2009 August 1 |
| 2 | # |
| 3 | # The author disclaims copyright to this source code. In place of |
| 4 | # a legal notice, here is a blessing: |
| 5 | # |
| 6 | # May you do good and not evil. |
| 7 | # May you find forgiveness for yourself and forgive others. |
| 8 | # May you share freely, never taking more than you give. |
| 9 | # |
| 10 | #*********************************************************************** |
| 11 | # |
| 12 | # Tests to make sure #3810 is fixed. |
| 13 | # |
drh | 3d5f74b | 2009-08-06 17:43:31 +0000 | [diff] [blame] | 14 | # $Id: tkt3810.test,v 1.4 2009/08/06 17:43:31 drh Exp $ |
drh | a0e0d8e | 2009-08-01 15:54:25 +0000 | [diff] [blame] | 15 | |
| 16 | set testdir [file dirname $argv0] |
| 17 | source $testdir/tester.tcl |
dan | 75cbd98 | 2009-09-21 16:06:03 +0000 | [diff] [blame] | 18 | ifcapable {!trigger} { |
| 19 | finish_test |
| 20 | return |
| 21 | } |
drh | a0e0d8e | 2009-08-01 15:54:25 +0000 | [diff] [blame] | 22 | |
| 23 | # Create a table using the first database connection. |
| 24 | # |
drh | 35ccb3d | 2009-08-01 16:27:00 +0000 | [diff] [blame] | 25 | do_test tkt3810-1.1 { |
drh | a0e0d8e | 2009-08-01 15:54:25 +0000 | [diff] [blame] | 26 | execsql { |
| 27 | CREATE TABLE t1(x); |
| 28 | INSERT INTO t1 VALUES(123); |
| 29 | SELECT * FROM t1; |
drh | 3d5f74b | 2009-08-06 17:43:31 +0000 | [diff] [blame] | 30 | CREATE TABLE t2(y); |
| 31 | CREATE TABLE t3(z); |
drh | a0e0d8e | 2009-08-01 15:54:25 +0000 | [diff] [blame] | 32 | } |
| 33 | } 123 |
| 34 | |
| 35 | # Create a second connection to the same database. Make sure the |
| 36 | # schema of the database has been parsed by the second connection. |
| 37 | # |
| 38 | do_test tkt3810-2 { |
| 39 | sqlite3 db2 test.db |
| 40 | execsql { |
| 41 | SELECT * FROM t1; |
| 42 | } db2 |
| 43 | } 123 |
| 44 | |
| 45 | # DROP the table using the second connection. The table no longer exists |
| 46 | # but the first connection does not yet know this. Then try to create a TEMP |
| 47 | # trigger in the first connection that references the table that was dropped. |
| 48 | # |
| 49 | do_test tkt3810-3 { |
| 50 | execsql {DROP TABLE t1} db2 |
| 51 | execsql { |
| 52 | CREATE TEMP TRIGGER r1 AFTER INSERT ON t1 BEGIN |
drh | 3d5f74b | 2009-08-06 17:43:31 +0000 | [diff] [blame] | 53 | INSERT INTO t2 VALUES(new.rowid); |
drh | a0e0d8e | 2009-08-01 15:54:25 +0000 | [diff] [blame] | 54 | END; |
drh | a0e0d8e | 2009-08-01 15:54:25 +0000 | [diff] [blame] | 55 | } |
drh | 35ccb3d | 2009-08-01 16:27:00 +0000 | [diff] [blame] | 56 | catchsql { |
drh | 3d5f74b | 2009-08-06 17:43:31 +0000 | [diff] [blame] | 57 | SELECT * FROM t3; |
drh | 35ccb3d | 2009-08-01 16:27:00 +0000 | [diff] [blame] | 58 | } |
drh | 3d5f74b | 2009-08-06 17:43:31 +0000 | [diff] [blame] | 59 | } {0 {}} |
| 60 | |
| 61 | # Trigger still exists in the sqlite_temp_master table, but now it is |
| 62 | # an orphan. |
| 63 | # |
| 64 | do_test tkt3810-4 { |
drh | e0a04a3 | 2016-12-16 01:00:21 +0000 | [diff] [blame] | 65 | execsql {SELECT name FROM temp.sqlite_master ORDER BY name} |
drh | 3d5f74b | 2009-08-06 17:43:31 +0000 | [diff] [blame] | 66 | } {r1} |
| 67 | |
| 68 | # Because it is an orphan, it cannot be dropped. |
| 69 | # |
| 70 | do_test tkt3810-5 { |
| 71 | catchsql {DROP TRIGGER r1} |
| 72 | } {1 {no such trigger: r1}} |
| 73 | |
| 74 | # Create a table t1 then drop the table in order to drop the orphaned |
| 75 | # trigger. |
| 76 | # |
| 77 | do_test tkt3810-6 { |
| 78 | execsql {CREATE TABLE t1(x)} db2 |
| 79 | execsql {DROP TABLE t1} |
| 80 | execsql { |
| 81 | SELECT name FROM sqlite_temp_master; |
| 82 | } |
| 83 | } {} |
drh | a0e0d8e | 2009-08-01 15:54:25 +0000 | [diff] [blame] | 84 | |
drh | b4bc2b7 | 2009-08-01 18:22:30 +0000 | [diff] [blame] | 85 | db2 close |
| 86 | |
drh | a0e0d8e | 2009-08-01 15:54:25 +0000 | [diff] [blame] | 87 | finish_test |