blob: 2951233a5bb974c5213b7df5bd3950f585848386 [file] [log] [blame]
shaneh1141ae22010-03-26 01:54:33 +00001# 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
dan8ad169a2013-08-12 20:14:04 +000019ifcapable !stat4&&!stat3 {
shaneh1141ae22010-03-26 01:54:33 +000020 finish_test
21 return
22}
23
danf52bb8d2013-08-03 20:24:58 +000024proc 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
shaneh1141ae22010-03-26 01:54:33 +000039do_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 {
dan8ad169a2013-08-12 20:14:04 +000057 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 }
shaneh1141ae22010-03-26 01:54:33 +000071 }
72} {}
73do_test tkt-cbd05-1.3 {
74 execsql {
danf52bb8d2013-08-03 20:24:58 +000075 SELECT tbl,idx,group_concat(s(sample),' ')
dan8ad169a2013-08-12 20:14:04 +000076 FROM vvv
shaneh1141ae22010-03-26 01:54:33 +000077 WHERE idx = 't1_x'
78 GROUP BY tbl,idx
79 }
dan8ad169a2013-08-12 20:14:04 +000080} {t1 t1_x { A B C D E F G H I}}
shaneh1141ae22010-03-26 01:54:33 +000081
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 {
danf52bb8d2013-08-03 20:24:58 +0000107 SELECT tbl,idx,group_concat(s(sample),' ')
dan8ad169a2013-08-12 20:14:04 +0000108 FROM vvv
shaneh1141ae22010-03-26 01:54:33 +0000109 WHERE idx = 't1_x'
110 GROUP BY tbl,idx
111 }
dan8ad169a2013-08-12 20:14:04 +0000112} {t1 t1_x { A B C D E F G H I}}
shaneh1141ae22010-03-26 01:54:33 +0000113
114finish_test