1*c5c4113dSnw141292 2*c5c4113dSnw141292#pragma ident "%Z%%M% %I% %E% SMI" 3*c5c4113dSnw141292 4*c5c4113dSnw141292# 2001 September 15 5*c5c4113dSnw141292# 6*c5c4113dSnw141292# The author disclaims copyright to this source code. In place of 7*c5c4113dSnw141292# a legal notice, here is a blessing: 8*c5c4113dSnw141292# 9*c5c4113dSnw141292# May you do good and not evil. 10*c5c4113dSnw141292# May you find forgiveness for yourself and forgive others. 11*c5c4113dSnw141292# May you share freely, never taking more than you give. 12*c5c4113dSnw141292# 13*c5c4113dSnw141292#*********************************************************************** 14*c5c4113dSnw141292# This file implements regression tests for SQLite library. The 15*c5c4113dSnw141292# focus of this file is testing the the library is able to correctly 16*c5c4113dSnw141292# handle file-format 3 (version 2.6.x) databases. 17*c5c4113dSnw141292# 18*c5c4113dSnw141292# $Id: format3.test,v 1.4 2003/12/23 02:17:35 drh Exp $ 19*c5c4113dSnw141292 20*c5c4113dSnw141292set testdir [file dirname $argv0] 21*c5c4113dSnw141292source $testdir/tester.tcl 22*c5c4113dSnw141292 23*c5c4113dSnw141292# Create a bunch of data to sort against 24*c5c4113dSnw141292# 25*c5c4113dSnw141292do_test format3-1.0 { 26*c5c4113dSnw141292 set fd [open data.txt w] 27*c5c4113dSnw141292 puts $fd "1\tone\t0\tI\t3.141592653" 28*c5c4113dSnw141292 puts $fd "2\ttwo\t1\tII\t2.15" 29*c5c4113dSnw141292 puts $fd "3\tthree\t1\tIII\t4221.0" 30*c5c4113dSnw141292 puts $fd "4\tfour\t2\tIV\t-0.0013442" 31*c5c4113dSnw141292 puts $fd "5\tfive\t2\tV\t-11" 32*c5c4113dSnw141292 puts $fd "6\tsix\t2\tVI\t0.123" 33*c5c4113dSnw141292 puts $fd "7\tseven\t2\tVII\t123.0" 34*c5c4113dSnw141292 puts $fd "8\teight\t3\tVIII\t-1.6" 35*c5c4113dSnw141292 close $fd 36*c5c4113dSnw141292 execsql { 37*c5c4113dSnw141292 CREATE TABLE t1( 38*c5c4113dSnw141292 n int, 39*c5c4113dSnw141292 v varchar(10), 40*c5c4113dSnw141292 log int, 41*c5c4113dSnw141292 roman varchar(10), 42*c5c4113dSnw141292 flt real 43*c5c4113dSnw141292 ); 44*c5c4113dSnw141292 COPY t1 FROM 'data.txt' 45*c5c4113dSnw141292 } 46*c5c4113dSnw141292 file delete data.txt 47*c5c4113dSnw141292 db close 48*c5c4113dSnw141292 set ::bt [btree_open test.db] 49*c5c4113dSnw141292 btree_begin_transaction $::bt 50*c5c4113dSnw141292 set m [btree_get_meta $::bt] 51*c5c4113dSnw141292 set m [lreplace $m 2 2 3] 52*c5c4113dSnw141292 eval btree_update_meta $::bt $m 53*c5c4113dSnw141292 btree_commit $::bt 54*c5c4113dSnw141292 btree_close $::bt 55*c5c4113dSnw141292 sqlite db test.db 56*c5c4113dSnw141292 execsql {SELECT count(*) FROM t1} 57*c5c4113dSnw141292} {8} 58*c5c4113dSnw141292 59*c5c4113dSnw141292do_test format3-1.1 { 60*c5c4113dSnw141292 execsql {SELECT n FROM t1 ORDER BY n} 61*c5c4113dSnw141292} {1 2 3 4 5 6 7 8} 62*c5c4113dSnw141292do_test format3-1.1.1 { 63*c5c4113dSnw141292 execsql {SELECT n FROM t1 ORDER BY n ASC} 64*c5c4113dSnw141292} {1 2 3 4 5 6 7 8} 65*c5c4113dSnw141292do_test format3-1.1.1 { 66*c5c4113dSnw141292 execsql {SELECT ALL n FROM t1 ORDER BY n ASC} 67*c5c4113dSnw141292} {1 2 3 4 5 6 7 8} 68*c5c4113dSnw141292do_test format3-1.2 { 69*c5c4113dSnw141292 execsql {SELECT n FROM t1 ORDER BY n DESC} 70*c5c4113dSnw141292} {8 7 6 5 4 3 2 1} 71*c5c4113dSnw141292do_test format3-1.3a { 72*c5c4113dSnw141292 execsql {SELECT v FROM t1 ORDER BY v} 73*c5c4113dSnw141292} {eight five four one seven six three two} 74*c5c4113dSnw141292do_test format3-1.3b { 75*c5c4113dSnw141292 execsql {SELECT n FROM t1 ORDER BY v} 76*c5c4113dSnw141292} {8 5 4 1 7 6 3 2} 77*c5c4113dSnw141292do_test format3-1.4 { 78*c5c4113dSnw141292 execsql {SELECT n FROM t1 ORDER BY v DESC} 79*c5c4113dSnw141292} {2 3 6 7 1 4 5 8} 80*c5c4113dSnw141292do_test format3-1.5 { 81*c5c4113dSnw141292 execsql {SELECT flt FROM t1 ORDER BY flt} 82*c5c4113dSnw141292} {-11 -1.6 -0.0013442 0.123 2.15 3.141592653 123.0 4221.0} 83*c5c4113dSnw141292do_test format3-1.6 { 84*c5c4113dSnw141292 execsql {SELECT flt FROM t1 ORDER BY flt DESC} 85*c5c4113dSnw141292} {4221.0 123.0 3.141592653 2.15 0.123 -0.0013442 -1.6 -11} 86*c5c4113dSnw141292do_test format3-1.7 { 87*c5c4113dSnw141292 execsql {SELECT roman FROM t1 ORDER BY roman} 88*c5c4113dSnw141292} {I II III IV V VI VII VIII} 89*c5c4113dSnw141292do_test format3-1.8 { 90*c5c4113dSnw141292 execsql {SELECT n FROM t1 ORDER BY log, flt} 91*c5c4113dSnw141292} {1 2 3 5 4 6 7 8} 92*c5c4113dSnw141292do_test format3-1.8.1 { 93*c5c4113dSnw141292 execsql {SELECT n FROM t1 ORDER BY log asc, flt} 94*c5c4113dSnw141292} {1 2 3 5 4 6 7 8} 95*c5c4113dSnw141292do_test format3-1.8.2 { 96*c5c4113dSnw141292 execsql {SELECT n FROM t1 ORDER BY log, flt ASC} 97*c5c4113dSnw141292} {1 2 3 5 4 6 7 8} 98*c5c4113dSnw141292do_test format3-1.8.3 { 99*c5c4113dSnw141292 execsql {SELECT n FROM t1 ORDER BY log ASC, flt asc} 100*c5c4113dSnw141292} {1 2 3 5 4 6 7 8} 101*c5c4113dSnw141292do_test format3-1.9 { 102*c5c4113dSnw141292 execsql {SELECT n FROM t1 ORDER BY log, flt DESC} 103*c5c4113dSnw141292} {1 3 2 7 6 4 5 8} 104*c5c4113dSnw141292do_test format3-1.9.1 { 105*c5c4113dSnw141292 execsql {SELECT n FROM t1 ORDER BY log ASC, flt DESC} 106*c5c4113dSnw141292} {1 3 2 7 6 4 5 8} 107*c5c4113dSnw141292do_test format3-1.10 { 108*c5c4113dSnw141292 execsql {SELECT n FROM t1 ORDER BY log DESC, flt} 109*c5c4113dSnw141292} {8 5 4 6 7 2 3 1} 110*c5c4113dSnw141292do_test format3-1.11 { 111*c5c4113dSnw141292 execsql {SELECT n FROM t1 ORDER BY log DESC, flt DESC} 112*c5c4113dSnw141292} {8 7 6 4 5 3 2 1} 113*c5c4113dSnw141292 114*c5c4113dSnw141292# These tests are designed to reach some hard-to-reach places 115*c5c4113dSnw141292# inside the string comparison routines. 116*c5c4113dSnw141292# 117*c5c4113dSnw141292# (Later) The sorting behavior changed in 2.7.0. But we will 118*c5c4113dSnw141292# keep these tests. You can never have too many test cases! 119*c5c4113dSnw141292# 120*c5c4113dSnw141292do_test format3-2.1.1 { 121*c5c4113dSnw141292 execsql { 122*c5c4113dSnw141292 UPDATE t1 SET v='x' || -flt; 123*c5c4113dSnw141292 UPDATE t1 SET v='x-2b' where v=='x-0.123'; 124*c5c4113dSnw141292 SELECT v FROM t1 ORDER BY v; 125*c5c4113dSnw141292 } 126*c5c4113dSnw141292} {x-123 x-2.15 x-2b x-3.141592653 x-4221 x0.0013442 x1.6 x11} 127*c5c4113dSnw141292do_test format3-2.1.2 { 128*c5c4113dSnw141292 execsql { 129*c5c4113dSnw141292 SELECT v FROM t1 ORDER BY substr(v,2,999); 130*c5c4113dSnw141292 } 131*c5c4113dSnw141292} {x-4221 x-123 x-3.141592653 x-2.15 x0.0013442 x1.6 x11 x-2b} 132*c5c4113dSnw141292do_test format3-2.1.3 { 133*c5c4113dSnw141292 execsql { 134*c5c4113dSnw141292 SELECT v FROM t1 ORDER BY substr(v,2,999)+0.0; 135*c5c4113dSnw141292 } 136*c5c4113dSnw141292} {x-4221 x-123 x-3.141592653 x-2.15 x-2b x0.0013442 x1.6 x11} 137*c5c4113dSnw141292do_test format3-2.1.4 { 138*c5c4113dSnw141292 execsql { 139*c5c4113dSnw141292 SELECT v FROM t1 ORDER BY substr(v,2,999) DESC; 140*c5c4113dSnw141292 } 141*c5c4113dSnw141292} {x-2b x11 x1.6 x0.0013442 x-2.15 x-3.141592653 x-123 x-4221} 142*c5c4113dSnw141292do_test format3-2.1.5 { 143*c5c4113dSnw141292 execsql { 144*c5c4113dSnw141292 SELECT v FROM t1 ORDER BY substr(v,2,999)+0.0 DESC; 145*c5c4113dSnw141292 } 146*c5c4113dSnw141292} {x11 x1.6 x0.0013442 x-2b x-2.15 x-3.141592653 x-123 x-4221} 147*c5c4113dSnw141292 148*c5c4113dSnw141292# This is a bug fix for 2.2.4. 149*c5c4113dSnw141292# Strings are normally mapped to upper-case for a caseless comparison. 150*c5c4113dSnw141292# But this can cause problems for characters in between 'Z' and 'a'. 151*c5c4113dSnw141292# 152*c5c4113dSnw141292do_test format3-3.1 { 153*c5c4113dSnw141292 execsql { 154*c5c4113dSnw141292 CREATE TABLE t2(a,b); 155*c5c4113dSnw141292 INSERT INTO t2 VALUES('AGLIENTU',1); 156*c5c4113dSnw141292 INSERT INTO t2 VALUES('AGLIE`',2); 157*c5c4113dSnw141292 INSERT INTO t2 VALUES('AGNA',3); 158*c5c4113dSnw141292 SELECT a, b FROM t2 ORDER BY a; 159*c5c4113dSnw141292 } 160*c5c4113dSnw141292} {AGLIENTU 1 AGLIE` 2 AGNA 3} 161*c5c4113dSnw141292do_test format3-3.2 { 162*c5c4113dSnw141292 execsql { 163*c5c4113dSnw141292 SELECT a, b FROM t2 ORDER BY a DESC; 164*c5c4113dSnw141292 } 165*c5c4113dSnw141292} {AGNA 3 AGLIE` 2 AGLIENTU 1} 166*c5c4113dSnw141292do_test format3-3.3 { 167*c5c4113dSnw141292 execsql { 168*c5c4113dSnw141292 DELETE FROM t2; 169*c5c4113dSnw141292 INSERT INTO t2 VALUES('aglientu',1); 170*c5c4113dSnw141292 INSERT INTO t2 VALUES('aglie`',2); 171*c5c4113dSnw141292 INSERT INTO t2 VALUES('agna',3); 172*c5c4113dSnw141292 SELECT a, b FROM t2 ORDER BY a; 173*c5c4113dSnw141292 } 174*c5c4113dSnw141292} {aglie` 2 aglientu 1 agna 3} 175*c5c4113dSnw141292do_test format3-3.4 { 176*c5c4113dSnw141292 execsql { 177*c5c4113dSnw141292 SELECT a, b FROM t2 ORDER BY a DESC; 178*c5c4113dSnw141292 } 179*c5c4113dSnw141292} {agna 3 aglientu 1 aglie` 2} 180*c5c4113dSnw141292 181*c5c4113dSnw141292# Version 2.7.0 testing. 182*c5c4113dSnw141292# 183*c5c4113dSnw141292do_test format3-4.1 { 184*c5c4113dSnw141292 execsql { 185*c5c4113dSnw141292 INSERT INTO t1 VALUES(9,'x2.7',3,'IX',4.0e5); 186*c5c4113dSnw141292 INSERT INTO t1 VALUES(10,'x5.0e10',3,'X',-4.0e5); 187*c5c4113dSnw141292 INSERT INTO t1 VALUES(11,'x-4.0e9',3,'XI',4.1e4); 188*c5c4113dSnw141292 INSERT INTO t1 VALUES(12,'x01234567890123456789',3,'XII',-4.2e3); 189*c5c4113dSnw141292 SELECT n FROM t1 ORDER BY n; 190*c5c4113dSnw141292 } 191*c5c4113dSnw141292} {1 2 3 4 5 6 7 8 9 10 11 12} 192*c5c4113dSnw141292do_test format3-4.2 { 193*c5c4113dSnw141292 execsql { 194*c5c4113dSnw141292 SELECT n||'' FROM t1 ORDER BY 1; 195*c5c4113dSnw141292 } 196*c5c4113dSnw141292} {1 2 3 4 5 6 7 8 9 10 11 12} 197*c5c4113dSnw141292do_test format3-4.3 { 198*c5c4113dSnw141292 execsql { 199*c5c4113dSnw141292 SELECT n+0 FROM t1 ORDER BY 1; 200*c5c4113dSnw141292 } 201*c5c4113dSnw141292} {1 2 3 4 5 6 7 8 9 10 11 12} 202*c5c4113dSnw141292do_test format3-4.4 { 203*c5c4113dSnw141292 execsql { 204*c5c4113dSnw141292 SELECT n||'' FROM t1 ORDER BY 1 DESC; 205*c5c4113dSnw141292 } 206*c5c4113dSnw141292} {12 11 10 9 8 7 6 5 4 3 2 1} 207*c5c4113dSnw141292do_test format3-4.5 { 208*c5c4113dSnw141292 execsql { 209*c5c4113dSnw141292 SELECT n+0 FROM t1 ORDER BY 1 DESC; 210*c5c4113dSnw141292 } 211*c5c4113dSnw141292} {12 11 10 9 8 7 6 5 4 3 2 1} 212*c5c4113dSnw141292do_test format3-4.6 { 213*c5c4113dSnw141292 execsql { 214*c5c4113dSnw141292 SELECT v FROM t1 ORDER BY 1; 215*c5c4113dSnw141292 } 216*c5c4113dSnw141292} {x-123 x-2.15 x-2b x-3.141592653 x-4.0e9 x-4221 x0.0013442 x01234567890123456789 x1.6 x11 x2.7 x5.0e10} 217*c5c4113dSnw141292do_test format3-4.7 { 218*c5c4113dSnw141292 execsql { 219*c5c4113dSnw141292 SELECT v FROM t1 ORDER BY 1 DESC; 220*c5c4113dSnw141292 } 221*c5c4113dSnw141292} {x5.0e10 x2.7 x11 x1.6 x01234567890123456789 x0.0013442 x-4221 x-4.0e9 x-3.141592653 x-2b x-2.15 x-123} 222*c5c4113dSnw141292do_test format3-4.8 { 223*c5c4113dSnw141292 execsql { 224*c5c4113dSnw141292 SELECT substr(v,2,99) FROM t1 ORDER BY 1; 225*c5c4113dSnw141292 } 226*c5c4113dSnw141292} {-4.0e9 -4221 -123 -3.141592653 -2.15 0.0013442 1.6 2.7 11 5.0e10 01234567890123456789 -2b} 227*c5c4113dSnw141292 228*c5c4113dSnw141292# Build some new test data, this time with indices. 229*c5c4113dSnw141292# 230*c5c4113dSnw141292do_test format3-5.0 { 231*c5c4113dSnw141292 execsql { 232*c5c4113dSnw141292 DROP TABLE t1; 233*c5c4113dSnw141292 CREATE TABLE t1(w int, x text, y blob); 234*c5c4113dSnw141292 DROP TABLE t2; 235*c5c4113dSnw141292 CREATE TABLE t2(p varchar(1), q clob, r real, s numeric(8)); 236*c5c4113dSnw141292 } 237*c5c4113dSnw141292 for {set i 1} {$i<=100} {incr i} { 238*c5c4113dSnw141292 set w $i 239*c5c4113dSnw141292 set x [expr {int(log($i)/log(2))}] 240*c5c4113dSnw141292 set y [expr {$i*$i + 2*$i + 1}] 241*c5c4113dSnw141292 execsql "INSERT INTO t1 VALUES($w,$x,$y)" 242*c5c4113dSnw141292 } 243*c5c4113dSnw141292 execsql { 244*c5c4113dSnw141292 INSERT INTO t2 SELECT 101-w, x, (SELECT max(y) FROM t1)+1-y, y FROM t1; 245*c5c4113dSnw141292 CREATE INDEX i1w ON t1(w); 246*c5c4113dSnw141292 CREATE INDEX i1xy ON t1(x,y); 247*c5c4113dSnw141292 CREATE INDEX i2p ON t2(p); 248*c5c4113dSnw141292 CREATE INDEX i2r ON t2(r); 249*c5c4113dSnw141292 CREATE INDEX i2qs ON t2(q, s); 250*c5c4113dSnw141292 } 251*c5c4113dSnw141292} {} 252*c5c4113dSnw141292 253*c5c4113dSnw141292# Do an SQL statement. Append the search count to the end of the result. 254*c5c4113dSnw141292# 255*c5c4113dSnw141292proc count sql { 256*c5c4113dSnw141292 set ::sqlite_search_count 0 257*c5c4113dSnw141292 return [concat [execsql $sql] $::sqlite_search_count] 258*c5c4113dSnw141292} 259*c5c4113dSnw141292 260*c5c4113dSnw141292# Verify that queries use an index. We are using the special variable 261*c5c4113dSnw141292# "sqlite_search_count" which tallys the number of executions of MoveTo 262*c5c4113dSnw141292# and Next operators in the VDBE. By verifing that the search count is 263*c5c4113dSnw141292# small we can be assured that indices are being used properly. 264*c5c4113dSnw141292# 265*c5c4113dSnw141292do_test format3-5.1 { 266*c5c4113dSnw141292 db close 267*c5c4113dSnw141292 sqlite db test.db 268*c5c4113dSnw141292 count {SELECT x, y FROM t1 WHERE w=10} 269*c5c4113dSnw141292} {3 121 3} 270*c5c4113dSnw141292do_test format3-5.2 { 271*c5c4113dSnw141292 count {SELECT x, y FROM t1 WHERE w=11} 272*c5c4113dSnw141292} {3 144 3} 273*c5c4113dSnw141292do_test format3-5.3 { 274*c5c4113dSnw141292 count {SELECT x, y FROM t1 WHERE 11=w} 275*c5c4113dSnw141292} {3 144 3} 276*c5c4113dSnw141292do_test format3-5.4 { 277*c5c4113dSnw141292 count {SELECT x, y FROM t1 WHERE 11=w AND x>2} 278*c5c4113dSnw141292} {3 144 3} 279*c5c4113dSnw141292do_test format3-5.5 { 280*c5c4113dSnw141292 count {SELECT x, y FROM t1 WHERE y<200 AND w=11 AND x>2} 281*c5c4113dSnw141292} {3 144 3} 282*c5c4113dSnw141292do_test format3-5.6 { 283*c5c4113dSnw141292 count {SELECT x, y FROM t1 WHERE y<200 AND x>2 AND w=11} 284*c5c4113dSnw141292} {3 144 3} 285*c5c4113dSnw141292do_test format3-5.7 { 286*c5c4113dSnw141292 count {SELECT x, y FROM t1 WHERE w=11 AND y<200 AND x>2} 287*c5c4113dSnw141292} {3 144 3} 288*c5c4113dSnw141292do_test format3-5.8 { 289*c5c4113dSnw141292 count {SELECT x, y FROM t1 WHERE w>10 AND y=144 AND x=3} 290*c5c4113dSnw141292} {3 144 3} 291*c5c4113dSnw141292do_test format3-5.9 { 292*c5c4113dSnw141292 count {SELECT x, y FROM t1 WHERE y=144 AND w>10 AND x=3} 293*c5c4113dSnw141292} {3 144 3} 294*c5c4113dSnw141292do_test format3-5.10 { 295*c5c4113dSnw141292 count {SELECT x, y FROM t1 WHERE x=3 AND w>=10 AND y=121} 296*c5c4113dSnw141292} {3 121 3} 297*c5c4113dSnw141292do_test format3-5.11 { 298*c5c4113dSnw141292 count {SELECT x, y FROM t1 WHERE x=3 AND y=100 AND w<10} 299*c5c4113dSnw141292} {3 100 3} 300*c5c4113dSnw141292 301*c5c4113dSnw141292# New for SQLite version 2.1: Verify that that inequality constraints 302*c5c4113dSnw141292# are used correctly. 303*c5c4113dSnw141292# 304*c5c4113dSnw141292do_test format3-5.12 { 305*c5c4113dSnw141292 count {SELECT w FROM t1 WHERE x=3 AND y<100} 306*c5c4113dSnw141292} {8 3} 307*c5c4113dSnw141292do_test format3-5.13 { 308*c5c4113dSnw141292 count {SELECT w FROM t1 WHERE x=3 AND 100>y} 309*c5c4113dSnw141292} {8 3} 310*c5c4113dSnw141292do_test format3-5.14 { 311*c5c4113dSnw141292 count {SELECT w FROM t1 WHERE 3=x AND y<100} 312*c5c4113dSnw141292} {8 3} 313*c5c4113dSnw141292do_test format3-5.15 { 314*c5c4113dSnw141292 count {SELECT w FROM t1 WHERE 3=x AND 100>y} 315*c5c4113dSnw141292} {8 3} 316*c5c4113dSnw141292do_test format3-5.16 { 317*c5c4113dSnw141292 count {SELECT w FROM t1 WHERE x=3 AND y<=100} 318*c5c4113dSnw141292} {8 9 5} 319*c5c4113dSnw141292do_test format3-5.17 { 320*c5c4113dSnw141292 count {SELECT w FROM t1 WHERE x=3 AND 100>=y} 321*c5c4113dSnw141292} {8 9 5} 322*c5c4113dSnw141292do_test format3-5.18 { 323*c5c4113dSnw141292 count {SELECT w FROM t1 WHERE x=3 AND y>225} 324*c5c4113dSnw141292} {15 3} 325*c5c4113dSnw141292do_test format3-5.19 { 326*c5c4113dSnw141292 count {SELECT w FROM t1 WHERE x=3 AND 225<y} 327*c5c4113dSnw141292} {15 3} 328*c5c4113dSnw141292do_test format3-5.20 { 329*c5c4113dSnw141292 count {SELECT w FROM t1 WHERE x=3 AND y>=225} 330*c5c4113dSnw141292} {14 15 5} 331*c5c4113dSnw141292do_test format3-5.21 { 332*c5c4113dSnw141292 count {SELECT w FROM t1 WHERE x=3 AND 225<=y} 333*c5c4113dSnw141292} {14 15 5} 334*c5c4113dSnw141292do_test format3-5.22 { 335*c5c4113dSnw141292 count {SELECT w FROM t1 WHERE x=3 AND y>121 AND y<196} 336*c5c4113dSnw141292} {11 12 5} 337*c5c4113dSnw141292do_test format3-5.23 { 338*c5c4113dSnw141292 count {SELECT w FROM t1 WHERE x=3 AND y>=121 AND y<=196} 339*c5c4113dSnw141292} {10 11 12 13 9} 340*c5c4113dSnw141292do_test format3-5.24 { 341*c5c4113dSnw141292 count {SELECT w FROM t1 WHERE x=3 AND 121<y AND 196>y} 342*c5c4113dSnw141292} {11 12 5} 343*c5c4113dSnw141292do_test format3-5.25 { 344*c5c4113dSnw141292 count {SELECT w FROM t1 WHERE x=3 AND 121<=y AND 196>=y} 345*c5c4113dSnw141292} {10 11 12 13 9} 346*c5c4113dSnw141292 347*c5c4113dSnw141292# Need to work on optimizing the BETWEEN operator. 348*c5c4113dSnw141292# 349*c5c4113dSnw141292# do_test format3-5.26 { 350*c5c4113dSnw141292# count {SELECT w FROM t1 WHERE x=3 AND y BETWEEN 121 AND 196} 351*c5c4113dSnw141292# } {10 11 12 13 9} 352*c5c4113dSnw141292 353*c5c4113dSnw141292do_test format3-5.27 { 354*c5c4113dSnw141292 count {SELECT w FROM t1 WHERE x=3 AND y+1==122} 355*c5c4113dSnw141292} {10 17} 356*c5c4113dSnw141292do_test format3-5.28 { 357*c5c4113dSnw141292 count {SELECT w FROM t1 WHERE x+1=4 AND y+1==122} 358*c5c4113dSnw141292} {10 99} 359*c5c4113dSnw141292do_test format3-5.29 { 360*c5c4113dSnw141292 count {SELECT w FROM t1 WHERE y==121} 361*c5c4113dSnw141292} {10 99} 362*c5c4113dSnw141292 363*c5c4113dSnw141292 364*c5c4113dSnw141292do_test format3-5.30 { 365*c5c4113dSnw141292 count {SELECT w FROM t1 WHERE w>97} 366*c5c4113dSnw141292} {98 99 100 6} 367*c5c4113dSnw141292do_test format3-5.31 { 368*c5c4113dSnw141292 count {SELECT w FROM t1 WHERE w>=97} 369*c5c4113dSnw141292} {97 98 99 100 8} 370*c5c4113dSnw141292do_test format3-5.33 { 371*c5c4113dSnw141292 count {SELECT w FROM t1 WHERE w==97} 372*c5c4113dSnw141292} {97 3} 373*c5c4113dSnw141292do_test format3-5.34 { 374*c5c4113dSnw141292 count {SELECT w FROM t1 WHERE w+1==98} 375*c5c4113dSnw141292} {97 99} 376*c5c4113dSnw141292do_test format3-5.35 { 377*c5c4113dSnw141292 count {SELECT w FROM t1 WHERE w<3} 378*c5c4113dSnw141292} {1 2 4} 379*c5c4113dSnw141292do_test format3-5.36 { 380*c5c4113dSnw141292 count {SELECT w FROM t1 WHERE w<=3} 381*c5c4113dSnw141292} {1 2 3 6} 382*c5c4113dSnw141292do_test format3-5.37 { 383*c5c4113dSnw141292 count {SELECT w FROM t1 WHERE w+1<=4 ORDER BY w} 384*c5c4113dSnw141292} {1 2 3 199} 385*c5c4113dSnw141292 386*c5c4113dSnw141292 387*c5c4113dSnw141292# Do the same kind of thing except use a join as the data source. 388*c5c4113dSnw141292# 389*c5c4113dSnw141292do_test format3-6.1 { 390*c5c4113dSnw141292 db close 391*c5c4113dSnw141292 sqlite db test.db 392*c5c4113dSnw141292 count { 393*c5c4113dSnw141292 SELECT w, p FROM t2, t1 394*c5c4113dSnw141292 WHERE x=q AND y=s AND r=8977 395*c5c4113dSnw141292 } 396*c5c4113dSnw141292} {34 67 6} 397*c5c4113dSnw141292do_test format3-6.2 { 398*c5c4113dSnw141292 count { 399*c5c4113dSnw141292 SELECT w, p FROM t2, t1 400*c5c4113dSnw141292 WHERE x=q AND s=y AND r=8977 401*c5c4113dSnw141292 } 402*c5c4113dSnw141292} {34 67 6} 403*c5c4113dSnw141292do_test format3-6.3 { 404*c5c4113dSnw141292 count { 405*c5c4113dSnw141292 SELECT w, p FROM t2, t1 406*c5c4113dSnw141292 WHERE x=q AND s=y AND r=8977 AND w>10 407*c5c4113dSnw141292 } 408*c5c4113dSnw141292} {34 67 6} 409*c5c4113dSnw141292do_test format3-6.4 { 410*c5c4113dSnw141292 count { 411*c5c4113dSnw141292 SELECT w, p FROM t2, t1 412*c5c4113dSnw141292 WHERE p<80 AND x=q AND s=y AND r=8977 AND w>10 413*c5c4113dSnw141292 } 414*c5c4113dSnw141292} {34 67 6} 415*c5c4113dSnw141292do_test format3-6.5 { 416*c5c4113dSnw141292 count { 417*c5c4113dSnw141292 SELECT w, p FROM t2, t1 418*c5c4113dSnw141292 WHERE p<80 AND x=q AND 8977=r AND s=y AND w>10 419*c5c4113dSnw141292 } 420*c5c4113dSnw141292} {34 67 6} 421*c5c4113dSnw141292do_test format3-6.6 { 422*c5c4113dSnw141292 count { 423*c5c4113dSnw141292 SELECT w, p FROM t2, t1 424*c5c4113dSnw141292 WHERE x=q AND p=77 AND s=y AND w>5 425*c5c4113dSnw141292 } 426*c5c4113dSnw141292} {24 77 6} 427*c5c4113dSnw141292do_test format3-6.7 { 428*c5c4113dSnw141292 count { 429*c5c4113dSnw141292 SELECT w, p FROM t1, t2 430*c5c4113dSnw141292 WHERE x=q AND p>77 AND s=y AND w=5 431*c5c4113dSnw141292 } 432*c5c4113dSnw141292} {5 96 6} 433*c5c4113dSnw141292 434*c5c4113dSnw141292# Lets do a 3-way join. 435*c5c4113dSnw141292# 436*c5c4113dSnw141292do_test format3-7.1 { 437*c5c4113dSnw141292 count { 438*c5c4113dSnw141292 SELECT A.w, B.p, C.w FROM t1 as A, t2 as B, t1 as C 439*c5c4113dSnw141292 WHERE C.w=101-B.p AND B.r=10202-A.y AND A.w=11 440*c5c4113dSnw141292 } 441*c5c4113dSnw141292} {11 90 11 9} 442*c5c4113dSnw141292do_test format3-7.2 { 443*c5c4113dSnw141292 count { 444*c5c4113dSnw141292 SELECT A.w, B.p, C.w FROM t1 as A, t2 as B, t1 as C 445*c5c4113dSnw141292 WHERE C.w=101-B.p AND B.r=10202-A.y AND A.w=12 446*c5c4113dSnw141292 } 447*c5c4113dSnw141292} {12 89 12 9} 448*c5c4113dSnw141292do_test format3-7.3 { 449*c5c4113dSnw141292 count { 450*c5c4113dSnw141292 SELECT A.w, B.p, C.w FROM t1 as A, t2 as B, t1 as C 451*c5c4113dSnw141292 WHERE A.w=15 AND B.p=C.w AND B.r=10202-A.y 452*c5c4113dSnw141292 } 453*c5c4113dSnw141292} {15 86 86 9} 454*c5c4113dSnw141292 455*c5c4113dSnw141292# Test to see that the special case of a constant WHERE clause is 456*c5c4113dSnw141292# handled. 457*c5c4113dSnw141292# 458*c5c4113dSnw141292do_test format3-8.1 { 459*c5c4113dSnw141292 count { 460*c5c4113dSnw141292 SELECT * FROM t1 WHERE 0 461*c5c4113dSnw141292 } 462*c5c4113dSnw141292} {0} 463*c5c4113dSnw141292do_test format3-8.2 { 464*c5c4113dSnw141292 count { 465*c5c4113dSnw141292 SELECT * FROM t1 WHERE 1 LIMIT 1 466*c5c4113dSnw141292 } 467*c5c4113dSnw141292} {1 0 4 1} 468*c5c4113dSnw141292do_test format3-8.3 { 469*c5c4113dSnw141292 execsql { 470*c5c4113dSnw141292 SELECT 99 WHERE 0 471*c5c4113dSnw141292 } 472*c5c4113dSnw141292} {} 473*c5c4113dSnw141292do_test format3-8.4 { 474*c5c4113dSnw141292 execsql { 475*c5c4113dSnw141292 SELECT 99 WHERE 1 476*c5c4113dSnw141292 } 477*c5c4113dSnw141292} {99} 478*c5c4113dSnw141292 479*c5c4113dSnw141292# Verify that IN operators in a WHERE clause are handled correctly. 480*c5c4113dSnw141292# 481*c5c4113dSnw141292do_test format3-9.1 { 482*c5c4113dSnw141292 count { 483*c5c4113dSnw141292 SELECT * FROM t1 WHERE rowid IN (1,2,3,1234) order by 1; 484*c5c4113dSnw141292 } 485*c5c4113dSnw141292} {1 0 4 2 1 9 3 1 16 0} 486*c5c4113dSnw141292do_test format3-9.2 { 487*c5c4113dSnw141292 count { 488*c5c4113dSnw141292 SELECT * FROM t1 WHERE rowid+0 IN (1,2,3,1234) order by 1; 489*c5c4113dSnw141292 } 490*c5c4113dSnw141292} {1 0 4 2 1 9 3 1 16 199} 491*c5c4113dSnw141292do_test format3-9.3 { 492*c5c4113dSnw141292 count { 493*c5c4113dSnw141292 SELECT * FROM t1 WHERE w IN (-1,1,2,3) order by 1; 494*c5c4113dSnw141292 } 495*c5c4113dSnw141292} {1 0 4 2 1 9 3 1 16 10} 496*c5c4113dSnw141292do_test format3-9.4 { 497*c5c4113dSnw141292 count { 498*c5c4113dSnw141292 SELECT * FROM t1 WHERE w+0 IN (-1,1,2,3) order by 1; 499*c5c4113dSnw141292 } 500*c5c4113dSnw141292} {1 0 4 2 1 9 3 1 16 199} 501*c5c4113dSnw141292do_test format3-9.5 { 502*c5c4113dSnw141292 count { 503*c5c4113dSnw141292 SELECT * FROM t1 WHERE rowid IN 504*c5c4113dSnw141292 (select rowid from t1 where rowid IN (-1,2,4)) 505*c5c4113dSnw141292 ORDER BY 1; 506*c5c4113dSnw141292 } 507*c5c4113dSnw141292} {2 1 9 4 2 25 1} 508*c5c4113dSnw141292do_test format3-9.6 { 509*c5c4113dSnw141292 count { 510*c5c4113dSnw141292 SELECT * FROM t1 WHERE rowid+0 IN 511*c5c4113dSnw141292 (select rowid from t1 where rowid IN (-1,2,4)) 512*c5c4113dSnw141292 ORDER BY 1; 513*c5c4113dSnw141292 } 514*c5c4113dSnw141292} {2 1 9 4 2 25 199} 515*c5c4113dSnw141292do_test format3-9.7 { 516*c5c4113dSnw141292 count { 517*c5c4113dSnw141292 SELECT * FROM t1 WHERE w IN 518*c5c4113dSnw141292 (select rowid from t1 where rowid IN (-1,2,4)) 519*c5c4113dSnw141292 ORDER BY 1; 520*c5c4113dSnw141292 } 521*c5c4113dSnw141292} {2 1 9 4 2 25 7} 522*c5c4113dSnw141292do_test format3-9.8 { 523*c5c4113dSnw141292 count { 524*c5c4113dSnw141292 SELECT * FROM t1 WHERE w+0 IN 525*c5c4113dSnw141292 (select rowid from t1 where rowid IN (-1,2,4)) 526*c5c4113dSnw141292 ORDER BY 1; 527*c5c4113dSnw141292 } 528*c5c4113dSnw141292} {2 1 9 4 2 25 199} 529*c5c4113dSnw141292do_test format3-9.9 { 530*c5c4113dSnw141292 count { 531*c5c4113dSnw141292 SELECT * FROM t1 WHERE x IN (1,7) ORDER BY 1; 532*c5c4113dSnw141292 } 533*c5c4113dSnw141292} {2 1 9 3 1 16 6} 534*c5c4113dSnw141292do_test format3-9.10 { 535*c5c4113dSnw141292 count { 536*c5c4113dSnw141292 SELECT * FROM t1 WHERE x+0 IN (1,7) ORDER BY 1; 537*c5c4113dSnw141292 } 538*c5c4113dSnw141292} {2 1 9 3 1 16 199} 539*c5c4113dSnw141292do_test format3-9.11 { 540*c5c4113dSnw141292 count { 541*c5c4113dSnw141292 SELECT * FROM t1 WHERE y IN (6400,8100) ORDER BY 1; 542*c5c4113dSnw141292 } 543*c5c4113dSnw141292} {79 6 6400 89 6 8100 199} 544*c5c4113dSnw141292do_test format3-9.12 { 545*c5c4113dSnw141292 count { 546*c5c4113dSnw141292 SELECT * FROM t1 WHERE x=6 AND y IN (6400,8100) ORDER BY 1; 547*c5c4113dSnw141292 } 548*c5c4113dSnw141292} {79 6 6400 89 6 8100 74} 549*c5c4113dSnw141292do_test format3-9.13 { 550*c5c4113dSnw141292 count { 551*c5c4113dSnw141292 SELECT * FROM t1 WHERE x IN (1,7) AND y NOT IN (6400,8100) ORDER BY 1; 552*c5c4113dSnw141292 } 553*c5c4113dSnw141292} {2 1 9 3 1 16 6} 554*c5c4113dSnw141292do_test format3-9.14 { 555*c5c4113dSnw141292 count { 556*c5c4113dSnw141292 SELECT * FROM t1 WHERE x IN (1,7) AND y IN (9,10) ORDER BY 1; 557*c5c4113dSnw141292 } 558*c5c4113dSnw141292} {2 1 9 6} 559*c5c4113dSnw141292 560*c5c4113dSnw141292# This procedure executes the SQL. Then it checks the generated program 561*c5c4113dSnw141292# for the SQL and appends a "nosort" to the result if the program contains the 562*c5c4113dSnw141292# SortCallback opcode. If the program does not contain the SortCallback 563*c5c4113dSnw141292# opcode it appends "sort" 564*c5c4113dSnw141292# 565*c5c4113dSnw141292proc cksort {sql} { 566*c5c4113dSnw141292 set data [execsql $sql] 567*c5c4113dSnw141292 set prog [execsql "EXPLAIN $sql"] 568*c5c4113dSnw141292 if {[regexp SortCallback $prog]} {set x sort} {set x nosort} 569*c5c4113dSnw141292 lappend data $x 570*c5c4113dSnw141292 return $data 571*c5c4113dSnw141292} 572*c5c4113dSnw141292# Check out the logic that attempts to implement the ORDER BY clause 573*c5c4113dSnw141292# using an index rather than by sorting. 574*c5c4113dSnw141292# 575*c5c4113dSnw141292do_test format3-10.1 { 576*c5c4113dSnw141292 execsql { 577*c5c4113dSnw141292 CREATE TABLE t3(a,b,c); 578*c5c4113dSnw141292 CREATE INDEX t3a ON t3(a); 579*c5c4113dSnw141292 CREATE INDEX t3bc ON t3(b,c); 580*c5c4113dSnw141292 CREATE INDEX t3acb ON t3(a,c,b); 581*c5c4113dSnw141292 INSERT INTO t3 SELECT w, 101-w, y FROM t1; 582*c5c4113dSnw141292 SELECT count(*), sum(a), sum(b), sum(c) FROM t3; 583*c5c4113dSnw141292 } 584*c5c4113dSnw141292} {100 5050 5050 348550} 585*c5c4113dSnw141292do_test format3-10.2 { 586*c5c4113dSnw141292 cksort { 587*c5c4113dSnw141292 SELECT * FROM t3 ORDER BY a LIMIT 3 588*c5c4113dSnw141292 } 589*c5c4113dSnw141292} {1 100 4 2 99 9 3 98 16 nosort} 590*c5c4113dSnw141292do_test format3-10.3 { 591*c5c4113dSnw141292 cksort { 592*c5c4113dSnw141292 SELECT * FROM t3 ORDER BY a+1 LIMIT 3 593*c5c4113dSnw141292 } 594*c5c4113dSnw141292} {1 100 4 2 99 9 3 98 16 sort} 595*c5c4113dSnw141292do_test format3-10.4 { 596*c5c4113dSnw141292 cksort { 597*c5c4113dSnw141292 SELECT * FROM t3 WHERE a<10 ORDER BY a LIMIT 3 598*c5c4113dSnw141292 } 599*c5c4113dSnw141292} {1 100 4 2 99 9 3 98 16 nosort} 600*c5c4113dSnw141292do_test format3-10.5 { 601*c5c4113dSnw141292 cksort { 602*c5c4113dSnw141292 SELECT * FROM t3 WHERE a>0 AND a<10 ORDER BY a LIMIT 3 603*c5c4113dSnw141292 } 604*c5c4113dSnw141292} {1 100 4 2 99 9 3 98 16 nosort} 605*c5c4113dSnw141292do_test format3-10.6 { 606*c5c4113dSnw141292 cksort { 607*c5c4113dSnw141292 SELECT * FROM t3 WHERE a>0 ORDER BY a LIMIT 3 608*c5c4113dSnw141292 } 609*c5c4113dSnw141292} {1 100 4 2 99 9 3 98 16 nosort} 610*c5c4113dSnw141292do_test format3-10.7 { 611*c5c4113dSnw141292 cksort { 612*c5c4113dSnw141292 SELECT * FROM t3 WHERE b>0 ORDER BY a LIMIT 3 613*c5c4113dSnw141292 } 614*c5c4113dSnw141292} {1 100 4 2 99 9 3 98 16 sort} 615*c5c4113dSnw141292do_test format3-10.8 { 616*c5c4113dSnw141292 cksort { 617*c5c4113dSnw141292 SELECT * FROM t3 WHERE a IN (3,5,7,1,9,4,2) ORDER BY a LIMIT 3 618*c5c4113dSnw141292 } 619*c5c4113dSnw141292} {1 100 4 2 99 9 3 98 16 sort} 620*c5c4113dSnw141292do_test format3-10.9 { 621*c5c4113dSnw141292 cksort { 622*c5c4113dSnw141292 SELECT * FROM t3 WHERE a=1 AND c>0 ORDER BY a LIMIT 3 623*c5c4113dSnw141292 } 624*c5c4113dSnw141292} {1 100 4 nosort} 625*c5c4113dSnw141292do_test format3-10.10 { 626*c5c4113dSnw141292 cksort { 627*c5c4113dSnw141292 SELECT * FROM t3 WHERE a=1 AND c>0 ORDER BY a LIMIT 3 628*c5c4113dSnw141292 } 629*c5c4113dSnw141292} {1 100 4 nosort} 630*c5c4113dSnw141292do_test format3-10.11 { 631*c5c4113dSnw141292 cksort { 632*c5c4113dSnw141292 SELECT * FROM t3 WHERE a=1 AND c>0 ORDER BY a,c LIMIT 3 633*c5c4113dSnw141292 } 634*c5c4113dSnw141292} {1 100 4 nosort} 635*c5c4113dSnw141292do_test format3-10.12 { 636*c5c4113dSnw141292 cksort { 637*c5c4113dSnw141292 SELECT * FROM t3 WHERE a=1 AND c>0 ORDER BY a,c,b LIMIT 3 638*c5c4113dSnw141292 } 639*c5c4113dSnw141292} {1 100 4 nosort} 640*c5c4113dSnw141292do_test format3-10.13 { 641*c5c4113dSnw141292 cksort { 642*c5c4113dSnw141292 SELECT * FROM t3 WHERE a>0 ORDER BY a DESC LIMIT 3 643*c5c4113dSnw141292 } 644*c5c4113dSnw141292} {100 1 10201 99 2 10000 98 3 9801 nosort} 645*c5c4113dSnw141292do_test format3-10.13.1 { 646*c5c4113dSnw141292 cksort { 647*c5c4113dSnw141292 SELECT * FROM t3 WHERE a>0 ORDER BY a+1 DESC LIMIT 3 648*c5c4113dSnw141292 } 649*c5c4113dSnw141292} {100 1 10201 99 2 10000 98 3 9801 sort} 650*c5c4113dSnw141292do_test format3-10.14 { 651*c5c4113dSnw141292 cksort { 652*c5c4113dSnw141292 SELECT * FROM t3 ORDER BY b LIMIT 3 653*c5c4113dSnw141292 } 654*c5c4113dSnw141292} {100 1 10201 99 2 10000 98 3 9801 nosort} 655*c5c4113dSnw141292do_test format3-10.15 { 656*c5c4113dSnw141292 cksort { 657*c5c4113dSnw141292 SELECT t3.a, t1.x FROM t3, t1 WHERE t3.a=t1.w ORDER BY t3.a LIMIT 3 658*c5c4113dSnw141292 } 659*c5c4113dSnw141292} {1 0 2 1 3 1 nosort} 660*c5c4113dSnw141292do_test format3-10.16 { 661*c5c4113dSnw141292 cksort { 662*c5c4113dSnw141292 SELECT t3.a, t1.x FROM t3, t1 WHERE t3.a=t1.w ORDER BY t1.x, t3.a LIMIT 3 663*c5c4113dSnw141292 } 664*c5c4113dSnw141292} {1 0 2 1 3 1 sort} 665*c5c4113dSnw141292do_test format3-10.17 { 666*c5c4113dSnw141292 cksort { 667*c5c4113dSnw141292 SELECT y FROM t1 ORDER BY w COLLATE text LIMIT 3; 668*c5c4113dSnw141292 } 669*c5c4113dSnw141292} {4 121 10201 sort} 670*c5c4113dSnw141292do_test format3-10.18 { 671*c5c4113dSnw141292 cksort { 672*c5c4113dSnw141292 SELECT y FROM t1 ORDER BY w COLLATE numeric LIMIT 3; 673*c5c4113dSnw141292 } 674*c5c4113dSnw141292} {4 9 16 sort} 675*c5c4113dSnw141292do_test format3-10.19 { 676*c5c4113dSnw141292 cksort { 677*c5c4113dSnw141292 SELECT y FROM t1 ORDER BY w LIMIT 3; 678*c5c4113dSnw141292 } 679*c5c4113dSnw141292} {4 9 16 nosort} 680*c5c4113dSnw141292 681*c5c4113dSnw141292# Check that all comparisons are numeric. Similar tests in misc1.test 682*c5c4113dSnw141292# check the same comparisons on a format4+ database and find that some 683*c5c4113dSnw141292# are numeric and some are text. 684*c5c4113dSnw141292# 685*c5c4113dSnw141292do_test format3-11.1 { 686*c5c4113dSnw141292 execsql {SELECT '0'=='0.0'} 687*c5c4113dSnw141292} {1} 688*c5c4113dSnw141292do_test format3-11.2 { 689*c5c4113dSnw141292 execsql {SELECT '0'==0.0} 690*c5c4113dSnw141292} {1} 691*c5c4113dSnw141292do_test format3-11.3 { 692*c5c4113dSnw141292 execsql {SELECT '123456789012345678901'=='123456789012345678900'} 693*c5c4113dSnw141292} {1} 694*c5c4113dSnw141292do_test format3-11.4 { 695*c5c4113dSnw141292 execsql { 696*c5c4113dSnw141292 CREATE TABLE t6(a INT UNIQUE, b TEXT UNIQUE); 697*c5c4113dSnw141292 INSERT INTO t6 VALUES('0','0.0'); 698*c5c4113dSnw141292 SELECT * FROM t6; 699*c5c4113dSnw141292 } 700*c5c4113dSnw141292} {0 0.0} 701*c5c4113dSnw141292do_test format3-11.5 { 702*c5c4113dSnw141292 execsql { 703*c5c4113dSnw141292 INSERT OR IGNORE INTO t6 VALUES(0.0,'x'); 704*c5c4113dSnw141292 SELECT * FROM t6; 705*c5c4113dSnw141292 } 706*c5c4113dSnw141292} {0 0.0} 707*c5c4113dSnw141292do_test format3-11.6 { 708*c5c4113dSnw141292 execsql { 709*c5c4113dSnw141292 INSERT OR IGNORE INTO t6 VALUES('y',0); 710*c5c4113dSnw141292 SELECT * FROM t6; 711*c5c4113dSnw141292 } 712*c5c4113dSnw141292} {0 0.0} 713*c5c4113dSnw141292do_test format3-11.7 { 714*c5c4113dSnw141292 execsql { 715*c5c4113dSnw141292 CREATE TABLE t7(x INTEGER, y TEXT, z); 716*c5c4113dSnw141292 INSERT INTO t7 VALUES(0,0,1); 717*c5c4113dSnw141292 INSERT INTO t7 VALUES(0.0,0,2); 718*c5c4113dSnw141292 INSERT INTO t7 VALUES(0,0.0,3); 719*c5c4113dSnw141292 INSERT INTO t7 VALUES(0.0,0.0,4); 720*c5c4113dSnw141292 SELECT DISTINCT x, y FROM t7 ORDER BY z; 721*c5c4113dSnw141292 } 722*c5c4113dSnw141292} {0 0} 723*c5c4113dSnw141292 724*c5c4113dSnw141292# Make sure attempts to attach a format 3 database fail. 725*c5c4113dSnw141292# 726*c5c4113dSnw141292do_test format3-12.1 { 727*c5c4113dSnw141292 file delete -force test2.db 728*c5c4113dSnw141292 sqlite db2 test2.db 729*c5c4113dSnw141292 catchsql { 730*c5c4113dSnw141292 CREATE TABLE t8(x,y); 731*c5c4113dSnw141292 ATTACH DATABASE 'test.db' AS format3; 732*c5c4113dSnw141292 } db2; 733*c5c4113dSnw141292} {1 {incompatible file format in auxiliary database: format3}} 734*c5c4113dSnw141292do_test format3-12.2 { 735*c5c4113dSnw141292 catchsql { 736*c5c4113dSnw141292 ATTACH DATABASE 'test2.db' AS test2; 737*c5c4113dSnw141292 } 738*c5c4113dSnw141292} {1 {cannot attach auxiliary databases to an older format master database}} 739*c5c4113dSnw141292db2 close 740*c5c4113dSnw141292 741*c5c4113dSnw141292finish_test 742