blob: 7faca7964252d56a29c30690f689364dac06fc7a [file] [log] [blame]
dan55388072011-09-20 15:53:02 +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#
12# Tests for the sqlite3_stmt_status() function
13#
14
15set testdir [file dirname $argv0]
16source $testdir/tester.tcl
17
18set ::testprefix stmtstatus
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 stmt_hit_miss {stmt {reset 0}} {
31 list [sqlite3_stmt_status $stmt SQLITE_STMTSTATUS_CACHE_HIT $reset] \
32 [sqlite3_stmt_status $stmt SQLITE_STMTSTATUS_CACHE_MISS $reset]
33}
34
35do_test 1.1 {
36 db close
37 sqlite3 db test.db
38 expr {[file size test.db] / 1024}
39} 6
40
41do_test 1.2 {
42 set ::stmt [sqlite3_prepare_v2 db "SELECT b FROM t1 WHERE a=2" -1 dummy]
43 stmt_hit_miss $::stmt
44} {0 0}
45
46breakpoint
47do_test 1.3 {
48 sqlite3_step $::stmt
49 sqlite3_reset $::stmt
50} SQLITE_OK
51do_test 1.4 { stmt_hit_miss $::stmt } {1 3}
52do_test 1.5 {
53 sqlite3_step $::stmt
54 sqlite3_reset $::stmt
55} SQLITE_OK
56do_test 1.6 { stmt_hit_miss $::stmt } {5 3}
57do_test 1.7 { stmt_hit_miss $::stmt 0 } {5 3}
58do_test 1.8 { stmt_hit_miss $::stmt 1 } {5 3}
59do_test 1.9 { stmt_hit_miss $::stmt 0 } {0 0}
60do_test 1.10 { sqlite3_finalize $::stmt } SQLITE_OK
61
62do_test 1.11 { sqlite3_db_status db CACHE_HIT 0 } {0 6 0}
63do_test 1.12 { sqlite3_db_status db CACHE_MISS 0 } {0 3 0}
64do_test 1.13 { sqlite3_db_status db CACHE_HIT 1 } {0 6 0}
65do_test 1.14 { sqlite3_db_status db CACHE_MISS 1 } {0 3 0}
66do_test 1.15 { sqlite3_db_status db CACHE_HIT 0 } {0 0 0}
67do_test 1.16 { sqlite3_db_status db CACHE_MISS 0 } {0 0 0}
68
69do_test 1.17 {
70 set fd [db incrblob main t1 b 1]
71 set len [string length [read $fd]]
72 close $fd
73 set len
74} 600
75do_test 1.18 { sqlite3_db_status db CACHE_HIT 0 } {0 2 0}
76do_test 1.19 { sqlite3_db_status db CACHE_MISS 0 } {0 1 0}
77
78
79finish_test