1# 2002 November 30 2# 3# The author disclaims copyright to this source code. In place of 4# 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. The 12# focus of this script testing the ability of SQLite to handle database 13# files larger than 4GB. 14# 15# $Id: bigfile.test,v 1.12 2009/03/05 04:27:08 shane Exp $ 16# 17 18if {[file exists skip-big-file]} return 19 20set testdir [file dirname $argv0] 21source $testdir/tester.tcl 22 23# Do not use a codec for this file, as the database is manipulated using 24# external methods (the [fake_big_file] and [hexio_write] commands). 25# 26do_not_use_codec 27 28# If SQLITE_DISABLE_LFS is defined, omit this file. 29ifcapable !lfs { 30 finish_test 31 return 32} 33 34# These tests only work for Tcl version 8.4 and later. Prior to 8.4, 35# Tcl was unable to handle large files. 36# 37scan $::tcl_version %f vx 38if {$vx<8.4} return 39 40# Mac OS X does not handle large files efficiently. So skip this test 41# on that platform. 42if {$tcl_platform(os)=="Darwin"} return 43 44# This is the md5 checksum of all the data in table t1 as created 45# by the first test. We will use this number to make sure that data 46# never changes. 47# 48set MAGIC_SUM {593f1efcfdbe698c28b4b1b693f7e4cf} 49 50do_test bigfile-1.1 { 51 execsql { 52 BEGIN; 53 CREATE TABLE t1(x); 54 INSERT INTO t1 VALUES('abcdefghijklmnopqrstuvwxyz'); 55 INSERT INTO t1 SELECT rowid || ' ' || x FROM t1; 56 INSERT INTO t1 SELECT rowid || ' ' || x FROM t1; 57 INSERT INTO t1 SELECT rowid || ' ' || x FROM t1; 58 INSERT INTO t1 SELECT rowid || ' ' || x FROM t1; 59 INSERT INTO t1 SELECT rowid || ' ' || x FROM t1; 60 INSERT INTO t1 SELECT rowid || ' ' || x FROM t1; 61 INSERT INTO t1 SELECT rowid || ' ' || x FROM t1; 62 COMMIT; 63 } 64 execsql { 65 SELECT md5sum(x) FROM t1; 66 } 67} $::MAGIC_SUM 68 69# Try to create a large file - a file that is larger than 2^32 bytes. 70# If this fails, it means that the system being tested does not support 71# large files. So skip all of the remaining tests in this file. 72# 73db close 74if {[catch {fake_big_file 4096 [pwd]/test.db} msg]} { 75 puts "**** Unable to create a file larger than 4096 MB. *****" 76 finish_test 77 return 78} 79hexio_write test.db 28 00000000 80 81do_test bigfile-1.2 { 82 sqlite3 db test.db 83 execsql { 84 SELECT md5sum(x) FROM t1; 85 } 86} $::MAGIC_SUM 87 88# The previous test may fail on some systems because they are unable 89# to handle large files. If that is so, then skip all of the following 90# tests. We will know the above test failed because the "db" command 91# does not exist. 92# 93if {[llength [info command db]]<=0} { 94 puts "**** Large file support appears to be broken. *****" 95 finish_test 96 return 97} 98 99do_test bigfile-1.3 { 100 execsql { 101 CREATE TABLE t2 AS SELECT * FROM t1; 102 SELECT md5sum(x) FROM t2; 103 } 104} $::MAGIC_SUM 105do_test bigfile-1.4 { 106 db close 107 sqlite3 db test.db 108 execsql { 109 SELECT md5sum(x) FROM t1; 110 } 111} $::MAGIC_SUM 112 113db close 114if {[catch {fake_big_file 8192 [pwd]/test.db}]} { 115 puts "**** Unable to create a file larger than 8192 MB. *****" 116 finish_test 117 return 118} 119hexio_write test.db 28 00000000 120 121do_test bigfile-1.5 { 122 sqlite3 db test.db 123 execsql { 124 SELECT md5sum(x) FROM t1; 125 } 126} $::MAGIC_SUM 127do_test bigfile-1.6 { 128 sqlite3 db test.db 129 execsql { 130 SELECT md5sum(x) FROM t2; 131 } 132} $::MAGIC_SUM 133do_test bigfile-1.7 { 134 execsql { 135 CREATE TABLE t3 AS SELECT * FROM t1; 136 SELECT md5sum(x) FROM t3; 137 } 138} $::MAGIC_SUM 139do_test bigfile-1.8 { 140 db close 141 sqlite3 db test.db 142 execsql { 143 SELECT md5sum(x) FROM t1; 144 } 145} $::MAGIC_SUM 146do_test bigfile-1.9 { 147 execsql { 148 SELECT md5sum(x) FROM t2; 149 } 150} $::MAGIC_SUM 151 152db close 153if {[catch {fake_big_file 16384 [pwd]/test.db}]} { 154 puts "**** Unable to create a file larger than 16384 MB. *****" 155 finish_test 156 return 157} 158hexio_write test.db 28 00000000 159 160do_test bigfile-1.10 { 161 sqlite3 db test.db 162 execsql { 163 SELECT md5sum(x) FROM t1; 164 } 165} $::MAGIC_SUM 166do_test bigfile-1.11 { 167 sqlite3 db test.db 168 execsql { 169 SELECT md5sum(x) FROM t2; 170 } 171} $::MAGIC_SUM 172do_test bigfile-1.12 { 173 sqlite3 db test.db 174 execsql { 175 SELECT md5sum(x) FROM t3; 176 } 177} $::MAGIC_SUM 178do_test bigfile-1.13 { 179 execsql { 180 CREATE TABLE t4 AS SELECT * FROM t1; 181 SELECT md5sum(x) FROM t4; 182 } 183} $::MAGIC_SUM 184do_test bigfile-1.14 { 185 db close 186 sqlite3 db test.db 187 execsql { 188 SELECT md5sum(x) FROM t1; 189 } 190} $::MAGIC_SUM 191do_test bigfile-1.15 { 192 execsql { 193 SELECT md5sum(x) FROM t2; 194 } 195} $::MAGIC_SUM 196do_test bigfile-1.16 { 197 execsql { 198 SELECT md5sum(x) FROM t3; 199 } 200} $::MAGIC_SUM 201 202finish_test 203