1be7721d1Sdan# 2008 December 23 2be7721d1Sdan# 3be7721d1Sdan# The author disclaims copyright to this source code. In place of 4be7721d1Sdan# a legal notice, here is a blessing: 5be7721d1Sdan# 6be7721d1Sdan# May you do good and not evil. 7be7721d1Sdan# May you find forgiveness for yourself and forgive others. 8be7721d1Sdan# May you share freely, never taking more than you give. 9be7721d1Sdan# 10be7721d1Sdan#*********************************************************************** 11be7721d1Sdan# This file implements regression tests for SQLite library. The focus 12be7721d1Sdan# is testing of where.c. More specifically, the focus is on handling OOM 13be7721d1Sdan# errors within the code that optimizes WHERE clauses that feature the 14be7721d1Sdan# OR operator. 15be7721d1Sdan# 16be7721d1Sdan 17be7721d1Sdanset testdir [file dirname $argv0] 18be7721d1Sdansource $testdir/tester.tcl 19be7721d1Sdan 20be7721d1Sdansource $testdir/malloc_common.tcl 21be7721d1Sdan 22be7721d1Sdanset testprefix wherefault 23be7721d1Sdan 24be7721d1Sdando_malloc_test 1 -sqlprep { 25be7721d1Sdan CREATE TABLE t1(a, b, c); 26be7721d1Sdan CREATE INDEX i1 ON t1(a); 27be7721d1Sdan CREATE INDEX i2 ON t1(b); 28be7721d1Sdan} -sqlbody { 29be7721d1Sdan SELECT c FROM t1 30be7721d1Sdan WHERE 31be7721d1Sdan a = 2 OR b = 'three' OR a = 4 OR b = 'five' OR a = 6 OR 32be7721d1Sdan b = 'seven' OR a = 8 OR b = 'nine' OR a = 10 33be7721d1Sdan ORDER BY rowid; 34be7721d1Sdan 35be7721d1Sdan SELECT c FROM t1 WHERE 36be7721d1Sdan a = 1 OR a = 2 OR a = 3 OR a = 4 OR a = 5 OR a = 6; 37be7721d1Sdan 38be7721d1Sdan SELECT c FROM t1 WHERE 39be7721d1Sdan a BETWEEN 1 AND 3 AND b < 5 AND b > 2 AND c = 4; 40be7721d1Sdan} 41be7721d1Sdan 42be7721d1Sdando_malloc_test 2 -tclprep { 43be7721d1Sdan db eval { 44be7721d1Sdan BEGIN; 45be7721d1Sdan CREATE TABLE t1(a, b, c); 46be7721d1Sdan CREATE INDEX i1 ON t1(a); 47be7721d1Sdan CREATE INDEX i2 ON t1(b); 48be7721d1Sdan } 49be7721d1Sdan for {set i 0} {$i < 1000} {incr i} { 50be7721d1Sdan set ii [expr $i*$i] 51be7721d1Sdan set iii [expr $i*$i] 52be7721d1Sdan db eval { INSERT INTO t1 VALUES($i, $ii, $iii) } 53be7721d1Sdan } 54be7721d1Sdan db eval COMMIT 55be7721d1Sdan} -sqlbody { 56be7721d1Sdan SELECT count(*) FROM t1 WHERE a BETWEEN 5 AND 995 OR b BETWEEN 5 AND 900000; 57be7721d1Sdan} 58be7721d1Sdan 59*37d4ec86Sdanreset_db 60*37d4ec86Sdando_execsql_test 3.0 { 61*37d4ec86Sdan PRAGMA writable_schema = 1; 62*37d4ec86Sdan BEGIN TRANSACTION; 63*37d4ec86Sdan CREATE TABLE t1( 64*37d4ec86Sdan a INT AS (c*11), 65*37d4ec86Sdan b TEXT AS (substr(d,1,3)) STORED, 66*37d4ec86Sdan c INTEGEB PRIMARI KEY, d TEXT 67*37d4ec86Sdan ); 68*37d4ec86Sdan CREATE INDEX t1a ON t1(a); 69*37d4ec86Sdan COMMIT; 70*37d4ec86Sdan} 71*37d4ec86Sdanfaultsim_save_and_close 72*37d4ec86Sdan 73*37d4ec86Sdando_faultsim_test 3.1 -faults oom* -prep { 74*37d4ec86Sdan faultsim_restore_and_reopen 75*37d4ec86Sdan} -body { 76*37d4ec86Sdan execsql { 77*37d4ec86Sdan SELECT * FROM (SELECT a FROM t1 NATURAL JOIN t1 WHERE a IN (SELECT b FROM t1 ORDER BY b)) WHERE (SELECT a FROM t1 NATURAL JOIN (SELECT * FROM (SELECT a FROM t1 NATURAL JOIN t1 WHERE a IN (SELECT CASE b WHEN 82 THEN 207 WHEN 869 THEN 406 WHEN 85 THEN 83 WHEN 705 THEN 698 ELSE 1992229051 END%5 FROM t1 ORDER BY b)) WHERE (SELECT a FROM t1 NATURAL JOIN (SELECT b FROM t1 ORDER BY b) WHERE a IN (SELECT b FROM t1 ORDER BY b))) WHERE a ); 78*37d4ec86Sdan } 79*37d4ec86Sdan} -test { 80*37d4ec86Sdan faultsim_test_result {0 {}} 81*37d4ec86Sdan} 82*37d4ec86Sdan 83be7721d1Sdanfinish_test 84