dbstatus2.test 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  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_db_status() function
  13. #
  14. set testdir [file dirname $argv0]
  15. source $testdir/tester.tcl
  16. set ::testprefix dbstatus2
  17. do_execsql_test 1.0 {
  18. PRAGMA page_size = 1024;
  19. PRAGMA auto_vacuum = 0;
  20. CREATE TABLE t1(a PRIMARY KEY, b);
  21. INSERT INTO t1 VALUES(1, randomblob(600));
  22. INSERT INTO t1 VALUES(2, randomblob(600));
  23. INSERT INTO t1 VALUES(3, randomblob(600));
  24. }
  25. proc db_hit_miss {db {reset 0}} {
  26. set nHit [sqlite3_db_status $db CACHE_HIT $reset]
  27. set nMiss [sqlite3_db_status $db CACHE_MISS $reset]
  28. list $nHit $nMiss
  29. }
  30. proc db_write {db {reset 0}} {
  31. sqlite3_db_status $db CACHE_WRITE $reset
  32. }
  33. do_test 1.1 {
  34. db close
  35. sqlite3 db test.db
  36. execsql { PRAGMA mmap_size = 0 }
  37. expr {[file size test.db] / 1024}
  38. } 6
  39. do_test 1.2 {
  40. execsql { SELECT b FROM t1 WHERE a=2 }
  41. db_hit_miss db
  42. } {{0 2 0} {0 4 0}}
  43. do_test 1.3 {
  44. execsql { SELECT b FROM t1 WHERE a=2 }
  45. db_hit_miss db
  46. } {{0 6 0} {0 4 0}}
  47. do_test 1.4 {
  48. execsql { SELECT b FROM t1 WHERE a=2 }
  49. db_hit_miss db
  50. } {{0 10 0} {0 4 0}}
  51. do_test 1.5 {
  52. db_hit_miss db 1
  53. } {{0 10 0} {0 4 0}}
  54. do_test 1.6 {
  55. db_hit_miss db 0
  56. } {{0 0 0} {0 0 0}}
  57. do_test 1.7 {
  58. set fd [db incrblob main t1 b 1]
  59. fconfigure $fd -translation binary
  60. set len [string length [read $fd]]
  61. close $fd
  62. set len
  63. } 600
  64. do_test 1.8 { sqlite3_db_status db CACHE_HIT 0 } {0 2 0}
  65. do_test 1.9 { sqlite3_db_status db CACHE_MISS 0 } {0 1 0}
  66. do_test 2.1 { db_write db } {0 0 0}
  67. do_test 2.2 {
  68. execsql { INSERT INTO t1 VALUES(4, randomblob(600)) }
  69. db_write db
  70. } {0 4 0}
  71. do_test 2.3 { db_write db 1 } {0 4 0}
  72. do_test 2.4 { db_write db 0 } {0 0 0}
  73. do_test 2.5 { db_write db 1 } {0 0 0}
  74. ifcapable wal {
  75. do_test 2.6 {
  76. execsql { PRAGMA journal_mode = WAL }
  77. db_write db 1
  78. } {0 1 0}
  79. }
  80. do_test 2.7 {
  81. execsql { INSERT INTO t1 VALUES(5, randomblob(600)) }
  82. db_write db
  83. } {0 4 0}
  84. do_test 2.8 { db_write db 1 } {0 4 0}
  85. do_test 2.9 { db_write db 0 } {0 0 0}
  86. finish_test