xref: /sqlite-3.40.0/test/dbpage.test (revision b5ef728d)
1# 2017-10-11
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 sqlite_dbpage virtual table.
13#
14
15set testdir [file dirname $argv0]
16source $testdir/tester.tcl
17set testprefix dbpage
18
19ifcapable !vtab||!compound {
20  finish_test
21  return
22}
23
24do_test 100 {
25  execsql {
26    PRAGMA auto_vacuum=0;
27    PRAGMA page_size=4096;
28    PRAGMA journal_mode=WAL;
29  }
30  execsql {
31    CREATE TABLE t1(a,b);
32    WITH RECURSIVE c(x) AS (VALUES(1) UNION ALL SELECT x+1 FROM c WHERE x<100)
33      INSERT INTO t1(a,b) SELECT x, printf('%d-x%.*c',x,x,'x') FROM c;
34    PRAGMA integrity_check;
35  }
36} {ok}
37do_execsql_test 110 {
38  SELECT pgno, quote(substr(data,1,5)) FROM sqlite_dbpage('main') ORDER BY pgno;
39} {1 X'53514C6974' 2 X'0500000001' 3 X'0D0000004E' 4 X'0D00000016'}
40do_execsql_test 120 {
41  SELECT pgno, quote(substr(data,1,5)) FROM sqlite_dbpage WHERE pgno=2;
42} {2 X'0500000001'}
43do_execsql_test 130 {
44  SELECT pgno, quote(substr(data,1,5)) FROM sqlite_dbpage WHERE pgno=4;
45} {4 X'0D00000016'}
46do_execsql_test 140 {
47  SELECT pgno, quote(substr(data,1,5)) FROM sqlite_dbpage WHERE pgno=5;
48} {}
49do_execsql_test 150 {
50  SELECT pgno, quote(substr(data,1,5)) FROM sqlite_dbpage WHERE pgno=0;
51} {}
52
53do_execsql_test 200 {
54  CREATE TEMP TABLE saved_content(x);
55  INSERT INTO saved_content(x) SELECT data FROM sqlite_dbpage WHERE pgno=4;
56  UPDATE sqlite_dbpage SET data=zeroblob(4096) WHERE pgno=4;
57} {}
58do_catchsql_test 210 {
59  PRAGMA integrity_check;
60} {1 {database disk image is malformed}}
61do_execsql_test 220 {
62  SELECT pgno, quote(substr(data,1,5)) FROM sqlite_dbpage('main') ORDER BY pgno;
63} {1 X'53514C6974' 2 X'0500000001' 3 X'0D0000004E' 4 X'0000000000'}
64do_execsql_test 230 {
65  UPDATE sqlite_dbpage SET data=(SELECT x FROM saved_content) WHERE pgno=4;
66} {}
67do_catchsql_test 230 {
68  PRAGMA integrity_check;
69} {0 ok}
70
71
72
73
74finish_test
75