AryaWu/sqlite
0
1# 2001 October 122#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 disk full13# errors.14# 15# $Id: diskfull.test,v 1.8 2008/07/12 14:52:20 drh Exp $16 17set testdir [file dirname $argv0]18source $testdir/tester.tcl19 20set sqlite_io_error_persist 021set sqlite_io_error_hit 022set sqlite_io_error_pending 023do_test diskfull-1.1 {24 execsql {25 CREATE TABLE t1(x);26 INSERT INTO t1 VALUES(randstr(1000,1000));27 INSERT INTO t1 SELECT * FROM t1;28 INSERT INTO t1 SELECT * FROM t1;29 INSERT INTO t1 SELECT * FROM t1;30 INSERT INTO t1 SELECT * FROM t1;31 CREATE INDEX t1i1 ON t1(x);32 CREATE TABLE t2 AS SELECT x AS a, x AS b FROM t1;33 CREATE INDEX t2i1 ON t2(b);34 }35} {}36set sqlite_diskfull_pending 037integrity_check diskfull-1.238do_test diskfull-1.3 {39 set sqlite_diskfull_pending 140 catchsql {41 INSERT INTO t1 SELECT * FROM t1;42 }43} {1 {database or disk is full}}44set sqlite_diskfull_pending 045integrity_check diskfull-1.446do_test diskfull-1.5 {47 set sqlite_diskfull_pending 148 catchsql {49 DELETE FROM t1;50 }51} {1 {database or disk is full}}52set sqlite_diskfull_pending 053set sqlite_io_error_hit 054integrity_check diskfull-1.655 56proc do_diskfull_test {prefix sql} {57 set ::go 158 set ::sql $sql59 set ::i 160 while {$::go} {61 incr ::i62 do_test ${prefix}.$::i.1 {63 set ::sqlite_diskfull_pending $::i64 set ::sqlite_diskfull 065 set r [catchsql $::sql]66 if {!$::sqlite_diskfull} {67 set r {1 {database or disk is full}}68 set ::go 069 }70 if {$r=="1 {disk I/O error}"} {71 set r {1 {database or disk is full}}72 }73 set r74 } {1 {database or disk is full}}75 set ::sqlite_diskfull_pending 076 db close77 sqlite3 db test.db78 integrity_check ${prefix}.$::i.279 }80}81 82do_diskfull_test diskfull-2 VACUUM83 84# db close85# forcedelete test.db86# forcedelete test.db-journal87# sqlite3 db test.db88# 89# do_test diskfull-3.1 {90# execsql {91# PRAGMA default_cache_size = 10;92# CREATE TABLE t3(a, b, UNIQUE(a, b));93# INSERT INTO t3 VALUES( randstr(100, 100), randstr(100, 100) );94# INSERT INTO t3 SELECT randstr(100, 100), randstr(100, 100) FROM t3;95# INSERT INTO t3 SELECT randstr(100, 100), randstr(100, 100) FROM t3;96# INSERT INTO t3 SELECT randstr(100, 100), randstr(100, 100) FROM t3;97# INSERT INTO t3 SELECT randstr(100, 100), randstr(100, 100) FROM t3;98# INSERT INTO t3 SELECT randstr(100, 100), randstr(100, 100) FROM t3;99# INSERT INTO t3 SELECT randstr(100, 100), randstr(100, 100) FROM t3;100# INSERT INTO t3 SELECT randstr(100, 100), randstr(100, 100) FROM t3;101# UPDATE t3 102# SET b = (SELECT a FROM t3 WHERE rowid = (SELECT max(rowid)-1 FROM t3))103# WHERE rowid = (SELECT max(rowid) FROM t3);104# PRAGMA cache_size;105# }106# } {10}107# 108# do_diskfull_test diskfull-3.2 {109# BEGIN;110# INSERT INTO t3 VALUES( randstr(100, 100), randstr(100, 100) );111# UPDATE t3 SET a = b;112# COMMIT;113# }114 115finish_test116 