blob: 52d74edbe60d1f8e631d4f9a05494b4f955e6e4e [file] [log] [blame]
drhd0d006e2002-12-01 02:00:57 +00001# 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#
shane3c9cfa92009-03-05 04:27:08 +000015# $Id: bigfile.test,v 1.12 2009/03/05 04:27:08 shane Exp $
drhd0d006e2002-12-01 02:00:57 +000016#
17
18set testdir [file dirname $argv0]
19source $testdir/tester.tcl
20
dan68928b62010-06-22 13:46:43 +000021# Do not use a codec for this file, as the database is manipulated using
22# external methods (the [fake_big_file] and [hexio_write] commands).
23#
24do_not_use_codec
25
danielk197726c5d792005-11-25 09:01:23 +000026# If SQLITE_DISABLE_LFS is defined, omit this file.
27ifcapable !lfs {
28 finish_test
29 return
30}
31
drh52025602003-12-19 12:31:19 +000032# These tests only work for Tcl version 8.4 and later. Prior to 8.4,
33# Tcl was unable to handle large files.
34#
35scan $::tcl_version %f vx
36if {$vx<8.4} return
37
drh3ea64402004-06-30 11:28:13 +000038# Mac OS X does not handle large files efficiently. So skip this test
39# on that platform.
40if {$tcl_platform(os)=="Darwin"} return
41
drhd0d006e2002-12-01 02:00:57 +000042# This is the md5 checksum of all the data in table t1 as created
43# by the first test. We will use this number to make sure that data
44# never changes.
45#
46set MAGIC_SUM {593f1efcfdbe698c28b4b1b693f7e4cf}
47
48do_test bigfile-1.1 {
49 execsql {
50 BEGIN;
51 CREATE TABLE t1(x);
52 INSERT INTO t1 VALUES('abcdefghijklmnopqrstuvwxyz');
53 INSERT INTO t1 SELECT rowid || ' ' || x FROM t1;
54 INSERT INTO t1 SELECT rowid || ' ' || x FROM t1;
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 COMMIT;
61 }
62 execsql {
63 SELECT md5sum(x) FROM t1;
64 }
65} $::MAGIC_SUM
66
drhf33cb422002-12-17 14:13:48 +000067# Try to create a large file - a file that is larger than 2^32 bytes.
68# If this fails, it means that the system being tested does not support
69# large files. So skip all of the remaining tests in this file.
70#
71db close
drh107886a2008-11-21 22:21:50 +000072if {[catch {fake_big_file 4096 [pwd]/test.db} msg]} {
drhf33cb422002-12-17 14:13:48 +000073 puts "**** Unable to create a file larger than 4096 MB. *****"
74 finish_test
75 return
76}
drh43377f52010-04-01 16:15:56 +000077hexio_write test.db 28 00000000
drhf33cb422002-12-17 14:13:48 +000078
drhd0d006e2002-12-01 02:00:57 +000079do_test bigfile-1.2 {
drhef4ac8f2004-06-19 00:16:31 +000080 sqlite3 db test.db
drhd0d006e2002-12-01 02:00:57 +000081 execsql {
82 SELECT md5sum(x) FROM t1;
83 }
84} $::MAGIC_SUM
85
86# The previous test may fail on some systems because they are unable
87# to handle large files. If that is so, then skip all of the following
88# tests. We will know the above test failed because the "db" command
89# does not exist.
90#
shane3c9cfa92009-03-05 04:27:08 +000091if {[llength [info command db]]<=0} {
92 puts "**** Large file support appears to be broken. *****"
93 finish_test
94 return
95}
drhd0d006e2002-12-01 02:00:57 +000096
97do_test bigfile-1.3 {
98 execsql {
99 CREATE TABLE t2 AS SELECT * FROM t1;
100 SELECT md5sum(x) FROM t2;
101 }
102} $::MAGIC_SUM
103do_test bigfile-1.4 {
104 db close
drhef4ac8f2004-06-19 00:16:31 +0000105 sqlite3 db test.db
drhd0d006e2002-12-01 02:00:57 +0000106 execsql {
107 SELECT md5sum(x) FROM t1;
108 }
109} $::MAGIC_SUM
drhf33cb422002-12-17 14:13:48 +0000110
111db close
drh107886a2008-11-21 22:21:50 +0000112if {[catch {fake_big_file 8192 [pwd]/test.db}]} {
drhf33cb422002-12-17 14:13:48 +0000113 puts "**** Unable to create a file larger than 8192 MB. *****"
114 finish_test
115 return
116}
drh43377f52010-04-01 16:15:56 +0000117hexio_write test.db 28 00000000
drhf33cb422002-12-17 14:13:48 +0000118
shane3c9cfa92009-03-05 04:27:08 +0000119do_test bigfile-1.5 {
drhef4ac8f2004-06-19 00:16:31 +0000120 sqlite3 db test.db
drhd0d006e2002-12-01 02:00:57 +0000121 execsql {
122 SELECT md5sum(x) FROM t1;
123 }
124} $::MAGIC_SUM
shane3c9cfa92009-03-05 04:27:08 +0000125do_test bigfile-1.6 {
126 sqlite3 db test.db
127 execsql {
128 SELECT md5sum(x) FROM t2;
129 }
130} $::MAGIC_SUM
drhd0d006e2002-12-01 02:00:57 +0000131do_test bigfile-1.7 {
132 execsql {
133 CREATE TABLE t3 AS SELECT * FROM t1;
134 SELECT md5sum(x) FROM t3;
135 }
136} $::MAGIC_SUM
137do_test bigfile-1.8 {
138 db close
drhef4ac8f2004-06-19 00:16:31 +0000139 sqlite3 db test.db
drhd0d006e2002-12-01 02:00:57 +0000140 execsql {
141 SELECT md5sum(x) FROM t1;
142 }
143} $::MAGIC_SUM
144do_test bigfile-1.9 {
145 execsql {
146 SELECT md5sum(x) FROM t2;
147 }
148} $::MAGIC_SUM
drhf33cb422002-12-17 14:13:48 +0000149
150db close
drh107886a2008-11-21 22:21:50 +0000151if {[catch {fake_big_file 16384 [pwd]/test.db}]} {
drhf33cb422002-12-17 14:13:48 +0000152 puts "**** Unable to create a file larger than 16384 MB. *****"
153 finish_test
154 return
155}
drh43377f52010-04-01 16:15:56 +0000156hexio_write test.db 28 00000000
drhf33cb422002-12-17 14:13:48 +0000157
shane3c9cfa92009-03-05 04:27:08 +0000158do_test bigfile-1.10 {
drhef4ac8f2004-06-19 00:16:31 +0000159 sqlite3 db test.db
drhd0d006e2002-12-01 02:00:57 +0000160 execsql {
161 SELECT md5sum(x) FROM t1;
162 }
163} $::MAGIC_SUM
shane3c9cfa92009-03-05 04:27:08 +0000164do_test bigfile-1.11 {
165 sqlite3 db test.db
166 execsql {
167 SELECT md5sum(x) FROM t2;
168 }
169} $::MAGIC_SUM
drhd0d006e2002-12-01 02:00:57 +0000170do_test bigfile-1.12 {
shane3c9cfa92009-03-05 04:27:08 +0000171 sqlite3 db test.db
172 execsql {
173 SELECT md5sum(x) FROM t3;
174 }
175} $::MAGIC_SUM
176do_test bigfile-1.13 {
drhd0d006e2002-12-01 02:00:57 +0000177 execsql {
178 CREATE TABLE t4 AS SELECT * FROM t1;
179 SELECT md5sum(x) FROM t4;
180 }
181} $::MAGIC_SUM
shane3c9cfa92009-03-05 04:27:08 +0000182do_test bigfile-1.14 {
drhd0d006e2002-12-01 02:00:57 +0000183 db close
drhef4ac8f2004-06-19 00:16:31 +0000184 sqlite3 db test.db
drhd0d006e2002-12-01 02:00:57 +0000185 execsql {
186 SELECT md5sum(x) FROM t1;
187 }
188} $::MAGIC_SUM
drhd0d006e2002-12-01 02:00:57 +0000189do_test bigfile-1.15 {
190 execsql {
shane3c9cfa92009-03-05 04:27:08 +0000191 SELECT md5sum(x) FROM t2;
drhd0d006e2002-12-01 02:00:57 +0000192 }
193} $::MAGIC_SUM
194do_test bigfile-1.16 {
195 execsql {
196 SELECT md5sum(x) FROM t3;
197 }
198} $::MAGIC_SUM
drhd0d006e2002-12-01 02:00:57 +0000199
200finish_test