xref: /sqlite-3.40.0/test/bigfile.test (revision 7aa3ebee)
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
19if {$tcl_platform(os)=="Darwin"} return
20
21set testdir [file dirname $argv0]
22source $testdir/tester.tcl
23
24# 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
29# If SQLITE_DISABLE_LFS is defined, omit this file.
30ifcapable !lfs {
31  finish_test
32  return
33}
34
35# 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
41# Mac OS X does not handle large files efficiently.  So skip this test
42# on that platform.
43if {$tcl_platform(os)=="Darwin"} return
44
45# 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
70# 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
75if {[catch {fake_big_file 4096 [get_pwd]/test.db} msg]} {
76  puts "**** Unable to create a file larger than 4096 MB. *****"
77  finish_test
78  return
79}
80hexio_write test.db 28 00000000
81
82do_test bigfile-1.2 {
83  sqlite3 db test.db
84  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#
94if {[llength [info command db]]<=0} {
95  puts "**** Large file support appears to be broken. *****"
96  finish_test
97  return
98}
99
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
108  sqlite3 db test.db
109  execsql {
110    SELECT md5sum(x) FROM t1;
111  }
112} $::MAGIC_SUM
113
114db close
115if {[catch {fake_big_file 8192 [get_pwd]/test.db}]} {
116  puts "**** Unable to create a file larger than 8192 MB. *****"
117  finish_test
118  return
119}
120hexio_write test.db 28 00000000
121
122do_test bigfile-1.5 {
123  sqlite3 db test.db
124  execsql {
125    SELECT md5sum(x) FROM t1;
126  }
127} $::MAGIC_SUM
128do_test bigfile-1.6 {
129  sqlite3 db test.db
130  execsql {
131    SELECT md5sum(x) FROM t2;
132  }
133} $::MAGIC_SUM
134do_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
142  sqlite3 db test.db
143  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
152
153db close
154if {[catch {fake_big_file 16384 [get_pwd]/test.db}]} {
155  puts "**** Unable to create a file larger than 16384 MB. *****"
156  finish_test
157  return
158}
159hexio_write test.db 28 00000000
160
161do_test bigfile-1.10 {
162  sqlite3 db test.db
163  execsql {
164    SELECT md5sum(x) FROM t1;
165  }
166} $::MAGIC_SUM
167do_test bigfile-1.11 {
168  sqlite3 db test.db
169  execsql {
170    SELECT md5sum(x) FROM t2;
171  }
172} $::MAGIC_SUM
173do_test bigfile-1.12 {
174  sqlite3 db test.db
175  execsql {
176    SELECT md5sum(x) FROM t3;
177  }
178} $::MAGIC_SUM
179do_test bigfile-1.13 {
180  execsql {
181    CREATE TABLE t4 AS SELECT * FROM t1;
182    SELECT md5sum(x) FROM t4;
183  }
184} $::MAGIC_SUM
185do_test bigfile-1.14 {
186  db close
187  sqlite3 db test.db
188  execsql {
189    SELECT md5sum(x) FROM t1;
190  }
191} $::MAGIC_SUM
192do_test bigfile-1.15 {
193  execsql {
194    SELECT md5sum(x) FROM t2;
195  }
196} $::MAGIC_SUM
197do_test bigfile-1.16 {
198  execsql {
199    SELECT md5sum(x) FROM t3;
200  }
201} $::MAGIC_SUM
202
203finish_test
204