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 regression tests for SQLite library. The
12 # focus of this file is testing the sqlite_dbpage virtual table.
15 set testdir [file dirname $argv0]
16 source $testdir/tester.tcl
19 ifcapable !vtab||!compound {
24 sqlite3_db_config db DEFENSIVE 0
28 PRAGMA page_size=4096;
29 PRAGMA journal_mode=WAL;
33 WITH RECURSIVE c(x) AS (VALUES(1) UNION ALL SELECT x+1 FROM c WHERE x<100)
34 INSERT INTO t1(a,b) SELECT x, printf('%d-x%.*c',x,x,'x') FROM c;
35 PRAGMA integrity_check;
39 SELECT pgno, quote(substr(data,1,5)) FROM sqlite_dbpage('main') ORDER BY pgno;
40 } {1 X'53514C6974' 2 X'0500000001' 3 X'0D0000004E' 4 X'0D00000016'}
42 SELECT pgno, quote(substr(data,1,5)) FROM sqlite_dbpage WHERE pgno=2;
45 SELECT pgno, quote(substr(data,1,5)) FROM sqlite_dbpage WHERE pgno=4;
48 SELECT pgno, quote(substr(data,1,5)) FROM sqlite_dbpage WHERE pgno=5;
51 SELECT pgno, quote(substr(data,1,5)) FROM sqlite_dbpage WHERE pgno=0;
54 ATTACH ':memory:' AS aux1;
55 PRAGMA aux1.page_size=4096;
56 CREATE TABLE aux1.t2(a,b,c);
57 INSERT INTO t2 VALUES(11,12,13);
58 SELECT pgno, quote(substr(data,1,5)) FROM sqlite_dbpage('aux1');
59 } {1 X'53514C6974' 2 X'0D00000001'}
61 CREATE TABLE aux1.x3(x,y,z);
62 INSERT INTO x3(x,y,z) VALUES(1,'main',1),(2,'aux1',1);
63 SELECT pgno, schema, substr(data,1,6)
64 FROM sqlite_dbpage, x3
65 WHERE sqlite_dbpage.schema=x3.y AND sqlite_dbpage.pgno=x3.z
67 } {1 main SQLite 1 aux1 SQLite}
70 CREATE TEMP TABLE saved_content(x);
71 INSERT INTO saved_content(x) SELECT data FROM sqlite_dbpage WHERE pgno=4;
72 UPDATE sqlite_dbpage SET data=zeroblob(4096) WHERE pgno=4;
74 do_catchsql_test 210 {
75 PRAGMA integrity_check;
76 } {1 {database disk image is malformed}}
78 SELECT pgno, quote(substr(data,1,5)) FROM sqlite_dbpage('main') ORDER BY pgno;
79 } {1 X'53514C6974' 2 X'0500000001' 3 X'0D0000004E' 4 X'0000000000'}
81 UPDATE sqlite_dbpage SET data=(SELECT x FROM saved_content) WHERE pgno=4;
83 do_catchsql_test 230 {
84 PRAGMA integrity_check;
87 DELETE FROM saved_content;
88 INSERT INTO saved_content(x)
89 SELECT data FROM sqlite_dbpage WHERE schema='aux1' AND pgno=2;
92 UPDATE sqlite_dbpage SET data=zeroblob(4096) WHERE pgno=2 AND schema='aux1';
94 do_catchsql_test 250 {
95 PRAGMA aux1.integrity_check;
96 } {1 {database disk image is malformed}}
98 UPDATE sqlite_dbpage SET data=(SELECT x FROM saved_content)
99 WHERE pgno=2 AND schema='aux1';
101 do_catchsql_test 270 {
102 PRAGMA aux1.integrity_check;