2 #pragma ident "%Z%%M% %I% %E% SMI"
6 # The author disclaims copyright to this source code. In place of
7 # a legal notice, here is a blessing:
9 # May you do good and not evil.
10 # May you find forgiveness for yourself and forgive others.
11 # May you share freely, never taking more than you give.
13 #***********************************************************************
14 # This file implements regression tests for SQLite library. The
15 # focus of this file is testing for correct handling of I/O errors
16 # such as writes failing because the disk is full.
18 # The tests in this file use special facilities that are only
19 # available in the SQLite test fixture.
21 # $Id: ioerr.test,v 1.3 2003/04/25 15:37:59 drh Exp $
23 set testdir [file dirname $argv0]
24 source $testdir/tester.tcl
27 for {set n 1} {$go} {incr n} {
28 do_test ioerr-1.$n.1 {
29 set ::sqlite_io_error_pending 0
31 catch {file delete -force test.db}
32 catch {file delete -force test.db-journal}
34 execsql {SELECT * FROM sqlite_master}
36 do_test ioerr-1.$n.2 [subst {
37 set ::sqlite_io_error_pending $n
39 do_test ioerr-1.$n.3 {
40 set r [catch {db eval {
41 CREATE TABLE t1(a,b,c);
42 SELECT * FROM sqlite_master;
44 INSERT INTO t1 VALUES(1,2,3);
45 INSERT INTO t1 VALUES(4,5,6);
49 INSERT INTO t1 VALUES(1,2,3);
50 INSERT INTO t1 VALUES(4,5,6);
53 DELETE FROM t1 WHERE a<100;
56 set ::go [expr {$::sqlite_io_error_pending<=0}]
57 expr {$::sqlite_io_error_pending>0 || $r!=0}
60 set ::sqlite_io_error_pending 0
62 proc cksum {{db db}} {
63 set txt [$db eval {SELECT name, type, sql FROM sqlite_master}]\n
64 foreach tbl [$db eval {SELECT name FROM sqlite_master WHERE type='table'}] {
65 append txt [$db eval "SELECT * FROM $tbl"]\n
67 foreach prag {default_synchronous default_cache_size} {
68 append txt $prag-[$db eval "PRAGMA $prag"]\n
70 set cksum [string length $txt]-[md5 $txt]
71 # puts $cksum-[file size test.db]
76 for {set n 1} {$go} {incr n} {
77 do_test ioerr-2.$n.1 {
78 set ::sqlite_io_error_pending 0
80 catch {file delete -force test.db}
81 catch {file delete -force test.db-journal}
85 CREATE TABLE t1(a, b, c);
86 INSERT INTO t1 VALUES(1, randstr(5,50), randstr(5,50));
87 INSERT INTO t1 SELECT a+2, b||'-'||rowid, c||'-'||rowid FROM t1;
88 INSERT INTO t1 SELECT a+4, b||'-'||rowid, c||'-'||rowid FROM t1;
89 INSERT INTO t1 SELECT a+8, b||'-'||rowid, c||'-'||rowid FROM t1;
90 INSERT INTO t1 SELECT a+16, b||'-'||rowid, c||'-'||rowid FROM t1;
91 INSERT INTO t1 SELECT a+32, b||'-'||rowid, c||'-'||rowid FROM t1;
92 INSERT INTO t1 SELECT a+64, b||'-'||rowid, c||'-'||rowid FROM t1;
93 INSERT INTO t1 SELECT a+128, b||'-'||rowid, c||'-'||rowid FROM t1;
94 CREATE TABLE t2 AS SELECT * FROM t1;
95 CREATE TABLE t3 AS SELECT * FROM t1;
101 SELECT name FROM sqlite_master WHERE type='table'
104 do_test ioerr-2.$n.2 [subst {
105 set ::sqlite_io_error_pending $n
107 do_test ioerr-2.$n.3 {
108 set r [catch {db eval {
111 # puts "error_pending=$::sqlite_io_error_pending"
112 # if {$r} {puts $msg}
113 set ::go [expr {$::sqlite_io_error_pending<=0}]
114 expr {$::sqlite_io_error_pending>0 || $r!=0}
115 set ::sqlite_io_error_pending 0
121 set ::sqlite_io_error_pending 0