1# 2014 November 1 2# 3# The author disclaims copyright to this source code. In place of 4# a legal notice, here is a blessing: 5# 6# May you do good and not evil. 7# May you find forgiveness for yourself and forgive others. 8# May you share freely, never taking more than you give. 9# 10#*********************************************************************** 11# 12 13set testdir [file dirname $argv0] 14source $testdir/tester.tcl 15set testprefix scanstatus 16 17do_execsql_test 1.0 { 18 CREATE TABLE t1(a, b); 19 CREATE TABLE t2(x, y); 20 INSERT INTO t1 VALUES(1, 2); 21 INSERT INTO t1 VALUES(3, 4); 22 INSERT INTO t2 VALUES('a', 'b'); 23 INSERT INTO t2 VALUES('c', 'd'); 24 INSERT INTO t2 VALUES('e', 'f'); 25} 26 27proc do_scanstatus_test {tn res} { 28 set stmt [db_last_stmt_ptr db] 29 set idx 0 30 set ret [list] 31 while {1} { 32 set r [sqlite3_stmt_scanstatus $stmt $idx] 33 if {[llength $r]==0} break 34 lappend ret {*}$r 35 incr idx 36 } 37 38 uplevel [list do_test $tn [list set {} $ret] [list {*}$res]] 39} 40 41do_execsql_test 1.1 { SELECT count(*) FROM t1, t2; } 6 42do_scanstatus_test 1.2 { 43 nLoop 1 nVisit 2 nEst 1048576 zName t1 zExplain {SCAN TABLE t1} 44 nLoop 2 nVisit 6 nEst 1048576 zName t2 zExplain {SCAN TABLE t2} 45} 46 47do_execsql_test 1.3 { 48 ANALYZE; 49 SELECT count(*) FROM t1, t2; 50} 6 51do_scanstatus_test 1.4 { 52 nLoop 1 nVisit 2 nEst 2 zName t1 zExplain {SCAN TABLE t1} 53 nLoop 2 nVisit 6 nEst 3 zName t2 zExplain {SCAN TABLE t2} 54} 55 56do_execsql_test 1.5 { 57 ANALYZE; 58 SELECT count(*) FROM t1, t2 WHERE t2.rowid>1; 59} 4 60do_scanstatus_test 1.6 { 61 nLoop 1 nVisit 2 nEst 2 zName t2 zExplain 62 {SEARCH TABLE t2 USING INTEGER PRIMARY KEY (rowid>?)} 63 nLoop 2 nVisit 4 nEst 2 zName t1 zExplain {SCAN TABLE t1} 64} 65 66 67 68 69finish_test 70