3 # The author disclaims copyright to this source code. In place of
4 # a legal notice, here is a blessing:
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.
10 #***********************************************************************
13 source [file join [file dirname [info script]] rbu_common.tcl]
14 set ::testprefix rbutemplimit
20 proc setup_databases {} {
25 -- Create target database schema.
27 CREATE TABLE t1(a INTEGER PRIMARY KEY, b BLOB(100), c BLOB(100));
28 CREATE TABLE t2(a INTEGER PRIMARY KEY, b BLOB(100), c BLOB(100));
29 CREATE INDEX i1b ON t1(b);
30 CREATE INDEX i1c ON t1(c);
31 CREATE INDEX i2b ON t2(b);
32 CREATE INDEX i2c ON t2(c);
34 -- Create a large RBU database.
36 ATTACH 'test.db2' AS rbu;
37 CREATE TABLE rbu.data_t1(a, b, c, rbu_control);
39 VALUES(1) UNION ALL SELECT i+1 FROM s WHERE i<10000
41 INSERT INTO data_t1 SELECT i, randomblob(100), randomblob(100), 0 FROM s;
42 CREATE TABLE rbu.data_t2(a, b, c, rbu_control);
44 VALUES(1) UNION ALL SELECT i+1 FROM s WHERE i<15000
46 INSERT INTO data_t2 SELECT i, randomblob(100), randomblob(100), 0 FROM s;
51 proc run_rbu_cachesize {target rbu cachesize temp_limit} {
52 sqlite3rbu rbu $target $rbu
53 rbu temp_size_limit $temp_limit
54 sqlite3_exec_nr [rbu db 1] "PRAGMA cache_size = $cachesize"
57 set ::A([rbu temp_size]) 1
58 if {$rc!="SQLITE_OK"} break
60 list [catch {rbu close} msg] $msg
63 proc step_rbu_cachesize {target rbu stepsize cachesize temp_limit} {
66 sqlite3rbu rbu $target $rbu
67 rbu temp_size_limit $temp_limit
68 sqlite3_exec_nr [rbu db 1] "PRAGMA cache_size = $cachesize"
69 for {set i 0} {$i < $stepsize} {incr i} {
71 set ::A([rbu temp_size]) 1
72 if {$rc!="SQLITE_OK"} break
74 set res [list [catch {rbu close} msg] $msg]
75 if {$res != "0 SQLITE_OK"} break
80 do_test 1.1.0 { setup_databases } {}
84 run_rbu_cachesize test.db test.db2 10 0
87 do_test 1.1.2 { llength [array names ::A] } 3
90 foreach {a0 a1 a2} [lsort -integer [array names ::A]] {}
92 [expr $a1>1048576] [expr $a1<1200000] \
93 [expr $a2>1500000] [expr $a2<1700000]
98 run_rbu_cachesize test.db test.db2 10 1000000
100 do_test 1.2.2 { info commands rbu } {}
104 run_rbu_cachesize test.db test.db2 10 1300000
106 do_test 1.3.2 { info commands rbu } {}
110 run_rbu_cachesize test.db test.db2 10 1800000
112 do_test 1.4.2 { info commands rbu } {}
116 unset -nocomplain ::A
117 step_rbu_cachesize test.db test.db2 1000 10 2400000
119 do_test 1.5.2 { info commands rbu } {}
123 unset -nocomplain ::A
124 step_rbu_cachesize test.db test.db2 1000 10 1400000
126 do_test 1.6.2 { info commands rbu } {}