AryaWu/sqlite
0
1# 2001 September 152#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 tests that rollback journals for databases that use a 12# page-size other than the default page-size can be rolled back Ok.13#14# $Id: crash6.test,v 1.2 2008/04/14 15:27:19 drh Exp $15 16set testdir [file dirname $argv0]17source $testdir/tester.tcl18 19ifcapable !crashtest {20 finish_test21 return22}23 24for {set ii 0} {$ii < 10} {incr ii} {25 catch {db close}26 forcedelete test.db test.db-journal27 crashsql -delay 2 -file test.db {28 PRAGMA auto_vacuum=OFF;29 PRAGMA page_size=4096;30 BEGIN;31 CREATE TABLE abc AS SELECT 1 AS a, 2 AS b, 3 AS c;32 COMMIT;33 BEGIN;34 CREATE TABLE def AS SELECT 1 AS d, 2 AS e, 3 AS f;35 COMMIT;36 }37 sqlite3 db test.db38 integrity_check crash6-1.$ii39}40 41for {set ii 0} {$ii < 10} {incr ii} {42 catch {db close}43 forcedelete test.db test.db-journal44 sqlite3 db test.db45 execsql {46 PRAGMA auto_vacuum=OFF;47 PRAGMA page_size=2048;48 BEGIN;49 CREATE TABLE abc AS SELECT 1 AS a, 2 AS b, 3 AS c;50 COMMIT;51 }52 db close53 crashsql -delay 1 -file test.db {54 INSERT INTO abc VALUES(5, 6, 7);55 }56 sqlite3 db test.db57 integrity_check crash6-2.$ii58}59 60proc signature {} {61 return [db eval {SELECT count(*), md5sum(a), md5sum(b), md5sum(c) FROM abc}]62}63 64# Test case for crashing during database sync with page-size values 65# from 1024 to 8192.66#67for {set ii 0} {$ii < 30} {incr ii} {68 db close69 forcedelete test.db70 sqlite3 db test.db71 72 set pagesize [expr 1024 << ($ii % 4)]73 if {$pagesize>$::SQLITE_MAX_PAGE_SIZE} {74 set pagesize $::SQLITE_MAX_PAGE_SIZE75 }76 do_test crash6-3.$ii.0 {77 execsql "pragma page_size = $pagesize"78 execsql "pragma page_size"79 } $pagesize80 81 do_test crash6-3.$ii.1 {82 83 execsql BEGIN84 execsql {CREATE TABLE abc(a, b, c)}85 for {set n 0} {$n < 1000} {incr n} {86 execsql "INSERT INTO abc VALUES($n, [expr 2*$n], [expr 3*$n])"87 }88 execsql {89 INSERT INTO abc SELECT * FROM abc;90 INSERT INTO abc SELECT * FROM abc;91 INSERT INTO abc SELECT * FROM abc;92 INSERT INTO abc SELECT * FROM abc;93 INSERT INTO abc SELECT * FROM abc;94 }95 execsql COMMIT96 expr ([file size test.db] / 1024) > 45097 } {1}98 99 set sig [signature]100 db close101 102 do_test crash6-3.$ii.2 {103 crashsql -file test.db "104 BEGIN;105 SELECT random() FROM abc LIMIT $ii;106 INSERT INTO abc SELECT randstr(10,10), 0, 0 FROM abc WHERE random()%2==0;107 DELETE FROM abc WHERE random()%2!=0;108 COMMIT;109 "110 } {1 {child process exited abnormally}}111 112 do_test crash6-3.$ii.3 {113 sqlite3 db test.db114 signature115 } $sig116} 117 118finish_test119 