2 #pragma ident "%Z%%M% %I% %E% SMI"
6 # The author disclaims copyright to this source code. In place of
7 # a legal notice, here is a blessing:
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.
13 #***********************************************************************
14 # This file implements regression tests for SQLite library. The
15 # focus of this file is stressing the library by putting large amounts
16 # of data in a single row of a table.
18 # $Id: bigrow.test,v 1.4 2001/11/24 00:31:47 drh Exp $
20 set testdir [file dirname $argv0]
21 source $testdir/tester.tcl
23 # Make a big string that we can use for test data
27 for {set i 1} {$i<=9999} {incr i} {
28 set sep [string index "abcdefghijklmnopqrstuvwxyz" [expr {$i%26}]]
29 append ::bigstr "$sep [format %04d $i] "
31 string length $::bigstr
34 # Make a table into which we can insert some but records.
38 CREATE TABLE t1(a text, b text, c text);
39 SELECT name FROM sqlite_master
40 WHERE type='table' OR type='index'
46 set ::big1 [string range $::bigstr 0 65519]
47 set sql "INSERT INTO t1 VALUES('abc',"
48 append sql "'$::big1', 'xyz');"
50 execsql {SELECT a, c FROM t1}
53 execsql {SELECT b FROM t1}
56 set ::big2 [string range $::bigstr 0 65520]
57 set sql "INSERT INTO t1 VALUES('abc2',"
58 append sql "'$::big2', 'xyz2');"
59 set r [catch {execsql $sql} msg]
62 do_test bigrow-1.4.1 {
63 execsql {SELECT b FROM t1 ORDER BY c}
64 } [list $::big1 $::big2]
65 do_test bigrow-1.4.2 {
66 execsql {SELECT c FROM t1 ORDER BY c}
68 do_test bigrow-1.4.3 {
69 execsql {DELETE FROM t1 WHERE a='abc2'}
70 execsql {SELECT c FROM t1}
75 UPDATE t1 SET a=b, b=a;
83 } [list $::big1 abc xyz]
86 INSERT INTO t1 VALUES('1','2','3');
87 INSERT INTO t1 VALUES('A','B','C');
88 SELECT b FROM t1 WHERE a=='1';
92 execsql "SELECT b FROM t1 WHERE a=='$::big1'"
95 execsql "SELECT b FROM t1 WHERE a!='$::big1' ORDER BY a"
98 # Try doing some indexing on big columns
102 CREATE INDEX i1 ON t1(a)
104 execsql "SELECT b FROM t1 WHERE a=='$::big1'"
108 UPDATE t1 SET a=b, b=a
110 execsql "SELECT b FROM t1 WHERE a=='abc'"
114 UPDATE t1 SET a=b, b=a
116 execsql "SELECT b FROM t1 WHERE a=='$::big1'"
118 catch {unset ::bigstr}
122 # Mosts of the tests above were created back when rows were limited in
123 # size to 64K. Now rows can be much bigger. Test that logic. Also
124 # make sure things work correctly at the transition boundries between
125 # row sizes of 256 to 257 bytes and from 65536 to 65537 bytes.
127 # We begin by testing the 256..257 transition.
132 INSERT INTO t1(a,b,c) VALUES('one','abcdefghijklmnopqrstuvwxyz0123','hi');
134 execsql {SELECT a,length(b),c FROM t1}
138 UPDATE t1 SET b=b||b;
139 UPDATE t1 SET b=b||b;
140 UPDATE t1 SET b=b||b;
142 execsql {SELECT a,length(b),c FROM t1}
144 for {set i 1} {$i<10} {incr i} {
145 do_test bigrow-3.3.$i {
146 execsql "UPDATE t1 SET b=b||'$i'"
147 execsql {SELECT a,length(b),c FROM t1}
148 } "one [expr {240+$i}] hi"
151 # Now test the 65536..65537 row-size transition.
156 INSERT INTO t1(a,b,c) VALUES('one','abcdefghijklmnopqrstuvwxyz0123','hi');
158 execsql {SELECT a,length(b),c FROM t1}
162 UPDATE t1 SET b=b||b;
163 UPDATE t1 SET b=b||b;
164 UPDATE t1 SET b=b||b;
165 UPDATE t1 SET b=b||b;
166 UPDATE t1 SET b=b||b;
167 UPDATE t1 SET b=b||b;
168 UPDATE t1 SET b=b||b;
169 UPDATE t1 SET b=b||b;
170 UPDATE t1 SET b=b||b;
171 UPDATE t1 SET b=b||b;
172 UPDATE t1 SET b=b||b;
173 UPDATE t1 SET b=b||b;
175 execsql {SELECT a,length(b),c FROM t1}
179 UPDATE t1 SET b=substr(b,1,65515)
181 execsql {SELECT a,length(b),c FROM t1}
183 for {set i 1} {$i<10} {incr i} {
184 do_test bigrow-4.4.$i {
185 execsql "UPDATE t1 SET b=b||'$i'"
186 execsql {SELECT a,length(b),c FROM t1}
187 } "one [expr {65515+$i}] hi"
190 # Check to make sure the library recovers safely if a row contains
196 INSERT INTO t1(a,b,c) VALUES('one','abcdefghijklmnopqrstuvwxyz0123','hi');
198 execsql {SELECT a,length(b),c FROM t1}
201 for {set sz 60} {$sz<1048560} {incr sz $sz} {
202 do_test bigrow-5.2.$i {
204 UPDATE t1 SET b=b||b;
205 SELECT a,length(b),c FROM t1;
211 set r [catch {execsql {UPDATE t1 SET b=b||b}} msg]
213 } {1 {too much data for one table row}}
215 execsql {DROP TABLE t1}