blob: 31c632322c726b085a543fde874aeaa63b3cb472 [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
drhee3a77d2012-03-01 22:33:41 +000018if {[file exists skip-big-file]} return
drhbefda462012-09-29 15:45:12 +000019if {$tcl_platform(os)=="Darwin"} return
drhee3a77d2012-03-01 22:33:41 +000020
drhd0d006e2002-12-01 02:00:57 +000021set testdir [file dirname $argv0]
22source $testdir/tester.tcl
23
dan68928b62010-06-22 13:46:43 +000024# Do not use a codec for this file, as the database is manipulated using
25# external methods (the [fake_big_file] and [hexio_write] commands).
26#
27do_not_use_codec
28
danielk197726c5d792005-11-25 09:01:23 +000029# If SQLITE_DISABLE_LFS is defined, omit this file.
30ifcapable !lfs {
31 finish_test
32 return
33}
34
drh52025602003-12-19 12:31:19 +000035# These tests only work for Tcl version 8.4 and later. Prior to 8.4,
36# Tcl was unable to handle large files.
37#
38scan $::tcl_version %f vx
39if {$vx<8.4} return
40
drh3ea64402004-06-30 11:28:13 +000041# Mac OS X does not handle large files efficiently. So skip this test
42# on that platform.
43if {$tcl_platform(os)=="Darwin"} return
44
drhd0d006e2002-12-01 02:00:57 +000045# This is the md5 checksum of all the data in table t1 as created
46# by the first test. We will use this number to make sure that data
47# never changes.
48#
49set MAGIC_SUM {593f1efcfdbe698c28b4b1b693f7e4cf}
50
51do_test bigfile-1.1 {
52 execsql {
53 BEGIN;
54 CREATE TABLE t1(x);
55 INSERT INTO t1 VALUES('abcdefghijklmnopqrstuvwxyz');
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 INSERT INTO t1 SELECT rowid || ' ' || x FROM t1;
63 COMMIT;
64 }
65 execsql {
66 SELECT md5sum(x) FROM t1;
67 }
68} $::MAGIC_SUM
69
drhf33cb422002-12-17 14:13:48 +000070# Try to create a large file - a file that is larger than 2^32 bytes.
71# If this fails, it means that the system being tested does not support
72# large files. So skip all of the remaining tests in this file.
73#
74db close
mistachkinf8a78462012-03-08 20:00:36 +000075if {[catch {fake_big_file 4096 [get_pwd]/test.db} msg]} {
drhf33cb422002-12-17 14:13:48 +000076 puts "**** Unable to create a file larger than 4096 MB. *****"
77 finish_test
78 return
79}
drh43377f52010-04-01 16:15:56 +000080hexio_write test.db 28 00000000
drhf33cb422002-12-17 14:13:48 +000081
drhd0d006e2002-12-01 02:00:57 +000082do_test bigfile-1.2 {
drhef4ac8f2004-06-19 00:16:31 +000083 sqlite3 db test.db
drhd0d006e2002-12-01 02:00:57 +000084 execsql {
85 SELECT md5sum(x) FROM t1;
86 }
87} $::MAGIC_SUM
88
89# The previous test may fail on some systems because they are unable
90# to handle large files. If that is so, then skip all of the following
91# tests. We will know the above test failed because the "db" command
92# does not exist.
93#
shane3c9cfa92009-03-05 04:27:08 +000094if {[llength [info command db]]<=0} {
95 puts "**** Large file support appears to be broken. *****"
96 finish_test
97 return
98}
drhd0d006e2002-12-01 02:00:57 +000099
100do_test bigfile-1.3 {
101 execsql {
102 CREATE TABLE t2 AS SELECT * FROM t1;
103 SELECT md5sum(x) FROM t2;
104 }
105} $::MAGIC_SUM
106do_test bigfile-1.4 {
107 db close
drhef4ac8f2004-06-19 00:16:31 +0000108 sqlite3 db test.db
drhd0d006e2002-12-01 02:00:57 +0000109 execsql {
110 SELECT md5sum(x) FROM t1;
111 }
112} $::MAGIC_SUM
drhf33cb422002-12-17 14:13:48 +0000113
114db close
mistachkinf8a78462012-03-08 20:00:36 +0000115if {[catch {fake_big_file 8192 [get_pwd]/test.db}]} {
drhf33cb422002-12-17 14:13:48 +0000116 puts "**** Unable to create a file larger than 8192 MB. *****"
117 finish_test
118 return
119}
drh43377f52010-04-01 16:15:56 +0000120hexio_write test.db 28 00000000
drhf33cb422002-12-17 14:13:48 +0000121
shane3c9cfa92009-03-05 04:27:08 +0000122do_test bigfile-1.5 {
drhef4ac8f2004-06-19 00:16:31 +0000123 sqlite3 db test.db
drhd0d006e2002-12-01 02:00:57 +0000124 execsql {
125 SELECT md5sum(x) FROM t1;
126 }
127} $::MAGIC_SUM
shane3c9cfa92009-03-05 04:27:08 +0000128do_test bigfile-1.6 {
129 sqlite3 db test.db
130 execsql {
131 SELECT md5sum(x) FROM t2;
132 }
133} $::MAGIC_SUM
drhd0d006e2002-12-01 02:00:57 +0000134do_test bigfile-1.7 {
135 execsql {
136 CREATE TABLE t3 AS SELECT * FROM t1;
137 SELECT md5sum(x) FROM t3;
138 }
139} $::MAGIC_SUM
140do_test bigfile-1.8 {
141 db close
drhef4ac8f2004-06-19 00:16:31 +0000142 sqlite3 db test.db
drhd0d006e2002-12-01 02:00:57 +0000143 execsql {
144 SELECT md5sum(x) FROM t1;
145 }
146} $::MAGIC_SUM
147do_test bigfile-1.9 {
148 execsql {
149 SELECT md5sum(x) FROM t2;
150 }
151} $::MAGIC_SUM
drhf33cb422002-12-17 14:13:48 +0000152
153db close
mistachkinf8a78462012-03-08 20:00:36 +0000154if {[catch {fake_big_file 16384 [get_pwd]/test.db}]} {
drhf33cb422002-12-17 14:13:48 +0000155 puts "**** Unable to create a file larger than 16384 MB. *****"
156 finish_test
157 return
158}
drh43377f52010-04-01 16:15:56 +0000159hexio_write test.db 28 00000000
drhf33cb422002-12-17 14:13:48 +0000160
shane3c9cfa92009-03-05 04:27:08 +0000161do_test bigfile-1.10 {
drhef4ac8f2004-06-19 00:16:31 +0000162 sqlite3 db test.db
drhd0d006e2002-12-01 02:00:57 +0000163 execsql {
164 SELECT md5sum(x) FROM t1;
165 }
166} $::MAGIC_SUM
shane3c9cfa92009-03-05 04:27:08 +0000167do_test bigfile-1.11 {
168 sqlite3 db test.db
169 execsql {
170 SELECT md5sum(x) FROM t2;
171 }
172} $::MAGIC_SUM
drhd0d006e2002-12-01 02:00:57 +0000173do_test bigfile-1.12 {
shane3c9cfa92009-03-05 04:27:08 +0000174 sqlite3 db test.db
175 execsql {
176 SELECT md5sum(x) FROM t3;
177 }
178} $::MAGIC_SUM
179do_test bigfile-1.13 {
drhd0d006e2002-12-01 02:00:57 +0000180 execsql {
181 CREATE TABLE t4 AS SELECT * FROM t1;
182 SELECT md5sum(x) FROM t4;
183 }
184} $::MAGIC_SUM
shane3c9cfa92009-03-05 04:27:08 +0000185do_test bigfile-1.14 {
drhd0d006e2002-12-01 02:00:57 +0000186 db close
drhef4ac8f2004-06-19 00:16:31 +0000187 sqlite3 db test.db
drhd0d006e2002-12-01 02:00:57 +0000188 execsql {
189 SELECT md5sum(x) FROM t1;
190 }
191} $::MAGIC_SUM
drhd0d006e2002-12-01 02:00:57 +0000192do_test bigfile-1.15 {
193 execsql {
shane3c9cfa92009-03-05 04:27:08 +0000194 SELECT md5sum(x) FROM t2;
drhd0d006e2002-12-01 02:00:57 +0000195 }
196} $::MAGIC_SUM
197do_test bigfile-1.16 {
198 execsql {
199 SELECT md5sum(x) FROM t3;
200 }
201} $::MAGIC_SUM
drhd0d006e2002-12-01 02:00:57 +0000202
203finish_test