Have "PRAGMA quick_check" compare the number of entries in tables and indexes.
[sqlite.git] / test / vtabK.test
blob07fe9c1312ff345513e24c8999b959802344261a
1 # 2020-09-24
3 # The author disclaims copyright to this source code.  In place of
4 # a legal notice, here is a blessing:
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.
10 #***********************************************************************
11 # This file implements tests for a strange scenario discovered by
12 # dbsqlfuzz (0ad6d441f9bf3dfc32626a9900bc1700495b16f9) in which a
13 # virtual table is named "sqlite_stat1".
16 set testdir [file dirname $argv0]
17 source $testdir/tester.tcl
18 set testprefix vtabK
20 ifcapable !vtab||!rtree||!fts5 {
21   finish_test
22   return
25 do_execsql_test 100 {
26   CREATE TABLE t1(x);
27   INSERT INTO t1 VALUES(123);
28   PRAGMA writable_schema=ON;
29   CREATE VIRTUAL TABLE sqlite_stat1 USING fts5(a);
30   PRAGMA writable_schema=OFF;
31   CREATE VIRTUAL TABLE t3 USING fts5(b);
32   INSERT INTO t3 VALUES('this is a test');
34 do_catchsql_test 110 {
35   CREATE VIRTUAL TABLE t2 USING rtree(id,x,y);
36 } {1 {no such column: stat}}
37 do_execsql_test 120 {
38   SELECT * FROM t1;
39 } {123}
40 do_execsql_test 130 {
41   INSERT INTO t3(b) VALUES('Four score and seven years ago');
42   SELECT * FROM t3 WHERE t3 MATCH 'this';
43 } {{this is a test}}
44 do_execsql_test 140 {
45   SELECT * FROM t3 WHERE t3 MATCH 'four seven';
46 } {{Four score and seven years ago}}
47 do_execsql_test 150 {
48   INSERT INTO sqlite_stat1(a)
49   VALUES('We hold these truths to be self-evident...');
50   SELECT * FROM sqlite_stat1;
51 } {{We hold these truths to be self-evident...}}
52 do_catchsql_test 160 {
53   ANALYZE;
54 } {1 {database disk image is malformed}}
55 do_execsql_test 170 {
56   PRAGMA integrity_check;
57 } {ok}
59 # Follow-on dbsqlfuzz bc02a0cde82dee801a8d6f653d2831680f87dca1
60 reset_db
61 do_execsql_test 200 {
62   CREATE TABLE t1(a);
63   INSERT INTO t1 VALUES('Ebed-malech');
64   CREATE TABLE x(a);
65   PRAGMA writable_schema=ON;
66   CREATE VIRTUAL TABLE sqlite_stat1 USING fts5(a);
67 } {}
68 do_catchsql_test 210 {
69   CREATE VIRTUAL TABLE t2 USING rtree(id,x,y);
70 } {1 {no such column: stat}}
71 do_execsql_test 220 {
72   SELECT * FROM t1;
73 } {Ebed-malech}
75 # Follow-on dbsqlfuzz a097eaad43c3c845b236126df92fb49b25449b0c
76 reset_db
77 do_catchsql_test 300 {
78   CREATE VIRTUAL TABLE t1 USING rtree(a,b,c);
79   CREATE TABLE t2(x);
80   ALTER TABLE t2 ADD d GENERATED ALWAYS AS (c IN (SELECT 1 FROM t1)) VIRTUAL;
81 } {1 {error in table t2 after add column: subqueries prohibited in generated columns}}
82   
83 finish_test