blob: f0447e450935dcc45cfcda374db51a70824ff5b2 [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
dan2f56da32012-02-13 10:00:35 +000018ifcapable !vtab||!compound {
dan6d3eb822010-07-12 18:12:41 +000019 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 {
dan1fab01a2010-09-13 14:38:19 +000030 PRAGMA auto_vacuum = OFF;
dan6d3eb822010-07-12 18:12:41 +000031 CREATE VIRTUAL TABLE temp.stat USING dbstat;
32 SELECT * FROM stat;
33} {}
shaneh9091f772010-08-24 18:35:12 +000034
35ifcapable wal {
36 do_execsql_test stat-0.1 {
37 PRAGMA journal_mode = WAL;
38 PRAGMA journal_mode = delete;
drh4c9f1292011-09-28 00:50:14 +000039 SELECT name, path, pageno, pagetype, ncell, payload, unused, mx_payload
40 FROM stat;
shaneh9091f772010-08-24 18:35:12 +000041 } {wal delete sqlite_master / 1 leaf 0 0 916 0}
42}
dan6d3eb822010-07-12 18:12:41 +000043
44do_test stat-1.0 {
45 execsql {
46 CREATE TABLE t1(a, b);
47 CREATE INDEX i1 ON t1(b);
dan2d07f262010-07-19 12:05:33 +000048 INSERT INTO t1(rowid, a, b) VALUES(2, 2, 3);
49 INSERT INTO t1(rowid, a, b) VALUES(3, 4, 5);
dan6d3eb822010-07-12 18:12:41 +000050 }
51} {}
52do_test stat-1.1 {
53 execsql {
drh4c9f1292011-09-28 00:50:14 +000054 SELECT name, path, pageno, pagetype, ncell, payload, unused, mx_payload
55 FROM stat WHERE name = 't1';
dan6d3eb822010-07-12 18:12:41 +000056 }
57} {t1 / 2 leaf 2 10 998 5}
58do_test stat-1.2 {
59 execsql {
drh4c9f1292011-09-28 00:50:14 +000060 SELECT name, path, pageno, pagetype, ncell, payload, unused, mx_payload
61 FROM stat WHERE name = 'i1';
dan6d3eb822010-07-12 18:12:41 +000062 }
63} {i1 / 3 leaf 2 10 1000 5}
64do_test stat-1.3 {
65 execsql {
drh4c9f1292011-09-28 00:50:14 +000066 SELECT name, path, pageno, pagetype, ncell, payload, unused, mx_payload
67 FROM stat WHERE name = 'sqlite_master';
dan6d3eb822010-07-12 18:12:41 +000068 }
69} {sqlite_master / 1 leaf 2 77 831 40}
70do_test stat-1.4 {
71 execsql {
72 DROP TABLE t1;
73 }
74} {}
75
76do_execsql_test stat-2.1 {
77 CREATE TABLE t3(a PRIMARY KEY, b);
dan2d07f262010-07-19 12:05:33 +000078 INSERT INTO t3(rowid, a, b) VALUES(2, a_string(111), a_string(222));
drh3f4d1d12012-09-15 18:45:54 +000079 INSERT INTO t3 SELECT a_string(110+rowid), a_string(221+rowid) FROM t3
80 ORDER BY rowid;
81 INSERT INTO t3 SELECT a_string(110+rowid), a_string(221+rowid) FROM t3
82 ORDER BY rowid;
83 INSERT INTO t3 SELECT a_string(110+rowid), a_string(221+rowid) FROM t3
84 ORDER BY rowid;
85 INSERT INTO t3 SELECT a_string(110+rowid), a_string(221+rowid) FROM t3
86 ORDER BY rowid;
87 INSERT INTO t3 SELECT a_string(110+rowid), a_string(221+rowid) FROM t3
88 ORDER BY rowid;
drh4c9f1292011-09-28 00:50:14 +000089 SELECT name, path, pageno, pagetype, ncell, payload, unused, mx_payload
90 FROM stat WHERE name != 'sqlite_master';
dan6d3eb822010-07-12 18:12:41 +000091} [list \
92 sqlite_autoindex_t3_1 / 3 internal 3 368 623 125 \
93 sqlite_autoindex_t3_1 /000/ 8 leaf 8 946 46 123 \
94 sqlite_autoindex_t3_1 /001/ 9 leaf 8 988 2 131 \
95 sqlite_autoindex_t3_1 /002/ 15 leaf 7 857 137 132 \
96 sqlite_autoindex_t3_1 /003/ 20 leaf 6 739 257 129 \
97 t3 / 2 internal 15 0 907 0 \
98 t3 /000/ 4 leaf 2 678 328 340 \
99 t3 /001/ 5 leaf 2 682 324 342 \
100 t3 /002/ 6 leaf 2 682 324 342 \
101 t3 /003/ 7 leaf 2 690 316 346 \
102 t3 /004/ 10 leaf 2 682 324 342 \
103 t3 /005/ 11 leaf 2 690 316 346 \
104 t3 /006/ 12 leaf 2 698 308 350 \
105 t3 /007/ 13 leaf 2 706 300 354 \
106 t3 /008/ 14 leaf 2 682 324 342 \
107 t3 /009/ 16 leaf 2 690 316 346 \
108 t3 /00a/ 17 leaf 2 698 308 350 \
109 t3 /00b/ 18 leaf 2 706 300 354 \
110 t3 /00c/ 19 leaf 2 714 292 358 \
111 t3 /00d/ 21 leaf 2 722 284 362 \
112 t3 /00e/ 22 leaf 2 730 276 366 \
113 t3 /00f/ 23 leaf 2 738 268 370 \
114]
drha4641712013-11-02 11:34:58 +0000115
116# With every index entry overflowing, make sure no pages are missed
117# (other than the locking page which is 64 in this test build.)
118#
119do_execsql_test stat-2.2 {
120 UPDATE t3 SET a=a||hex(randomblob(700));
121 VACUUM;
122 SELECT pageno FROM stat EXCEPT SELECT pageno-1 FROM stat;
123} {64 136}
124
125do_execsql_test stat-2.3 { DROP TABLE t3; VACUUM; } {}
dan6d3eb822010-07-12 18:12:41 +0000126
127do_execsql_test stat-3.1 {
128 CREATE TABLE t4(x);
129 CREATE INDEX i4 ON t4(x);
dan2d07f262010-07-19 12:05:33 +0000130 INSERT INTO t4(rowid, x) VALUES(2, a_string(7777));
drh4c9f1292011-09-28 00:50:14 +0000131 SELECT name, path, pageno, pagetype, ncell, payload, unused, mx_payload
132 FROM stat WHERE name != 'sqlite_master';
dan6d3eb822010-07-12 18:12:41 +0000133} [list \
134 i4 / 3 leaf 1 103 905 7782 \
drha4641712013-11-02 11:34:58 +0000135 i4 /000+000000 4 overflow 0 1020 0 0 \
136 i4 /000+000001 5 overflow 0 1020 0 0 \
137 i4 /000+000002 6 overflow 0 1020 0 0 \
138 i4 /000+000003 7 overflow 0 1020 0 0 \
139 i4 /000+000004 8 overflow 0 1020 0 0 \
140 i4 /000+000005 9 overflow 0 1020 0 0 \
141 i4 /000+000006 10 overflow 0 1020 0 0 \
142 i4 /000+000007 11 overflow 0 539 481 0 \
dan6d3eb822010-07-12 18:12:41 +0000143 t4 / 2 leaf 1 640 367 7780 \
drha4641712013-11-02 11:34:58 +0000144 t4 /000+000000 12 overflow 0 1020 0 0 \
145 t4 /000+000001 13 overflow 0 1020 0 0 \
146 t4 /000+000002 14 overflow 0 1020 0 0 \
147 t4 /000+000003 15 overflow 0 1020 0 0 \
148 t4 /000+000004 16 overflow 0 1020 0 0 \
149 t4 /000+000005 17 overflow 0 1020 0 0 \
150 t4 /000+000006 18 overflow 0 1020 0 0 \
dan6d3eb822010-07-12 18:12:41 +0000151]
152
153do_execsql_test stat-4.1 {
154 CREATE TABLE t5(x);
155 CREATE INDEX i5 ON t5(x);
drh4c9f1292011-09-28 00:50:14 +0000156 SELECT name, path, pageno, pagetype, ncell, payload, unused, mx_payload
157 FROM stat WHERE name = 't5' OR name = 'i5';
dan6d3eb822010-07-12 18:12:41 +0000158} [list \
drha4641712013-11-02 11:34:58 +0000159 i5 / 20 leaf 0 0 1016 0 \
160 t5 / 19 leaf 0 0 1016 0 \
dan6d3eb822010-07-12 18:12:41 +0000161]
162
163db close
mistachkinfda06be2011-08-02 00:57:34 +0000164forcedelete test.db
dan6d3eb822010-07-12 18:12:41 +0000165sqlite3 db test.db
166register_dbstat_vtab db
dan6d3eb822010-07-12 18:12:41 +0000167do_execsql_test stat-5.1 {
dan1fab01a2010-09-13 14:38:19 +0000168 PRAGMA auto_vacuum = OFF;
dan6d3eb822010-07-12 18:12:41 +0000169 CREATE VIRTUAL TABLE temp.stat USING dbstat;
170 CREATE TABLE t1(x);
171 INSERT INTO t1 VALUES(zeroblob(1513));
172 INSERT INTO t1 VALUES(zeroblob(1514));
drh4c9f1292011-09-28 00:50:14 +0000173 SELECT name, path, pageno, pagetype, ncell, payload, unused, mx_payload
174 FROM stat WHERE name = 't1';
dan6d3eb822010-07-12 18:12:41 +0000175} [list \
176 t1 / 2 leaf 2 993 5 1517 \
177 t1 /000+000000 3 overflow 0 1020 0 0 \
178 t1 /001+000000 4 overflow 0 1020 0 0 \
179]
180
181finish_test