2N/A#pragma ident "%Z%%M% %I% %E% SMI"
2N/A# The author disclaims copyright to this source code. In place of
2N/A# a legal notice, here is a blessing:
2N/A# May you do good and not evil.
2N/A# May you find forgiveness for yourself and forgive others.
2N/A# May you share freely, never taking more than you give.
2N/A#***********************************************************************
2N/A# This file implements regression tests for SQLite library. The
2N/A# focus of this file is testing for correct handling of I/O errors
2N/A# such as writes failing because the disk is full.
2N/A# The tests in this file use special facilities that are only
2N/A# available in the SQLite test fixture.
2N/Aset testdir [file dirname $argv0]
2N/Afor {set n 1} {$go} {incr n} {
2N/A do_test ioerr-1.$n.1 {
2N/A set ::sqlite_io_error_pending 0
2N/A execsql {SELECT * FROM sqlite_master}
2N/A do_test ioerr-1.$n.2 [subst {
2N/A set ::sqlite_io_error_pending $n
2N/A do_test ioerr-1.$n.3 {
2N/A set r [catch {db eval {
2N/A CREATE TABLE t1(a,b,c);
2N/A SELECT * FROM sqlite_master;
2N/A INSERT INTO t1 VALUES(1,2,3);
2N/A INSERT INTO t1 VALUES(4,5,6);
2N/A INSERT INTO t1 VALUES(1,2,3);
2N/A INSERT INTO t1 VALUES(4,5,6);
2N/A DELETE FROM t1 WHERE a<100;
2N/A # if {$r} {puts $msg}
2N/A set ::go [expr {$::sqlite_io_error_pending<=0}]
2N/A expr {$::sqlite_io_error_pending>0 || $r!=0}
2N/Aset ::sqlite_io_error_pending 0
2N/Aproc cksum {{db db}} {
2N/A set txt [$db eval {SELECT name, type, sql FROM sqlite_master}]\n
2N/A foreach tbl [$db eval {SELECT name FROM sqlite_master WHERE type='table'}] {
2N/A append txt [$db eval "SELECT * FROM $tbl"]\n
2N/A foreach prag {default_synchronous default_cache_size} {
2N/A append txt $prag-[$db eval "PRAGMA $prag"]\n
2N/A set cksum [string length $txt]-[md5 $txt]
2N/Afor {set n 1} {$go} {incr n} {
2N/A do_test ioerr-2.$n.1 {
2N/A set ::sqlite_io_error_pending 0
2N/A CREATE TABLE t1(a, b, c);
2N/A INSERT INTO t1 VALUES(1, randstr(5,50), randstr(5,50));
2N/A INSERT INTO t1 SELECT a+2, b||'-'||rowid, c||'-'||rowid FROM t1;
2N/A INSERT INTO t1 SELECT a+4, b||'-'||rowid, c||'-'||rowid FROM t1;
2N/A INSERT INTO t1 SELECT a+8, b||'-'||rowid, c||'-'||rowid FROM t1;
2N/A INSERT INTO t1 SELECT a+16, b||'-'||rowid, c||'-'||rowid FROM t1;
2N/A INSERT INTO t1 SELECT a+32, b||'-'||rowid, c||'-'||rowid FROM t1;
2N/A INSERT INTO t1 SELECT a+64, b||'-'||rowid, c||'-'||rowid FROM t1;
2N/A INSERT INTO t1 SELECT a+128, b||'-'||rowid, c||'-'||rowid FROM t1;
2N/A CREATE TABLE t2 AS SELECT * FROM t1;
2N/A CREATE TABLE t3 AS SELECT * FROM t1;
2N/A SELECT name FROM sqlite_master WHERE type='table'
2N/A do_test ioerr-2.$n.2 [subst {
2N/A set ::sqlite_io_error_pending $n
2N/A do_test ioerr-2.$n.3 {
2N/A set r [catch {db eval {
2N/A # puts "error_pending=$::sqlite_io_error_pending"
2N/A # if {$r} {puts $msg}
2N/A set ::go [expr {$::sqlite_io_error_pending<=0}]
2N/A expr {$::sqlite_io_error_pending>0 || $r!=0}
2N/A set ::sqlite_io_error_pending 0
2N/Aset ::sqlite_io_error_pending 0