| OLD | NEW |
| (Empty) |
| 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 # | |
| 14 # $Id: tkt3810.test,v 1.4 2009/08/06 17:43:31 drh Exp $ | |
| 15 | |
| 16 set testdir [file dirname $argv0] | |
| 17 source $testdir/tester.tcl | |
| 18 | |
| 19 # Create a table using the first database connection. | |
| 20 # | |
| 21 do_test tkt3810-1.1 { | |
| 22 execsql { | |
| 23 CREATE TABLE t1(x); | |
| 24 INSERT INTO t1 VALUES(123); | |
| 25 SELECT * FROM t1; | |
| 26 CREATE TABLE t2(y); | |
| 27 CREATE TABLE t3(z); | |
| 28 } | |
| 29 } 123 | |
| 30 | |
| 31 # Create a second connection to the same database. Make sure the | |
| 32 # schema of the database has been parsed by the second connection. | |
| 33 # | |
| 34 do_test tkt3810-2 { | |
| 35 sqlite3 db2 test.db | |
| 36 execsql { | |
| 37 SELECT * FROM t1; | |
| 38 } db2 | |
| 39 } 123 | |
| 40 | |
| 41 # DROP the table using the second connection. The table no longer exists | |
| 42 # but the first connection does not yet know this. Then try to create a TEMP | |
| 43 # trigger in the first connection that references the table that was dropped. | |
| 44 # | |
| 45 do_test tkt3810-3 { | |
| 46 execsql {DROP TABLE t1} db2 | |
| 47 execsql { | |
| 48 CREATE TEMP TRIGGER r1 AFTER INSERT ON t1 BEGIN | |
| 49 INSERT INTO t2 VALUES(new.rowid); | |
| 50 END; | |
| 51 } | |
| 52 catchsql { | |
| 53 SELECT * FROM t3; | |
| 54 } | |
| 55 } {0 {}} | |
| 56 | |
| 57 # Trigger still exists in the sqlite_temp_master table, but now it is | |
| 58 # an orphan. | |
| 59 # | |
| 60 do_test tkt3810-4 { | |
| 61 execsql {SELECT name FROM sqlite_temp_master ORDER BY name} | |
| 62 } {r1} | |
| 63 | |
| 64 # Because it is an orphan, it cannot be dropped. | |
| 65 # | |
| 66 do_test tkt3810-5 { | |
| 67 catchsql {DROP TRIGGER r1} | |
| 68 } {1 {no such trigger: r1}} | |
| 69 | |
| 70 # Create a table t1 then drop the table in order to drop the orphaned | |
| 71 # trigger. | |
| 72 # | |
| 73 do_test tkt3810-6 { | |
| 74 execsql {CREATE TABLE t1(x)} db2 | |
| 75 execsql {DROP TABLE t1} | |
| 76 execsql { | |
| 77 SELECT name FROM sqlite_temp_master; | |
| 78 } | |
| 79 } {} | |
| 80 | |
| 81 db2 close | |
| 82 | |
| 83 finish_test | |
| OLD | NEW |