xref: /sqlite-3.40.0/test/dbstatus2.test (revision 2d44d556)
158ca31c9Sdan# 2011 September 20
258ca31c9Sdan#
358ca31c9Sdan# The author disclaims copyright to this source code.  In place of
458ca31c9Sdan# a legal notice, here is a blessing:
558ca31c9Sdan#
658ca31c9Sdan#    May you do good and not evil.
758ca31c9Sdan#    May you find forgiveness for yourself and forgive others.
858ca31c9Sdan#    May you share freely, never taking more than you give.
958ca31c9Sdan#
1058ca31c9Sdan#***********************************************************************
1158ca31c9Sdan#
129ad3ee40Sdrh# Tests for the sqlite3_db_status() function
1358ca31c9Sdan#
1458ca31c9Sdan
1558ca31c9Sdanset testdir [file dirname $argv0]
1658ca31c9Sdansource $testdir/tester.tcl
1758ca31c9Sdan
1858ca31c9Sdanset ::testprefix dbstatus2
1958ca31c9Sdan
2058ca31c9Sdando_execsql_test 1.0 {
2158ca31c9Sdan  PRAGMA page_size = 1024;
2258ca31c9Sdan  PRAGMA auto_vacuum = 0;
2358ca31c9Sdan
2458ca31c9Sdan  CREATE TABLE t1(a PRIMARY KEY, b);
2558ca31c9Sdan  INSERT INTO t1 VALUES(1, randomblob(600));
2658ca31c9Sdan  INSERT INTO t1 VALUES(2, randomblob(600));
2758ca31c9Sdan  INSERT INTO t1 VALUES(3, randomblob(600));
2858ca31c9Sdan}
2958ca31c9Sdan
3058ca31c9Sdanproc db_hit_miss {db {reset 0}} {
3158ca31c9Sdan  set nHit  [sqlite3_db_status $db CACHE_HIT $reset]
3258ca31c9Sdan  set nMiss [sqlite3_db_status $db CACHE_MISS $reset]
3358ca31c9Sdan  list $nHit $nMiss
3458ca31c9Sdan}
3558ca31c9Sdan
369ad3ee40Sdrhproc db_write {db {reset 0}} {
379ad3ee40Sdrh  sqlite3_db_status $db CACHE_WRITE $reset
389ad3ee40Sdrh}
399ad3ee40Sdrh
40ffc78a41Sdrhproc db_spill {db {reset 0}} {
41ffc78a41Sdrh  sqlite3_db_status $db CACHE_SPILL $reset
42ffc78a41Sdrh}
43ffc78a41Sdrh
4458ca31c9Sdando_test 1.1 {
4558ca31c9Sdan  db close
4658ca31c9Sdan  sqlite3 db test.db
479b4c59faSdrh  execsql { PRAGMA mmap_size = 0 }
4858ca31c9Sdan  expr {[file size test.db] / 1024}
4958ca31c9Sdan} 6
5058ca31c9Sdan
5158ca31c9Sdando_test 1.2 {
5258ca31c9Sdan  execsql { SELECT b FROM t1 WHERE a=2 }
5358ca31c9Sdan  db_hit_miss db
5458ca31c9Sdan} {{0 2 0} {0 4 0}}
5558ca31c9Sdan
5658ca31c9Sdando_test 1.3 {
5758ca31c9Sdan  execsql { SELECT b FROM t1 WHERE a=2 }
5858ca31c9Sdan  db_hit_miss db
5958ca31c9Sdan} {{0 6 0} {0 4 0}}
6058ca31c9Sdan
6158ca31c9Sdando_test 1.4 {
6258ca31c9Sdan  execsql { SELECT b FROM t1 WHERE a=2 }
6358ca31c9Sdan  db_hit_miss db
6458ca31c9Sdan} {{0 10 0} {0 4 0}}
6558ca31c9Sdan
6658ca31c9Sdando_test 1.5 {
6758ca31c9Sdan  db_hit_miss db 1
6858ca31c9Sdan} {{0 10 0} {0 4 0}}
6958ca31c9Sdan
7058ca31c9Sdando_test 1.6 {
7158ca31c9Sdan  db_hit_miss db 0
7258ca31c9Sdan} {{0 0 0} {0 0 0}}
7358ca31c9Sdan
7458ca31c9Sdando_test 1.7 {
7558ca31c9Sdan  set fd [db incrblob main t1 b 1]
7658ca31c9Sdan  fconfigure $fd -translation binary
7758ca31c9Sdan  set len [string length [read $fd]]
7858ca31c9Sdan  close $fd
7958ca31c9Sdan  set len
8058ca31c9Sdan} 600
8158ca31c9Sdando_test 1.8 { sqlite3_db_status db CACHE_HIT  0 } {0 2 0}
8258ca31c9Sdando_test 1.9 { sqlite3_db_status db CACHE_MISS 0 } {0 1 0}
8358ca31c9Sdan
849ad3ee40Sdrhdo_test 2.1 { db_write db } {0 0 0}
859ad3ee40Sdrhdo_test 2.2 {
869ad3ee40Sdrh  execsql { INSERT INTO t1 VALUES(4, randomblob(600)) }
879ad3ee40Sdrh  db_write db
889ad3ee40Sdrh} {0 4 0}
899ad3ee40Sdrhdo_test 2.3 { db_write db 1 } {0 4 0}
909ad3ee40Sdrhdo_test 2.4 { db_write db 0 } {0 0 0}
919ad3ee40Sdrhdo_test 2.5 { db_write db 1 } {0 0 0}
929ad3ee40Sdrh
9305accd22Sdanif {[wal_is_capable]} {
949ad3ee40Sdrh  do_test 2.6 {
959ad3ee40Sdrh    execsql { PRAGMA journal_mode = WAL }
969ad3ee40Sdrh    db_write db 1
979ad3ee40Sdrh  } {0 1 0}
98c60941f8Smistachkin}
999ad3ee40Sdrhdo_test 2.7 {
1009ad3ee40Sdrh  execsql { INSERT INTO t1 VALUES(5, randomblob(600)) }
1019ad3ee40Sdrh  db_write db
1029ad3ee40Sdrh} {0 4 0}
1039ad3ee40Sdrhdo_test 2.8 { db_write db 1 } {0 4 0}
1049ad3ee40Sdrhdo_test 2.9 { db_write db 0 } {0 0 0}
10558ca31c9Sdan
106ffc78a41Sdrhdo_test 3.0 { db_spill db 1 } {0 0 0}
107ffc78a41Sdrhdo_test 3.1 { db_spill db 0 } {0 0 0}
108ffc78a41Sdrhdo_execsql_test 3.2 {
109ffc78a41Sdrh  PRAGMA journal_mode=DELETE;
110ffc78a41Sdrh  PRAGMA cache_size=3;
111ffc78a41Sdrh  UPDATE t1 SET b=randomblob(1000);
112ffc78a41Sdrh} {delete}
113*2d44d556Smistachkindo_test 3.3 { db_spill db 0 } {0 8 0}
114ffc78a41Sdrh
11558ca31c9Sdanfinish_test
116