3 # The author disclaims copyright to this source code. In place of
4 # a legal notice, here is a blessing:
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.
10 #***********************************************************************
12 # This file is to test that ticket #2820 has been fixed.
13 # Ticket #2820 observes that a DROP TABLE statement that
14 # occurs while a query is in process will fail with a
15 # "database is locked" error, but the entry in the sqlite_master
16 # table will still be removed. This is incorrect. The
17 # entry in the sqlite_master table should persist when
18 # the DROP fails due to an error.
20 # $Id: tkt2820.test,v 1.1 2007/12/04 16:54:53 drh Exp $
23 set testdir [file dirname $argv0]
24 source $testdir/tester.tcl
26 proc test_schema_change {testid init ddl res} {
28 forcedelete test.db test.db-journal
31 do_test tkt2820-$testid.1 {
32 set STMT [sqlite3_prepare db {SELECT * FROM sqlite_master} -1 DUMMY]
35 #if {$testid==3} {execsql {PRAGMA vdbe_trace=ON}}
36 do_test tkt2820-$testid.2 "catchsql [list $ddl]" \
37 {1 {database table is locked}}
38 do_test tkt2820-$testid.3 {
39 sqlite3_finalize $STMT
40 execsql {SELECT name FROM sqlite_master ORDER BY 1}
42 integrity_check tkt2820-$testid.4
45 integrity_check tkt2820-$testid.5
48 test_schema_change 1 {
53 test_schema_change 2 {
59 test_schema_change 3 {
61 CREATE INDEX i1 ON t1(a);
66 # We further observe that prior to the fix associated with ticket #2820,
67 # no statement journal would be created on an SQL statement that was run
68 # while a second statement was active, as long as we are in autocommit
69 # mode. This is incorrect.
73 forcedelete test.db test.db-journal
76 CREATE TABLE t1(a INTEGER PRIMARY KEY);
77 INSERT INTO t1 VALUES(1);
78 INSERT INTO t1 VALUES(2);
81 # The INSERT statement within the loop should fail on a
82 # constraint violation on the second inserted row. This
83 # should cause the entire INSERT to rollback using a statement
86 db eval {SELECT name FROM sqlite_master} {
88 INSERT INTO t1 SELECT a+1 FROM t1 ORDER BY a DESC
91 db eval {SELECT a FROM t1 ORDER BY a}