1: # 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: #
12: # Tests for the sqlite3_stmt_status() function
13: #
14:
15: set testdir [file dirname $argv0]
16: source $testdir/tester.tcl
17:
18: set ::testprefix dbstatus2
19:
20: do_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:
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]
33: list $nHit $nMiss
34: }
35:
36: do_test 1.1 {
37: db close
38: sqlite3 db test.db
39: expr {[file size test.db] / 1024}
40: } 6
41:
42: do_test 1.2 {
43: execsql { SELECT b FROM t1 WHERE a=2 }
44: db_hit_miss db
45: } {{0 2 0} {0 4 0}}
46:
47: do_test 1.3 {
48: execsql { SELECT b FROM t1 WHERE a=2 }
49: db_hit_miss db
50: } {{0 6 0} {0 4 0}}
51:
52: do_test 1.4 {
53: execsql { SELECT b FROM t1 WHERE a=2 }
54: db_hit_miss db
55: } {{0 10 0} {0 4 0}}
56:
57: do_test 1.5 {
58: db_hit_miss db 1
59: } {{0 10 0} {0 4 0}}
60:
61: do_test 1.6 {
62: db_hit_miss db 0
63: } {{0 0 0} {0 0 0}}
64:
65: do_test 1.7 {
66: set fd [db incrblob main t1 b 1]
67: fconfigure $fd -translation binary
68: set len [string length [read $fd]]
69: close $fd
70: set len
71: } 600
72: do_test 1.8 { sqlite3_db_status db CACHE_HIT 0 } {0 2 0}
73: do_test 1.9 { sqlite3_db_status db CACHE_MISS 0 } {0 1 0}
74:
75:
76: finish_test
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>