sl@0
|
1 |
# 2001 October 12
|
sl@0
|
2 |
#
|
sl@0
|
3 |
# The author disclaims copyright to this source code. In place of
|
sl@0
|
4 |
# a legal notice, here is a blessing:
|
sl@0
|
5 |
#
|
sl@0
|
6 |
# May you do good and not evil.
|
sl@0
|
7 |
# May you find forgiveness for yourself and forgive others.
|
sl@0
|
8 |
# May you share freely, never taking more than you give.
|
sl@0
|
9 |
#
|
sl@0
|
10 |
#***********************************************************************
|
sl@0
|
11 |
# This file implements regression tests for SQLite library. The
|
sl@0
|
12 |
# focus of this file is testing for correct handling of disk full
|
sl@0
|
13 |
# errors.
|
sl@0
|
14 |
#
|
sl@0
|
15 |
# $Id: diskfull.test,v 1.8 2008/07/12 14:52:20 drh Exp $
|
sl@0
|
16 |
|
sl@0
|
17 |
set testdir [file dirname $argv0]
|
sl@0
|
18 |
source $testdir/tester.tcl
|
sl@0
|
19 |
|
sl@0
|
20 |
set sqlite_io_error_persist 0
|
sl@0
|
21 |
set sqlite_io_error_hit 0
|
sl@0
|
22 |
set sqlite_io_error_pending 0
|
sl@0
|
23 |
do_test diskfull-1.1 {
|
sl@0
|
24 |
execsql {
|
sl@0
|
25 |
CREATE TABLE t1(x);
|
sl@0
|
26 |
INSERT INTO t1 VALUES(randstr(1000,1000));
|
sl@0
|
27 |
INSERT INTO t1 SELECT * FROM t1;
|
sl@0
|
28 |
INSERT INTO t1 SELECT * FROM t1;
|
sl@0
|
29 |
INSERT INTO t1 SELECT * FROM t1;
|
sl@0
|
30 |
INSERT INTO t1 SELECT * FROM t1;
|
sl@0
|
31 |
CREATE INDEX t1i1 ON t1(x);
|
sl@0
|
32 |
CREATE TABLE t2 AS SELECT x AS a, x AS b FROM t1;
|
sl@0
|
33 |
CREATE INDEX t2i1 ON t2(b);
|
sl@0
|
34 |
}
|
sl@0
|
35 |
} {}
|
sl@0
|
36 |
set sqlite_diskfull_pending 0
|
sl@0
|
37 |
integrity_check diskfull-1.2
|
sl@0
|
38 |
do_test diskfull-1.3 {
|
sl@0
|
39 |
set sqlite_diskfull_pending 1
|
sl@0
|
40 |
catchsql {
|
sl@0
|
41 |
INSERT INTO t1 SELECT * FROM t1;
|
sl@0
|
42 |
}
|
sl@0
|
43 |
} {1 {database or disk is full}}
|
sl@0
|
44 |
set sqlite_diskfull_pending 0
|
sl@0
|
45 |
integrity_check diskfull-1.4
|
sl@0
|
46 |
do_test diskfull-1.5 {
|
sl@0
|
47 |
set sqlite_diskfull_pending 1
|
sl@0
|
48 |
catchsql {
|
sl@0
|
49 |
DELETE FROM t1;
|
sl@0
|
50 |
}
|
sl@0
|
51 |
} {1 {database or disk is full}}
|
sl@0
|
52 |
set sqlite_diskfull_pending 0
|
sl@0
|
53 |
set sqlite_io_error_hit 0
|
sl@0
|
54 |
integrity_check diskfull-1.6
|
sl@0
|
55 |
|
sl@0
|
56 |
proc do_diskfull_test {prefix sql} {
|
sl@0
|
57 |
set ::go 1
|
sl@0
|
58 |
set ::sql $sql
|
sl@0
|
59 |
set ::i 1
|
sl@0
|
60 |
while {$::go} {
|
sl@0
|
61 |
incr ::i
|
sl@0
|
62 |
do_test ${prefix}.$::i.1 {
|
sl@0
|
63 |
set ::sqlite_diskfull_pending $::i
|
sl@0
|
64 |
set ::sqlite_diskfull 0
|
sl@0
|
65 |
set r [catchsql $::sql]
|
sl@0
|
66 |
if {!$::sqlite_diskfull} {
|
sl@0
|
67 |
set r {1 {database or disk is full}}
|
sl@0
|
68 |
set ::go 0
|
sl@0
|
69 |
}
|
sl@0
|
70 |
if {$r=="1 {disk I/O error}"} {
|
sl@0
|
71 |
set r {1 {database or disk is full}}
|
sl@0
|
72 |
}
|
sl@0
|
73 |
set r
|
sl@0
|
74 |
} {1 {database or disk is full}}
|
sl@0
|
75 |
set ::sqlite_diskfull_pending 0
|
sl@0
|
76 |
db close
|
sl@0
|
77 |
sqlite3 db test.db
|
sl@0
|
78 |
integrity_check ${prefix}.$::i.2
|
sl@0
|
79 |
}
|
sl@0
|
80 |
}
|
sl@0
|
81 |
|
sl@0
|
82 |
do_diskfull_test diskfull-2 VACUUM
|
sl@0
|
83 |
|
sl@0
|
84 |
# db close
|
sl@0
|
85 |
# file delete -force test.db
|
sl@0
|
86 |
# file delete -force test.db-journal
|
sl@0
|
87 |
# sqlite3 db test.db
|
sl@0
|
88 |
#
|
sl@0
|
89 |
# do_test diskfull-3.1 {
|
sl@0
|
90 |
# execsql {
|
sl@0
|
91 |
# PRAGMA default_cache_size = 10;
|
sl@0
|
92 |
# CREATE TABLE t3(a, b, UNIQUE(a, b));
|
sl@0
|
93 |
# INSERT INTO t3 VALUES( randstr(100, 100), randstr(100, 100) );
|
sl@0
|
94 |
# INSERT INTO t3 SELECT randstr(100, 100), randstr(100, 100) FROM t3;
|
sl@0
|
95 |
# INSERT INTO t3 SELECT randstr(100, 100), randstr(100, 100) FROM t3;
|
sl@0
|
96 |
# INSERT INTO t3 SELECT randstr(100, 100), randstr(100, 100) FROM t3;
|
sl@0
|
97 |
# INSERT INTO t3 SELECT randstr(100, 100), randstr(100, 100) FROM t3;
|
sl@0
|
98 |
# INSERT INTO t3 SELECT randstr(100, 100), randstr(100, 100) FROM t3;
|
sl@0
|
99 |
# INSERT INTO t3 SELECT randstr(100, 100), randstr(100, 100) FROM t3;
|
sl@0
|
100 |
# INSERT INTO t3 SELECT randstr(100, 100), randstr(100, 100) FROM t3;
|
sl@0
|
101 |
# UPDATE t3
|
sl@0
|
102 |
# SET b = (SELECT a FROM t3 WHERE rowid = (SELECT max(rowid)-1 FROM t3))
|
sl@0
|
103 |
# WHERE rowid = (SELECT max(rowid) FROM t3);
|
sl@0
|
104 |
# PRAGMA cache_size;
|
sl@0
|
105 |
# }
|
sl@0
|
106 |
# } {10}
|
sl@0
|
107 |
#
|
sl@0
|
108 |
# do_diskfull_test diskfull-3.2 {
|
sl@0
|
109 |
# BEGIN;
|
sl@0
|
110 |
# INSERT INTO t3 VALUES( randstr(100, 100), randstr(100, 100) );
|
sl@0
|
111 |
# UPDATE t3 SET a = b;
|
sl@0
|
112 |
# COMMIT;
|
sl@0
|
113 |
# }
|
sl@0
|
114 |
|
sl@0
|
115 |
finish_test
|