1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/persistentdata/persistentstorage/sqlite3api/TEST/TclScript/bigrow.test Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,223 @@
1.4 +# 2001 September 23
1.5 +#
1.6 +# The author disclaims copyright to this source code. In place of
1.7 +# a legal notice, here is a blessing:
1.8 +#
1.9 +# May you do good and not evil.
1.10 +# May you find forgiveness for yourself and forgive others.
1.11 +# May you share freely, never taking more than you give.
1.12 +#
1.13 +#***********************************************************************
1.14 +# This file implements regression tests for SQLite library. The
1.15 +# focus of this file is stressing the library by putting large amounts
1.16 +# of data in a single row of a table.
1.17 +#
1.18 +# $Id: bigrow.test,v 1.5 2004/08/07 23:54:48 drh Exp $
1.19 +
1.20 +set testdir [file dirname $argv0]
1.21 +source $testdir/tester.tcl
1.22 +
1.23 +# Make a big string that we can use for test data
1.24 +#
1.25 +do_test bigrow-1.0 {
1.26 + set ::bigstr {}
1.27 + for {set i 1} {$i<=9999} {incr i} {
1.28 + set sep [string index "abcdefghijklmnopqrstuvwxyz" [expr {$i%26}]]
1.29 + append ::bigstr "$sep [format %04d $i] "
1.30 + }
1.31 + string length $::bigstr
1.32 +} {69993}
1.33 +
1.34 +# Make a table into which we can insert some but records.
1.35 +#
1.36 +do_test bigrow-1.1 {
1.37 + execsql {
1.38 + CREATE TABLE t1(a text, b text, c text);
1.39 + SELECT name FROM sqlite_master
1.40 + WHERE type='table' OR type='index'
1.41 + ORDER BY name
1.42 + }
1.43 +} {t1}
1.44 +
1.45 +do_test bigrow-1.2 {
1.46 + set ::big1 [string range $::bigstr 0 65519]
1.47 + set sql "INSERT INTO t1 VALUES('abc',"
1.48 + append sql "'$::big1', 'xyz');"
1.49 + execsql $sql
1.50 + execsql {SELECT a, c FROM t1}
1.51 +} {abc xyz}
1.52 +do_test bigrow-1.3 {
1.53 + execsql {SELECT b FROM t1}
1.54 +} [list $::big1]
1.55 +do_test bigrow-1.4 {
1.56 + set ::big2 [string range $::bigstr 0 65520]
1.57 + set sql "INSERT INTO t1 VALUES('abc2',"
1.58 + append sql "'$::big2', 'xyz2');"
1.59 + set r [catch {execsql $sql} msg]
1.60 + lappend r $msg
1.61 +} {0 {}}
1.62 +do_test bigrow-1.4.1 {
1.63 + execsql {SELECT b FROM t1 ORDER BY c}
1.64 +} [list $::big1 $::big2]
1.65 +do_test bigrow-1.4.2 {
1.66 + execsql {SELECT c FROM t1 ORDER BY c}
1.67 +} {xyz xyz2}
1.68 +do_test bigrow-1.4.3 {
1.69 + execsql {DELETE FROM t1 WHERE a='abc2'}
1.70 + execsql {SELECT c FROM t1}
1.71 +} {xyz}
1.72 +
1.73 +do_test bigrow-1.5 {
1.74 + execsql {
1.75 + UPDATE t1 SET a=b, b=a;
1.76 + SELECT b,c FROM t1
1.77 + }
1.78 +} {abc xyz}
1.79 +do_test bigrow-1.6 {
1.80 + execsql {
1.81 + SELECT * FROM t1
1.82 + }
1.83 +} [list $::big1 abc xyz]
1.84 +do_test bigrow-1.7 {
1.85 + execsql {
1.86 + INSERT INTO t1 VALUES('1','2','3');
1.87 + INSERT INTO t1 VALUES('A','B','C');
1.88 + SELECT b FROM t1 WHERE a=='1';
1.89 + }
1.90 +} {2}
1.91 +do_test bigrow-1.8 {
1.92 + execsql "SELECT b FROM t1 WHERE a=='$::big1'"
1.93 +} {abc}
1.94 +do_test bigrow-1.9 {
1.95 + execsql "SELECT b FROM t1 WHERE a!='$::big1' ORDER BY a"
1.96 +} {2 B}
1.97 +
1.98 +# Try doing some indexing on big columns
1.99 +#
1.100 +do_test bigrow-2.1 {
1.101 + execsql {
1.102 + CREATE INDEX i1 ON t1(a)
1.103 + }
1.104 + execsql "SELECT b FROM t1 WHERE a=='$::big1'"
1.105 +} {abc}
1.106 +do_test bigrow-2.2 {
1.107 + execsql {
1.108 + UPDATE t1 SET a=b, b=a
1.109 + }
1.110 + execsql "SELECT b FROM t1 WHERE a=='abc'"
1.111 +} [list $::big1]
1.112 +do_test bigrow-2.3 {
1.113 + execsql {
1.114 + UPDATE t1 SET a=b, b=a
1.115 + }
1.116 + execsql "SELECT b FROM t1 WHERE a=='$::big1'"
1.117 +} {abc}
1.118 +catch {unset ::bigstr}
1.119 +catch {unset ::big1}
1.120 +catch {unset ::big2}
1.121 +
1.122 +# Mosts of the tests above were created back when rows were limited in
1.123 +# size to 64K. Now rows can be much bigger. Test that logic. Also
1.124 +# make sure things work correctly at the transition boundries between
1.125 +# row sizes of 256 to 257 bytes and from 65536 to 65537 bytes.
1.126 +#
1.127 +# We begin by testing the 256..257 transition.
1.128 +#
1.129 +do_test bigrow-3.1 {
1.130 + execsql {
1.131 + DELETE FROM t1;
1.132 + INSERT INTO t1(a,b,c) VALUES('one','abcdefghijklmnopqrstuvwxyz0123','hi');
1.133 + }
1.134 + execsql {SELECT a,length(b),c FROM t1}
1.135 +} {one 30 hi}
1.136 +do_test bigrow-3.2 {
1.137 + execsql {
1.138 + UPDATE t1 SET b=b||b;
1.139 + UPDATE t1 SET b=b||b;
1.140 + UPDATE t1 SET b=b||b;
1.141 + }
1.142 + execsql {SELECT a,length(b),c FROM t1}
1.143 +} {one 240 hi}
1.144 +for {set i 1} {$i<10} {incr i} {
1.145 + do_test bigrow-3.3.$i {
1.146 + execsql "UPDATE t1 SET b=b||'$i'"
1.147 + execsql {SELECT a,length(b),c FROM t1}
1.148 + } "one [expr {240+$i}] hi"
1.149 +}
1.150 +
1.151 +# Now test the 65536..65537 row-size transition.
1.152 +#
1.153 +do_test bigrow-4.1 {
1.154 + execsql {
1.155 + DELETE FROM t1;
1.156 + INSERT INTO t1(a,b,c) VALUES('one','abcdefghijklmnopqrstuvwxyz0123','hi');
1.157 + }
1.158 + execsql {SELECT a,length(b),c FROM t1}
1.159 +} {one 30 hi}
1.160 +do_test bigrow-4.2 {
1.161 + execsql {
1.162 + UPDATE t1 SET b=b||b;
1.163 + UPDATE t1 SET b=b||b;
1.164 + UPDATE t1 SET b=b||b;
1.165 + UPDATE t1 SET b=b||b;
1.166 + UPDATE t1 SET b=b||b;
1.167 + UPDATE t1 SET b=b||b;
1.168 + UPDATE t1 SET b=b||b;
1.169 + UPDATE t1 SET b=b||b;
1.170 + UPDATE t1 SET b=b||b;
1.171 + UPDATE t1 SET b=b||b;
1.172 + UPDATE t1 SET b=b||b;
1.173 + UPDATE t1 SET b=b||b;
1.174 + }
1.175 + execsql {SELECT a,length(b),c FROM t1}
1.176 +} {one 122880 hi}
1.177 +do_test bigrow-4.3 {
1.178 + execsql {
1.179 + UPDATE t1 SET b=substr(b,1,65515)
1.180 + }
1.181 + execsql {SELECT a,length(b),c FROM t1}
1.182 +} {one 65515 hi}
1.183 +for {set i 1} {$i<10} {incr i} {
1.184 + do_test bigrow-4.4.$i {
1.185 + execsql "UPDATE t1 SET b=b||'$i'"
1.186 + execsql {SELECT a,length(b),c FROM t1}
1.187 + } "one [expr {65515+$i}] hi"
1.188 +}
1.189 +
1.190 +# Check to make sure the library recovers safely if a row contains
1.191 +# too much data.
1.192 +#
1.193 +do_test bigrow-5.1 {
1.194 + execsql {
1.195 + DELETE FROM t1;
1.196 + INSERT INTO t1(a,b,c) VALUES('one','abcdefghijklmnopqrstuvwxyz0123','hi');
1.197 + }
1.198 + execsql {SELECT a,length(b),c FROM t1}
1.199 +} {one 30 hi}
1.200 +set i 1
1.201 +for {set sz 60} {$sz<1048560} {incr sz $sz} {
1.202 + do_test bigrow-5.2.$i {
1.203 + execsql {
1.204 + UPDATE t1 SET b=b||b;
1.205 + SELECT a,length(b),c FROM t1;
1.206 + }
1.207 + } "one $sz hi"
1.208 + incr i
1.209 +}
1.210 +do_test bigrow-5.3 {
1.211 + catchsql {UPDATE t1 SET b=b||b}
1.212 +} {0 {}}
1.213 +do_test bigrow-5.4 {
1.214 + execsql {SELECT length(b) FROM t1}
1.215 +} 1966080
1.216 +do_test bigrow-5.5 {
1.217 + catchsql {UPDATE t1 SET b=b||b}
1.218 +} {0 {}}
1.219 +do_test bigrow-5.6 {
1.220 + execsql {SELECT length(b) FROM t1}
1.221 +} 3932160
1.222 +do_test bigrow-5.99 {
1.223 + execsql {DROP TABLE t1}
1.224 +} {}
1.225 +
1.226 +finish_test