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