sl@0: # 2007 March 24 sl@0: # sl@0: # The author disclaims copyright to this source code. In place of sl@0: # a legal notice, here is a blessing: sl@0: # sl@0: # May you do good and not evil. sl@0: # May you find forgiveness for yourself and forgive others. sl@0: # May you share freely, never taking more than you give. sl@0: # sl@0: #*********************************************************************** sl@0: # sl@0: # $Id: cache.test,v 1.4 2007/08/22 02:56:44 drh Exp $ sl@0: sl@0: set testdir [file dirname $argv0] sl@0: source $testdir/tester.tcl sl@0: sl@0: ifcapable {!pager_pragmas} { sl@0: finish_test sl@0: return sl@0: } sl@0: sqlite3_soft_heap_limit 0 sl@0: sl@0: proc pager_cache_size {db} { sl@0: set bt [btree_from_db $db] sl@0: db_enter $db sl@0: array set stats [btree_pager_stats $bt] sl@0: db_leave $db sl@0: return $stats(page) sl@0: } sl@0: sl@0: do_test cache-1.1 { sl@0: pager_cache_size db sl@0: } {0} sl@0: sl@0: do_test cache-1.2 { sl@0: execsql { sl@0: PRAGMA auto_vacuum=OFF; sl@0: CREATE TABLE abc(a, b, c); sl@0: INSERT INTO abc VALUES(1, 2, 3); sl@0: } sl@0: pager_cache_size db sl@0: } {2} sl@0: sl@0: # At one point, repeatedly locking and unlocking the cache was causing sl@0: # a resource leak of one page per repetition. The page wasn't actually sl@0: # leaked, but would not be reused until the pager-cache was full (i.e. sl@0: # 2000 pages by default). sl@0: # sl@0: # This tests that once the pager-cache is initialised, it can be locked sl@0: # and unlocked repeatedly without internally allocating any new pages. sl@0: # sl@0: set cache_size [pager_cache_size db] sl@0: for {set ii 0} {$ii < 10} {incr ii} { sl@0: sl@0: do_test cache-1.3.$ii { sl@0: execsql {SELECT * FROM abc} sl@0: pager_cache_size db sl@0: } $::cache_size sl@0: sl@0: } sl@0: sqlite3_soft_heap_limit $soft_limit sl@0: sl@0: finish_test