1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/persistentdata/persistentstorage/sqlite3api/TEST/TclScript/descidx3.test Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,149 @@
1.4 +# 2006 January 02
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 script is descending indices.
1.16 +#
1.17 +# $Id: descidx3.test,v 1.6 2008/03/19 00:21:31 drh Exp $
1.18 +#
1.19 +
1.20 +set testdir [file dirname $argv0]
1.21 +source $testdir/tester.tcl
1.22 +
1.23 +ifcapable !bloblit {
1.24 + finish_test
1.25 + return
1.26 +}
1.27 +db eval {PRAGMA legacy_file_format=OFF}
1.28 +
1.29 +# This procedure sets the value of the file-format in file 'test.db'
1.30 +# to $newval. Also, the schema cookie is incremented.
1.31 +#
1.32 +proc set_file_format {newval} {
1.33 + hexio_write test.db 44 [hexio_render_int32 $newval]
1.34 + set schemacookie [hexio_get_int [hexio_read test.db 40 4]]
1.35 + incr schemacookie
1.36 + hexio_write test.db 40 [hexio_render_int32 $schemacookie]
1.37 + return {}
1.38 +}
1.39 +
1.40 +# This procedure returns the value of the file-format in file 'test.db'.
1.41 +#
1.42 +proc get_file_format {{fname test.db}} {
1.43 + return [hexio_get_int [hexio_read $fname 44 4]]
1.44 +}
1.45 +
1.46 +# Verify that the file format starts as 4.
1.47 +#
1.48 +do_test descidx3-1.1 {
1.49 + execsql {
1.50 + CREATE TABLE t1(i INTEGER PRIMARY KEY,a,b,c,d);
1.51 + CREATE INDEX t1i1 ON t1(a DESC, b ASC, c DESC);
1.52 + CREATE INDEX t1i2 ON t1(b DESC, c ASC, d DESC);
1.53 + }
1.54 + get_file_format
1.55 +} {4}
1.56 +
1.57 +# Put some information in the table and verify that the descending
1.58 +# index actually works.
1.59 +#
1.60 +do_test descidx3-2.1 {
1.61 + execsql {
1.62 + INSERT INTO t1 VALUES(1, NULL, NULL, NULL, NULL);
1.63 + INSERT INTO t1 VALUES(2, 2, 2, 2, 2);
1.64 + INSERT INTO t1 VALUES(3, 3, 3, 3, 3);
1.65 + INSERT INTO t1 VALUES(4, 2.5, 2.5, 2.5, 2.5);
1.66 + INSERT INTO t1 VALUES(5, -5, -5, -5, -5);
1.67 + INSERT INTO t1 VALUES(6, 'six', 'six', 'six', 'six');
1.68 + INSERT INTO t1 VALUES(7, x'77', x'77', x'77', x'77');
1.69 + INSERT INTO t1 VALUES(8, 'eight', 'eight', 'eight', 'eight');
1.70 + INSERT INTO t1 VALUES(9, x'7979', x'7979', x'7979', x'7979');
1.71 + SELECT count(*) FROM t1;
1.72 + }
1.73 +} 9
1.74 +do_test descidx3-2.2 {
1.75 + execsql {
1.76 + SELECT i FROM t1 ORDER BY a;
1.77 + }
1.78 +} {1 5 2 4 3 8 6 7 9}
1.79 +do_test descidx3-2.3 {
1.80 + execsql {
1.81 + SELECT i FROM t1 ORDER BY a DESC;
1.82 + }
1.83 +} {9 7 6 8 3 4 2 5 1}
1.84 +
1.85 +# The "natural" order for the index is decreasing
1.86 +do_test descidx3-2.4 {
1.87 + execsql {
1.88 + SELECT i FROM t1 WHERE a<=x'7979';
1.89 + }
1.90 +} {9 7 6 8 3 4 2 5}
1.91 +do_test descidx3-2.5 {
1.92 + execsql {
1.93 + SELECT i FROM t1 WHERE a>-99;
1.94 + }
1.95 +} {9 7 6 8 3 4 2 5}
1.96 +
1.97 +# Even when all values of t1.a are the same, sorting by A returns
1.98 +# the rows in reverse order because this the natural order of the
1.99 +# index.
1.100 +#
1.101 +do_test descidx3-3.1 {
1.102 + execsql {
1.103 + UPDATE t1 SET a=1;
1.104 + SELECT i FROM t1 ORDER BY a;
1.105 + }
1.106 +} {9 7 6 8 3 4 2 5 1}
1.107 +do_test descidx3-3.2 {
1.108 + execsql {
1.109 + SELECT i FROM t1 WHERE a=1 AND b>0 AND b<'zzz'
1.110 + }
1.111 +} {2 4 3 8 6}
1.112 +do_test descidx3-3.3 {
1.113 + execsql {
1.114 + SELECT i FROM t1 WHERE b>0 AND b<'zzz'
1.115 + }
1.116 +} {6 8 3 4 2}
1.117 +do_test descidx3-3.4 {
1.118 + execsql {
1.119 + SELECT i FROM t1 WHERE a=1 AND b>-9999 AND b<x'ffffffff'
1.120 + }
1.121 +} {5 2 4 3 8 6 7 9}
1.122 +do_test descidx3-3.5 {
1.123 + execsql {
1.124 + SELECT i FROM t1 WHERE b>-9999 AND b<x'ffffffff'
1.125 + }
1.126 +} {9 7 6 8 3 4 2 5}
1.127 +
1.128 +ifcapable subquery {
1.129 + # If the subquery capability is not compiled in to the binary, then
1.130 + # the IN(...) operator is not available. Hence these tests cannot be
1.131 + # run.
1.132 + do_test descidx3-4.1 {
1.133 + execsql {
1.134 + UPDATE t1 SET a=2 WHERE i<6;
1.135 + SELECT i FROM t1 WHERE a IN (1,2) AND b>0 AND b<'zzz';
1.136 + }
1.137 + } {8 6 2 4 3}
1.138 + do_test descidx3-4.2 {
1.139 + execsql {
1.140 + UPDATE t1 SET a=1;
1.141 + SELECT i FROM t1 WHERE a IN (1,2) AND b>0 AND b<'zzz';
1.142 + }
1.143 + } {2 4 3 8 6}
1.144 + do_test descidx3-4.3 {
1.145 + execsql {
1.146 + UPDATE t1 SET b=2;
1.147 + SELECT i FROM t1 WHERE a IN (1,2) AND b>0 AND b<'zzz';
1.148 + }
1.149 + } {9 7 6 8 3 4 2 5 1}
1.150 +}
1.151 +
1.152 +finish_test