CoolFace
Modelpublic

AryaWu/sqlite

sourceHugging Faceupdated 9mo agoView on Hugging Face
0likes
tkt2820.test95 linesDownload Raw Back to test
1# 2007 Dec 42#3# The author disclaims copyright to this source code. In place of4# 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# This file is to test that ticket #2820 has been fixed.13# Ticket #2820 observes that a DROP TABLE statement that14# occurs while a query is in process will fail with a15# "database is locked" error, but the entry in the sqlite_master16# table will still be removed.  This is incorrect.  The17# entry in the sqlite_master table should persist when 18# the DROP fails due to an error.19#20# $Id: tkt2820.test,v 1.1 2007/12/04 16:54:53 drh Exp $21#22 23set testdir [file dirname $argv0]24source $testdir/tester.tcl25 26proc test_schema_change {testid init ddl res} {27  db close28  forcedelete test.db test.db-journal29  sqlite3 db test.db30  execsql $init31  do_test tkt2820-$testid.1 {32    set STMT [sqlite3_prepare db {SELECT * FROM sqlite_master} -1 DUMMY]33    sqlite3_step $STMT34  } {SQLITE_ROW}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 $STMT40    execsql {SELECT name FROM sqlite_master ORDER BY 1}41  } $res42  integrity_check tkt2820-$testid.443  db close44  sqlite3 db test.db45  integrity_check tkt2820-$testid.546}47 48test_schema_change 1 {49  CREATE TABLE t1(a);50} {51  DROP TABLE t152} {t1}53test_schema_change 2 {54  CREATE TABLE t1(a);55  CREATE TABLE t2(b);56} {57  DROP TABLE t258} {t1 t2}59test_schema_change 3 {60  CREATE TABLE t1(a);61  CREATE INDEX i1 ON t1(a);62} {63  DROP INDEX i164} {i1 t1}65 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 run68# while a second statement was active, as long as we are in autocommit69# mode.  This is incorrect.70#71do_test tkt2820-4.1 {72  db close73  forcedelete test.db test.db-journal74  sqlite3 db test.db75  db eval {76    CREATE TABLE t1(a INTEGER PRIMARY KEY);77    INSERT INTO t1 VALUES(1);78    INSERT INTO t1 VALUES(2);79  }80 81  # The INSERT statement within the loop should fail on a82  # constraint violation on the second inserted row.  This83  # should cause the entire INSERT to rollback using a statement84  # journal.85  #86  db eval {SELECT name FROM sqlite_master} {87    catch {db eval {88      INSERT INTO t1 SELECT a+1 FROM t1 ORDER BY a DESC89    }}90  }91  db eval {SELECT a FROM t1 ORDER BY a}92} {1 2}93 94finish_test95