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
43 execsql { PRAGMA mmap_size = 0 }
44 expr {[file size test.db] / 1024}
48 execsql { SELECT b FROM t1 WHERE a=2 }
53 execsql { SELECT b FROM t1 WHERE a=2 }
58 execsql { SELECT b FROM t1 WHERE a=2 }
71 set fd [db incrblob main t1 b 1]
72 fconfigure $fd -translation binary
73 set len [string length [read $fd]]
77 do_test 1.8 { sqlite3_db_status db CACHE_HIT 0 } {0 2 0}
78 do_test 1.9 { sqlite3_db_status db CACHE_MISS 0 } {0 1 0}
80 do_test 2.1 { db_write db } {0 0 0}
82 execsql { INSERT INTO t1 VALUES(4, randomblob(600)) }
85 do_test 2.3 { db_write db 1 } {0 4 0}
86 do_test 2.4 { db_write db 0 } {0 0 0}
87 do_test 2.5 { db_write db 1 } {0 0 0}
91 execsql { PRAGMA journal_mode = WAL }
96 execsql { INSERT INTO t1 VALUES(5, randomblob(600)) }
99 do_test 2.8 { db_write db 1 } {0 4 0}
100 do_test 2.9 { db_write db 0 } {0 0 0}