2007-04-02 20:46:23 +04:00
|
|
|
# 2007 April 2
|
|
|
|
#
|
|
|
|
# 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
|
|
|
|
# such as writes failing because the disk is full.
|
|
|
|
#
|
|
|
|
# The tests in this file use special facilities that are only
|
|
|
|
# available in the SQLite test fixture.
|
|
|
|
#
|
2009-06-05 21:09:11 +04:00
|
|
|
# $Id: ioerr2.test,v 1.12 2009/06/05 17:09:12 drh Exp $
|
2007-04-02 20:46:23 +04:00
|
|
|
|
|
|
|
set testdir [file dirname $argv0]
|
|
|
|
source $testdir/tester.tcl
|
|
|
|
|
2007-09-12 21:01:45 +04:00
|
|
|
ifcapable !integrityck {
|
|
|
|
finish_test
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2007-04-02 20:46:23 +04:00
|
|
|
do_test ioerr2-1.1 {
|
|
|
|
execsql {
|
|
|
|
PRAGMA cache_size = 10;
|
|
|
|
PRAGMA default_cache_size = 10;
|
|
|
|
CREATE TABLE t1(a, b, PRIMARY KEY(a, b));
|
|
|
|
INSERT INTO t1 VALUES(randstr(400,400),randstr(400,400));
|
|
|
|
INSERT INTO t1 SELECT randstr(400,400), randstr(400,400) FROM t1; -- 2
|
|
|
|
INSERT INTO t1 SELECT randstr(400,400), randstr(400,400) FROM t1; -- 4
|
|
|
|
INSERT INTO t1 SELECT randstr(400,400), randstr(400,400) FROM t1; -- 8
|
|
|
|
INSERT INTO t1 SELECT randstr(400,400), randstr(400,400) FROM t1; -- 16
|
|
|
|
INSERT INTO t1 SELECT randstr(400,400), randstr(400,400) FROM t1; -- 32
|
|
|
|
}
|
|
|
|
} {}
|
|
|
|
|
|
|
|
set ::cksum [execsql {SELECT md5sum(a, b) FROM t1}]
|
|
|
|
proc check_db {testname} {
|
|
|
|
|
|
|
|
# Make sure no I/O errors are simulated in this proc.
|
|
|
|
set ::sqlite_io_error_hit 0
|
|
|
|
set ::sqlite_io_error_persist 0
|
|
|
|
set ::sqlite_io_error_pending 0
|
|
|
|
|
|
|
|
# Run an integrity-check. If "disk I/O error" is returned, the
|
|
|
|
# pager must be in error state. In this case open a new database
|
|
|
|
# connection. Otherwise, try a ROLLBACK, in case a transaction
|
|
|
|
# is still active.
|
|
|
|
set rc [catch {execsql {PRAGMA integrity_check}} msg]
|
2008-03-07 22:51:14 +03:00
|
|
|
if {$rc && ($msg eq "disk I/O error" || $msg eq "database is locked")} {
|
2007-04-02 20:46:23 +04:00
|
|
|
db close
|
|
|
|
sqlite3 db test.db
|
2007-04-09 16:45:02 +04:00
|
|
|
set refcnt 0
|
2007-04-02 20:46:23 +04:00
|
|
|
} else {
|
2007-04-09 15:20:54 +04:00
|
|
|
if {$rc || $msg ne "ok"} {
|
|
|
|
error $msg
|
|
|
|
}
|
2007-04-02 20:46:23 +04:00
|
|
|
catch {execsql ROLLBACK}
|
|
|
|
}
|
|
|
|
|
|
|
|
# Check that the database checksum is still $::cksum, and that
|
|
|
|
# the integrity-check passes.
|
|
|
|
set ck [execsql {SELECT md5sum(a, b) FROM t1}]
|
|
|
|
do_test ${testname}.cksum [list set ck $ck] $::cksum
|
|
|
|
integrity_check ${testname}.integrity
|
2007-04-09 16:45:02 +04:00
|
|
|
do_test ${testname}.refcnt {
|
|
|
|
lindex [sqlite3_pager_refcounts db] 0
|
|
|
|
} 0
|
2007-04-02 20:46:23 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
check_db ioerr2-2
|
|
|
|
|
|
|
|
set sql {
|
|
|
|
PRAGMA cache_size = 10;
|
|
|
|
PRAGMA default_cache_size = 10;
|
|
|
|
BEGIN;
|
|
|
|
DELETE FROM t1 WHERE (oid%7)==0;
|
|
|
|
INSERT INTO t1 SELECT randstr(400,400), randstr(400,400)
|
|
|
|
WHERE (random()%7)==0;
|
|
|
|
UPDATE t1 SET a = randstr(400,400), b = randstr(400,400)
|
|
|
|
WHERE (random()%7)==0;
|
|
|
|
ROLLBACK;
|
|
|
|
}
|
|
|
|
|
|
|
|
foreach bPersist [list 0 1] {
|
|
|
|
set ::go 1
|
|
|
|
for {set ::N 1} {$::go} {incr ::N} {
|
2007-04-13 06:14:30 +04:00
|
|
|
db close
|
|
|
|
sqlite3 db test.db
|
2007-04-02 20:46:23 +04:00
|
|
|
set ::sqlite_io_error_hit 0
|
|
|
|
set ::sqlite_io_error_persist $bPersist
|
|
|
|
set ::sqlite_io_error_pending $::N
|
|
|
|
|
|
|
|
foreach {::go res} [catchsql $sql] {}
|
|
|
|
check_db ioerr2-3.$bPersist.$::N
|
|
|
|
}
|
|
|
|
}
|
2007-04-13 06:14:30 +04:00
|
|
|
foreach bPersist [list 0 1] {
|
|
|
|
set ::go 1
|
|
|
|
for {set ::N 1} {$::go} {incr ::N} {
|
|
|
|
set ::sqlite_io_error_hit 0
|
|
|
|
set ::sqlite_io_error_persist $bPersist
|
|
|
|
set ::sqlite_io_error_pending $::N
|
|
|
|
|
|
|
|
foreach {::go res} [catchsql $sql] {}
|
2007-05-23 20:23:09 +04:00
|
|
|
check_db ioerr2-4.[expr {$bPersist+2}].$::N
|
2007-04-13 06:14:30 +04:00
|
|
|
}
|
|
|
|
}
|
2007-04-02 20:46:23 +04:00
|
|
|
|
2014-11-18 23:16:27 +03:00
|
|
|
# When this test was written, an IO error within the UPDATE statement caused
|
|
|
|
# a rollback, which tripped all read-cursors, causing the outer SELECT to
|
|
|
|
# fail with "abort due to ROLLBACK". Now, the loop continues until the UPDATE
|
|
|
|
# is run successfully. At this point the next IO error occurs within the
|
|
|
|
# SELECT - throwing the "disk I/O error" that the test case now expects.
|
|
|
|
#
|
2008-07-08 19:59:51 +04:00
|
|
|
do_test ioerr2-5 {
|
|
|
|
execsql {
|
|
|
|
CREATE TABLE t2 AS SELECT * FROM t1;
|
2008-08-20 18:49:23 +04:00
|
|
|
PRAGMA temp_store = memory;
|
2008-07-08 19:59:51 +04:00
|
|
|
}
|
|
|
|
set ::sqlite_io_error_persist 0
|
|
|
|
set ::go 1
|
|
|
|
set rc [catch {
|
2008-08-20 18:49:23 +04:00
|
|
|
for {set ::N 2} {$::N<200} {incr ::N} {
|
2008-07-08 19:59:51 +04:00
|
|
|
db eval {SELECT * FROM t1 WHERE rowid IN (1, 5, 10, 15, 20)} {
|
|
|
|
set ::sqlite_io_error_hit 0
|
|
|
|
set ::sqlite_io_error_pending $::N
|
|
|
|
set sql {UPDATE t2 SET b = randstr(400,400)}
|
|
|
|
foreach {::go res} [catchsql $sql] {}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} msg]
|
|
|
|
list $rc $msg
|
2014-11-18 23:16:27 +03:00
|
|
|
} {1 {disk I/O error}} ;# used to be "{1 {abort due to ROLLBACK}}"
|
2008-07-08 19:59:51 +04:00
|
|
|
|
2008-09-16 18:38:02 +04:00
|
|
|
if {$::tcl_platform(platform) == "unix"} {
|
|
|
|
# Cause the call to xAccess used by [pragma temp_store_directory] to
|
|
|
|
# determine if the specified directory is writable to fail. This causes
|
|
|
|
# SQLite to report "not a writable directory", which is probably the
|
|
|
|
# right answer.
|
|
|
|
#
|
|
|
|
do_test ioerr2-6 {
|
|
|
|
set ::sqlite_io_error_hit 0
|
|
|
|
set ::sqlite_io_error_pending 1
|
|
|
|
catchsql {PRAGMA temp_store_directory = '/tmp/'}
|
|
|
|
} {1 {not a writable directory}}
|
|
|
|
}
|
|
|
|
|
2009-02-12 12:11:56 +03:00
|
|
|
do_ioerr_test ioerr2-7 -persist 0 -sqlprep {
|
|
|
|
PRAGMA cache_size = 10;
|
|
|
|
PRAGMA auto_vacuum = 1;
|
|
|
|
CREATE TABLE ab(a, b);
|
|
|
|
CREATE TABLE de(d, e);
|
|
|
|
INSERT INTO ab VALUES(1, randstr(200,200));
|
|
|
|
INSERT INTO ab SELECT a+1, randstr(200,200) FROM ab;
|
|
|
|
INSERT INTO ab SELECT a+2, randstr(200,200) FROM ab;
|
|
|
|
INSERT INTO ab SELECT a+4, randstr(200,200) FROM ab;
|
|
|
|
INSERT INTO ab SELECT a+8, randstr(200,200) FROM ab;
|
|
|
|
INSERT INTO ab SELECT a+16, randstr(200,200) FROM ab;
|
|
|
|
INSERT INTO ab SELECT a+32, randstr(200,200) FROM ab;
|
|
|
|
INSERT INTO ab SELECT a+64, randstr(200,200) FROM ab;
|
|
|
|
INSERT INTO de SELECT * FROM ab;
|
|
|
|
} -sqlbody {
|
|
|
|
BEGIN;
|
|
|
|
UPDATE ab SET b = randstr(200,200);
|
|
|
|
UPDATE de SET e = randstr(200,200) WHERE d = (SELECT max(d) FROM de);
|
|
|
|
DELETE FROM ab;
|
|
|
|
COMMIT;
|
|
|
|
}
|
|
|
|
|
2007-04-02 20:46:23 +04:00
|
|
|
finish_test
|