AryaWu/sqlite
0
1# 2007 December 192#3# The author disclaims copyright to this source code. In place of4# 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. The12# focus of this file is testing for correct handling of I/O errors13# during incremental vacuum with a shared cache.14#15# $Id: ioerr4.test,v 1.2 2008/05/08 01:11:42 drh Exp $16 17set testdir [file dirname $argv0]18source $testdir/tester.tcl19 20# This test requires both shared cache and incremental vacuum.21#22ifcapable {!shared_cache || !autovacuum} {23 finish_test24 return25}26 27# Enable shared cache mode and incremental vacuum.28#29do_test ioerr4-1.1 {30 db close31 set ::enable_shared_cache [sqlite3_enable_shared_cache 1]32} {0}33do_test ioerr4-1.2 {34 forcedelete test.db test.db-journal35 sqlite3 db test.db36 sqlite3 db2 test.db37 db eval {38 PRAGMA auto_vacuum=INCREMENTAL;39 CREATE TABLE a(i INTEGER, b BLOB);40 }41 db2 eval {42 SELECT name FROM sqlite_master43 }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 pages52# 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_count68 }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 vacuum78# with two connections on shared cache.79#80db close81db2 close82forcecopy test.db test.db-bu83do_ioerr_test ioerr4-2 -tclprep {84 catch {db2 close}85 db close86 forcedelete test.db test.db-journal87 forcecopy test.db-bu test.db88 sqlite3_enable_shared_cache 189 set ::DB [sqlite3 db test.db; sqlite3_connection_pointer db]90 db eval {PRAGMA auto_vacuum=INCREMENTAL}91 sqlite3 db2 test.db92} -tclbody {93 db eval {PRAGMA incremental_vacuum(5)}94}95 96db2 close97forcedelete test.db-bu98sqlite3_enable_shared_cache $::enable_shared_cache99 100finish_test101 