1*c5c4113dSnw141292 2*c5c4113dSnw141292#pragma ident "%Z%%M% %I% %E% SMI" 3*c5c4113dSnw141292 4*c5c4113dSnw141292# 2002 November 30 5*c5c4113dSnw141292# 6*c5c4113dSnw141292# The author disclaims copyright to this source code. In place of 7*c5c4113dSnw141292# a legal notice, here is a blessing: 8*c5c4113dSnw141292# 9*c5c4113dSnw141292# May you do good and not evil. 10*c5c4113dSnw141292# May you find forgiveness for yourself and forgive others. 11*c5c4113dSnw141292# May you share freely, never taking more than you give. 12*c5c4113dSnw141292# 13*c5c4113dSnw141292#*********************************************************************** 14*c5c4113dSnw141292# This file implements regression tests for SQLite library. The 15*c5c4113dSnw141292# focus of this script testing the ability of SQLite to handle database 16*c5c4113dSnw141292# files larger than 4GB. 17*c5c4113dSnw141292# 18*c5c4113dSnw141292# $Id: bigfile.test,v 1.3 2003/12/19 12:31:22 drh Exp $ 19*c5c4113dSnw141292# 20*c5c4113dSnw141292 21*c5c4113dSnw141292set testdir [file dirname $argv0] 22*c5c4113dSnw141292source $testdir/tester.tcl 23*c5c4113dSnw141292 24*c5c4113dSnw141292# These tests only work for Tcl version 8.4 and later. Prior to 8.4, 25*c5c4113dSnw141292# Tcl was unable to handle large files. 26*c5c4113dSnw141292# 27*c5c4113dSnw141292scan $::tcl_version %f vx 28*c5c4113dSnw141292if {$vx<8.4} return 29*c5c4113dSnw141292 30*c5c4113dSnw141292# This is the md5 checksum of all the data in table t1 as created 31*c5c4113dSnw141292# by the first test. We will use this number to make sure that data 32*c5c4113dSnw141292# never changes. 33*c5c4113dSnw141292# 34*c5c4113dSnw141292set MAGIC_SUM {593f1efcfdbe698c28b4b1b693f7e4cf} 35*c5c4113dSnw141292 36*c5c4113dSnw141292do_test bigfile-1.1 { 37*c5c4113dSnw141292 execsql { 38*c5c4113dSnw141292 BEGIN; 39*c5c4113dSnw141292 CREATE TABLE t1(x); 40*c5c4113dSnw141292 INSERT INTO t1 VALUES('abcdefghijklmnopqrstuvwxyz'); 41*c5c4113dSnw141292 INSERT INTO t1 SELECT rowid || ' ' || x FROM t1; 42*c5c4113dSnw141292 INSERT INTO t1 SELECT rowid || ' ' || x FROM t1; 43*c5c4113dSnw141292 INSERT INTO t1 SELECT rowid || ' ' || x FROM t1; 44*c5c4113dSnw141292 INSERT INTO t1 SELECT rowid || ' ' || x FROM t1; 45*c5c4113dSnw141292 INSERT INTO t1 SELECT rowid || ' ' || x FROM t1; 46*c5c4113dSnw141292 INSERT INTO t1 SELECT rowid || ' ' || x FROM t1; 47*c5c4113dSnw141292 INSERT INTO t1 SELECT rowid || ' ' || x FROM t1; 48*c5c4113dSnw141292 COMMIT; 49*c5c4113dSnw141292 } 50*c5c4113dSnw141292 execsql { 51*c5c4113dSnw141292 SELECT md5sum(x) FROM t1; 52*c5c4113dSnw141292 } 53*c5c4113dSnw141292} $::MAGIC_SUM 54*c5c4113dSnw141292 55*c5c4113dSnw141292# Try to create a large file - a file that is larger than 2^32 bytes. 56*c5c4113dSnw141292# If this fails, it means that the system being tested does not support 57*c5c4113dSnw141292# large files. So skip all of the remaining tests in this file. 58*c5c4113dSnw141292# 59*c5c4113dSnw141292db close 60*c5c4113dSnw141292if {[catch {fake_big_file 4096 test.db}]} { 61*c5c4113dSnw141292 puts "**** Unable to create a file larger than 4096 MB. *****" 62*c5c4113dSnw141292 finish_test 63*c5c4113dSnw141292 return 64*c5c4113dSnw141292} 65*c5c4113dSnw141292 66*c5c4113dSnw141292do_test bigfile-1.2 { 67*c5c4113dSnw141292 sqlite db test.db 68*c5c4113dSnw141292 execsql { 69*c5c4113dSnw141292 SELECT md5sum(x) FROM t1; 70*c5c4113dSnw141292 } 71*c5c4113dSnw141292} $::MAGIC_SUM 72*c5c4113dSnw141292 73*c5c4113dSnw141292# The previous test may fail on some systems because they are unable 74*c5c4113dSnw141292# to handle large files. If that is so, then skip all of the following 75*c5c4113dSnw141292# tests. We will know the above test failed because the "db" command 76*c5c4113dSnw141292# does not exist. 77*c5c4113dSnw141292# 78*c5c4113dSnw141292if {[llength [info command db]]>0} { 79*c5c4113dSnw141292 80*c5c4113dSnw141292do_test bigfile-1.3 { 81*c5c4113dSnw141292 execsql { 82*c5c4113dSnw141292 CREATE TABLE t2 AS SELECT * FROM t1; 83*c5c4113dSnw141292 SELECT md5sum(x) FROM t2; 84*c5c4113dSnw141292 } 85*c5c4113dSnw141292} $::MAGIC_SUM 86*c5c4113dSnw141292do_test bigfile-1.4 { 87*c5c4113dSnw141292 db close 88*c5c4113dSnw141292 sqlite db test.db 89*c5c4113dSnw141292 execsql { 90*c5c4113dSnw141292 SELECT md5sum(x) FROM t1; 91*c5c4113dSnw141292 } 92*c5c4113dSnw141292} $::MAGIC_SUM 93*c5c4113dSnw141292do_test bigfile-1.5 { 94*c5c4113dSnw141292 execsql { 95*c5c4113dSnw141292 SELECT md5sum(x) FROM t2; 96*c5c4113dSnw141292 } 97*c5c4113dSnw141292} $::MAGIC_SUM 98*c5c4113dSnw141292 99*c5c4113dSnw141292db close 100*c5c4113dSnw141292if {[catch {fake_big_file 8192 test.db}]} { 101*c5c4113dSnw141292 puts "**** Unable to create a file larger than 8192 MB. *****" 102*c5c4113dSnw141292 finish_test 103*c5c4113dSnw141292 return 104*c5c4113dSnw141292} 105*c5c4113dSnw141292 106*c5c4113dSnw141292do_test bigfile-1.6 { 107*c5c4113dSnw141292 sqlite db test.db 108*c5c4113dSnw141292 execsql { 109*c5c4113dSnw141292 SELECT md5sum(x) FROM t1; 110*c5c4113dSnw141292 } 111*c5c4113dSnw141292} $::MAGIC_SUM 112*c5c4113dSnw141292do_test bigfile-1.7 { 113*c5c4113dSnw141292 execsql { 114*c5c4113dSnw141292 CREATE TABLE t3 AS SELECT * FROM t1; 115*c5c4113dSnw141292 SELECT md5sum(x) FROM t3; 116*c5c4113dSnw141292 } 117*c5c4113dSnw141292} $::MAGIC_SUM 118*c5c4113dSnw141292do_test bigfile-1.8 { 119*c5c4113dSnw141292 db close 120*c5c4113dSnw141292 sqlite db test.db 121*c5c4113dSnw141292 execsql { 122*c5c4113dSnw141292 SELECT md5sum(x) FROM t1; 123*c5c4113dSnw141292 } 124*c5c4113dSnw141292} $::MAGIC_SUM 125*c5c4113dSnw141292do_test bigfile-1.9 { 126*c5c4113dSnw141292 execsql { 127*c5c4113dSnw141292 SELECT md5sum(x) FROM t2; 128*c5c4113dSnw141292 } 129*c5c4113dSnw141292} $::MAGIC_SUM 130*c5c4113dSnw141292do_test bigfile-1.10 { 131*c5c4113dSnw141292 execsql { 132*c5c4113dSnw141292 SELECT md5sum(x) FROM t3; 133*c5c4113dSnw141292 } 134*c5c4113dSnw141292} $::MAGIC_SUM 135*c5c4113dSnw141292 136*c5c4113dSnw141292db close 137*c5c4113dSnw141292if {[catch {fake_big_file 16384 test.db}]} { 138*c5c4113dSnw141292 puts "**** Unable to create a file larger than 16384 MB. *****" 139*c5c4113dSnw141292 finish_test 140*c5c4113dSnw141292 return 141*c5c4113dSnw141292} 142*c5c4113dSnw141292 143*c5c4113dSnw141292do_test bigfile-1.11 { 144*c5c4113dSnw141292 sqlite db test.db 145*c5c4113dSnw141292 execsql { 146*c5c4113dSnw141292 SELECT md5sum(x) FROM t1; 147*c5c4113dSnw141292 } 148*c5c4113dSnw141292} $::MAGIC_SUM 149*c5c4113dSnw141292do_test bigfile-1.12 { 150*c5c4113dSnw141292 execsql { 151*c5c4113dSnw141292 CREATE TABLE t4 AS SELECT * FROM t1; 152*c5c4113dSnw141292 SELECT md5sum(x) FROM t4; 153*c5c4113dSnw141292 } 154*c5c4113dSnw141292} $::MAGIC_SUM 155*c5c4113dSnw141292do_test bigfile-1.13 { 156*c5c4113dSnw141292 db close 157*c5c4113dSnw141292 sqlite db test.db 158*c5c4113dSnw141292 execsql { 159*c5c4113dSnw141292 SELECT md5sum(x) FROM t1; 160*c5c4113dSnw141292 } 161*c5c4113dSnw141292} $::MAGIC_SUM 162*c5c4113dSnw141292do_test bigfile-1.14 { 163*c5c4113dSnw141292 execsql { 164*c5c4113dSnw141292 SELECT md5sum(x) FROM t2; 165*c5c4113dSnw141292 } 166*c5c4113dSnw141292} $::MAGIC_SUM 167*c5c4113dSnw141292do_test bigfile-1.15 { 168*c5c4113dSnw141292 execsql { 169*c5c4113dSnw141292 SELECT md5sum(x) FROM t3; 170*c5c4113dSnw141292 } 171*c5c4113dSnw141292} $::MAGIC_SUM 172*c5c4113dSnw141292do_test bigfile-1.16 { 173*c5c4113dSnw141292 execsql { 174*c5c4113dSnw141292 SELECT md5sum(x) FROM t3; 175*c5c4113dSnw141292 } 176*c5c4113dSnw141292} $::MAGIC_SUM 177*c5c4113dSnw141292 178*c5c4113dSnw141292} ;# End of the "if( db command exists )" 179*c5c4113dSnw141292 180*c5c4113dSnw141292finish_test 181