blob: defa32686878d932a790b4cc945661dcfde5cc05 [file] [log] [blame]
drhef5a2e12008-05-07 13:28:38 +00001# 2007 December 19
2#
3# The author disclaims copyright to this source code. In place of
4# a legal notice, here is a blessing:
5#
6# May you do good and not evil.
7# May you find forgiveness for yourself and forgive others.
8# May you share freely, never taking more than you give.
9#
10#***********************************************************************
11# This file implements regression tests for SQLite library. The
12# focus of this file is testing for correct handling of I/O errors
13# during incremental vacuum with a shared cache.
14#
drh95ed6bc2008-05-08 01:11:42 +000015# $Id: ioerr4.test,v 1.2 2008/05/08 01:11:42 drh Exp $
drhef5a2e12008-05-07 13:28:38 +000016
17set testdir [file dirname $argv0]
18source $testdir/tester.tcl
19
20# This test requires both shared cache and incremental vacuum.
21#
22ifcapable {!shared_cache || !autovacuum} {
23 finish_test
24 return
25}
26
27# Enable shared cache mode and incremental vacuum.
28#
29do_test ioerr4-1.1 {
30 db close
drh95ed6bc2008-05-08 01:11:42 +000031 set ::enable_shared_cache [sqlite3_enable_shared_cache 1]
drhef5a2e12008-05-07 13:28:38 +000032} {0}
33do_test ioerr4-1.2 {
mistachkinfda06be2011-08-02 00:57:34 +000034 forcedelete test.db test.db-journal
drhef5a2e12008-05-07 13:28:38 +000035 sqlite3 db test.db
36 sqlite3 db2 test.db
37 db eval {
38 PRAGMA auto_vacuum=INCREMENTAL;
39 CREATE TABLE a(i INTEGER, b BLOB);
40 }
41 db2 eval {
42 SELECT name FROM sqlite_master
43 }
44} {a}
45do_test ioerr4-1.3 {
46 db eval {
47 PRAGMA auto_vacuum;
48 }
49} {2}
50
51# Insert and delete many records in order to put lots of pages
52# on the freelist.
53#
54do_test ioerr4-1.4 {
55 db eval {
56 INSERT INTO a VALUES(1, zeroblob(2000));
57 INSERT INTO a VALUES(2, zeroblob(2000));
58 INSERT INTO a SELECT i+2, zeroblob(2000) FROM a;
59 INSERT INTO a SELECT i+4, zeroblob(2000) FROM a;
60 INSERT INTO a SELECT i+8, zeroblob(2000) FROM a;
61 INSERT INTO a SELECT i+16, zeroblob(2000) FROM a;
62 SELECT count(*) FROM a;
63 }
64} {32}
65do_test ioerr4-1.5 {
66 db eval {
67 PRAGMA freelist_count
68 }
69} {0}
70do_test ioerr4-1.6 {
71 db eval {
72 DELETE FROM a;
73 PRAGMA freelist_count;
74 }
75} {64}
76
77# Set up for an I/O error on incremental vacuum
78# with two connections on shared cache.
79#
80db close
81db2 close
mistachkinfda06be2011-08-02 00:57:34 +000082forcecopy test.db test.db-bu
drhef5a2e12008-05-07 13:28:38 +000083do_ioerr_test ioerr4-2 -tclprep {
84 catch {db2 close}
85 db close
mistachkinfda06be2011-08-02 00:57:34 +000086 forcedelete test.db test.db-journal
87 forcecopy test.db-bu test.db
drhef5a2e12008-05-07 13:28:38 +000088 sqlite3_enable_shared_cache 1
89 set ::DB [sqlite3 db test.db; sqlite3_connection_pointer db]
90 db eval {PRAGMA auto_vacuum=INCREMENTAL}
91 sqlite3 db2 test.db
92} -tclbody {
93 db eval {PRAGMA incremental_vacuum(5)}
94}
95
drh95ed6bc2008-05-08 01:11:42 +000096db2 close
mistachkinfda06be2011-08-02 00:57:34 +000097forcedelete test.db-bu
drh95ed6bc2008-05-08 01:11:42 +000098sqlite3_enable_shared_cache $::enable_shared_cache
99
drhef5a2e12008-05-07 13:28:38 +0000100finish_test