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 #***********************************************************************
12 # Tests for the sqlite3_db_status() function
15 set testdir [file dirname $argv0]
16 source $testdir/tester.tcl
18 set ::testprefix dbstatus2
21 PRAGMA page_size = 1024;
22 PRAGMA auto_vacuum = 0;
24 CREATE TABLE t1(a PRIMARY KEY, b);
25 INSERT INTO t1 VALUES(1, randomblob(600));
26 INSERT INTO t1 VALUES(2, randomblob(600));
27 INSERT INTO t1 VALUES(3, randomblob(600));
30 proc db_hit_miss {db {reset 0}} {
31 set nHit [sqlite3_db_status $db CACHE_HIT $reset]
32 set nMiss [sqlite3_db_status $db CACHE_MISS $reset]
36 proc db_write {db {reset 0}} {
37 sqlite3_db_status $db CACHE_WRITE $reset
40 proc db_spill {db {reset 0}} {
41 sqlite3_db_status $db CACHE_SPILL $reset
47 execsql { PRAGMA mmap_size = 0 }
48 expr {[file size test.db] / 1024}
52 execsql { SELECT b FROM t1 WHERE a=2 }
57 execsql { SELECT b FROM t1 WHERE a=2 }
62 execsql { SELECT b FROM t1 WHERE a=2 }
75 set fd [db incrblob main t1 b 1]
76 fconfigure $fd -translation binary
77 set len [string length [read $fd]]
81 do_test 1.8 { sqlite3_db_status db CACHE_HIT 0 } {0 2 0}
82 do_test 1.9 { sqlite3_db_status db CACHE_MISS 0 } {0 1 0}
84 do_test 2.1 { db_write db } {0 0 0}
86 execsql { INSERT INTO t1 VALUES(4, randomblob(600)) }
89 do_test 2.3 { db_write db 1 } {0 4 0}
90 do_test 2.4 { db_write db 0 } {0 0 0}
91 do_test 2.5 { db_write db 1 } {0 0 0}
93 if {[wal_is_capable]} {
95 execsql { PRAGMA journal_mode = WAL }
100 execsql { INSERT INTO t1 VALUES(5, randomblob(600)) }
103 do_test 2.8 { db_write db 1 } {0 4 0}
104 do_test 2.9 { db_write db 0 } {0 0 0}
106 do_test 3.0 { db_spill db 1 } {0 0 0}
107 do_test 3.1 { db_spill db 0 } {0 0 0}
108 do_execsql_test 3.2 {
109 PRAGMA journal_mode=DELETE;
111 UPDATE t1 SET b=randomblob(1000);
113 do_test 3.3 { db_spill db 0 } {0 8 0}