xref: /sqlite-3.40.0/test/ovfl.test (revision a23bc8a3)
1*9501a645Sdan# 2014 October 01
2*9501a645Sdan#
3*9501a645Sdan# The author disclaims copyright to this source code.  In place of
4*9501a645Sdan# a legal notice, here is a blessing:
5*9501a645Sdan#
6*9501a645Sdan#    May you do good and not evil.
7*9501a645Sdan#    May you find forgiveness for yourself and forgive others.
8*9501a645Sdan#    May you share freely, never taking more than you give.
9*9501a645Sdan#
10*9501a645Sdan#***********************************************************************
11*9501a645Sdan# This file implements regression tests for SQLite library.  The
12*9501a645Sdan# focus of this file is testing the SQLITE_DIRECT_OVERFLOW_READ logic.
13*9501a645Sdan#
14*9501a645Sdan
15*9501a645Sdanset testdir [file dirname $argv0]
16*9501a645Sdansource $testdir/tester.tcl
17*9501a645Sdanset testprefix ovfl
18*9501a645Sdan
19*9501a645Sdan# Populate table t2:
20*9501a645Sdan#
21*9501a645Sdan#   CREATE TABLE t1(c1 TEXT, c2 TEXT);
22*9501a645Sdan#
23*9501a645Sdan# with 2000 rows. In each row, c2 spans multiple overflow pages. The text
24*9501a645Sdan# value of c1 ranges in size from 1 to 2000 bytes. The idea is to create
25*9501a645Sdan# at least one row where the first byte of c2 is also the first byte of
26*9501a645Sdan# an overflow page. This was at one point exposing an obscure bug in the
27*9501a645Sdan# SQLITE_DIRECT_OVERFLOW_READ logic.
28*9501a645Sdan#
29*9501a645Sdando_test 1.1 {
30*9501a645Sdan  set c2 [string repeat abcdefghij 200]
31*9501a645Sdan  execsql {
32*9501a645Sdan    PRAGMA cache_size = 10;
33*9501a645Sdan    CREATE TABLE t1(c1 TEXT, c2 TEXT);
34*9501a645Sdan    BEGIN;
35*9501a645Sdan  }
36*9501a645Sdan  for {set i 1} {$i <= 2000} {incr i} {
37*9501a645Sdan    set c1 [string repeat . $i]
38*9501a645Sdan    execsql { INSERT INTO t1 VALUES($c1, $c2) }
39*9501a645Sdan  }
40*9501a645Sdan  execsql COMMIT
41*9501a645Sdan} {}
42*9501a645Sdan
43*9501a645Sdando_execsql_test 1.2 {
44*9501a645Sdan  SELECT sum(length(c2)) FROM t1;
45*9501a645Sdan} [expr 2000 * 2000]
46*9501a645Sdan
47*9501a645Sdanfinish_test
48