1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/persistentdata/persistentstorage/sqlite3api/TEST/TclScript/in2.test Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,67 @@
1.4 +# 2007 May 12
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 tests a special case in the b-tree code that can be
1.15 +# hit by the "IN" operator (or EXISTS, NOT IN, etc.).
1.16 +#
1.17 +# $Id: in2.test,v 1.3 2008/07/12 14:52:20 drh Exp $
1.18 +
1.19 +set testdir [file dirname $argv0]
1.20 +source $testdir/tester.tcl
1.21 +
1.22 +do_test in2-1 {
1.23 + execsql {
1.24 + CREATE TABLE a(i INTEGER PRIMARY KEY, a);
1.25 + }
1.26 +} {}
1.27 +
1.28 +set ::N 2000
1.29 +
1.30 +do_test in2-2 {
1.31 + db transaction {
1.32 + for {set ::ii 0} {$::ii < $::N} {incr ::ii} {
1.33 + execsql {INSERT INTO a VALUES($::ii, $::ii)}
1.34 + }
1.35 + execsql {INSERT INTO a VALUES(4000, '')}
1.36 +
1.37 + for {set ::ii 0} {$::ii < $::N} {incr ::ii} {
1.38 + set ::t [format "x%04d" $ii]
1.39 + execsql {INSERT INTO a VALUES(NULL, $::t)}
1.40 + }
1.41 + }
1.42 +} {}
1.43 +
1.44 +# Each iteration of this loop builds a slightly different b-tree to
1.45 +# evaluate the "IN (...)" operator in the SQL statement. The contents
1.46 +# of the b-tree are (in sorted order):
1.47 +#
1.48 +# $::ii integers.
1.49 +# a string of zero length.
1.50 +# $::N short strings.
1.51 +#
1.52 +# Records are inserted in sorted order.
1.53 +#
1.54 +# The string of zero-length is stored in a b-tree cell with 3 bytes
1.55 +# of payload. Moving this cell from a leaf node to a internal node
1.56 +# during b-tree balancing was causing an assertion failure.
1.57 +#
1.58 +# This bug only applied to b-trees generated to evaluate IN (..)
1.59 +# clauses, as it is impossible for persistent b-trees (SQL tables +
1.60 +# indices) to contain cells smaller than 4 bytes.
1.61 +#
1.62 +for {set ::ii 3} {$::ii < $::N} {incr ::ii} {
1.63 + do_test in2-$::ii {
1.64 + execsql {
1.65 + SELECT 1 IN (SELECT a FROM a WHERE (i < $::ii) OR (i >= $::N))
1.66 + }
1.67 + } {1}
1.68 +}
1.69 +
1.70 +finish_test