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 I/O errors13# such as writes failing because the disk is full.14# 15# The tests in this file use special facilities that are only16# available in the SQLite test fixture.17#18# $Id: autovacuum_ioerr2.test,v 1.7 2008/07/12 14:52:20 drh Exp $19 20set testdir [file dirname $argv0]21source $testdir/tester.tcl22 23# If this build of the library does not support auto-vacuum, omit this24# whole file.25ifcapable {!autovacuum} {26 finish_test27 return28}29 30do_ioerr_test autovacuum-ioerr2-1 -sqlprep {31 PRAGMA auto_vacuum = 1;32 CREATE TABLE abc(a);33 INSERT INTO abc VALUES(randstr(1500,1500));34} -sqlbody {35 CREATE TABLE abc2(a);36 BEGIN;37 DELETE FROM abc;38 INSERT INTO abc VALUES(randstr(1500,1500));39 CREATE TABLE abc3(a);40 COMMIT;41}42 43do_ioerr_test autovacuum-ioerr2-2 -tclprep {44 execsql {45 PRAGMA auto_vacuum = 1;46 PRAGMA cache_size = 10;47 BEGIN;48 CREATE TABLE abc(a);49 INSERT INTO abc VALUES(randstr(1100,1100)); -- Page 4 is overflow50 INSERT INTO abc VALUES(randstr(1100,1100)); -- Page 5 is overflow51 }52 for {set i 0} {$i<150} {incr i} {53 execsql {54 INSERT INTO abc VALUES(randstr(100,100)); 55 }56 }57 execsql COMMIT58} -sqlbody {59 BEGIN;60 DELETE FROM abc WHERE length(a)>100;61 UPDATE abc SET a = randstr(90,90);62 CREATE TABLE abc3(a);63 COMMIT;64}65 66do_ioerr_test autovacuum-ioerr2-3 -sqlprep {67 PRAGMA auto_vacuum = 1;68 CREATE TABLE abc(a);69 CREATE TABLE abc2(b);70} -sqlbody {71 BEGIN;72 INSERT INTO abc2 VALUES(10);73 DROP TABLE abc;74 COMMIT;75 DROP TABLE abc2;76}77 78forcedelete backup.db79ifcapable subquery {80 do_ioerr_test autovacuum-ioerr2-4 -tclprep {81 if {![file exists backup.db]} {82 sqlite3 dbb backup.db 83 execsql {84 PRAGMA auto_vacuum = 1;85 BEGIN;86 CREATE TABLE abc(a);87 INSERT INTO abc VALUES(randstr(1100,1100)); -- Page 4 is overflow88 INSERT INTO abc VALUES(randstr(1100,1100)); -- Page 5 is overflow89 } dbb90 for {set i 0} {$i<2500} {incr i} {91 execsql {92 INSERT INTO abc VALUES(randstr(100,100)); 93 } dbb94 }95 execsql {96 COMMIT;97 PRAGMA cache_size = 10;98 } dbb99 dbb close100 }101 db close102 forcedelete test.db103 forcedelete test.db-journal104 forcecopy backup.db test.db105 set ::DB [sqlite3 db test.db]106 execsql {107 PRAGMA cache_size = 10;108 }109 } -sqlbody {110 BEGIN;111 DELETE FROM abc WHERE oid < 3;112 UPDATE abc SET a = randstr(100,100) WHERE oid > 2300;113 UPDATE abc SET a = randstr(1100,1100) WHERE oid = 114 (select max(oid) from abc);115 COMMIT;116 }117}118 119do_ioerr_test autovacuum-ioerr2-1 -sqlprep {120 PRAGMA auto_vacuum = 1;121 CREATE TABLE abc(a);122 INSERT INTO abc VALUES(randstr(1500,1500));123} -sqlbody {124 CREATE TABLE abc2(a);125 BEGIN;126 DELETE FROM abc;127 INSERT INTO abc VALUES(randstr(1500,1500));128 CREATE TABLE abc3(a);129 COMMIT;130}131 132finish_test133 