xref: /sqlite-3.40.0/test/bigfile2.test (revision f8a78464)
1# 2011 December 20
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
16set testdir [file dirname $argv0]
17source $testdir/tester.tcl
18set testprefix bigfile2
19
20# Create a small database.
21#
22do_execsql_test 1.1 {
23  CREATE TABLE t1(a, b);
24  INSERT INTO t1 VALUES(1, 2);
25}
26
27# Pad the file out to 4GB in size. Then clear the file-size field in the
28# db header. This will cause SQLite to assume that the first 4GB of pages
29# are actually in use and new pages will be appended to the file.
30#
31db close
32if {[catch {fake_big_file 4096 [get_pwd]/test.db} msg]} {
33  puts "**** Unable to create a file larger than 4096 MB. *****"
34  finish_test
35  return
36}
37hexio_write test.db 28 00000000
38
39do_test 1.2 {
40  file size test.db
41} [expr 14 + 4096 * (1<<20)]
42
43# Now insert a large row. The overflow pages will be located past the 4GB
44# boundary. Then, after opening and closing the database, test that the row
45# can be read back in.
46#
47set str [string repeat k 30000]
48do_test 1.3 {
49  sqlite3 db test.db
50  execsql { INSERT INTO t1 VALUES(3, $str) }
51  db close
52  sqlite3 db test.db
53  db one { SELECT b FROM t1 WHERE a = 3 }
54} $str
55
56db close
57file delete test.db
58
59finish_test
60