1# 2010 March 25 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# This file implements tests to verify that ticket [cbd054fa6b] has been 13# fixed. 14# 15 16set testdir [file dirname $argv0] 17source $testdir/tester.tcl 18 19ifcapable !stat4&&!stat3 { 20 finish_test 21 return 22} 23 24proc s {blob} { 25 set ret "" 26 binary scan $blob c* bytes 27 foreach b $bytes { 28 set t [binary format c $b] 29 if {[string is print $t]} { 30 append ret $t 31 } else { 32 append ret . 33 } 34 } 35 return $ret 36} 37db function s s 38 39do_test tkt-cbd05-1.1 { 40 db eval { 41 CREATE TABLE t1(a INTEGER PRIMARY KEY, b TEXT UNIQUE NOT NULL); 42 CREATE INDEX t1_x ON t1(b); 43 INSERT INTO t1 VALUES (NULL, ''); 44 INSERT INTO t1 VALUES (NULL, 'A'); 45 INSERT INTO t1 VALUES (NULL, 'B'); 46 INSERT INTO t1 VALUES (NULL, 'C'); 47 INSERT INTO t1 VALUES (NULL, 'D'); 48 INSERT INTO t1 VALUES (NULL, 'E'); 49 INSERT INTO t1 VALUES (NULL, 'F'); 50 INSERT INTO t1 VALUES (NULL, 'G'); 51 INSERT INTO t1 VALUES (NULL, 'H'); 52 INSERT INTO t1 VALUES (NULL, 'I'); 53 SELECT count(*) FROM t1; 54 } 55} {10} 56do_test tkt-cbd05-1.2 { 57 db eval { ANALYZE; } 58 ifcapable stat4 { 59 db eval { 60 PRAGMA writable_schema = 1; 61 CREATE VIEW vvv AS 62 SELECT tbl,idx,neq,nlt,ndlt,test_extract(sample,0) AS sample 63 FROM sqlite_stat4; 64 PRAGMA writable_schema = 0; 65 } 66 } else { 67 db eval { 68 CREATE VIEW vvv AS 69 SELECT tbl,idx,neq,nlt,ndlt,sample FROM sqlite_stat3; 70 } 71 } 72} {} 73do_test tkt-cbd05-1.3 { 74 execsql { 75 SELECT tbl,idx,group_concat(s(sample),' ') 76 FROM vvv 77 WHERE idx = 't1_x' 78 GROUP BY tbl,idx 79 } 80} {t1 t1_x { A B C D E F G H I}} 81 82do_test tkt-cbd05-2.1 { 83 db eval { 84 DROP TABLE t1; 85 CREATE TABLE t1(a INTEGER PRIMARY KEY, b BLOB UNIQUE NOT NULL); 86 CREATE INDEX t1_x ON t1(b); 87 INSERT INTO t1 VALUES(NULL, X''); 88 INSERT INTO t1 VALUES(NULL, X'41'); 89 INSERT INTO t1 VALUES(NULL, X'42'); 90 INSERT INTO t1 VALUES(NULL, X'43'); 91 INSERT INTO t1 VALUES(NULL, X'44'); 92 INSERT INTO t1 VALUES(NULL, X'45'); 93 INSERT INTO t1 VALUES(NULL, X'46'); 94 INSERT INTO t1 VALUES(NULL, X'47'); 95 INSERT INTO t1 VALUES(NULL, X'48'); 96 INSERT INTO t1 VALUES(NULL, X'49'); 97 SELECT count(*) FROM t1; 98 } 99} {10} 100do_test tkt-cbd05-2.2 { 101 db eval { 102 ANALYZE; 103 } 104} {} 105do_test tkt-cbd05-2.3 { 106 execsql { 107 SELECT tbl,idx,group_concat(s(sample),' ') 108 FROM vvv 109 WHERE idx = 't1_x' 110 GROUP BY tbl,idx 111 } 112} {t1 t1_x { A B C D E F G H I}} 113 114finish_test 115