3 # The author disclaims copyright to this source code. In place of
4 # a legal notice, here is a blessing:
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.
10 #***********************************************************************
11 # This file implements regression tests for SQLite library. The
12 # focus of this file is stressing the library by putting large amounts
13 # of data in a single row of a table.
15 # $Id: bigrow.test,v 1.5 2004/08/07 23:54:48 drh Exp $
17 set testdir [file dirname $argv0]
18 source $testdir/tester.tcl
20 # Make a big string that we can use for test data
24 for {set i 1} {$i<=9999} {incr i} {
25 set sep [string index "abcdefghijklmnopqrstuvwxyz" [expr {$i%26}]]
26 append ::bigstr "$sep [format %04d $i] "
28 string length $::bigstr
31 # Make a table into which we can insert some but records.
35 CREATE TABLE t1(a text, b text, c text);
36 SELECT name FROM sqlite_master
37 WHERE type='table' OR type='index'
43 set ::big1 [string range $::bigstr 0 65519]
44 set sql "INSERT INTO t1 VALUES('abc',"
45 append sql "'$::big1', 'xyz');"
47 execsql {SELECT a, c FROM t1}
50 execsql {SELECT b FROM t1}
53 set ::big2 [string range $::bigstr 0 65520]
54 set sql "INSERT INTO t1 VALUES('abc2',"
55 append sql "'$::big2', 'xyz2');"
56 set r [catch {execsql $sql} msg]
59 do_test bigrow-1.4.1 {
60 execsql {SELECT b FROM t1 ORDER BY c}
61 } [list $::big1 $::big2]
62 do_test bigrow-1.4.2 {
63 execsql {SELECT c FROM t1 ORDER BY c}
65 do_test bigrow-1.4.3 {
66 execsql {DELETE FROM t1 WHERE a='abc2'}
67 execsql {SELECT c FROM t1}
72 UPDATE t1 SET a=b, b=a;
80 } [list $::big1 abc xyz]
83 INSERT INTO t1 VALUES('1','2','3');
84 INSERT INTO t1 VALUES('A','B','C');
85 SELECT b FROM t1 WHERE a=='1';
89 execsql "SELECT b FROM t1 WHERE a=='$::big1'"
92 execsql "SELECT b FROM t1 WHERE a!='$::big1' ORDER BY a"
95 # Try doing some indexing on big columns
99 CREATE INDEX i1 ON t1(a)
101 execsql "SELECT b FROM t1 WHERE a=='$::big1'"
105 UPDATE t1 SET a=b, b=a
107 execsql "SELECT b FROM t1 WHERE a=='abc'"
111 UPDATE t1 SET a=b, b=a
113 execsql "SELECT b FROM t1 WHERE a=='$::big1'"
115 catch {unset ::bigstr}
119 # Mosts of the tests above were created back when rows were limited in
120 # size to 64K. Now rows can be much bigger. Test that logic. Also
121 # make sure things work correctly at the transition boundries between
122 # row sizes of 256 to 257 bytes and from 65536 to 65537 bytes.
124 # We begin by testing the 256..257 transition.
129 INSERT INTO t1(a,b,c) VALUES('one','abcdefghijklmnopqrstuvwxyz0123','hi');
131 execsql {SELECT a,length(b),c FROM t1}
135 UPDATE t1 SET b=b||b;
136 UPDATE t1 SET b=b||b;
137 UPDATE t1 SET b=b||b;
139 execsql {SELECT a,length(b),c FROM t1}
141 for {set i 1} {$i<10} {incr i} {
142 do_test bigrow-3.3.$i {
143 execsql "UPDATE t1 SET b=b||'$i'"
144 execsql {SELECT a,length(b),c FROM t1}
145 } "one [expr {240+$i}] hi"
148 # Now test the 65536..65537 row-size transition.
153 INSERT INTO t1(a,b,c) VALUES('one','abcdefghijklmnopqrstuvwxyz0123','hi');
155 execsql {SELECT a,length(b),c FROM t1}
159 UPDATE t1 SET b=b||b;
160 UPDATE t1 SET b=b||b;
161 UPDATE t1 SET b=b||b;
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;
172 execsql {SELECT a,length(b),c FROM t1}
176 UPDATE t1 SET b=substr(b,1,65515)
178 execsql {SELECT a,length(b),c FROM t1}
180 for {set i 1} {$i<10} {incr i} {
181 do_test bigrow-4.4.$i {
182 execsql "UPDATE t1 SET b=b||'$i'"
183 execsql {SELECT a,length(b),c FROM t1}
184 } "one [expr {65515+$i}] hi"
187 # Check to make sure the library recovers safely if a row contains
193 INSERT INTO t1(a,b,c) VALUES('one','abcdefghijklmnopqrstuvwxyz0123','hi');
195 execsql {SELECT a,length(b),c FROM t1}
198 for {set sz 60} {$sz<1048560} {incr sz $sz} {
199 do_test bigrow-5.2.$i {
201 UPDATE t1 SET b=b||b;
202 SELECT a,length(b),c FROM t1;
208 catchsql {UPDATE t1 SET b=b||b}
211 execsql {SELECT length(b) FROM t1}
214 catchsql {UPDATE t1 SET b=b||b}
217 execsql {SELECT length(b) FROM t1}
219 do_test bigrow-5.99 {
220 execsql {DROP TABLE t1}