1d8ecefa5Sdan# 2017-07-15 2d8ecefa5Sdan# 3d8ecefa5Sdan# The author disclaims copyright to this source code. In place of 4d8ecefa5Sdan# a legal notice, here is a blessing: 5d8ecefa5Sdan# 6d8ecefa5Sdan# May you do good and not evil. 7d8ecefa5Sdan# May you find forgiveness for yourself and forgive others. 8d8ecefa5Sdan# May you share freely, never taking more than you give. 9d8ecefa5Sdan# 10d8ecefa5Sdan#*********************************************************************** 11d8ecefa5Sdan# This file implements regression tests for SQLite library. The 12d8ecefa5Sdan# focus of this file is percentile.c extension 13d8ecefa5Sdan# 14d8ecefa5Sdan 15d8ecefa5Sdanset testdir [file dirname $argv0] 16d8ecefa5Sdansource $testdir/tester.tcl 17d8ecefa5Sdanset testprefix unionvtab 18d8ecefa5Sdan 19*fb920e7eSdanifcapable !vtab { 20*fb920e7eSdan finish_test 21*fb920e7eSdan return 22*fb920e7eSdan} 23*fb920e7eSdan 24d8ecefa5Sdanload_static_extension db unionvtab 25d8ecefa5Sdan 26d8ecefa5Sdan#------------------------------------------------------------------------- 27d8ecefa5Sdan# Warm body tests. 28d8ecefa5Sdan# 29d8ecefa5Sdanforcedelete test.db2 30d8ecefa5Sdando_execsql_test 1.0 { 31d8ecefa5Sdan ATTACH 'test.db2' AS aux; 32d8ecefa5Sdan 33d8ecefa5Sdan CREATE TABLE t1(a INTEGER PRIMARY KEY, b TEXT); 34d8ecefa5Sdan CREATE TABLE t2(a INTEGER PRIMARY KEY, b TEXT); 35d8ecefa5Sdan CREATE TABLE aux.t3(a INTEGER PRIMARY KEY, b TEXT); 36d8ecefa5Sdan 37d8ecefa5Sdan 38d8ecefa5Sdan INSERT INTO t1 VALUES(1, 'one'), (2, 'two'), (3, 'three'); 39d8ecefa5Sdan INSERT INTO t2 VALUES(10, 'ten'), (11, 'eleven'), (12, 'twelve'); 40d8ecefa5Sdan INSERT INTO t3 VALUES(20, 'twenty'), (21, 'twenty-one'), (22, 'twenty-two'); 41d8ecefa5Sdan} 42d8ecefa5Sdan 43d8ecefa5Sdando_execsql_test 1.1 { 44d8ecefa5Sdan CREATE VIRTUAL TABLE temp.uuu USING unionvtab( 45d8ecefa5Sdan "VALUES(NULL, 't1', 1, 9), ('main', 't2', 10, 19), ('aux', 't3', 20, 29)" 46d8ecefa5Sdan ); 47d8ecefa5Sdan SELECT * FROM uuu; 48d8ecefa5Sdan} { 49d8ecefa5Sdan 1 one 2 two 3 three 50d8ecefa5Sdan 10 ten 11 eleven 12 twelve 51d8ecefa5Sdan 20 twenty 21 twenty-one 22 twenty-two 52d8ecefa5Sdan} 53d8ecefa5Sdan 54d8ecefa5Sdando_execsql_test 1.2 { 55d8ecefa5Sdan PRAGMA table_info(uuu); 56d8ecefa5Sdan} { 57d8ecefa5Sdan 0 a INTEGER 0 {} 0 58d8ecefa5Sdan 1 b TEXT 0 {} 0 59d8ecefa5Sdan} 60d8ecefa5Sdan 61d8ecefa5Sdando_execsql_test 1.3 { 62d8ecefa5Sdan SELECT * FROM uuu WHERE rowid = 3; 63d8ecefa5Sdan SELECT * FROM uuu WHERE rowid = 11; 64d8ecefa5Sdan} {3 three 11 eleven} 65d8ecefa5Sdan 66d8ecefa5Sdando_execsql_test 1.4 { 67d8ecefa5Sdan SELECT * FROM uuu WHERE rowid IN (12, 10, 2); 68d8ecefa5Sdan} {2 two 10 ten 12 twelve} 69d8ecefa5Sdan 70d8ecefa5Sdando_execsql_test 1.5 { 71d8ecefa5Sdan SELECT * FROM uuu WHERE rowid BETWEEN 3 AND 11; 72d8ecefa5Sdan} {3 three 10 ten 11 eleven} 73d8ecefa5Sdan 74d8ecefa5Sdando_execsql_test 1.6 { 75d8ecefa5Sdan SELECT * FROM uuu WHERE rowid BETWEEN 11 AND 15; 76d8ecefa5Sdan} {11 eleven 12 twelve} 77d8ecefa5Sdan 78d8ecefa5Sdando_execsql_test 1.7 { 79d8ecefa5Sdan SELECT * FROM uuu WHERE rowid BETWEEN -46 AND 1500; 80d8ecefa5Sdan} { 81d8ecefa5Sdan 1 one 2 two 3 three 82d8ecefa5Sdan 10 ten 11 eleven 12 twelve 83d8ecefa5Sdan 20 twenty 21 twenty-one 22 twenty-two 84d8ecefa5Sdan} 85d8ecefa5Sdan 867f3d20acSdando_execsql_test 1.8 { 877f3d20acSdan CREATE TABLE src(db, tbl, min, max); 887f3d20acSdan INSERT INTO src VALUES(NULL, 't1', 1, 9); 897f3d20acSdan INSERT INTO src VALUES('main', 't2', 10, 19); 907f3d20acSdan INSERT INTO src VALUES('aux', 't3', 20, 29); 917f3d20acSdan CREATE VIRTUAL TABLE temp.opp USING unionvtab(src); 927f3d20acSdan SELECT * FROM opp; 937f3d20acSdan} { 947f3d20acSdan 1 one 2 two 3 three 957f3d20acSdan 10 ten 11 eleven 12 twelve 967f3d20acSdan 20 twenty 21 twenty-one 22 twenty-two 977f3d20acSdan} 987f3d20acSdan 99d4603a2cSdando_execsql_test 1.9 { 100d4603a2cSdan CREATE VIRTUAL TABLE temp.qll USING unionvtab( 101d4603a2cSdan 'SELECT * FROM src WHERE db!=''xyz''' 102d4603a2cSdan ); 103d4603a2cSdan SELECT * FROM qll WHERE rowid BETWEEN 10 AND 21; 104d4603a2cSdan} { 105d4603a2cSdan 10 ten 11 eleven 12 twelve 106d4603a2cSdan 20 twenty 21 twenty-one 107d4603a2cSdan} 108d4603a2cSdan 109d8ecefa5Sdan#------------------------------------------------------------------------- 110d8ecefa5Sdan# Error conditions. 111d8ecefa5Sdan# 112d8ecefa5Sdan# 2.1.*: Attempt to create a unionvtab table outside of the TEMP schema. 113d8ecefa5Sdan# 2.2.*: Tables that do not exist. 11416bab5a7Sdan# 2.3.*: Non rowid tables. 115d8ecefa5Sdan# 2.4.*: Tables with mismatched schemas. 1167f3d20acSdan# 2.5.*: A unionvtab table with zero source tables. 117d8ecefa5Sdan# 118d8ecefa5Sdando_catchsql_test 2.1.1 { 119d8ecefa5Sdan CREATE VIRTUAL TABLE u1 USING unionvtab("VALUES(NULL, 't1', 1, 100)"); 120d8ecefa5Sdan} {1 {unionvtab tables must be created in TEMP schema}} 121d8ecefa5Sdando_catchsql_test 2.1.2 { 122d8ecefa5Sdan CREATE VIRTUAL TABLE main.u1 USING unionvtab("VALUES('', 't1', 1, 100)"); 123d8ecefa5Sdan} {1 {unionvtab tables must be created in TEMP schema}} 124d8ecefa5Sdando_catchsql_test 2.1.3 { 125d8ecefa5Sdan CREATE VIRTUAL TABLE aux.u1 USING unionvtab("VALUES('', 't1', 1, 100)"); 126d8ecefa5Sdan} {1 {unionvtab tables must be created in TEMP schema}} 127d8ecefa5Sdan 128d8ecefa5Sdando_catchsql_test 2.2.1 { 129d8ecefa5Sdan CREATE VIRTUAL TABLE temp.u1 USING unionvtab("VALUES(NULL, 't555', 1, 100)"); 130bcd303acSdan} {1 {no such rowid table: t555}} 131d8ecefa5Sdando_catchsql_test 2.2.2 { 132d8ecefa5Sdan CREATE VIRTUAL TABLE temp.u1 USING unionvtab("VALUES('aux', 't555', 1, 100)"); 133bcd303acSdan} {1 {no such rowid table: aux.t555}} 134d8ecefa5Sdando_catchsql_test 2.2.3 { 135d8ecefa5Sdan CREATE VIRTUAL TABLE temp.u1 USING unionvtab("VALUES('xua', 't555', 1, 100)"); 136bcd303acSdan} {1 {no such rowid table: xua.t555}} 137d8ecefa5Sdan 13816bab5a7Sdando_execsql_test 2.3.0 { 13916bab5a7Sdan CREATE TABLE wr1(a, b, c PRIMARY KEY) WITHOUT ROWID; 14016bab5a7Sdan CREATE VIEW v1 AS SELECT * FROM t1; 14116bab5a7Sdan CREATE VIEW v2 AS SELECT _rowid_, * FROM t1; 142d4603a2cSdan 143d4603a2cSdan CREATE TABLE wr2(a, _rowid_ INTEGER, c PRIMARY KEY) WITHOUT ROWID; 144d4603a2cSdan CREATE TABLE wr3(a, b, _rowid_ PRIMARY KEY) WITHOUT ROWID; 14516bab5a7Sdan} 14616bab5a7Sdando_catchsql_test 2.3.1 { 14716bab5a7Sdan CREATE VIRTUAL TABLE temp.u1 USING unionvtab("VALUES('main', 'wr1', 1, 2)"); 14816bab5a7Sdan} {1 {no such rowid table: main.wr1}} 14916bab5a7Sdando_catchsql_test 2.3.2 { 15016bab5a7Sdan CREATE VIRTUAL TABLE temp.u1 USING unionvtab("VALUES(NULL, 'v1', 1, 2)"); 15116bab5a7Sdan} {1 {no such rowid table: v1}} 15216bab5a7Sdando_catchsql_test 2.3.3 { 15316bab5a7Sdan CREATE VIRTUAL TABLE temp.u1 USING unionvtab("VALUES(NULL, 'v2', 1, 2)"); 15416bab5a7Sdan} {1 {no such rowid table: v2}} 155d4603a2cSdando_catchsql_test 2.3.4 { 156d4603a2cSdan CREATE VIRTUAL TABLE temp.u1 USING unionvtab("VALUES(NULL, 'wr2', 1, 2)"); 157d4603a2cSdan} {1 {no such rowid table: wr2}} 158d4603a2cSdando_catchsql_test 2.3.5 { 159d4603a2cSdan CREATE VIRTUAL TABLE temp.u1 USING unionvtab("VALUES(NULL, 'wr3', 1, 2)"); 160d4603a2cSdan} {1 {no such rowid table: wr3}} 16116bab5a7Sdan 162d8ecefa5Sdando_execsql_test 2.4.0 { 163d8ecefa5Sdan CREATE TABLE x1(a BLOB, b); 164d8ecefa5Sdan CREATE TABLE x2(a BLOB, b); 165d8ecefa5Sdan CREATE TEMP TABLE x3(a BLOB, b); 166d8ecefa5Sdan 167d8ecefa5Sdan CREATE TABLE aux.y1(one, two, three INTEGER PRIMARY KEY); 168d8ecefa5Sdan CREATE TEMP TABLE y2(one, two, three INTEGER PRIMARY KEY); 169d8ecefa5Sdan CREATE TABLE y3(one, two, three INTEGER PRIMARY KEY); 170d8ecefa5Sdan} 171d8ecefa5Sdan 172d8ecefa5Sdanforeach {tn dbs res} { 173d8ecefa5Sdan 1 {x1 x2 x3} {0 {}} 174d8ecefa5Sdan 2 {y1 y2 y3} {0 {}} 175d8ecefa5Sdan 3 {x1 y2 y3} {1 {source table schema mismatch}} 176d8ecefa5Sdan 4 {x1 y2 x3} {1 {source table schema mismatch}} 177d8ecefa5Sdan 5 {x1 x2 y3} {1 {source table schema mismatch}} 178d8ecefa5Sdan} { 179d8ecefa5Sdan set L [list] 180d8ecefa5Sdan set iMin 0 181d8ecefa5Sdan foreach e $dbs { 182d8ecefa5Sdan set E [split $e .] 183d8ecefa5Sdan if {[llength $E]>1} { 184d8ecefa5Sdan lappend L "('[lindex $E 0]', '[lindex $E 1]', $iMin, $iMin)" 185d8ecefa5Sdan } else { 186d8ecefa5Sdan lappend L "(NULL, '$e', $iMin, $iMin)" 187d8ecefa5Sdan } 188d8ecefa5Sdan incr iMin 189d8ecefa5Sdan } 190d8ecefa5Sdan 191d8ecefa5Sdan set sql "CREATE VIRTUAL TABLE temp.a1 USING unionvtab(\"VALUES [join $L ,]\")" 192d8ecefa5Sdan do_catchsql_test 2.4.$tn " 193d8ecefa5Sdan DROP TABLE IF EXISTS temp.a1; 194d8ecefa5Sdan CREATE VIRTUAL TABLE temp.a1 USING unionvtab(\"VALUES [join $L ,]\"); 195d8ecefa5Sdan " $res 196d8ecefa5Sdan} 197d8ecefa5Sdan 1987f3d20acSdando_catchsql_test 2.5 { 1997f3d20acSdan CREATE VIRTUAL TABLE temp.b1 USING unionvtab( 2007f3d20acSdan [SELECT 'main', 'b1', 0, 100 WHERE 0] 2017f3d20acSdan ) 2027f3d20acSdan} {1 {no source tables configured}} 2037f3d20acSdan 2047f3d20acSdanforeach {tn sql} { 2057f3d20acSdan 1 { VALUES('main', 't1', 10, 20), ('main', 't2', 30, 29) } 2067f3d20acSdan 2 { VALUES('main', 't1', 10, 20), ('main', 't2', 15, 30) } 2077f3d20acSdan} { 2087f3d20acSdan do_catchsql_test 2.6.$tn " 2097f3d20acSdan CREATE VIRTUAL TABLE temp.a1 USING unionvtab(`$sql`) 2107f3d20acSdan " {1 {rowid range mismatch error}} 2117f3d20acSdan} 2127f3d20acSdan 2137f3d20acSdando_catchsql_test 2.7.1 { 2147f3d20acSdan CREATE VIRTUAL TABLE temp.b1 USING unionvtab(1, 2, 3, 4) 2157f3d20acSdan} {1 {wrong number of arguments for unionvtab}} 2167f3d20acSdan 21716bab5a7Sdan#------------------------------------------------------------------------- 21816bab5a7Sdan# 21916bab5a7Sdanreset_db 22016bab5a7Sdanload_static_extension db unionvtab 22116bab5a7Sdando_execsql_test 3.0 { 22216bab5a7Sdan CREATE TABLE tbl1(a INTEGER PRIMARY KEY, b); 22316bab5a7Sdan CREATE TABLE tbl2(a INTEGER PRIMARY KEY, b); 22416bab5a7Sdan CREATE TABLE tbl3(a INTEGER PRIMARY KEY, b); 22516bab5a7Sdan 22616bab5a7Sdan WITH ss(ii) AS ( SELECT 1 UNION ALL SELECT ii+1 FROM ss WHERE ii<100 ) 22716bab5a7Sdan INSERT INTO tbl1 SELECT ii, '1.' || ii FROM ss; 22816bab5a7Sdan 22916bab5a7Sdan WITH ss(ii) AS ( SELECT 1 UNION ALL SELECT ii+1 FROM ss WHERE ii<100 ) 23016bab5a7Sdan INSERT INTO tbl2 SELECT ii, '2.' || ii FROM ss; 23116bab5a7Sdan 23216bab5a7Sdan WITH ss(ii) AS ( SELECT 1 UNION ALL SELECT ii+1 FROM ss WHERE ii<100 ) 23316bab5a7Sdan INSERT INTO tbl3 SELECT ii, '3.' || ii FROM ss; 23416bab5a7Sdan 23516bab5a7Sdan CREATE VIRTUAL TABLE temp.uu USING unionvtab( 23616bab5a7Sdan "VALUES(NULL,'tbl2', 26, 74), (NULL,'tbl3', 75, 100), (NULL,'tbl1', 1, 25)" 23716bab5a7Sdan ); 23816bab5a7Sdan} 23916bab5a7Sdan 24016bab5a7Sdando_execsql_test 3.1 { 24116bab5a7Sdan SELECT * FROM uu WHERE rowid = 10; 24216bab5a7Sdan} {10 {1.10}} 24316bab5a7Sdando_execsql_test 3.2 { 24416bab5a7Sdan SELECT * FROM uu WHERE rowid = 25; 24516bab5a7Sdan} {25 {1.25}} 24616bab5a7Sdan 24716bab5a7Sdando_execsql_test 3.3 { SELECT count(*) FROM uu WHERE rowid <= 24 } {24} 24816bab5a7Sdan 24916bab5a7Sdan# The following queries get the "wrong" answers. This is because the 25016bab5a7Sdan# module assumes that each source table contains rowids from only within 25116bab5a7Sdan# the range specified. For example, (rowid <= 25) matches 100 rows. This 25216bab5a7Sdan# is because the module implements (rowid <= 25) as a full table scan 25316bab5a7Sdan# of tbl1 only. 25416bab5a7Sdando_execsql_test 3.4.1 { SELECT count(*) FROM uu WHERE rowid <= 25 } {100} 25516bab5a7Sdando_execsql_test 3.4.2 { SELECT count(*) FROM uu WHERE rowid <= 26 } {126} 25616bab5a7Sdando_execsql_test 3.4.3 { SELECT count(*) FROM uu WHERE rowid <= 73 } {173} 25716bab5a7Sdando_execsql_test 3.4.4 { SELECT count(*) FROM uu WHERE rowid <= 74 } {200} 25816bab5a7Sdando_execsql_test 3.4.5 { SELECT count(*) FROM uu WHERE rowid <= 75 } {275} 25916bab5a7Sdando_execsql_test 3.4.6 { SELECT count(*) FROM uu WHERE rowid <= 99 } {299} 26016bab5a7Sdando_execsql_test 3.4.7 { SELECT count(*) FROM uu WHERE rowid <= 100 } {300} 26116bab5a7Sdando_execsql_test 3.4.8 { SELECT count(*) FROM uu WHERE rowid <= 101 } {300} 26216bab5a7Sdan 26316bab5a7Sdando_execsql_test 3.5.1 { SELECT count(*) FROM uu WHERE rowid < 25 } {24} 26416bab5a7Sdando_execsql_test 3.5.2 { SELECT count(*) FROM uu WHERE rowid < 26 } {100} 26516bab5a7Sdando_execsql_test 3.5.3 { SELECT count(*) FROM uu WHERE rowid < 27 } {126} 26616bab5a7Sdando_execsql_test 3.5.4 { SELECT count(*) FROM uu WHERE rowid < 73 } {172} 26716bab5a7Sdando_execsql_test 3.5.5 { SELECT count(*) FROM uu WHERE rowid < 74 } {173} 26816bab5a7Sdando_execsql_test 3.5.6 { SELECT count(*) FROM uu WHERE rowid < 75 } {200} 26916bab5a7Sdando_execsql_test 3.5.7 { SELECT count(*) FROM uu WHERE rowid < 76 } {275} 27016bab5a7Sdando_execsql_test 3.5.8 { SELECT count(*) FROM uu WHERE rowid < 99 } {298} 27116bab5a7Sdando_execsql_test 3.5.9 { SELECT count(*) FROM uu WHERE rowid < 100 } {299} 27216bab5a7Sdando_execsql_test 3.5.10 { SELECT count(*) FROM uu WHERE rowid < 101 } {300} 27316bab5a7Sdan 27416bab5a7Sdando_execsql_test 3.6.1 { SELECT count(*) FROM uu WHERE rowid > 24 } {276} 27516bab5a7Sdando_execsql_test 3.6.1 { SELECT count(*) FROM uu WHERE rowid > 25 } {200} 27616bab5a7Sdando_execsql_test 3.6.2 { SELECT count(*) FROM uu WHERE rowid > 26 } {174} 27716bab5a7Sdando_execsql_test 3.6.3 { SELECT count(*) FROM uu WHERE rowid > 27 } {173} 27816bab5a7Sdando_execsql_test 3.6.4 { SELECT count(*) FROM uu WHERE rowid > 73 } {127} 27916bab5a7Sdando_execsql_test 3.6.5 { SELECT count(*) FROM uu WHERE rowid > 74 } {100} 28016bab5a7Sdando_execsql_test 3.6.6 { SELECT count(*) FROM uu WHERE rowid > 75 } {25} 28116bab5a7Sdando_execsql_test 3.6.7 { SELECT count(*) FROM uu WHERE rowid > 76 } {24} 28216bab5a7Sdando_execsql_test 3.6.8 { SELECT count(*) FROM uu WHERE rowid > 99 } {1} 28316bab5a7Sdando_execsql_test 3.6.9 { SELECT count(*) FROM uu WHERE rowid > 100 } {0} 28416bab5a7Sdando_execsql_test 3.6.10 { SELECT count(*) FROM uu WHERE rowid > 101 } {0} 28516bab5a7Sdan 28616bab5a7Sdando_execsql_test 3.7.1 { SELECT count(*) FROM uu WHERE rowid >= 24 } {277} 28716bab5a7Sdando_execsql_test 3.7.1 { SELECT count(*) FROM uu WHERE rowid >= 25 } {276} 28816bab5a7Sdando_execsql_test 3.7.2 { SELECT count(*) FROM uu WHERE rowid >= 26 } {200} 28916bab5a7Sdando_execsql_test 3.7.3 { SELECT count(*) FROM uu WHERE rowid >= 27 } {174} 29016bab5a7Sdando_execsql_test 3.7.4 { SELECT count(*) FROM uu WHERE rowid >= 73 } {128} 29116bab5a7Sdando_execsql_test 3.7.5 { SELECT count(*) FROM uu WHERE rowid >= 74 } {127} 29216bab5a7Sdando_execsql_test 3.7.6 { SELECT count(*) FROM uu WHERE rowid >= 75 } {100} 29316bab5a7Sdando_execsql_test 3.7.7 { SELECT count(*) FROM uu WHERE rowid >= 76 } {25} 29416bab5a7Sdando_execsql_test 3.7.8 { SELECT count(*) FROM uu WHERE rowid >= 99 } {2} 29516bab5a7Sdando_execsql_test 3.7.9 { SELECT count(*) FROM uu WHERE rowid >= 100 } {1} 29616bab5a7Sdando_execsql_test 3.7.10 { SELECT count(*) FROM uu WHERE rowid >= 101 } {0} 297d8ecefa5Sdan 2988342aa0dSdanset L [expr 9223372036854775807] 2998342aa0dSdanset S [expr -9223372036854775808] 3008342aa0dSdan 3018342aa0dSdando_execsql_test 3.8.1 { SELECT count(*) FROM uu WHERE rowid >= $S } {300} 3028342aa0dSdando_execsql_test 3.8.2 { SELECT count(*) FROM uu WHERE rowid > $S } {300} 3038342aa0dSdando_execsql_test 3.8.3 { SELECT count(*) FROM uu WHERE rowid <= $S } {0} 3048342aa0dSdando_execsql_test 3.8.4 { SELECT count(*) FROM uu WHERE rowid < $S } {0} 3058342aa0dSdan 3068342aa0dSdando_execsql_test 3.9.1 { SELECT count(*) FROM uu WHERE rowid >= $L } {0} 3078342aa0dSdando_execsql_test 3.9.2 { SELECT count(*) FROM uu WHERE rowid > $L } {0} 3088342aa0dSdando_execsql_test 3.9.3 { SELECT count(*) FROM uu WHERE rowid <= $L } {300} 3098342aa0dSdando_execsql_test 3.9.4 { SELECT count(*) FROM uu WHERE rowid < $L } {300} 3108342aa0dSdan 311090f68a3Sdando_execsql_test 3.10.1 { SELECT count(*) FROM uu WHERE a < 25 } {24} 312090f68a3Sdando_execsql_test 3.10.2 { SELECT count(*) FROM uu WHERE a < 26 } {100} 313090f68a3Sdando_execsql_test 3.10.3 { SELECT count(*) FROM uu WHERE a < 27 } {126} 314090f68a3Sdando_execsql_test 3.10.4 { SELECT count(*) FROM uu WHERE a < 73 } {172} 315090f68a3Sdando_execsql_test 3.10.5 { SELECT count(*) FROM uu WHERE a < 74 } {173} 316090f68a3Sdando_execsql_test 3.10.6 { SELECT count(*) FROM uu WHERE a < 75 } {200} 317090f68a3Sdando_execsql_test 3.10.7 { SELECT count(*) FROM uu WHERE a < 76 } {275} 318090f68a3Sdando_execsql_test 3.10.8 { SELECT count(*) FROM uu WHERE a < 99 } {298} 319090f68a3Sdando_execsql_test 3.10.9 { SELECT count(*) FROM uu WHERE a < 100 } {299} 320090f68a3Sdando_execsql_test 3.10.10 { SELECT count(*) FROM uu WHERE a < 101 } {300} 321090f68a3Sdan 322090f68a3Sdan 3238342aa0dSdan#------------------------------------------------------------------------- 3248342aa0dSdan# 3258342aa0dSdando_execsql_test 4.0 { 3268342aa0dSdan CREATE TABLE s1(k INTEGER PRIMARY KEY, v); 3278342aa0dSdan INSERT INTO s1 VALUES($S, 'one'); 3288342aa0dSdan INSERT INTO s1 VALUES($S+1, 'two'); 3298342aa0dSdan INSERT INTO s1 VALUES($S+2, 'three'); 3308342aa0dSdan 3318342aa0dSdan CREATE TABLE l1(k INTEGER PRIMARY KEY, v); 3328342aa0dSdan INSERT INTO l1 VALUES($L, 'six'); 3338342aa0dSdan INSERT INTO l1 VALUES($L-1, 'five'); 3348342aa0dSdan INSERT INTO l1 VALUES($L-2, 'four'); 3358342aa0dSdan 3368342aa0dSdan CREATE VIRTUAL TABLE temp.sl USING unionvtab( 3378342aa0dSdan "SELECT NULL, 'l1', 0, 9223372036854775807 3388342aa0dSdan UNION ALL 3398342aa0dSdan SELECT NULL, 's1', -9223372036854775808, -1" 3408342aa0dSdan ); 3418342aa0dSdan} 3428342aa0dSdan 3438342aa0dSdando_execsql_test 4.1 { 3448342aa0dSdan SELECT * FROM sl; 3458342aa0dSdan} { 3468342aa0dSdan -9223372036854775808 one -9223372036854775807 two -9223372036854775806 three 3478342aa0dSdan 9223372036854775805 four 9223372036854775806 five 9223372036854775807 six 3488342aa0dSdan} 3498342aa0dSdan 3508342aa0dSdanforeach {k v} { 3518342aa0dSdan -9223372036854775808 one -9223372036854775807 two -9223372036854775806 three 3528342aa0dSdan 9223372036854775805 four 9223372036854775806 five 9223372036854775807 six 3538342aa0dSdan} { 3548342aa0dSdan do_execsql_test 4.2.$v { SELECT * FROM sl WHERE rowid=$k } [list $k $v] 3558342aa0dSdan} 3568342aa0dSdan 3578342aa0dSdando_execsql_test 4.3.1 { 3588342aa0dSdan SELECT * FROM sl WHERE rowid>-9223372036854775808 3598342aa0dSdan} { 3608342aa0dSdan -9223372036854775807 two -9223372036854775806 three 3618342aa0dSdan 9223372036854775805 four 9223372036854775806 five 9223372036854775807 six 3628342aa0dSdan} 3638342aa0dSdando_execsql_test 4.3.2 { 3648342aa0dSdan SELECT * FROM sl WHERE rowid>=-9223372036854775808 3658342aa0dSdan} { 3668342aa0dSdan -9223372036854775808 one -9223372036854775807 two -9223372036854775806 three 3678342aa0dSdan 9223372036854775805 four 9223372036854775806 five 9223372036854775807 six 3688342aa0dSdan} 3698342aa0dSdando_execsql_test 4.3.3 { 3708342aa0dSdan SELECT * FROM sl WHERE rowid<=-9223372036854775808 3718342aa0dSdan} { 3728342aa0dSdan -9223372036854775808 one 3738342aa0dSdan} 3748342aa0dSdando_execsql_test 4.3.4 { 3758342aa0dSdan SELECT * FROM sl WHERE rowid<-9223372036854775808 3768342aa0dSdan} {} 3778342aa0dSdan 3788342aa0dSdando_execsql_test 4.4.1 { 3798342aa0dSdan SELECT * FROM sl WHERE rowid<9223372036854775807 3808342aa0dSdan} { 3818342aa0dSdan -9223372036854775808 one -9223372036854775807 two -9223372036854775806 three 3828342aa0dSdan 9223372036854775805 four 9223372036854775806 five 3838342aa0dSdan} 3848342aa0dSdando_execsql_test 4.4.2 { 3858342aa0dSdan SELECT * FROM sl WHERE rowid<=9223372036854775807 3868342aa0dSdan} { 3878342aa0dSdan -9223372036854775808 one -9223372036854775807 two -9223372036854775806 three 3888342aa0dSdan 9223372036854775805 four 9223372036854775806 five 9223372036854775807 six 3898342aa0dSdan} 390aecd4387Smistachkindo_execsql_test 4.4.3 { 3918342aa0dSdan SELECT * FROM sl WHERE rowid>=9223372036854775807 3928342aa0dSdan} { 3938342aa0dSdan 9223372036854775807 six 3948342aa0dSdan} 3958342aa0dSdando_execsql_test 4.4.4 { 3968342aa0dSdan SELECT * FROM sl WHERE rowid>9223372036854775807 3978342aa0dSdan} {} 3988342aa0dSdan 399d4603a2cSdan#------------------------------------------------------------------------- 400d4603a2cSdan# More than 8 source tables. 401d4603a2cSdan# 402d4603a2cSdando_execsql_test 5.0 { 403d4603a2cSdan CREATE TABLE c0(one, two INTEGER PRIMARY KEY); 404d4603a2cSdan CREATE TABLE c1(one, two INTEGER PRIMARY KEY); 405d4603a2cSdan CREATE TABLE c2(one, two INTEGER PRIMARY KEY); 406d4603a2cSdan CREATE TABLE c3(one, two INTEGER PRIMARY KEY); 407d4603a2cSdan CREATE TABLE c4(one, two INTEGER PRIMARY KEY); 408d4603a2cSdan CREATE TABLE c5(one, two INTEGER PRIMARY KEY); 409d4603a2cSdan CREATE TABLE c6(one, two INTEGER PRIMARY KEY); 410d4603a2cSdan CREATE TABLE c7(one, two INTEGER PRIMARY KEY); 411d4603a2cSdan CREATE TABLE c8(one, two INTEGER PRIMARY KEY); 412d4603a2cSdan CREATE TABLE c9(one, two INTEGER PRIMARY KEY); 413d4603a2cSdan 414d4603a2cSdan INSERT INTO c0 VALUES('zero', 0); 415d4603a2cSdan INSERT INTO c1 VALUES('one', 1); 416d4603a2cSdan INSERT INTO c2 VALUES('two', 2); 417d4603a2cSdan INSERT INTO c3 VALUES('three', 3); 418d4603a2cSdan INSERT INTO c4 VALUES('four', 4); 419d4603a2cSdan INSERT INTO c5 VALUES('five', 5); 420d4603a2cSdan INSERT INTO c6 VALUES('six', 6); 421d4603a2cSdan INSERT INTO c7 VALUES('seven', 7); 422d4603a2cSdan INSERT INTO c8 VALUES('eight', 8); 423d4603a2cSdan INSERT INTO c9 VALUES('nine', 9); 424d4603a2cSdan 425d4603a2cSdan CREATE VIRTUAL TABLE temp.cc USING unionvtab([ 426d4603a2cSdan SELECT 'main', 'c9', 9, 9 UNION ALL 427d4603a2cSdan SELECT 'main', 'c8', 8, 8 UNION ALL 428d4603a2cSdan SELECT 'main', 'c7', 7, 7 UNION ALL 429d4603a2cSdan SELECT 'main', 'c6', 6, 6 UNION ALL 430d4603a2cSdan SELECT 'main', 'c5', 5, 5 UNION ALL 431d4603a2cSdan SELECT 'main', 'c4', 4, 4 UNION ALL 432d4603a2cSdan SELECT 'main', 'c3', 3, 3 UNION ALL 433d4603a2cSdan SELECT 'main', 'c2', 2, 2 UNION ALL 434d4603a2cSdan SELECT 'main', 'c1', 1, 1 UNION ALL 435d4603a2cSdan SELECT 'main', 'c0', 0, 0 436d4603a2cSdan ]); 437d4603a2cSdan 438d4603a2cSdan SELECT sum(two) FROM cc; 439d4603a2cSdan} {45} 440d4603a2cSdan 441d4603a2cSdando_execsql_test 5.1 { 442d4603a2cSdan SELECT one FROM cc WHERE one>='seven' 443d4603a2cSdan} {zero two three six seven} 444d4603a2cSdan 445d4603a2cSdando_execsql_test 5.2 { 446d4603a2cSdan SELECT y.one FROM cc AS x, cc AS y WHERE x.one=y.one AND x.rowid>5 447d4603a2cSdan} {six seven eight nine} 448d4603a2cSdan 449d4603a2cSdando_execsql_test 5.3 { 450d4603a2cSdan SELECT cc.one FROM c4, cc WHERE cc.rowid>c4.rowid 451d4603a2cSdan} {five six seven eight nine} 452d4603a2cSdan 453d4603a2cSdando_execsql_test 5.4 { 454d4603a2cSdan SELECT * FROM cc WHERE two LIKE '6' 455d4603a2cSdan} {six 6} 456d4603a2cSdan 457d8ecefa5Sdanfinish_test 458