sl@0: # 2007 Dec 4 sl@0: # sl@0: # The author disclaims copyright to this source code. In place of sl@0: # a legal notice, here is a blessing: sl@0: # sl@0: # May you do good and not evil. sl@0: # May you find forgiveness for yourself and forgive others. sl@0: # May you share freely, never taking more than you give. sl@0: # sl@0: #*********************************************************************** sl@0: # sl@0: # This file is to test that ticket #2820 has been fixed. sl@0: # Ticket #2820 observes that a DROP TABLE statement that sl@0: # occurs while a query is in process will fail with a sl@0: # "database is locked" error, but the entry in the sqlite_master sl@0: # table will still be removed. This is incorrect. The sl@0: # entry in the sqlite_master table should persist when sl@0: # the DROP fails due to an error. sl@0: # sl@0: # $Id: tkt2820.test,v 1.1 2007/12/04 16:54:53 drh Exp $ sl@0: # sl@0: sl@0: set testdir [file dirname $argv0] sl@0: source $testdir/tester.tcl sl@0: sl@0: proc test_schema_change {testid init ddl res} { sl@0: db close sl@0: file delete -force test.db test.db-journal sl@0: sqlite3 db test.db sl@0: execsql $init sl@0: do_test tkt2820-$testid.1 { sl@0: set STMT [sqlite3_prepare db {SELECT * FROM sqlite_master} -1 DUMMY] sl@0: sqlite3_step $STMT sl@0: } {SQLITE_ROW} sl@0: #if {$testid==3} {execsql {PRAGMA vdbe_trace=ON}} sl@0: do_test tkt2820-$testid.2 "catchsql [list $ddl]" \ sl@0: {1 {database table is locked}} sl@0: do_test tkt2820-$testid.3 { sl@0: sqlite3_finalize $STMT sl@0: execsql {SELECT name FROM sqlite_master ORDER BY 1} sl@0: } $res sl@0: integrity_check tkt2820-$testid.4 sl@0: db close sl@0: sqlite3 db test.db sl@0: integrity_check tkt2820-$testid.5 sl@0: } sl@0: sl@0: test_schema_change 1 { sl@0: CREATE TABLE t1(a); sl@0: } { sl@0: DROP TABLE t1 sl@0: } {t1} sl@0: test_schema_change 2 { sl@0: CREATE TABLE t1(a); sl@0: CREATE TABLE t2(b); sl@0: } { sl@0: DROP TABLE t2 sl@0: } {t1 t2} sl@0: test_schema_change 3 { sl@0: CREATE TABLE t1(a); sl@0: CREATE INDEX i1 ON t1(a); sl@0: } { sl@0: DROP INDEX i1 sl@0: } {i1 t1} sl@0: sl@0: # We further observe that prior to the fix associated with ticket #2820, sl@0: # no statement journal would be created on an SQL statement that was run sl@0: # while a second statement was active, as long as we are in autocommit sl@0: # mode. This is incorrect. sl@0: # sl@0: do_test tkt2820-4.1 { sl@0: db close sl@0: file delete -force test.db test.db-journal sl@0: sqlite3 db test.db sl@0: db eval { sl@0: CREATE TABLE t1(a INTEGER PRIMARY KEY); sl@0: INSERT INTO t1 VALUES(1); sl@0: INSERT INTO t1 VALUES(2); sl@0: } sl@0: sl@0: # The INSERT statement within the loop should fail on a sl@0: # constraint violation on the second inserted row. This sl@0: # should cause the entire INSERT to rollback using a statement sl@0: # journal. sl@0: # sl@0: db eval {SELECT name FROM sqlite_master} { sl@0: catch {db eval { sl@0: INSERT INTO t1 SELECT a+1 FROM t1 ORDER BY a DESC sl@0: }} sl@0: } sl@0: db eval {SELECT a FROM t1 ORDER BY a} sl@0: } {1 2} sl@0: sl@0: finish_test