xref: /sqlite-3.40.0/test/bigfile2.test (revision 9ac99313)
127d47fbeSdan# 2011 December 20
227d47fbeSdan#
327d47fbeSdan# The author disclaims copyright to this source code.  In place of
427d47fbeSdan# a legal notice, here is a blessing:
527d47fbeSdan#
627d47fbeSdan#    May you do good and not evil.
727d47fbeSdan#    May you find forgiveness for yourself and forgive others.
827d47fbeSdan#    May you share freely, never taking more than you give.
927d47fbeSdan#
1027d47fbeSdan#***********************************************************************
1127d47fbeSdan# This file implements regression tests for SQLite library.  The
1227d47fbeSdan# focus of this script testing the ability of SQLite to handle database
1327d47fbeSdan# files larger than 4GB.
1427d47fbeSdan#
1527d47fbeSdan
16ee3a77deSdrhif {[file exists skip-big-file]} return
17befda465Sdrhif {$tcl_platform(os)=="Darwin"} return
18ee3a77deSdrh
1927d47fbeSdanset testdir [file dirname $argv0]
2027d47fbeSdansource $testdir/tester.tcl
2127d47fbeSdanset testprefix bigfile2
2227d47fbeSdan
2327d47fbeSdan# Create a small database.
2427d47fbeSdan#
2527d47fbeSdando_execsql_test 1.1 {
2627d47fbeSdan  CREATE TABLE t1(a, b);
2727d47fbeSdan  INSERT INTO t1 VALUES(1, 2);
2827d47fbeSdan}
2927d47fbeSdan
3027d47fbeSdan# Pad the file out to 4GB in size. Then clear the file-size field in the
3127d47fbeSdan# db header. This will cause SQLite to assume that the first 4GB of pages
3227d47fbeSdan# are actually in use and new pages will be appended to the file.
3327d47fbeSdan#
3427d47fbeSdandb close
35f8a78464Smistachkinif {[catch {fake_big_file 4096 [get_pwd]/test.db} msg]} {
3627d47fbeSdan  puts "**** Unable to create a file larger than 4096 MB. *****"
3727d47fbeSdan  finish_test
3827d47fbeSdan  return
3927d47fbeSdan}
4027d47fbeSdanhexio_write test.db 28 00000000
4127d47fbeSdan
4227d47fbeSdando_test 1.2 {
4327d47fbeSdan  file size test.db
4427d47fbeSdan} [expr 14 + 4096 * (1<<20)]
4527d47fbeSdan
4627d47fbeSdan# Now insert a large row. The overflow pages will be located past the 4GB
4727d47fbeSdan# boundary. Then, after opening and closing the database, test that the row
4827d47fbeSdan# can be read back in.
4927d47fbeSdan#
5027d47fbeSdanset str [string repeat k 30000]
5127d47fbeSdando_test 1.3 {
5227d47fbeSdan  sqlite3 db test.db
5327d47fbeSdan  execsql { INSERT INTO t1 VALUES(3, $str) }
5427d47fbeSdan  db close
5527d47fbeSdan  sqlite3 db test.db
5627d47fbeSdan  db one { SELECT b FROM t1 WHERE a = 3 }
5727d47fbeSdan} $str
5827d47fbeSdan
5927d47fbeSdandb close
60*9ac99313Smistachkindelete_file test.db
6127d47fbeSdan
6227d47fbeSdanfinish_test
63