sl@0: # 2007 December 19 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: # This file implements regression tests for SQLite library. The sl@0: # focus of this file is testing for correct handling of I/O errors sl@0: # during incremental vacuum with a shared cache. sl@0: # sl@0: # $Id: ioerr4.test,v 1.2 2008/05/08 01:11:42 drh Exp $ sl@0: sl@0: set testdir [file dirname $argv0] sl@0: source $testdir/tester.tcl sl@0: sl@0: # This test requires both shared cache and incremental vacuum. sl@0: # sl@0: ifcapable {!shared_cache || !autovacuum} { sl@0: finish_test sl@0: return sl@0: } sl@0: sl@0: # Enable shared cache mode and incremental vacuum. sl@0: # sl@0: do_test ioerr4-1.1 { sl@0: db close sl@0: set ::enable_shared_cache [sqlite3_enable_shared_cache 1] sl@0: } {0} sl@0: do_test ioerr4-1.2 { sl@0: file delete -force test.db test.db-journal sl@0: sqlite3 db test.db sl@0: sqlite3 db2 test.db sl@0: db eval { sl@0: PRAGMA auto_vacuum=INCREMENTAL; sl@0: CREATE TABLE a(i INTEGER, b BLOB); sl@0: } sl@0: db2 eval { sl@0: SELECT name FROM sqlite_master sl@0: } sl@0: } {a} sl@0: do_test ioerr4-1.3 { sl@0: db eval { sl@0: PRAGMA auto_vacuum; sl@0: } sl@0: } {2} sl@0: sl@0: # Insert and delete many records in order to put lots of pages sl@0: # on the freelist. sl@0: # sl@0: do_test ioerr4-1.4 { sl@0: db eval { sl@0: INSERT INTO a VALUES(1, zeroblob(2000)); sl@0: INSERT INTO a VALUES(2, zeroblob(2000)); sl@0: INSERT INTO a SELECT i+2, zeroblob(2000) FROM a; sl@0: INSERT INTO a SELECT i+4, zeroblob(2000) FROM a; sl@0: INSERT INTO a SELECT i+8, zeroblob(2000) FROM a; sl@0: INSERT INTO a SELECT i+16, zeroblob(2000) FROM a; sl@0: SELECT count(*) FROM a; sl@0: } sl@0: } {32} sl@0: do_test ioerr4-1.5 { sl@0: db eval { sl@0: PRAGMA freelist_count sl@0: } sl@0: } {0} sl@0: do_test ioerr4-1.6 { sl@0: db eval { sl@0: DELETE FROM a; sl@0: PRAGMA freelist_count; sl@0: } sl@0: } {64} sl@0: sl@0: # Set up for an I/O error on incremental vacuum sl@0: # with two connections on shared cache. sl@0: # sl@0: db close sl@0: db2 close sl@0: file copy -force test.db test.db-bu sl@0: do_ioerr_test ioerr4-2 -tclprep { sl@0: catch {db2 close} sl@0: db close sl@0: file delete -force test.db test.db-journal sl@0: file copy -force test.db-bu test.db sl@0: sqlite3_enable_shared_cache 1 sl@0: set ::DB [sqlite3 db test.db; sqlite3_connection_pointer db] sl@0: db eval {PRAGMA auto_vacuum=INCREMENTAL} sl@0: sqlite3 db2 test.db sl@0: } -tclbody { sl@0: db eval {PRAGMA incremental_vacuum(5)} sl@0: } sl@0: sl@0: db2 close sl@0: file delete -force test.db-bu sl@0: sqlite3_enable_shared_cache $::enable_shared_cache sl@0: sl@0: finish_test