2009-08-01 19:54:25 +04:00
|
|
|
# 2009 August 1
|
|
|
|
#
|
|
|
|
# The author disclaims copyright to this source code. In place of
|
|
|
|
# a legal notice, here is a blessing:
|
|
|
|
#
|
|
|
|
# May you do good and not evil.
|
|
|
|
# May you find forgiveness for yourself and forgive others.
|
|
|
|
# May you share freely, never taking more than you give.
|
|
|
|
#
|
|
|
|
#***********************************************************************
|
|
|
|
#
|
|
|
|
# Tests to make sure #3810 is fixed.
|
|
|
|
#
|
2009-08-06 21:43:31 +04:00
|
|
|
# $Id: tkt3810.test,v 1.4 2009/08/06 17:43:31 drh Exp $
|
2009-08-01 19:54:25 +04:00
|
|
|
|
|
|
|
set testdir [file dirname $argv0]
|
|
|
|
source $testdir/tester.tcl
|
2009-09-21 20:06:03 +04:00
|
|
|
ifcapable {!trigger} {
|
|
|
|
finish_test
|
|
|
|
return
|
|
|
|
}
|
2009-08-01 19:54:25 +04:00
|
|
|
|
|
|
|
# Create a table using the first database connection.
|
|
|
|
#
|
2009-08-01 20:27:00 +04:00
|
|
|
do_test tkt3810-1.1 {
|
2009-08-01 19:54:25 +04:00
|
|
|
execsql {
|
|
|
|
CREATE TABLE t1(x);
|
|
|
|
INSERT INTO t1 VALUES(123);
|
|
|
|
SELECT * FROM t1;
|
2009-08-06 21:43:31 +04:00
|
|
|
CREATE TABLE t2(y);
|
|
|
|
CREATE TABLE t3(z);
|
2009-08-01 19:54:25 +04:00
|
|
|
}
|
|
|
|
} 123
|
|
|
|
|
|
|
|
# Create a second connection to the same database. Make sure the
|
|
|
|
# schema of the database has been parsed by the second connection.
|
|
|
|
#
|
|
|
|
do_test tkt3810-2 {
|
|
|
|
sqlite3 db2 test.db
|
|
|
|
execsql {
|
|
|
|
SELECT * FROM t1;
|
|
|
|
} db2
|
|
|
|
} 123
|
|
|
|
|
|
|
|
# DROP the table using the second connection. The table no longer exists
|
|
|
|
# but the first connection does not yet know this. Then try to create a TEMP
|
|
|
|
# trigger in the first connection that references the table that was dropped.
|
|
|
|
#
|
|
|
|
do_test tkt3810-3 {
|
|
|
|
execsql {DROP TABLE t1} db2
|
|
|
|
execsql {
|
|
|
|
CREATE TEMP TRIGGER r1 AFTER INSERT ON t1 BEGIN
|
2009-08-06 21:43:31 +04:00
|
|
|
INSERT INTO t2 VALUES(new.rowid);
|
2009-08-01 19:54:25 +04:00
|
|
|
END;
|
|
|
|
}
|
2009-08-01 20:27:00 +04:00
|
|
|
catchsql {
|
2009-08-06 21:43:31 +04:00
|
|
|
SELECT * FROM t3;
|
|
|
|
}
|
|
|
|
} {0 {}}
|
|
|
|
|
|
|
|
# Trigger still exists in the sqlite_temp_master table, but now it is
|
|
|
|
# an orphan.
|
|
|
|
#
|
|
|
|
do_test tkt3810-4 {
|
|
|
|
execsql {SELECT name FROM sqlite_temp_master ORDER BY name}
|
|
|
|
} {r1}
|
|
|
|
|
|
|
|
# Because it is an orphan, it cannot be dropped.
|
|
|
|
#
|
|
|
|
do_test tkt3810-5 {
|
|
|
|
catchsql {DROP TRIGGER r1}
|
|
|
|
} {1 {no such trigger: r1}}
|
|
|
|
|
|
|
|
# Create a table t1 then drop the table in order to drop the orphaned
|
|
|
|
# trigger.
|
|
|
|
#
|
|
|
|
do_test tkt3810-6 {
|
|
|
|
execsql {CREATE TABLE t1(x)} db2
|
|
|
|
execsql {DROP TABLE t1}
|
|
|
|
execsql {
|
|
|
|
SELECT name FROM sqlite_temp_master;
|
2009-08-01 20:27:00 +04:00
|
|
|
}
|
2009-08-06 21:43:31 +04:00
|
|
|
} {}
|
2009-08-01 19:54:25 +04:00
|
|
|
|
2009-08-01 22:22:30 +04:00
|
|
|
db2 close
|
|
|
|
|
2009-08-01 19:54:25 +04:00
|
|
|
finish_test
|