2011-09-22 18:41:16 +04:00
|
|
|
# 2011 September 20
|
|
|
|
#
|
|
|
|
# The author disclaims copyright to this source code. In place of
|
|
|
|
# a legal notice, here is a blessing:
|
|
|
|
#
|
|
|
|
# May you do good and not evil.
|
|
|
|
# May you find forgiveness for yourself and forgive others.
|
|
|
|
# May you share freely, never taking more than you give.
|
|
|
|
#
|
|
|
|
#***********************************************************************
|
|
|
|
#
|
2012-03-25 00:06:14 +04:00
|
|
|
# Tests for the sqlite3_db_status() function
|
2011-09-22 18:41:16 +04:00
|
|
|
#
|
|
|
|
|
|
|
|
set testdir [file dirname $argv0]
|
|
|
|
source $testdir/tester.tcl
|
|
|
|
|
|
|
|
set ::testprefix dbstatus2
|
|
|
|
|
|
|
|
do_execsql_test 1.0 {
|
|
|
|
PRAGMA page_size = 1024;
|
|
|
|
PRAGMA auto_vacuum = 0;
|
|
|
|
|
|
|
|
CREATE TABLE t1(a PRIMARY KEY, b);
|
|
|
|
INSERT INTO t1 VALUES(1, randomblob(600));
|
|
|
|
INSERT INTO t1 VALUES(2, randomblob(600));
|
|
|
|
INSERT INTO t1 VALUES(3, randomblob(600));
|
|
|
|
}
|
|
|
|
|
|
|
|
proc db_hit_miss {db {reset 0}} {
|
|
|
|
set nHit [sqlite3_db_status $db CACHE_HIT $reset]
|
|
|
|
set nMiss [sqlite3_db_status $db CACHE_MISS $reset]
|
|
|
|
list $nHit $nMiss
|
|
|
|
}
|
|
|
|
|
2012-03-25 00:06:14 +04:00
|
|
|
proc db_write {db {reset 0}} {
|
|
|
|
sqlite3_db_status $db CACHE_WRITE $reset
|
|
|
|
}
|
|
|
|
|
2011-09-22 18:41:16 +04:00
|
|
|
do_test 1.1 {
|
|
|
|
db close
|
|
|
|
sqlite3 db test.db
|
2013-04-15 21:03:42 +04:00
|
|
|
execsql { PRAGMA mmap_size = 0 }
|
2011-09-22 18:41:16 +04:00
|
|
|
expr {[file size test.db] / 1024}
|
|
|
|
} 6
|
|
|
|
|
|
|
|
do_test 1.2 {
|
|
|
|
execsql { SELECT b FROM t1 WHERE a=2 }
|
|
|
|
db_hit_miss db
|
|
|
|
} {{0 2 0} {0 4 0}}
|
|
|
|
|
|
|
|
do_test 1.3 {
|
|
|
|
execsql { SELECT b FROM t1 WHERE a=2 }
|
|
|
|
db_hit_miss db
|
|
|
|
} {{0 6 0} {0 4 0}}
|
|
|
|
|
|
|
|
do_test 1.4 {
|
|
|
|
execsql { SELECT b FROM t1 WHERE a=2 }
|
|
|
|
db_hit_miss db
|
|
|
|
} {{0 10 0} {0 4 0}}
|
|
|
|
|
|
|
|
do_test 1.5 {
|
|
|
|
db_hit_miss db 1
|
|
|
|
} {{0 10 0} {0 4 0}}
|
|
|
|
|
|
|
|
do_test 1.6 {
|
|
|
|
db_hit_miss db 0
|
|
|
|
} {{0 0 0} {0 0 0}}
|
|
|
|
|
|
|
|
do_test 1.7 {
|
|
|
|
set fd [db incrblob main t1 b 1]
|
|
|
|
fconfigure $fd -translation binary
|
|
|
|
set len [string length [read $fd]]
|
|
|
|
close $fd
|
|
|
|
set len
|
|
|
|
} 600
|
|
|
|
do_test 1.8 { sqlite3_db_status db CACHE_HIT 0 } {0 2 0}
|
|
|
|
do_test 1.9 { sqlite3_db_status db CACHE_MISS 0 } {0 1 0}
|
|
|
|
|
2012-03-25 00:06:14 +04:00
|
|
|
do_test 2.1 { db_write db } {0 0 0}
|
|
|
|
do_test 2.2 {
|
|
|
|
execsql { INSERT INTO t1 VALUES(4, randomblob(600)) }
|
|
|
|
db_write db
|
|
|
|
} {0 4 0}
|
|
|
|
do_test 2.3 { db_write db 1 } {0 4 0}
|
|
|
|
do_test 2.4 { db_write db 0 } {0 0 0}
|
|
|
|
do_test 2.5 { db_write db 1 } {0 0 0}
|
|
|
|
|
2016-04-27 21:54:49 +03:00
|
|
|
if {[wal_is_capable]} {
|
2012-09-13 05:51:02 +04:00
|
|
|
do_test 2.6 {
|
|
|
|
execsql { PRAGMA journal_mode = WAL }
|
|
|
|
db_write db 1
|
|
|
|
} {0 1 0}
|
|
|
|
}
|
2012-03-25 00:06:14 +04:00
|
|
|
do_test 2.7 {
|
|
|
|
execsql { INSERT INTO t1 VALUES(5, randomblob(600)) }
|
|
|
|
db_write db
|
|
|
|
} {0 4 0}
|
|
|
|
do_test 2.8 { db_write db 1 } {0 4 0}
|
|
|
|
do_test 2.9 { db_write db 0 } {0 0 0}
|
2011-09-22 18:41:16 +04:00
|
|
|
|
|
|
|
finish_test
|