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