Files
sqlite/test/vtabK.test
T
drh ebd1ff62c5 Ensure that sqlite_stat1 and sqlite_stat4 are ordinary tables (not views or
virtual tables) before trying to load them
(dbsqlfuzz bc02a0cde82dee801a8d6f653d2831680f87dca1).  This prevents
sqlite3_declare_vtab() from running with db->init.busy turned on.  Even so,
enhance sqlite3_declare_vtab() to be able to deal with db->init.busy being on,
in case there are undiscovered paths to that state.
Each of these two changes are independently sufficient to prevent the problem
fixed by the previous check-in [c7560c1329965ab5] but there
is no harm in keeping that third layer of protection in place.

FossilOrigin-Name: eb94f4a8174436b1f0deed0a43618a20018387bb815be658314ca6b454c446fb
2021-09-24 12:59:33 +00:00

76 lines
2.0 KiB
Plaintext

# 2020-09-24
#
# The author disclaims copyright to this source code. In place of
# a legal notice, here is a blessing:
#
# May you do good and not evil.
# May you find forgiveness for yourself and forgive others.
# May you share freely, never taking more than you give.
#
#***********************************************************************
# This file implements tests for a strange scenario discovered by
# dbsqlfuzz (0ad6d441f9bf3dfc32626a9900bc1700495b16f9) in which a
# virtual table is named "sqlite_stat1".
#
set testdir [file dirname $argv0]
source $testdir/tester.tcl
set testprefix vtabK
ifcapable !vtab||!rtree||!fts5 {
finish_test
return
}
do_execsql_test 100 {
CREATE TABLE t1(x);
INSERT INTO t1 VALUES(123);
PRAGMA writable_schema=ON;
CREATE VIRTUAL TABLE sqlite_stat1 USING fts5(a);
PRAGMA writable_schema=OFF;
CREATE VIRTUAL TABLE t3 USING fts5(b);
INSERT INTO t3 VALUES('this is a test');
}
do_catchsql_test 110 {
CREATE VIRTUAL TABLE t2 USING rtree(id,x,y);
} {1 {no such column: stat}}
do_execsql_test 120 {
SELECT * FROM t1;
} {123}
do_execsql_test 130 {
INSERT INTO t3(b) VALUES('Four score and seven years ago');
SELECT * FROM t3 WHERE t3 MATCH 'this';
} {{this is a test}}
do_execsql_test 140 {
SELECT * FROM t3 WHERE t3 MATCH 'four seven';
} {{Four score and seven years ago}}
do_execsql_test 150 {
INSERT INTO sqlite_stat1(a)
VALUES('We hold these truths to be self-evident...');
SELECT * FROM sqlite_stat1;
} {{We hold these truths to be self-evident...}}
do_catchsql_test 160 {
ANALYZE;
} {1 {database disk image is malformed}}
do_execsql_test 170 {
PRAGMA integrity_check;
} {ok}
# Follow-on dbsqlfuzz bc02a0cde82dee801a8d6f653d2831680f87dca1
reset_db
do_execsql_test 200 {
CREATE TABLE t1(a);
INSERT INTO t1 VALUES('Ebed-malech');
CREATE TABLE x(a);
PRAGMA writable_schema=ON;
CREATE VIRTUAL TABLE sqlite_stat1 USING fts5(a);
} {}
do_catchsql_test 210 {
CREATE VIRTUAL TABLE t2 USING rtree(id,x,y);
} {1 {no such column: stat}}
do_execsql_test 220 {
SELECT * FROM t1;
} {Ebed-malech}
finish_test