blob: 2541a1a82312ed4035e1c78af7f475cf06ebab1b [file] [log] [blame]
dan58ca31c2011-09-22 14:41:16 +00001# 2011 September 20
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#
drh9ad3ee42012-03-24 20:06:14 +000012# Tests for the sqlite3_db_status() function
dan58ca31c2011-09-22 14:41:16 +000013#
14
15set testdir [file dirname $argv0]
16source $testdir/tester.tcl
17
18set ::testprefix dbstatus2
19
20do_execsql_test 1.0 {
21 PRAGMA page_size = 1024;
22 PRAGMA auto_vacuum = 0;
23
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));
28}
29
30proc 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]
33 list $nHit $nMiss
34}
35
drh9ad3ee42012-03-24 20:06:14 +000036proc db_write {db {reset 0}} {
37 sqlite3_db_status $db CACHE_WRITE $reset
38}
39
dan58ca31c2011-09-22 14:41:16 +000040do_test 1.1 {
41 db close
42 sqlite3 db test.db
drh9b4c59f2013-04-15 17:03:42 +000043 execsql { PRAGMA mmap_size = 0 }
dan58ca31c2011-09-22 14:41:16 +000044 expr {[file size test.db] / 1024}
45} 6
46
47do_test 1.2 {
48 execsql { SELECT b FROM t1 WHERE a=2 }
49 db_hit_miss db
50} {{0 2 0} {0 4 0}}
51
52do_test 1.3 {
53 execsql { SELECT b FROM t1 WHERE a=2 }
54 db_hit_miss db
55} {{0 6 0} {0 4 0}}
56
57do_test 1.4 {
58 execsql { SELECT b FROM t1 WHERE a=2 }
59 db_hit_miss db
60} {{0 10 0} {0 4 0}}
61
62do_test 1.5 {
63 db_hit_miss db 1
64} {{0 10 0} {0 4 0}}
65
66do_test 1.6 {
67 db_hit_miss db 0
68} {{0 0 0} {0 0 0}}
69
70do_test 1.7 {
71 set fd [db incrblob main t1 b 1]
72 fconfigure $fd -translation binary
73 set len [string length [read $fd]]
74 close $fd
75 set len
76} 600
77do_test 1.8 { sqlite3_db_status db CACHE_HIT 0 } {0 2 0}
78do_test 1.9 { sqlite3_db_status db CACHE_MISS 0 } {0 1 0}
79
drh9ad3ee42012-03-24 20:06:14 +000080do_test 2.1 { db_write db } {0 0 0}
81do_test 2.2 {
82 execsql { INSERT INTO t1 VALUES(4, randomblob(600)) }
83 db_write db
84} {0 4 0}
85do_test 2.3 { db_write db 1 } {0 4 0}
86do_test 2.4 { db_write db 0 } {0 0 0}
87do_test 2.5 { db_write db 1 } {0 0 0}
88
mistachkinc60941f2012-09-13 01:51:02 +000089ifcapable wal {
90 do_test 2.6 {
91 execsql { PRAGMA journal_mode = WAL }
92 db_write db 1
93 } {0 1 0}
94}
drh9ad3ee42012-03-24 20:06:14 +000095do_test 2.7 {
96 execsql { INSERT INTO t1 VALUES(5, randomblob(600)) }
97 db_write db
98} {0 4 0}
99do_test 2.8 { db_write db 1 } {0 4 0}
100do_test 2.9 { db_write db 0 } {0 0 0}
dan58ca31c2011-09-22 14:41:16 +0000101
102finish_test