blob: 06e97792dfd7c326151502007ed111eeb9a2ff8f [file] [log] [blame]
dan6d3eb822010-07-12 18:12:41 +00001# 2010 July 09
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# This file implements regression tests for SQLite library. The
12# focus of this file is testing the SELECT statement.
13#
14
15set testdir [file dirname $argv0]
16source $testdir/tester.tcl
17
18ifcapable !vtab {
19 finish_test
20 return
21}
22
23
24set ::asc 1
25proc a_string {n} { string range [string repeat [incr ::asc]. $n] 1 $n }
26db func a_string a_string
27
28register_dbstat_vtab db
29do_execsql_test stat-0.0 {
30 CREATE VIRTUAL TABLE temp.stat USING dbstat;
31 SELECT * FROM stat;
32} {}
shaneh9091f772010-08-24 18:35:12 +000033
34ifcapable wal {
35 do_execsql_test stat-0.1 {
36 PRAGMA journal_mode = WAL;
37 PRAGMA journal_mode = delete;
38 SELECT * FROM stat;
39 } {wal delete sqlite_master / 1 leaf 0 0 916 0}
40}
dan6d3eb822010-07-12 18:12:41 +000041
42do_test stat-1.0 {
43 execsql {
44 CREATE TABLE t1(a, b);
45 CREATE INDEX i1 ON t1(b);
dan2d07f262010-07-19 12:05:33 +000046 INSERT INTO t1(rowid, a, b) VALUES(2, 2, 3);
47 INSERT INTO t1(rowid, a, b) VALUES(3, 4, 5);
dan6d3eb822010-07-12 18:12:41 +000048 }
49} {}
50do_test stat-1.1 {
51 execsql {
52 SELECT * FROM stat WHERE name = 't1';
53 }
54} {t1 / 2 leaf 2 10 998 5}
55do_test stat-1.2 {
56 execsql {
57 SELECT * FROM stat WHERE name = 'i1';
58 }
59} {i1 / 3 leaf 2 10 1000 5}
60do_test stat-1.3 {
61 execsql {
62 SELECT * FROM stat WHERE name = 'sqlite_master';
63 }
64} {sqlite_master / 1 leaf 2 77 831 40}
65do_test stat-1.4 {
66 execsql {
67 DROP TABLE t1;
68 }
69} {}
70
71do_execsql_test stat-2.1 {
72 CREATE TABLE t3(a PRIMARY KEY, b);
dan2d07f262010-07-19 12:05:33 +000073 INSERT INTO t3(rowid, a, b) VALUES(2, a_string(111), a_string(222));
74 INSERT INTO t3 SELECT a_string(110+rowid), a_string(221+rowid) FROM t3;
75 INSERT INTO t3 SELECT a_string(110+rowid), a_string(221+rowid) FROM t3;
76 INSERT INTO t3 SELECT a_string(110+rowid), a_string(221+rowid) FROM t3;
77 INSERT INTO t3 SELECT a_string(110+rowid), a_string(221+rowid) FROM t3;
78 INSERT INTO t3 SELECT a_string(110+rowid), a_string(221+rowid) FROM t3;
dan6d3eb822010-07-12 18:12:41 +000079 SELECT * FROM stat WHERE name != 'sqlite_master';
80} [list \
81 sqlite_autoindex_t3_1 / 3 internal 3 368 623 125 \
82 sqlite_autoindex_t3_1 /000/ 8 leaf 8 946 46 123 \
83 sqlite_autoindex_t3_1 /001/ 9 leaf 8 988 2 131 \
84 sqlite_autoindex_t3_1 /002/ 15 leaf 7 857 137 132 \
85 sqlite_autoindex_t3_1 /003/ 20 leaf 6 739 257 129 \
86 t3 / 2 internal 15 0 907 0 \
87 t3 /000/ 4 leaf 2 678 328 340 \
88 t3 /001/ 5 leaf 2 682 324 342 \
89 t3 /002/ 6 leaf 2 682 324 342 \
90 t3 /003/ 7 leaf 2 690 316 346 \
91 t3 /004/ 10 leaf 2 682 324 342 \
92 t3 /005/ 11 leaf 2 690 316 346 \
93 t3 /006/ 12 leaf 2 698 308 350 \
94 t3 /007/ 13 leaf 2 706 300 354 \
95 t3 /008/ 14 leaf 2 682 324 342 \
96 t3 /009/ 16 leaf 2 690 316 346 \
97 t3 /00a/ 17 leaf 2 698 308 350 \
98 t3 /00b/ 18 leaf 2 706 300 354 \
99 t3 /00c/ 19 leaf 2 714 292 358 \
100 t3 /00d/ 21 leaf 2 722 284 362 \
101 t3 /00e/ 22 leaf 2 730 276 366 \
102 t3 /00f/ 23 leaf 2 738 268 370 \
103]
104do_execsql_test stat-2.2 { DROP TABLE t3 } {}
105
106do_execsql_test stat-3.1 {
107 CREATE TABLE t4(x);
108 CREATE INDEX i4 ON t4(x);
dan2d07f262010-07-19 12:05:33 +0000109 INSERT INTO t4(rowid, x) VALUES(2, a_string(7777));
dan6d3eb822010-07-12 18:12:41 +0000110 SELECT * FROM stat WHERE name != 'sqlite_master';
111} [list \
112 i4 / 3 leaf 1 103 905 7782 \
113 i4 /000+000000 9 overflow 0 1020 0 0 \
114 i4 /000+000001 10 overflow 0 1020 0 0 \
115 i4 /000+000002 11 overflow 0 1020 0 0 \
116 i4 /000+000003 12 overflow 0 1020 0 0 \
117 i4 /000+000004 13 overflow 0 1020 0 0 \
118 i4 /000+000005 14 overflow 0 1020 0 0 \
119 i4 /000+000006 15 overflow 0 1020 0 0 \
120 i4 /000+000007 16 overflow 0 539 481 0 \
121 t4 / 2 leaf 1 640 367 7780 \
122 t4 /000+000000 22 overflow 0 1020 0 0 \
123 t4 /000+000001 23 overflow 0 1020 0 0 \
124 t4 /000+000002 21 overflow 0 1020 0 0 \
125 t4 /000+000003 20 overflow 0 1020 0 0 \
126 t4 /000+000004 19 overflow 0 1020 0 0 \
127 t4 /000+000005 18 overflow 0 1020 0 0 \
128 t4 /000+000006 17 overflow 0 1020 0 0 \
129]
130
131do_execsql_test stat-4.1 {
132 CREATE TABLE t5(x);
133 CREATE INDEX i5 ON t5(x);
134 SELECT * FROM stat WHERE name = 't5' OR name = 'i5';
135} [list \
136 i5 / 5 leaf 0 0 1016 0 \
137 t5 / 4 leaf 0 0 1016 0 \
138]
139
140db close
141file delete -force test.db
142sqlite3 db test.db
143register_dbstat_vtab db
144breakpoint
145do_execsql_test stat-5.1 {
146 CREATE VIRTUAL TABLE temp.stat USING dbstat;
147 CREATE TABLE t1(x);
148 INSERT INTO t1 VALUES(zeroblob(1513));
149 INSERT INTO t1 VALUES(zeroblob(1514));
150 SELECT * FROM stat WHERE name = 't1';
151} [list \
152 t1 / 2 leaf 2 993 5 1517 \
153 t1 /000+000000 3 overflow 0 1020 0 0 \
154 t1 /001+000000 4 overflow 0 1020 0 0 \
155]
156
157finish_test