mirror of
https://github.com/sqlite/sqlite.git
synced 2025-07-29 08:01:23 +03:00
Add tests to insure VACUUM works in the presence of I/O errors. Fix some
problems that came to light by these tests. (CVS 935) FossilOrigin-Name: 8d3e879349fc9523c72cb46111e0058b57ce9341
This commit is contained in:
@ -15,7 +15,7 @@
|
||||
# The tests in this file use special facilities that are only
|
||||
# available in the SQLite test fixture.
|
||||
#
|
||||
# $Id: ioerr.test,v 1.2 2003/02/16 22:21:33 drh Exp $
|
||||
# $Id: ioerr.test,v 1.3 2003/04/25 15:37:59 drh Exp $
|
||||
|
||||
set testdir [file dirname $argv0]
|
||||
source $testdir/tester.tcl
|
||||
@ -56,5 +56,65 @@ for {set n 1} {$go} {incr n} {
|
||||
}
|
||||
set ::sqlite_io_error_pending 0
|
||||
|
||||
proc cksum {{db db}} {
|
||||
set txt [$db eval {SELECT name, type, sql FROM sqlite_master}]\n
|
||||
foreach tbl [$db eval {SELECT name FROM sqlite_master WHERE type='table'}] {
|
||||
append txt [$db eval "SELECT * FROM $tbl"]\n
|
||||
}
|
||||
foreach prag {default_synchronous default_cache_size} {
|
||||
append txt $prag-[$db eval "PRAGMA $prag"]\n
|
||||
}
|
||||
set cksum [string length $txt]-[md5 $txt]
|
||||
# puts $cksum-[file size test.db]
|
||||
return $cksum
|
||||
}
|
||||
|
||||
set ::go 1
|
||||
for {set n 1} {$go} {incr n} {
|
||||
do_test ioerr-2.$n.1 {
|
||||
set ::sqlite_io_error_pending 0
|
||||
db close
|
||||
catch {file delete -force test.db}
|
||||
catch {file delete -force test.db-journal}
|
||||
sqlite db test.db
|
||||
execsql {
|
||||
BEGIN;
|
||||
CREATE TABLE t1(a, b, c);
|
||||
INSERT INTO t1 VALUES(1, randstr(5,50), randstr(5,50));
|
||||
INSERT INTO t1 SELECT a+2, b||'-'||rowid, c||'-'||rowid FROM t1;
|
||||
INSERT INTO t1 SELECT a+4, b||'-'||rowid, c||'-'||rowid FROM t1;
|
||||
INSERT INTO t1 SELECT a+8, b||'-'||rowid, c||'-'||rowid FROM t1;
|
||||
INSERT INTO t1 SELECT a+16, b||'-'||rowid, c||'-'||rowid FROM t1;
|
||||
INSERT INTO t1 SELECT a+32, b||'-'||rowid, c||'-'||rowid FROM t1;
|
||||
INSERT INTO t1 SELECT a+64, b||'-'||rowid, c||'-'||rowid FROM t1;
|
||||
INSERT INTO t1 SELECT a+128, b||'-'||rowid, c||'-'||rowid FROM t1;
|
||||
CREATE TABLE t2 AS SELECT * FROM t1;
|
||||
CREATE TABLE t3 AS SELECT * FROM t1;
|
||||
COMMIT;
|
||||
DROP TABLE t2;
|
||||
}
|
||||
set ::cksum [cksum]
|
||||
execsql {
|
||||
SELECT name FROM sqlite_master WHERE type='table'
|
||||
}
|
||||
} {t1 t3}
|
||||
do_test ioerr-2.$n.2 [subst {
|
||||
set ::sqlite_io_error_pending $n
|
||||
}] $n
|
||||
do_test ioerr-2.$n.3 {
|
||||
set r [catch {db eval {
|
||||
VACUUM;
|
||||
}} msg]
|
||||
# puts "error_pending=$::sqlite_io_error_pending"
|
||||
# if {$r} {puts $msg}
|
||||
set ::go [expr {$::sqlite_io_error_pending<=0}]
|
||||
expr {$::sqlite_io_error_pending>0 || $r!=0}
|
||||
set ::sqlite_io_error_pending 0
|
||||
db close
|
||||
sqlite db test.db
|
||||
cksum
|
||||
} $cksum
|
||||
}
|
||||
set ::sqlite_io_error_pending 0
|
||||
|
||||
finish_test
|
||||
|
Reference in New Issue
Block a user